|
Mixes for Privacy and Anonymity in the Internet
|
This class could be used for encryption/decryption of data (streams) with AES using 128bit OFB mode. More...
Public Member Functions | |
| CASymCipher () | |
| ~CASymCipher () | |
| bool | isKeyValid () |
| SINT32 | setKey (const UINT8 *key) |
| Sets the keys for crypt1() and crypt2() to the same key. | |
| SINT32 | setKeys (const UINT8 *key, UINT32 keysize) |
| 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. | |
| SINT32 | setKey (const UINT8 *key, bool bEncrypt) |
| Sets the key1 and key2 used for encryption/decryption to the same value of key. | |
| SINT32 | setIVs (const UINT8 *p_iv) |
| Sets iv1 and iv2 to p_iv. | |
| SINT32 | setIV2 (const UINT8 *p_iv) |
| Sets iv2 to p_iv. | |
| SINT32 | crypt1 (const UINT8 *in, UINT8 *out, UINT32 len) |
| Encryptes/Decrpytes in to out using iv1 and key1. | |
| SINT32 | crypt2 (const UINT8 *in, UINT8 *out, UINT32 len) |
| Decryptes in to out using iv2 and key2. | |
| SINT32 | decrypt1CBCwithPKCS7 (const UINT8 *in, UINT8 *out, UINT32 *len) |
| En-/Decryptes in to out using iv1 and key1. | |
| SINT32 | encrypt1CBCwithPKCS7 (const UINT8 *in, UINT32 inlen, UINT8 *out, UINT32 *len) |
| En-/Decryptes in to out using IV1 and key1. | |
| void | setGCMKeys (UINT8 *keyRecv, UINT8 *keySend) |
| SINT32 | encryptMessage (const UINT8 *in, UINT32 inlen, UINT8 *out) |
| SINT32 | decryptMessage (const UINT8 *in, UINT32 inlen, UINT8 *out, bool integrityCheck) |
Static Public Member Functions | |
| static SINT32 | testSpeed () |
Protected Attributes | |
| AES_KEY * | m_keyAES1 |
| AES_KEY * | m_keyAES2 |
| UINT8 * | m_iv1 |
| UINT8 * | m_iv2 |
| bool | m_bKeySet |
Private Attributes | |
| CAMutex * | m_pcsEnc |
| CAMutex * | m_pcsDec |
| gcm_ctx_64k * | m_pGCMCtxEnc |
| gcm_ctx_64k * | m_pGCMCtxDec |
| UINT32 | m_nEncMsgCounter |
| UINT32 * | m_pEncMsgIV |
| UINT32 | m_nDecMsgCounter |
| UINT32 * | m_pDecMsgIV |
This class could be used for encryption/decryption of data (streams) with AES using 128bit OFB mode.
Because of the OFB mode technical encryption and decrpytion are the same (depending on the kind of input). Therefore there is only a general crypt() function. This class has a 2-in-1 feature: Two independent IVs are available. Therefore we have crypt1() and crypt2() depending on the used IV.
References m_bKeySet, m_iv1, m_iv2, m_keyAES1, m_keyAES2, m_nDecMsgCounter, m_nEncMsgCounter, m_pcsDec, m_pcsEnc, m_pDecMsgIV, m_pEncMsgIV, m_pGCMCtxDec, and m_pGCMCtxEnc.
Referenced by testSpeed().
References m_iv1, m_iv2, m_keyAES1, m_keyAES2, m_pcsDec, m_pcsEnc, m_pDecMsgIV, m_pEncMsgIV, m_pGCMCtxDec, m_pGCMCtxEnc, and CALockAble::waitForDestroy().
| SINT32 CASymCipher::crypt1 | ( | const UINT8 * | in, |
| UINT8 * | out, | ||
| UINT32 | len | ||
| ) |
Encryptes/Decrpytes in to out using iv1 and key1.
AES is used for encryption and the encryption is done with a special 128bit-OFB mode: In the case that (len mod 16 !=0) the unused cipher output bits are discarded and NOT used next time encryptAES() is called. That means that every time encrpytAES() is called at first new cipher output is created by calling AES-encrypt(iv).
| in | input (plain text) bytes |
| out | output (encrpyted) bytes |
| len | len of input. because the cipher preserves the size, len of output=len of input |
| E_SUCCESS |
References E_SUCCESS, KEY_SIZE, len, m_iv1, and m_keyAES1.
Referenced by CALastMixA::loop(), CAFirstMixB::loop(), CAFirstMixA::loop(), CALastMixB::loop(), CALocalProxy::loop(), mm_loopReadFromMixBefore(), CAMuxSocket::prepareForSend(), CAMuxSocket::receive(), CAMuxSocket::send(), and testSpeed().
| SINT32 CASymCipher::crypt2 | ( | const UINT8 * | in, |
| UINT8 * | out, | ||
| UINT32 | len | ||
| ) |
Decryptes in to out using iv2 and key2.
| in | input (encrypted) bytes |
| out | output (decrpyted) bytes |
| len | len of input. because the cipher preserves the size, len of output=len of input |
| E_SUCCESS |
References E_SUCCESS, KEY_SIZE, len, m_iv1, m_iv2, and m_keyAES2.
Referenced by CALastMixA::loop(), CAFirstMixB::loop(), CAFirstMixA::loop(), CALocalProxy::loop(), mm_loopReadFromMixAfter(), and CAChain::processDownstream().
| SINT32 CASymCipher::decrypt1CBCwithPKCS7 | ( | 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.
| in | input (plain or ciphertext) bytes |
| out | output (plain or ciphertext) bytes |
| len | len of input. on return the output len, which is always <= len of input |
| E_SUCCESS | |
| E_UNKNOWN,if | error |
References E_SUCCESS, E_UNKNOWN, m_iv1, and m_keyAES1.
Referenced by decryptXMLElement().
| SINT32 CASymCipher::decryptMessage | ( | const UINT8 * | in, |
| UINT32 | inlen, | ||
| UINT8 * | out, | ||
| bool | integrityCheck | ||
| ) |
References E_SUCCESS, E_UNKNOWN, m_nDecMsgCounter, m_pDecMsgIV, and m_pGCMCtxDec.
Referenced by CALastMixA::loop().
| SINT32 CASymCipher::encrypt1CBCwithPKCS7 | ( | 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.
| in | input (plain or ciphertext) bytes |
| inlen | size of the input buffer |
| out | output (plain or ciphertext) bytes |
| len | on call len of output buffer; on return size of output buffer used, which is always > len of input |
| E_SUCCESS |
References E_SPACE, E_SUCCESS, m_iv1, and m_keyAES1.
Referenced by encryptXMLElement().
| SINT32 CASymCipher::encryptMessage | ( | const UINT8 * | in, |
| UINT32 | inlen, | ||
| UINT8 * | out | ||
| ) |
References E_SUCCESS, m_nEncMsgCounter, m_pEncMsgIV, and m_pGCMCtxEnc.
Referenced by CALastMixA::loop().
| bool CASymCipher::isKeyValid | ( | ) |
References m_bKeySet.
Referenced by CALocalProxy::loop().
| void CASymCipher::setGCMKeys | ( | UINT8 * | keyRecv, |
| UINT8 * | keySend | ||
| ) |
References m_iv1, m_keyAES1, m_keyAES2, m_nDecMsgCounter, m_nEncMsgCounter, m_pDecMsgIV, m_pEncMsgIV, m_pGCMCtxDec, and m_pGCMCtxEnc.
Referenced by CALastMixA::loop().
| SINT32 CASymCipher::setIV2 | ( | const UINT8 * | p_iv | ) |
Sets iv2 to p_iv.
| p_iv | 16 random bytes used for new iv2. |
| E_SUCCESS |
References E_SUCCESS, and m_iv2.
Referenced by CAFirstMixB::loop(), CAFirstMixA::loop(), and CALocalProxy::loop().
| SINT32 CASymCipher::setIVs | ( | const UINT8 * | p_iv | ) |
Sets iv1 and iv2 to p_iv.
| p_iv | 16 random bytes used for new iv1 and iv2. |
| E_SUCCESS |
References E_SUCCESS, m_iv1, and m_iv2.
Referenced by decryptXMLElement(), CAFirstMix::doUserLogin_internal(), encryptXMLElement(), CALocalProxy::processKeyExchange(), CAMuxSocket::setReceiveKey(), and CAMuxSocket::setSendKey().
| SINT32 CASymCipher::setKey | ( | const UINT8 * | key | ) |
Sets the keys for crypt1() and crypt2() to the same key.
Sets the key1 and key2 used for encryption/decryption.
Also resets the IVs to zero!
| key | 16 random bytes used as key |
| E_SUCCESS |
Referenced by decryptXMLElement(), CAFirstMix::doUserLogin_internal(), encryptXMLElement(), CAFirstMixB::loop(), CALastMixB::loop(), CALocalProxy::processKeyExchange(), CAMuxSocket::setKey(), setKeys(), CAMuxSocket::setReceiveKey(), CAMuxSocket::setSendKey(), and testSpeed().
| SINT32 CASymCipher::setKey | ( | const UINT8 * | key, |
| bool | bEncrypt | ||
| ) |
Sets the key1 and key2 used for encryption/decryption to the same value of key.
Also resets the IVs to zero!
| key | 16 random bytes used as key |
| bEncrypt | if true, the key should be used for encryption (otherwise it will be used for decryption) |
| E_SUCCESS |
References E_SUCCESS, m_bKeySet, m_iv1, m_iv2, m_keyAES1, and m_keyAES2.
| SINT32 CASymCipher::setKeys | ( | const UINT8 * | key, |
| UINT32 | keysize | ||
| ) |
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.
References E_SUCCESS, E_UNKNOWN, KEY_SIZE, m_bKeySet, m_iv1, m_iv2, m_keyAES1, m_keyAES2, and setKey().
Referenced by CALastMixA::loop(), CAFirstMixA::loop(), CALocalProxy::loop(), and mm_loopReadFromMixBefore().
| SINT32 CASymCipher::testSpeed | ( | ) | [static] |
References CASymCipher(), crypt1(), diff64(), E_SUCCESS, getcurrentTimeMillis(), getRandom(), and setKey().
bool CASymCipher::m_bKeySet [protected] |
Referenced by CASymCipher(), isKeyValid(), setKey(), and setKeys().
UINT8* CASymCipher::m_iv1 [protected] |
Referenced by CASymCipher(), crypt1(), crypt2(), decrypt1CBCwithPKCS7(), encrypt1CBCwithPKCS7(), setGCMKeys(), setIVs(), setKey(), setKeys(), and ~CASymCipher().
UINT8* CASymCipher::m_iv2 [protected] |
Referenced by CASymCipher(), crypt2(), setIV2(), setIVs(), setKey(), setKeys(), and ~CASymCipher().
AES_KEY* CASymCipher::m_keyAES1 [protected] |
Referenced by CASymCipher(), crypt1(), decrypt1CBCwithPKCS7(), encrypt1CBCwithPKCS7(), setGCMKeys(), setKey(), setKeys(), and ~CASymCipher().
AES_KEY* CASymCipher::m_keyAES2 [protected] |
Referenced by CASymCipher(), crypt2(), setGCMKeys(), setKey(), setKeys(), and ~CASymCipher().
UINT32 CASymCipher::m_nDecMsgCounter [private] |
Referenced by CASymCipher(), decryptMessage(), and setGCMKeys().
UINT32 CASymCipher::m_nEncMsgCounter [private] |
Referenced by CASymCipher(), encryptMessage(), and setGCMKeys().
CAMutex* CASymCipher::m_pcsDec [private] |
Referenced by CASymCipher(), and ~CASymCipher().
CAMutex* CASymCipher::m_pcsEnc [private] |
Referenced by CASymCipher(), and ~CASymCipher().
UINT32* CASymCipher::m_pDecMsgIV [private] |
Referenced by CASymCipher(), decryptMessage(), setGCMKeys(), and ~CASymCipher().
UINT32* CASymCipher::m_pEncMsgIV [private] |
Referenced by CASymCipher(), encryptMessage(), setGCMKeys(), and ~CASymCipher().
gcm_ctx_64k* CASymCipher::m_pGCMCtxDec [private] |
Referenced by CASymCipher(), decryptMessage(), setGCMKeys(), and ~CASymCipher().
gcm_ctx_64k* CASymCipher::m_pGCMCtxEnc [private] |
Referenced by CASymCipher(), encryptMessage(), setGCMKeys(), and ~CASymCipher().
1.7.6.1