feisty meow concerns codebase 2.140
cryptical_envelopment.h
Go to the documentation of this file.
1#ifndef CRYPTICAL_ENVELOPMENT_CLASS
2#define CRYPTICAL_ENVELOPMENT_CLASS
3
4/*
5* Name : cryptical_envelopment
6* Author : Chris Koeritz
7*
8* Purpose:
9*
10* A base class that implements the majority of encryption processing using the
11* OpenSSL EVP methods, aka the digital envelope routines.
12*
13*****
14* Copyright (c) 2005-$now By Author. This program is free software; you can
15* redistribute it and/or modify it under the terms of the GNU General Public
16* License as published by the Free Software Foundation; either version 2 of
17* the License or (at your option) any later version. This is online at:
18* http://www.fsf.org/copyleft/gpl.html
19* Please send any updates to: fred@gruntose.com
20*/
21
22#include <basis/byte_array.h>
23#include <basis/contracts.h>
24
25// forward.
26struct evp_cipher_st;
27typedef struct evp_cipher_st EVP_CIPHER;
28
29namespace crypto {
30
32{
33public:
34 cryptical_envelopment(const EVP_CIPHER *cipher_type);
37
38 virtual ~cryptical_envelopment();
39
41
42 bool set_key(int key_size);
44
46 bool set_key(const basis::byte_array &new_key, int key_size);
48
49 DEFINE_CLASS_NAME("cryptical_envelopment");
50
51 int key_size() const; // returns the size of our key, in bits.
52
53 // derived classes must provide the min and max for key sizes.
54 virtual int minimum_key_size_in_bits() const = 0;
56 virtual int maximum_key_size_in_bits() const = 0;
58
59 const basis::byte_array &get_key() const;
60
61 bool generate_key(int size, basis::byte_array &new_key);
63
64 bool encrypt(const basis::byte_array &source, basis::byte_array &target) const;
66
67 bool decrypt(const basis::byte_array &source, basis::byte_array &target) const;
69
70 // seldom-needed methods...
71
72 static const basis::byte_array &init_vector();
74
82private:
83 int _key_size;
84 basis::byte_array *_key;
85 const EVP_CIPHER *_cipher_type;
86};
87
88} //namespace.
89
90#endif
91
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
Root object for any class that knows its own name.
Definition contracts.h:123
DEFINE_CLASS_NAME("cryptical_envelopment")
virtual int minimum_key_size_in_bits() const =0
returns the minimum key size in bits supported here.
bool set_key(int key_size)
this will create a new random key of the "key_size", in bits.
bool encrypt(const basis::byte_array &source, basis::byte_array &target) const
encrypts the "source" array into the "target" array.
virtual int maximum_key_size_in_bits() const =0
returns the maximum key size in bits supported here.
bool decrypt(const basis::byte_array &source, basis::byte_array &target) const
decrypts the "target" array from the encrypted "source" array.
bool generate_key(int size, basis::byte_array &new_key)
creates a "new_key" of the "size" (in bits) specified.
cryptical_envelopment & operator=(const cryptical_envelopment &to_copy)
static const basis::byte_array & init_vector()
returns the initialization vector that is used by this class.
const basis::byte_array & get_key() const
returns our current key.
struct evp_cipher_st EVP_CIPHER