#include <crypt.h>
Available methods to
Public Types | |
typedef unsigned char | byte |
default key type | |
typedef std::vector< byte > | Key |
container for key | |
typedef std::string | Base64Key |
container for Base64 key. | |
typedef std::vector< Key > | SplitKeys |
container for TSS split keys. | |
typedef unsigned short | shortByte |
key type for SSS key | |
typedef std::vector< shortByte > | ShortKey |
container for SSS key | |
typedef std::vector< shortByte > | Polynom |
container for SSS polynom representation. | |
typedef std::vector< ShortKey > | SplitShortKeys |
container for SSS split keys. | |
typedef unsigned long | longByte |
key type for SSS key processing | |
typedef std::vector< longByte > | LongKey |
container for SSS key processing | |
Public Member Functions | |
Crypt (const std::string cipher="bf-cbc", int keyLength=0) | |
default constructor | |
~Crypt () | |
default destructor | |
void | encrypt (byte *in, int isize, byte *&out, int &osize) const |
encrypts a data buffer | |
void | encrypt (const std::string &ifile, const std::string &ofile) const |
encrypts a file | |
void | decrypt (byte *in, int isize, byte *&out, int &osize) const |
decrypts an input data buffer | |
void | decrypt (const std::string &ifile, const std::string &ofile) const |
decrypts a file | |
void | encodeBase64 (const Key &key, Base64Key &b64key) const |
Base64 encode an input key. | |
void | decodeBase64 (const Base64Key &b64key, Key &key) const |
Base64 decode an input key. | |
void | splitKeyTSS (const Key &key, int nShares, SplitKeys &keys) const |
Split Key using Trivial Secret Sharing. | |
void | joinKeyTSS (const SplitKeys &keys, Key &key) const |
Join Keys using Trivial Secret Sharing. | |
void | splitKeySSS (const Key &key, int nNeeded, int nShares, Key &x, SplitShortKeys &keys) const |
Split Key using Shamir Secret Sharing. | |
void | joinKeySSS (const int nNeeded, const Key &x, const SplitShortKeys &keys, Key &key) const |
Join Keys using Shamir Secret Sharing. | |
void | setKeyAndIV (const Key &key, const Key &iv=Key()) |
Set an encryption/decryption key and initialisation vector (optional). | |
Key | getKey () const |
Return current encryption/decryption key. | |
Key | getIV () const |
Return current initialisation vector. | |
void | setBufferSize (int size) |
Set buffer size to encrypt/decrypt file. | |
int | getBufferSize () const |
Return current buffer size. | |
void | setVerbose (int verbose) |
Set verbose level. | |
int | getVerbose () const |
Return current verbose level. | |
void | printOn (std::ostream &os) const |
Print state of Crypter object. | |
Private Member Functions | |
void | seedPRNG (int bytes=1) const |
Seed the pseudo random number generator. | |
void | drawKey () |
Draw a pseudo random key and set the encryption/decryption key. | |
void | drawIV () |
Draw a pseudo-random initialisation vector and set the initialisation vector. | |
void | initCrypters () |
Initialise Crypter object for encryption/decryption. | |
void | handleError (const char *thisFile, int thisLine) const |
Handle error and throw an exception. | |
void | drawPRN (Key &key) const |
Draw a random key (TSS). | |
void | drawPRN (Polynom &p) const |
Draw a random polynom (SSS). | |
Polynom | initPolynom (int k, byte a0) const |
Initialise a polynomial to be used in SSS. | |
longByte | evalPolynom (const Polynom &p, const longByte x) const |
Evaluate a polynomial at a given value (SSS). | |
longByte | inverseModulo (const longByte n) const |
Calculate the modular (prime) inverse of a number. | |
longByte | divideModulo (const longByte numerator, const longByte denominator) const |
Compute the modular (prime) division of two numbers. | |
void | evalLagrangeInterpAt0 (const Key &x, LongKey &numerator, LongKey &denominator) const |
Compute Lagrange interpolation at zero. | |
Private Attributes | |
const std::string | m_cipherName |
name of OpenSSL cypher type | |
unsigned int | m_keyLength |
encryption/decryption key length | |
unsigned int | m_ivLength |
initialisation vector length | |
int | m_bufferSize |
buffer size to encrypt/decrypt file | |
EVP_CIPHER_CTX * | m_ectx |
OpenSSL encrypting cipher context. | |
EVP_CIPHER_CTX * | m_dctx |
OpenSSL decrypting cipher context. | |
const EVP_CIPHER * | m_type |
OpenSSL EVP_CIPHER structure. | |
Key | m_key |
encryption/decryption key | |
Key | m_iv |
initialisation vector | |
int | m_verbose |
verbose level |
|
container for Base64 key.
|
|
default key type
|
|
container for key
|
|
key type for SSS key processing
|
|
container for SSS key processing
|
|
container for SSS polynom representation.
|
|
key type for SSS key
|
|
container for SSS key
|
|
container for TSS split keys.
|
|
container for SSS split keys.
|
|
default constructor builds an encrypter/decrypter and initialise the associated OpenSSL context
|
|
default destructor
|
|
Base64 decode an input key.
|
|
decrypts a file
|
|
decrypts an input data buffer
|
|
Compute the modular (prime) division of two numbers.
|
|
Draw a pseudo-random initialisation vector and set the initialisation vector.
|
|
Draw a pseudo random key and set the encryption/decryption key.
|
|
Draw a random polynom (SSS).
|
|
Draw a random key (TSS).
|
|
Base64 encode an input key.
|
|
encrypts a file
|
|
encrypts a data buffer
|
|
Compute Lagrange interpolation at zero.
|
|
Evaluate a polynomial at a given value (SSS).
|
|
Return current buffer size.
|
|
Return current initialisation vector.
|
|
Return current encryption/decryption key.
|
|
Return current verbose level.
|
|
Handle error and throw an exception.
|
|
Initialise Crypter object for encryption/decryption.
|
|
Initialise a polynomial to be used in SSS. Polynomial represented in descending powers
where |
|
Calculate the modular (prime) inverse of a number. calculate the modular inverse using Extended Euclidean Algorithm The Extended Euclidean algorithm not only computes gcd(n,m), but also returns the numbers a and b such that gcd(n,m)=a*n+b*m. If gcd(n,m)=1 this solves the problem of computing modular inverses, which is the case for gcd(prime,n) = 1 |
|
Join Keys using Shamir Secret Sharing.
|
|
Join Keys using Trivial Secret Sharing.
|
|
Print state of Crypter object.
|
|
Seed the pseudo random number generator.
|
|
Set buffer size to encrypt/decrypt file.
|
|
Set an encryption/decryption key and initialisation vector (optional).
|
|
Set verbose level.
|
|
Split Key using Shamir Secret Sharing.
|
|
Split Key using Trivial Secret Sharing.
|
|
buffer size to encrypt/decrypt file
|
|
name of OpenSSL cypher type
|
|
OpenSSL decrypting cipher context.
|
|
OpenSSL encrypting cipher context.
|
|
initialisation vector
|
|
initialisation vector length
|
|
encryption/decryption key
|
|
encryption/decryption key length
|
|
OpenSSL EVP_CIPHER structure.
|
|
verbose level
|