Mixes for Privacy and Anonymity in the Internet
Public Member Functions | Protected Attributes | Private Attributes | List of all members
CASymCipher Class Reference

This class could be used for encryption/decryption of data (streams) with AES using 128bit CBC mode. More...

Inheritance diagram for CASymCipher:
CALockAble

Public Member Functions

 CASymCipher ()
 
 ~CASymCipher ()
 
bool isKeyValid ()
 
SINT32 setKey (const UINT8 *key)
 Sets the key for encryption. More...
 
SINT32 setKey (const UINT8 *key, bool bEncrypt)
 Sets the keys for crypt1() and crypt2() either to the same key (if keysize==KEY_SIZE) or to different values, if keysize==2* KEY_SIZE. More...
 
SINT32 setIV (const UINT8 *p_iv)
 Sets iv to p_iv. More...
 
SINT32 decryptCBCwithPKCS7 (const UINT8 *in, UINT8 *out, UINT32 *len)
 En-/Decryptes in to out using iv1 and key1. More...
 
SINT32 encryptCBCwithPKCS7 (const UINT8 *in, UINT32 inlen, UINT8 *out, UINT32 *len)
 En-/Decryptes in to out using IV1 and key1. More...
 
- Public Member Functions inherited from CALockAble
 CALockAble ()
 
virtual ~CALockAble ()
 
SINT32 lock ()
 Locks the lockable object by threadsafe incrementing a reference counter. More...
 
SINT32 unlock ()
 Unlocks the lockable object by threadsafe decrementing a reference counter. More...
 

Protected Attributes

AES_KEY * m_keyAES1
 
UINT8m_iv1
 
bool m_bKeySet
 

Private Attributes

CAMutexm_pcsEnc
 
CAMutexm_pcsDec
 

Additional Inherited Members

- Protected Member Functions inherited from CALockAble
SINT32 waitForDestroy ()
 If called checks if the reference counter equals zero. More...
 

Detailed Description

This class could be used for encryption/decryption of data (streams) with AES using 128bit CBC mode.

Constructor & Destructor Documentation

◆ CASymCipher()

CASymCipher::CASymCipher ( )

References m_bKeySet, m_iv1, m_keyAES1, m_pcsDec, and m_pcsEnc.

◆ ~CASymCipher()

CASymCipher::~CASymCipher ( )

Member Function Documentation

◆ decryptCBCwithPKCS7()

SINT32 CASymCipher::decryptCBCwithPKCS7 ( const UINT8 in,
UINT8 out,
UINT32 len 
)

En-/Decryptes in to out using iv1 and key1.

AES is used for en-/dcryption and the cryption is done with CBC mode and PKCS7 padding.

Parameters
ininput (plain or ciphertext) bytes
outoutput (plain or ciphertext) bytes
lenlen of input. on return the output len, which is always <= len of input
Return values
E_SUCCESS
E_UNKNOWN,iferror

References E_SUCCESS, E_UNKNOWN, len, m_iv1, and m_keyAES1.

Referenced by decryptXMLElement().

◆ encryptCBCwithPKCS7()

SINT32 CASymCipher::encryptCBCwithPKCS7 ( const UINT8 in,
UINT32  inlen,
UINT8 out,
UINT32 len 
)

En-/Decryptes in to out using IV1 and key1.

AES is used for en-/decryption and the cryption is done with CBC mode and PKCS7 padding.

Parameters
ininput (plain or ciphertext) bytes
inlensize of the input buffer
outoutput (plain or ciphertext) bytes
lenon call len of output buffer; on return size of output buffer used, which is always > len of input
Return values
E_SUCCESS

References E_SPACE, E_SUCCESS, len, m_iv1, and m_keyAES1.

Referenced by encryptXMLElement().

◆ isKeyValid()

bool CASymCipher::isKeyValid ( )

References m_bKeySet.

◆ setIV()

SINT32 CASymCipher::setIV ( const UINT8 p_iv)

Sets iv to p_iv.

Parameters
p_iv16 random bytes used for new iv1 and iv2.
Return values
E_SUCCESS

References E_SUCCESS, and m_iv1.

Referenced by decryptXMLElement(), and encryptXMLElement().

◆ setKey() [1/2]

SINT32 CASymCipher::setKey ( const UINT8 key)

Sets the key for encryption.

Sets the key1 and key2 used for encryption/decryption.

Also resets the IVs to zero!

Parameters
key16 random bytes used as key
Return values
E_SUCCESS

Referenced by decryptXMLElement(), encryptXMLElement(), CAFirstMixB::loop(), and CALastMixB::loop().

◆ setKey() [2/2]

SINT32 CASymCipher::setKey ( const UINT8 key,
bool  bEncrypt 
)

Sets the keys for crypt1() and crypt2() either to the same key (if keysize==KEY_SIZE) or to different values, if keysize==2* KEY_SIZE.

Sets the key1 and key2 used for encryption/decryption to the same value of key.

Also resets the IVs to zero!

Parameters
key16 random bytes used as key
bEncryptif true, the key should be used for encryption (otherwise it will be used for decryption)
Return values
E_SUCCESS

References E_SUCCESS, m_bKeySet, m_iv1, and m_keyAES1.

Member Data Documentation

◆ m_bKeySet

bool CASymCipher::m_bKeySet
protected

Referenced by CASymCipher(), isKeyValid(), and setKey().

◆ m_iv1

UINT8* CASymCipher::m_iv1
protected

◆ m_keyAES1

AES_KEY* CASymCipher::m_keyAES1
protected

◆ m_pcsDec

CAMutex* CASymCipher::m_pcsDec
private

Referenced by CASymCipher(), and ~CASymCipher().

◆ m_pcsEnc

CAMutex* CASymCipher::m_pcsEnc
private

Referenced by CASymCipher(), and ~CASymCipher().