Main Page | Namespace List | Class List | File List | Namespace Members | Class Members | File Members

glite::Crypt Class Reference

#include <crypt.h>

List of all members.


Detailed Description

Class for encryted data storage.

Available methods to


Public Types

typedef unsigned char byte
 default key type

typedef std::vector< byteKey
 container for key

typedef std::string Base64Key
 container for Base64 key.

typedef std::vector< KeySplitKeys
 container for TSS split keys.

typedef unsigned short shortByte
 key type for SSS key

typedef std::vector< shortByteShortKey
 container for SSS key

typedef std::vector< shortBytePolynom
 container for SSS polynom representation.

typedef std::vector< ShortKeySplitShortKeys
 container for SSS split keys.

typedef unsigned long longByte
 key type for SSS key processing

typedef std::vector< longByteLongKey
 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


Member Typedef Documentation

typedef std::string glite::Crypt::Base64Key
 

container for Base64 key.

typedef unsigned char glite::Crypt::byte
 

default key type

typedef std::vector<byte> glite::Crypt::Key
 

container for key

typedef unsigned long glite::Crypt::longByte
 

key type for SSS key processing

typedef std::vector<longByte> glite::Crypt::LongKey
 

container for SSS key processing

typedef std::vector<shortByte> glite::Crypt::Polynom
 

container for SSS polynom representation.

typedef unsigned short glite::Crypt::shortByte
 

key type for SSS key

typedef std::vector<shortByte> glite::Crypt::ShortKey
 

container for SSS key

typedef std::vector<Key> glite::Crypt::SplitKeys
 

container for TSS split keys.

typedef std::vector<ShortKey > glite::Crypt::SplitShortKeys
 

container for SSS split keys.


Constructor & Destructor Documentation

glite::Crypt::Crypt const std::string  cipherName = "bf-cbc",
int  keyLength = 0
 

default constructor

builds an encrypter/decrypter and initialise the associated OpenSSL context

Parameters:
in] cipherName OpenSSL cipher name (see man enc for a list of supported ciphers)
in] keyLength length of the encryption key in bits

glite::Crypt::~Crypt  ) 
 

default destructor


Member Function Documentation

void glite::Crypt::decodeBase64 const Base64Key b64message,
Key message
const
 

Base64 decode an input key.

Parameters:
in] b64message input Base64 key to decode
out] message output decoded key

void glite::Crypt::decrypt const std::string &  ifile,
const std::string &  ofile
const
 

decrypts a file

Parameters:
in] ifile input filename.
in] ofile output filename.

void glite::Crypt::decrypt byte in,
int  isize,
byte *&  out,
int &  osize
const
 

decrypts an input data buffer

Parameters:
in] in input data buffer
in] isize input data buffer size
out] out output data buffer Newly allocated decrypted data buffer: it is up to the caller to deallocate it
out] osize returned size of decrypted data buffer

Crypt::longByte glite::Crypt::divideModulo const longByte  numerator,
const longByte  denominator
const [private]
 

Compute the modular (prime) division of two numbers.

void glite::Crypt::drawIV  )  [private]
 

Draw a pseudo-random initialisation vector and set the initialisation vector.

void glite::Crypt::drawKey  )  [private]
 

Draw a pseudo random key and set the encryption/decryption key.

void glite::Crypt::drawPRN Polynom p  )  const [private]
 

Draw a random polynom (SSS).

void glite::Crypt::drawPRN Key key  )  const [private]
 

Draw a random key (TSS).

void glite::Crypt::encodeBase64 const Key message,
Base64Key b64message
const
 

Base64 encode an input key.

Parameters:
in] message input key to encode
out] b64message output encoded key

void glite::Crypt::encrypt const std::string &  ifile,
const std::string &  ofile
const
 

encrypts a file

Parameters:
in] ifile input filename.
in] ofile output filename.

void glite::Crypt::encrypt byte in,
int  isize,
byte *&  out,
int &  osize
const
 

encrypts a data buffer

Parameters:
in] in input data buffer.
in] isize input data buffer size.
out] out output data buffer. Newly allocated encrypted data buffer: it is up to the caller to deallocate it.
out] osize returned size of encrypting data buffer (must be known for decrypting)

void glite::Crypt::evalLagrangeInterpAt0 const Key x,
LongKey numerator,
LongKey denominator
const [private]
 

Compute Lagrange interpolation at zero.

Crypt::longByte glite::Crypt::evalPolynom const Polynom p,
const longByte  x
const [private]
 

Evaluate a polynomial at a given value (SSS).

int glite::Crypt::getBufferSize  )  const
 

Return current buffer size.

Crypt::Key glite::Crypt::getIV  )  const
 

Return current initialisation vector.

Crypt::Key glite::Crypt::getKey  )  const
 

Return current encryption/decryption key.

int glite::Crypt::getVerbose  )  const
 

Return current verbose level.

void glite::Crypt::handleError const char *  thisFile,
int  thisLine
const [private]
 

Handle error and throw an exception.

void glite::Crypt::initCrypters  )  [private]
 

Initialise Crypter object for encryption/decryption.

Crypt::Polynom glite::Crypt::initPolynom int  k,
byte  a0
const [private]
 

Initialise a polynomial to be used in SSS.

Polynomial represented in descending powers

\[Y = P(0)*X^{k-1} + P(1)*X^{k-2} + ... + P(k-2)*X + P(k-1)\]

where $P(k-1)$ is the secret to share and all other coefficients are randomly chosen numbers modulo prime.

Crypt::longByte glite::Crypt::inverseModulo const longByte  n  )  const [private]
 

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

void glite::Crypt::joinKeySSS const int  nNeeded,
const Key x,
const SplitShortKeys keys,
Key key
const
 

Join Keys using Shamir Secret Sharing.

Parameters:
in] nNeeded keys to join
in] x values at interpolation
in] keys to join
out] key joint key

void glite::Crypt::joinKeyTSS const SplitKeys keys,
Key key
const
 

Join Keys using Trivial Secret Sharing.

Parameters:
in] keys input keys to join
out] key output join key

void glite::Crypt::printOn std::ostream &  os  )  const
 

Print state of Crypter object.

void glite::Crypt::seedPRNG int  bytes = 1  )  const [private]
 

Seed the pseudo random number generator.

void glite::Crypt::setBufferSize int  size  ) 
 

Set buffer size to encrypt/decrypt file.

void glite::Crypt::setKeyAndIV const Key key,
const Key iv = Key()
 

Set an encryption/decryption key and initialisation vector (optional).

void glite::Crypt::setVerbose int  verbose  ) 
 

Set verbose level.

void glite::Crypt::splitKeySSS const Key key,
int  nNeeded,
int  nShares,
Key x,
SplitShortKeys keys
const
 

Split Key using Shamir Secret Sharing.

Parameters:
in] key input key to split
in] nNeeded input number of shares needed
in] nShares input number of shares
out] x output
out] keys output split keys

void glite::Crypt::splitKeyTSS const Key key,
int  n,
SplitKeys keys
const
 

Split Key using Trivial Secret Sharing.

Parameters:
in] key input key to split
in] nShares input number of shares
out] keys output split keys


Member Data Documentation

int glite::Crypt::m_bufferSize [private]
 

buffer size to encrypt/decrypt file

const std::string glite::Crypt::m_cipherName [private]
 

name of OpenSSL cypher type

EVP_CIPHER_CTX* glite::Crypt::m_dctx [private]
 

OpenSSL decrypting cipher context.

EVP_CIPHER_CTX* glite::Crypt::m_ectx [private]
 

OpenSSL encrypting cipher context.

Key glite::Crypt::m_iv [private]
 

initialisation vector

unsigned int glite::Crypt::m_ivLength [private]
 

initialisation vector length

Key glite::Crypt::m_key [private]
 

encryption/decryption key

unsigned int glite::Crypt::m_keyLength [private]
 

encryption/decryption key length

const EVP_CIPHER* glite::Crypt::m_type [private]
 

OpenSSL EVP_CIPHER structure.

int glite::Crypt::m_verbose [private]
 

verbose level


The documentation for this class was generated from the following files:
Generated on Thu May 11 18:54:33 2006 for Glite Security encrypted storage cpp by doxygen 1.3.5