In file /home/eternity/Source/Common/Cipherer/H/cipherer.h:

class Cipherer : public Debugable

Class that handles encryption algorithms

Inheritance:

Cipherer < Debugable


Public Methods

Cipherer::Cipherer (LogFile * ciphererLogFile)
Cipherer constructor
Err Cipherer::DecryptBlockWithPrivateKey (GMessage *gmPrivateKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen)
Decrypts one PKCS1 block by private key
Err Cipherer::DecryptBlockWithPublicKey (GMessage *gmPublicKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen)
Decrypts one PKCS1 block by public key
Err Cipherer::DecryptKeyWithPrivateKey (GMessage *privKey, MsgField *eSymKey, GMessage **pSymKey)
Decrypts symetric key with private key
Err Cipherer::DecryptWithPrivateKey (GMessage * privateKey, MsgField * eData, MsgField ** pData)
Decrypts data with private key
Err Cipherer::DecryptWithPublicKey (GMessage * publicKey, MsgField * eData, MsgField ** pData)
Decrypts data with public key
Err Cipherer::DecryptWithSymetricKey (GMessage * symKey, MsgField * eData, MsgField ** dData)
Decrypt data using symetric key
Err Cipherer::DecryptWithSymetricKeys (GMessage * symKeys, MsgField * eData, MsgField ** dData)
Decrypt multiple encrypted data using symetric keys
Err Cipherer::EncryptBlockWithPrivateKey (GMessage *gmPrivateKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen)
Encrypts one PKCS1 block by private key
Err Cipherer::EncryptBlockWithPublicKey (GMessage *gmPublicKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen)
Encrypts one PKCS1 block by public key
Err Cipherer::EncryptKeyWithPublicKey (GMessage *pubKey, GMessage *pSymKey, MsgField **eSymKey)
Encrypts symetric key with asymetric
Err Cipherer::EncryptWithPrivateKey (GMessage * privateKey, MsgField * pData, MsgField ** eData)
Encrypts data with private key
Err Cipherer::EncryptWithPublicKey (GMessage * publicKey, MsgField * pData, MsgField ** eData)
Encrypt data with public key
Err Cipherer::EncryptWithSymetricKey (GMessage * symKey, MsgField * pData, MsgField ** eData)
Encrypt data using symetric key
Err Cipherer::EncryptWithSymetricKeys (GMessage * symKeys, MsgField * pData, MsgField ** eData, int useAlsoKeyOne)
Encrypt data using multiple symetric keys
GMessage* Cipherer::GenerateAsymetricKey (GMessage *parameters = NULL)
Generate asymetric key pair
char unsigned Cipherer::GenerateRandomByte ()
Very simple method for generation of one byte
GMessage* Cipherer::GenerateSymetricKey (GMessage *parameters = NULL)
Generate symetric key
Err Cipherer::MessageDigest (MsgField *dataToDigest, MsgField **dig, GMessage *parameters = NULL)
Creates a message digest over given data
Err Cipherer::OpenSealed (GMessage *privateKeyInfo, GMessage *publicKeyInfo, MsgField *dataIn, MsgField **dataOut)
Opens sealed data
Err Cipherer::ProcessWithSymetricKey (GMessage * symKey, MsgField * mfDataIn, MsgField ** mfDataOut, int actionFlag)
Generic method for symetric procession
Err Cipherer::ProcessWithSymetricKey_RawVersion (GMessage *symKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen, int actionFlag)
Generic method for symetric procession
GMessage* Cipherer::ReturnGMsgFullOfSymKeys (Size hopCount, GMessage *parameters = NULL)
Returns GMessage full of symetric keys
Err Cipherer::Seal (GMessage *privateKeyInfo, GMessage *publicKeyInfo, MsgField *dataIn, MsgField **dataOut, GMessage *parameters = NULL)
Seals given data
Err Cipherer::Sign (GMessage *privKeyGM, MsgField *dataToSign, MsgField **sig, GMessage *parameters = NULL)
Signs given data
Err Cipherer::VerifySignature (GMessage *pubKeyGM, MsgField *dataToVerify, MsgField *sig, GMessage *parameters = NULL)
Verifies signed data
Cipherer::~Cipherer ()
Cipherer destructor

Public

methods

General methods for asymetric encryption and decription, keys have type of the key information inside

Hi-level methods for asymetric encryption of symetric keys

General methods for symetric encryption and decryption, keys have type of the key information inside

General methods for symetric sealing and opening digital envelopes

General methods for signing, verification and digesting

General methods for key generation of symetric and asymetric keys
unsigned char GenerateRandomByte ()
Auxiliary public methods, not too efficient, but fully functional.
GMessage* ReturnGMsgFullOfSymKeys (Size hopCount, GMessage *params = NULL)
Auxiliary method for MessageCreator's methods.

Private

methods
Err ProcessWithSymetricKey (GMessage * symKey, MsgField * inData, MsgField ** outData, int actionFlag)
Used by methods for symetric enctryption.
Err ProcessWithSymetricKey_RawVersion (GMessage *symKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen, int flag)
Used by ProcessWithSymetricKey()

Process one PKCS1 block. Methods use RSAEuro's RSA implementation.

Inherited from Debugable:

Public Methods

string* Debugable::CreateString(char *firstStr, int firstInt, int secondInt)
Debugable::Debugable(LogFile * debugLogFile)
int Debugable::SetDebugOptions(int newLogOptions)
void Debugable::SetLogFile(LogFile *aLogFile)
void Debugable::WriteString(LogLevel debugLevel, char * format, ...)
Debugable::~Debugable()

Public

attributes

int debugOptions
What messages should be logged
LogFile* logFile
Log file for debug messages

Documentation

Class that handles encryption algorithms. It implements various algorithms like DES, RSA, MD5 ... All the data passed to it should be in a message field (MsgField). The data returned is also a message field. (data + length)
methods

General methods for asymetric encryption and decription, keys have type of the key information inside. For now, only RSA algorithm is implemented.

Hi-level methods for asymetric encryption of symetric keys. Symetric key can of any type, but symKey->SizeOf() can't be bigger than (RSA_BLOCK_LEN - RSAREF_RESERVED_BYTES).
See Also:
cipherer.h

General methods for symetric encryption and decryption, keys have type of the key information inside. For now, only DES algorithm is implemented (because of RSAEuro toolkit).

General methods for symetric sealing and opening digital envelopes. For now, only RSA, DES and MD5 is implemented.

General methods for signing, verification and digesting. Only RSA and MD5 is implemented for now.

General methods for key generation of symetric and asymetric keys. For now, only RSA and DES keys are implemented.

unsigned char GenerateRandomByte()
Auxiliary public methods, not too efficient, but fully functional.

GMessage* ReturnGMsgFullOfSymKeys(Size hopCount, GMessage *params = NULL)
Auxiliary method for MessageCreator's methods.

methods

Err ProcessWithSymetricKey(GMessage * symKey, MsgField * inData, MsgField ** outData, int actionFlag)
Used by methods for symetric enctryption.

Err ProcessWithSymetricKey_RawVersion(GMessage *symKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen, int flag)
Used by ProcessWithSymetricKey(). Inside, RSAEuro's DES implementation is used.

Process one PKCS1 block. Methods use RSAEuro's RSA implementation.

Cipherer::Cipherer(LogFile * ciphererLogFile)
Cipherer constructor. Cipherer constructor. For now, nothing is needed to run here (random generator is initialized in main.cc).
Parameters:
ciphererLogFile - Log file.
Author:
Pechy
See Also:

Err Cipherer::DecryptBlockWithPrivateKey(GMessage *gmPrivateKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen)
Decrypts one PKCS1 block by private key. Decrypts one PKCS1 block by private key, the block is defined by PKCS1 standard. Inside we use RSAEuro function.
Returns:
KO if decryption fails, OK otherwise.
Parameters:
gmPrivateKey - Private key.
dataIn - Input data octet stream.
dataInLen - Length of input data octet stream.
dataOut - Output data octet stream.
dataOutLen - Length of output data octet stream.
Author:
Pechy
See Also:
other encryption methods

Err Cipherer::DecryptBlockWithPublicKey(GMessage *gmPublicKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen)
Decrypts one PKCS1 block by public key. Decrypts one PKCS1 block by public key, the block is defined by PKCS1 standard. Inside we use RSAEuro function.
Returns:
KO if decryption fails, OK otherwise.
Parameters:
gmPublicKey - Public key.
dataIn - Input data octet stream.
dataInLen - Length of input data octet stream.
dataOut - Output data octet stream.
dataOutLen - Length of output data octet stream.
Author:
Pechy
See Also:
other encryption methods

Err Cipherer::DecryptKeyWithPrivateKey(GMessage *privKey, MsgField *eSymKey, GMessage **pSymKey)
Decrypts symetric key with private key. Due to efficiency and implementation, we use sealing, so this method decrypts a symetric key (of GMessage type) with private key.
Returns:
KO if encryption failes, OK otherwise.
Parameters:
privKey - Private key.
eSymKey - Symetric key to process.
pSymKey - Decrypted symetric key to process.
Author:
Pechy
See Also:
other cryptography methods.

Err Cipherer::DecryptWithPrivateKey(GMessage * privateKey, MsgField * eData, MsgField ** pData)
Decrypts data with private key. Decrypts data with private key. The data is in msgField, output is inserted in a msgField too. The msgField is freshly allocated.
Returns:
KO if an action fails, OK otherwise.
Parameters:
privateKey - Private key.
eData - Encrypted data to process.
pData - Processed data.
Author:
Pechy
See Also:
other cryptography methods

Err Cipherer::DecryptWithPublicKey(GMessage * publicKey, MsgField * eData, MsgField ** pData)
Decrypts data with public key. Decrypts data with public key. The data is in msgField, output is inserted in a msgField too. The msgField is freshly allocated.
Returns:
KO if an action fails, OK otherwise.
Parameters:
publicKey - Public key.
eData - Encrypted data to process.
pData - Processed data.
Author:
Pechy
See Also:
other cryptography methods

Err Cipherer::DecryptWithSymetricKey(GMessage * symKey, MsgField * eData, MsgField ** dData)
Decrypt data using symetric key. We use ,,fields'', because it's quite easy to work with them in connection with gMessages. MsgField is abstract data type, so whenever we need create an instance of that, we use BytesMsgField.

Uses auxiliary method ProcessWithSymetricKey() defined in another module, in RSAEuro decrypting with DES is not the same as encrypting.

Returns:
KO if action fails, OK otherwise.
Parameters:
symKey - What symetric key to use.
eData - Encrypted data
pData - Plain data to process.
Author:
Pechy
See Also:
other crypthographic methods

Err Cipherer::DecryptWithSymetricKeys(GMessage * symKeys, MsgField * eData, MsgField ** dData)
Decrypt multiple encrypted data using symetric keys. When we use onions and chunks to make traffic analysis harder, we make a special peel for each hops the chunk goes through. When we make these chunks or process received data, we use encryption or decryption in a loop, each loop for one hop included.
Returns:
KO if action fails, OK otherwise.
Parameters:
symKeys - What symetric keys to use.
eData - Encrypted data
pData - Plain data to process.
Author:
Pechy
See Also:
other crypthographic methods

Err Cipherer::EncryptBlockWithPrivateKey(GMessage *gmPrivateKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen)
Encrypts one PKCS1 block by private key. Encrypts one PKCS1 block by private key, the block is defined by PKCS1 standard. Inside we use RSAEuro function.
Returns:
KO if encryption fails, OK otherwise.
Parameters:
gmPrivateKey - Private key.
dataIn - Input data octet stream.
dataInLen - Length of input data octet stream.
dataOut - Output data octet stream.
dataOutLen - Length of output data octet stream.
Author:
Pechy
See Also:
other encryption methods

Err Cipherer::EncryptBlockWithPublicKey(GMessage *gmPublicKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen)
Encrypts one PKCS1 block by public key. Encrypts one PKCS1 block by public key, the block is defined by PKCS1 standard. Inside we use RSAEuro function.
Returns:
KO if encryption fails, OK otherwise.
Parameters:
gmPublicKey - Public key.
dataIn - Input data octet stream.
dataInLen - Length of input data octet stream.
dataOut - Output data octet stream.
dataOutLen - Length of output data octet stream.
Author:
Pechy
See Also:
other encryption methods

Err Cipherer::EncryptKeyWithPublicKey(GMessage *pubKey, GMessage *pSymKey, MsgField **eSymKey)
Encrypts symetric key with asymetric. Due to efficiency and implementation, we use sealing, so this method encrypts a symetric key (of GMessage type) with public key.
Returns:
KO if encryption failes, OK otherwise.
Parameters:
pubKey - Public key.
pSymKey - Symetric key to process.
eSymKey - Encrypted symetric key to process.
Author:
Pechy
See Also:
other cryptography methods.

Err Cipherer::EncryptWithPrivateKey(GMessage * privateKey, MsgField * pData, MsgField ** eData)
Encrypts data with private key. Encrypts data with private key. The data is in msgField, output is inserted in a msgField too. The msgField is freshly allocated.
Returns:
KO if an action fails, OK otherwise.
Parameters:
privateKey - Private key.
pData - Plain data to process.
eData - Processed data.
Author:
Pechy
See Also:
other cryptography methods

Err Cipherer::EncryptWithPublicKey(GMessage * publicKey, MsgField * pData, MsgField ** eData)
Encrypt data with public key. This method is not too clean, we count on the fact that RSAPublicEncrypt() function from RSAEuro encodes one chunk (ie. stream with current modulus in length) and symetric key's gMessage is short.

Currently we use 512 bits long modulus, so we can have symetric key's gMessages 64 bytes long (ie. gMessage converted to an octet stream can be maximally 64 bytes in length).

Returns:
Error code OK - KO
Parameters:
parametr -
Author:
Pechy
See Also:
EncryptWithPrivateKey()

Err Cipherer::EncryptWithSymetricKey(GMessage * symKey, MsgField * pData, MsgField ** eData)
Encrypt data using symetric key. We use ,,fields'', because it's quite easy to work with them in connection with gMessages. MsgField is abstract data type, so whenever we need create an instance of that, we use BytesMsgField.

eData is encoded octet-stream createt from gMessage, ie. the whole gMessage is saved to an octet-stream, encoded and then BytesMsgField is initialized from it.

Uses auxiliary method ProcessWithSymetricKey() defined in another module, in RSAEuro decrypting with DES is not the same as encrypting.

Returns:
KO if action fails, OK otherwise.
Parameters:
symKey - What symetric key to use.
pData - Plain data to process.
eData - Encrypted data.
Author:
Pechy
See Also:
other crypthographic methods

Err Cipherer::EncryptWithSymetricKeys(GMessage * symKeys, MsgField * pData, MsgField ** eData, int useAlsoKeyOne)
Encrypt data using multiple symetric keys. When we use onions and chunks to make traffic analysis harder, we make a special peel for each hops the chunk goes through. When we make these chunks or process received data, we use encryption or decryption in a loop, each loop for one hop included.
Returns:
KO if action fails, OK otherwise.
Parameters:
symKeys - What symetric keys to use.
pData - Plain data.
eData - Encrypted data to process.
Author:
Pechy
See Also:
other crypthographic methods

GMessage* Cipherer::GenerateAsymetricKey(GMessage *parameters = NULL)
Generate asymetric key pair. Generates one asymetric key pair, in parameters we can insert what type of key to generate. RSA key is generated by default (because of RSAEuro toolkit). For now, only RSA is supported
Returns:
GMessage with generated asymetric key.
GM_PUBLIC_KEY_INFO
GM_PUBLIC_KEY			- native structure from RSAEuro
GM_ASYMETRIC_CIPHER_TYPE		- ie. "RSA"
GM_ASYMETRIC_CIPHER_VERSION	- obsolete, still supported, not used
GM_PRIVATE_KEY_INFO
GM_PRIVATE_KEY			- native structure from RSAEuro
GM_ASYMETRIC_CIPHER_TYPE		- ie. "RSA"
GM_ASYMETRIC_CIPHER_VERSION	- obsolete, still supported, not used

Parameters:
parameters - What type of algorithm.
Author:
Pechy
See Also:
other crypthographic methods

char unsigned Cipherer::GenerateRandomByte()
Very simple method for generation of one byte. Very simple method, uses standard random number generator, should be replaced in future by R_GenerateBytes(rsaeuro) and /dev/random at least. Relies * on the fact that somebody has already seeded generator with srandom(). For now, we seed srandom() with randomness got from /dev/urandom (it's good !)
Returns:
One random byte.
Author:
Pechy
See Also:
other cryptography methods.

GMessage* Cipherer::GenerateSymetricKey(GMessage *parameters = NULL)
Generate symetric key. Generates one symetric key, in parameters we can insert what type of key to generate. DES key is generated by default (because of RSAEuro toolkit).
Returns:
GMessage Symetric key, NULL if generation failed:
GM_SYMETRIC_KEY			- ie. 8 random bytes of DES key
GM_INITIALIZATION_VECTOR		- ie. 8 random bytes of DES iv
GM_SYMETRIC_CIPHER_TYPE		- ie. "DES" by default
Parameters:
parameters - What type of key to generate.
Author:
Pechy
See Also:
other crypthographic methods

Err Cipherer::MessageDigest(MsgField *dataToDigest, MsgField **dig, GMessage *parameters = NULL)
Creates a message digest over given data. Creates a message digest over given data. Inside, a RSAEuro function is used. We use only MD5 for now, but type of digest can be specified in parameters.
Returns:
KO if digest creation fails, OK otherwise.
Parameters:
dataToDigest - Data to digest.
dig - Created digest.
parameters - Parameters - which digest to use.
Author:
Pechy
See Also:
other cryptographic methods

Err Cipherer::OpenSealed(GMessage *privateKeyInfo, GMessage *publicKeyInfo, MsgField *dataIn, MsgField **dataOut)
Opens sealed data. Verifies whether given data is not tempered and returns it. For now, we use only RSA, DES and MD5 algorithms, but we can insert parameters with additional information which algs to use (in Seal() method).
Returns:
KO if opening fails, OK otherwise.
Parameters:
privKeyGM - Private key used for data decryption.
publicKeyInfo - Public key used to data verification.
dataIn - Data to process.
dataOut - Processed data.
Author:
Pechy
See Also:
other cryptographic methods

Err Cipherer::ProcessWithSymetricKey(GMessage * symKey, MsgField * mfDataIn, MsgField ** mfDataOut, int actionFlag)
Generic method for symetric procession.. Symetric encryption and decryption is almost identical, so we made this auxiliary method.
Returns:
KO if procession fails, OK otherwise
Parameters:
symKey - Symetric key to use.
mfDataIn - Input data in a MsgField.
mfDataOut - Output data in a MsgField.
Author:
Pechy
See Also:
other crypthographic methods

Err Cipherer::ProcessWithSymetricKey_RawVersion(GMessage *symKey, char *dataIn, Size dataInLen, char **dataOut, Size *dataOutLen, int actionFlag)
Generic method for symetric procession.. Symetric encryption and decryption is almost identical, so we made this auxiliary method. This method process octet stream.
Returns:
KO if procession fails, OK otherwise
Parameters:
symKey - Symetric key to use.
dataIn - Input data stream.
dataInLen - Input data stream length.
dataOut - Output data stream.
dataOutLen - Output data stream length.
Author:
Pechy
See Also:
other crypthographic methods

GMessage* Cipherer::ReturnGMsgFullOfSymKeys(Size hopCount, GMessage *parameters = NULL)
Returns GMessage full of symetric keys. When we need to create a new onion of a chunk, we have to use some symetric keys. So this method gives them to us.
Returns:
GMessage full of symetric keys:
GM_SYMETRIC_KEY_COUNT
GM_SYMETRIC_KEY_INFO_1
...
...
GM_SYMETRIC_KEY_INFO_"hopCount"
Parameters:
hopCount - How many keys do we need.
parameters - What types of keys do we need.
Author:
Pechy
See Also:
other cryptography methods.

Err Cipherer::Seal(GMessage *privateKeyInfo, GMessage *publicKeyInfo, MsgField *dataIn, MsgField **dataOut, GMessage *parameters = NULL)
Seals given data. Seals given data into a digital envelope, using (for now) only RSA, DES and MD5 algorithms, but in parameters, there could be given customization.
Returns:
KO if sealing fails, OK otherwise.
Parameters:
privKeyGM - Private key used to sign the data.
dataToSign - Data to sign.
sig - Created signature.
parameters - Parameters - which algorithms to use.
Author:
Pechy
See Also:
other cryptographic methods

Err Cipherer::Sign(GMessage *privKeyGM, MsgField *dataToSign, MsgField **sig, GMessage *parameters = NULL)
Signs given data. Signs given data using message digest. For now, only MD5 is supported. Asymetric algorithm is RSA for now. In parameters, there could be given customization.
Returns:
KO if sealing fails, OK otherwise.
Parameters:
privKeyGM - Private key used to sign the data.
dataToSign - Data to sign.
sig - Created signature.
parameters - Parameters - which algorithms to use.
Author:
Pechy
See Also:
other cryptographic methods

Err Cipherer::VerifySignature(GMessage *pubKeyGM, MsgField *dataToVerify, MsgField *sig, GMessage *parameters = NULL)
Verifies signed data. Verifies given data, using (for now) only RSA and MD5 algorithms, but in parameters, there could be given customization.
Returns:
KO if verification fails, OK otherwise.
Parameters:
pubKeyGM - Public key to verify signature.
dataToVerify - Data to verify.
sig - Given signature.
parameters - Parameters - which algorithms to use.
Author:
Pechy
See Also:
other cryptographic methods

Cipherer::~Cipherer()
Cipherer destructor. Cipherer destructor. For now, nothing is needed to run here.
Author:
Pechy
See Also:
Cipherer()


This class has no child classes.
Author:
Pechy
See Also:
Translator Client Bank MessageCreator Eso

alphabetic index hierarchy of classes


generated by doc++