54 key(NULL), algorithm(algo) {
63 gcry_cipher_close(static_cast<gcry_cipher_hd_t>(
key));
66 delete[] (uint8_t*)
key;
72 static int twoFishInit = 0;
79 gcry_cipher_close(static_cast<gcry_cipher_hd_t>(
key));
84 if (keyLength == 16) {
85 algo = GCRY_CIPHER_AES;
87 else if (keyLength == 32) {
88 algo = GCRY_CIPHER_AES256;
94 gcry_cipher_open(&tmp, algo, GCRY_CIPHER_MODE_ECB, 0);
96 gcry_cipher_setkey(static_cast<gcry_cipher_hd_t>(
key), k, keyLength);
104 delete[] (uint8_t*)
key;
120 gcry_cipher_encrypt (static_cast<gcry_cipher_hd_t>(
key),
136 iv[14] = (uint8_t)((ctr & 0xFF00) >> 8);
137 iv[15] = (uint8_t)((ctr & 0x00FF));
143 iv[14] = (uint8_t)((ctr & 0xFF00) >> 8);
144 iv[15] = (uint8_t)((ctr & 0x00FF));
147 memcpy(&output[ctr*SRTP_BLOCK_SIZE], temp, length % SRTP_BLOCK_SIZE);
152 uint8_t* output, uint8_t* iv ) {
161 for ( ctr = 0; ctr < l; ctr++ ) {
162 iv[14] = (uint8_t)((ctr & 0xFF00) >> 8);
163 iv[15] = (uint8_t)((ctr & 0x00FF));
167 *output++ = temp[i] ^ *input++;
174 iv[14] = (uint8_t)((ctr & 0xFF00) >> 8);
175 iv[15] = (uint8_t)((ctr & 0x00FF));
178 for (
int i = 0; i < l; i++ ) {
179 *output++ = temp[i] ^ *input++;
193 for (ctr = 0; ctr < l; ctr++ ) {
194 iv[14] = (uint8_t)((ctr & 0xFF00) >> 8);
195 iv[15] = (uint8_t)((ctr & 0x00FF));
206 iv[14] = (uint8_t)((ctr & 0xFF00) >> 8);
207 iv[15] = (uint8_t)((ctr & 0x00FF));
210 for (
int i = 0; i < l; i++ ) {
219 f8_encrypt(data, data_length, const_cast<uint8_t*>(data), iv, f8Cipher);
222 #define MAX_KEYLEN 32
225 uint8_t* salt, int32_t saltLen) {
227 unsigned char *cp_in, *cp_in1, *cp_out;
235 if (saltLen > keyLen)
241 memcpy(saltMask, salt, saltLen);
242 memset(saltMask+saltLen, 0x55, keyLen-saltLen);
251 for (
int i = 0; i < keyLen; i++) {
252 *cp_out++ = *cp_in++ ^ *cp_in1++;
300 const uint8_t *cp_in;
301 uint8_t* cp_in1, *cp_out;
311 *cp_out++ ^= *cp_in++;
316 ui32p = (uint32_t *)f8ctx->
S;
317 ui32p[3] ^= htonl(f8ctx->
J);
330 for (i = 0; i < length; i++) {
331 *cp_out++ = *cp_in++ ^ *cp_in1++;
Implments the SRTP encryption modes as defined in RFC3711.
bool setNewKey(const uint8_t *key, int32_t keyLength)
Set new key.
Structure that contains a prepared Twofish key.
unsigned char Twofish_Byte
A Twofish_Byte must be an unsigned 8-bit integer.
int Twofish_initialise()
Initialise and test the Twofish implementation.
unsigned char * ivAccent
second IV
const int SrtpEncryptionAESF8
void get_ctr_cipher_stream(uint8_t *output, uint32_t length, uint8_t *iv)
Computes the cipher stream for AES CM mode.
const int SrtpEncryptionTWOF8
int processBlock(F8_CIPHER_CTX *f8ctx, const uint8_t *in, int32_t length, uint8_t *out)
const int SrtpEncryptionTWOCM
SrtpSymCrypto(int algo=SrtpEncryptionAESCM)
void ctr_encrypt(const uint8_t *input, uint32_t inputLen, uint8_t *output, uint8_t *iv)
Counter-mode encryption.
void f8_encrypt(const uint8_t *data, uint32_t dataLen, uint8_t *iv, SrtpSymCrypto *f8Cipher)
AES F8 mode encryption, in place.
unsigned char * S
Intermetiade buffer.
Class which implements SRTP AES cryptographic functions.
void Twofish_encrypt(Twofish_key *xkey, Twofish_Byte p[16], Twofish_Byte c[16])
Encrypt a single block of data.
int Twofish_prepare_key(Twofish_Byte key[], int key_len, Twofish_key *xkey)
Convert a cipher key to the internal form used for encryption and decryption.
void f8_deriveForIV(SrtpSymCrypto *f8Cipher, uint8_t *key, int32_t keyLen, uint8_t *salt, int32_t saltLen)
Derive a AES context to compute the IV'.
const int SrtpEncryptionAESCM
void encrypt(const uint8_t *input, uint8_t *output)
Encrypts the inpout to the output.