Commit a54de816 authored by Geir Istad's avatar Geir Istad

Merge remote-tracking branch 'cisco/master' into unit_tests

parents 483dd549 d1ef7694
......@@ -93,8 +93,8 @@ static srtp_err_status_t srtp_aes_gcm_openssl_alloc (srtp_cipher_t **c, int key_
/*
* Verify the key_len is valid for one of: AES-128/256
*/
if (key_len != SRTP_AES_128_GCM_KEYSIZE_WSALT &&
key_len != SRTP_AES_256_GCM_KEYSIZE_WSALT) {
if (key_len != SRTP_AES_GCM_128_KEYSIZE_WSALT &&
key_len != SRTP_AES_GCM_256_KEYSIZE_WSALT) {
return (srtp_err_status_bad_param);
}
......@@ -131,15 +131,15 @@ static srtp_err_status_t srtp_aes_gcm_openssl_alloc (srtp_cipher_t **c, int key_
/* setup cipher attributes */
switch (key_len) {
case SRTP_AES_128_GCM_KEYSIZE_WSALT:
case SRTP_AES_GCM_128_KEYSIZE_WSALT:
(*c)->type = &srtp_aes_gcm_128_openssl;
(*c)->algorithm = SRTP_AES_128_GCM;
(*c)->algorithm = SRTP_AES_GCM_128;
gcm->key_size = SRTP_AES_128_KEYSIZE;
gcm->tag_len = tlen;
break;
case SRTP_AES_256_GCM_KEYSIZE_WSALT:
case SRTP_AES_GCM_256_KEYSIZE_WSALT:
(*c)->type = &srtp_aes_gcm_256_openssl;
(*c)->algorithm = SRTP_AES_256_GCM;
(*c)->algorithm = SRTP_AES_GCM_256;
gcm->key_size = SRTP_AES_256_KEYSIZE;
gcm->tag_len = tlen;
break;
......@@ -386,7 +386,7 @@ static const char srtp_aes_gcm_256_openssl_description[] = "AES-256 GCM using op
* values we're derived from independent test code
* using OpenSSL.
*/
static const uint8_t srtp_aes_gcm_test_case_0_key[SRTP_AES_128_GCM_KEYSIZE_WSALT] = {
static const uint8_t srtp_aes_gcm_test_case_0_key[SRTP_AES_GCM_128_KEYSIZE_WSALT] = {
0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
......@@ -430,7 +430,7 @@ static const uint8_t srtp_aes_gcm_test_case_0_ciphertext[76] = {
};
static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_0a = {
SRTP_AES_128_GCM_KEYSIZE_WSALT, /* octets in key */
SRTP_AES_GCM_128_KEYSIZE_WSALT, /* octets in key */
srtp_aes_gcm_test_case_0_key, /* key */
srtp_aes_gcm_test_case_0_iv, /* packet index */
60, /* octets in plaintext */
......@@ -444,7 +444,7 @@ static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_0a = {
};
static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_0 = {
SRTP_AES_128_GCM_KEYSIZE_WSALT, /* octets in key */
SRTP_AES_GCM_128_KEYSIZE_WSALT, /* octets in key */
srtp_aes_gcm_test_case_0_key, /* key */
srtp_aes_gcm_test_case_0_iv, /* packet index */
60, /* octets in plaintext */
......@@ -457,7 +457,7 @@ static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_0 = {
&srtp_aes_gcm_test_case_0a /* pointer to next testcase */
};
static const uint8_t srtp_aes_gcm_test_case_1_key[SRTP_AES_256_GCM_KEYSIZE_WSALT] = {
static const uint8_t srtp_aes_gcm_test_case_1_key[SRTP_AES_GCM_256_KEYSIZE_WSALT] = {
0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
0xa5, 0x59, 0x09, 0xc5, 0x54, 0x66, 0x93, 0x1c,
0xaf, 0xf5, 0x26, 0x9a, 0x21, 0xd5, 0x14, 0xb2,
......@@ -504,7 +504,7 @@ static const uint8_t srtp_aes_gcm_test_case_1_ciphertext[76] = {
};
static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_1a = {
SRTP_AES_256_GCM_KEYSIZE_WSALT, /* octets in key */
SRTP_AES_GCM_256_KEYSIZE_WSALT, /* octets in key */
srtp_aes_gcm_test_case_1_key, /* key */
srtp_aes_gcm_test_case_1_iv, /* packet index */
60, /* octets in plaintext */
......@@ -518,7 +518,7 @@ static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_1a = {
};
static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_1 = {
SRTP_AES_256_GCM_KEYSIZE_WSALT, /* octets in key */
SRTP_AES_GCM_256_KEYSIZE_WSALT, /* octets in key */
srtp_aes_gcm_test_case_1_key, /* key */
srtp_aes_gcm_test_case_1_iv, /* packet index */
60, /* octets in plaintext */
......@@ -545,7 +545,7 @@ const srtp_cipher_type_t srtp_aes_gcm_128_openssl = {
srtp_aes_gcm_openssl_get_tag,
srtp_aes_gcm_128_openssl_description,
&srtp_aes_gcm_test_case_0,
SRTP_AES_128_GCM
SRTP_AES_GCM_128
};
/*
......@@ -562,6 +562,6 @@ const srtp_cipher_type_t srtp_aes_gcm_256_openssl = {
srtp_aes_gcm_openssl_get_tag,
srtp_aes_gcm_256_openssl_description,
&srtp_aes_gcm_test_case_1,
SRTP_AES_256_GCM
SRTP_AES_GCM_256
};
......@@ -57,6 +57,8 @@ srtp_debug_module_t srtp_mod_aes_icm = {
0, /* debugging is off by default */
"aes icm" /* printable module name */
};
extern const srtp_cipher_type_t srtp_aes_icm_128;
extern const srtp_cipher_type_t srtp_aes_icm_256;
/*
* integer counter mode works as follows:
......@@ -94,7 +96,6 @@ srtp_debug_module_t srtp_mod_aes_icm = {
static srtp_err_status_t srtp_aes_icm_alloc (srtp_cipher_t **c, int key_len, int tlen)
{
extern const srtp_cipher_type_t srtp_aes_icm;
srtp_aes_icm_ctx_t *icm;
debug_print(srtp_mod_aes_icm,
......@@ -106,7 +107,7 @@ static srtp_err_status_t srtp_aes_icm_alloc (srtp_cipher_t **c, int key_len, int
* has not broken anything. Don't know what would be the
* effect of skipping this check for srtp in general.
*/
if (key_len != 30 && key_len != 38 && key_len != 46) {
if (key_len != 30 && key_len != 46) {
return srtp_err_status_bad_param;
}
......@@ -126,17 +127,15 @@ static srtp_err_status_t srtp_aes_icm_alloc (srtp_cipher_t **c, int key_len, int
/* set pointers */
(*c)->state = icm;
(*c)->type = &srtp_aes_icm;
switch (key_len) {
case 46:
(*c)->algorithm = SRTP_AES_256_ICM;
break;
case 38:
(*c)->algorithm = SRTP_AES_192_ICM;
(*c)->algorithm = SRTP_AES_ICM_256;
(*c)->type = &srtp_aes_icm_256;
break;
default:
(*c)->algorithm = SRTP_AES_128_ICM;
(*c)->algorithm = SRTP_AES_ICM_128;
(*c)->type = &srtp_aes_icm_128;
break;
}
......@@ -402,49 +401,50 @@ static srtp_err_status_t srtp_aes_icm_encrypt (void *cv,
return srtp_err_status_ok;
}
static const char srtp_aes_icm_description[] = "aes integer counter mode";
static const char srtp_aes_icm_128_description[] = "AES-128 integer counter mode";
static const char srtp_aes_icm_256_description[] = "AES-256 integer counter mode";
static const uint8_t srtp_aes_icm_test_case_0_key[30] = {
static const uint8_t srtp_aes_icm_128_test_case_0_key[30] = {
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
};
static uint8_t srtp_aes_icm_test_case_0_nonce[16] = {
static uint8_t srtp_aes_icm_128_test_case_0_nonce[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const uint8_t srtp_aes_icm_test_case_0_plaintext[32] = {
static const uint8_t srtp_aes_icm_128_test_case_0_plaintext[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t srtp_aes_icm_test_case_0_ciphertext[32] = {
static const uint8_t srtp_aes_icm_128_test_case_0_ciphertext[32] = {
0xe0, 0x3e, 0xad, 0x09, 0x35, 0xc9, 0x5e, 0x80,
0xe1, 0x66, 0xb1, 0x6d, 0xd9, 0x2b, 0x4e, 0xb4,
0xd2, 0x35, 0x13, 0x16, 0x2b, 0x02, 0xd0, 0xf7,
0x2a, 0x43, 0xa2, 0xfe, 0x4a, 0x5f, 0x97, 0xab
};
static const srtp_cipher_test_case_t srtp_aes_icm_test_case_0 = {
static const srtp_cipher_test_case_t srtp_aes_icm_128_test_case_0 = {
30, /* octets in key */
srtp_aes_icm_test_case_0_key, /* key */
srtp_aes_icm_test_case_0_nonce, /* packet index */
srtp_aes_icm_128_test_case_0_key, /* key */
srtp_aes_icm_128_test_case_0_nonce, /* packet index */
32, /* octets in plaintext */
srtp_aes_icm_test_case_0_plaintext, /* plaintext */
srtp_aes_icm_128_test_case_0_plaintext, /* plaintext */
32, /* octets in ciphertext */
srtp_aes_icm_test_case_0_ciphertext, /* ciphertext */
srtp_aes_icm_128_test_case_0_ciphertext, /* ciphertext */
0,
NULL,
0,
NULL /* pointer to next testcase */
};
static const uint8_t srtp_aes_icm_test_case_1_key[46] = {
static const uint8_t srtp_aes_icm_256_test_case_0_key[46] = {
0x57, 0xf8, 0x2f, 0xe3, 0x61, 0x3f, 0xd1, 0x70,
0xa8, 0x5e, 0xc9, 0x3c, 0x40, 0xb1, 0xf0, 0x92,
0x2e, 0xc4, 0xcb, 0x0d, 0xc0, 0x25, 0xb5, 0x82,
......@@ -453,37 +453,37 @@ static const uint8_t srtp_aes_icm_test_case_1_key[46] = {
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
};
static uint8_t srtp_aes_icm_test_case_1_nonce[16] = {
static uint8_t srtp_aes_icm_256_test_case_0_nonce[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const uint8_t srtp_aes_icm_test_case_1_plaintext[32] = {
static const uint8_t srtp_aes_icm_256_test_case_0_plaintext[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t srtp_aes_icm_test_case_1_ciphertext[32] = {
static const uint8_t srtp_aes_icm_256_test_case_0_ciphertext[32] = {
0x92, 0xbd, 0xd2, 0x8a, 0x93, 0xc3, 0xf5, 0x25,
0x11, 0xc6, 0x77, 0xd0, 0x8b, 0x55, 0x15, 0xa4,
0x9d, 0xa7, 0x1b, 0x23, 0x78, 0xa8, 0x54, 0xf6,
0x70, 0x50, 0x75, 0x6d, 0xed, 0x16, 0x5b, 0xac
};
static const srtp_cipher_test_case_t srtp_aes_icm_test_case_1 = {
static const srtp_cipher_test_case_t srtp_aes_icm_256_test_case_0 = {
46, /* octets in key */
srtp_aes_icm_test_case_1_key, /* key */
srtp_aes_icm_test_case_1_nonce, /* packet index */
srtp_aes_icm_256_test_case_0_key, /* key */
srtp_aes_icm_256_test_case_0_nonce, /* packet index */
32, /* octets in plaintext */
srtp_aes_icm_test_case_1_plaintext, /* plaintext */
srtp_aes_icm_256_test_case_0_plaintext, /* plaintext */
32, /* octets in ciphertext */
srtp_aes_icm_test_case_1_ciphertext, /* ciphertext */
srtp_aes_icm_256_test_case_0_ciphertext, /* ciphertext */
0,
NULL,
0,
&srtp_aes_icm_test_case_0 /* pointer to next testcase */
NULL, /* pointer to next testcase */
};
......@@ -492,7 +492,7 @@ static const srtp_cipher_test_case_t srtp_aes_icm_test_case_1 = {
* note: the encrypt function is identical to the decrypt function
*/
const srtp_cipher_type_t srtp_aes_icm = {
const srtp_cipher_type_t srtp_aes_icm_128 = {
srtp_aes_icm_alloc,
srtp_aes_icm_dealloc,
srtp_aes_icm_context_init,
......@@ -501,8 +501,21 @@ const srtp_cipher_type_t srtp_aes_icm = {
srtp_aes_icm_encrypt,
srtp_aes_icm_set_iv,
0, /* get_tag */
srtp_aes_icm_description,
&srtp_aes_icm_test_case_1,
SRTP_AES_ICM
srtp_aes_icm_128_description,
&srtp_aes_icm_128_test_case_0,
SRTP_AES_ICM_128
};
const srtp_cipher_type_t srtp_aes_icm_256 = {
srtp_aes_icm_alloc,
srtp_aes_icm_dealloc,
srtp_aes_icm_context_init,
0, /* set_aad */
srtp_aes_icm_encrypt,
srtp_aes_icm_encrypt,
srtp_aes_icm_set_iv,
0, /* get_tag */
srtp_aes_icm_256_description,
&srtp_aes_icm_256_test_case_0,
SRTP_AES_ICM_256
};
......@@ -63,7 +63,7 @@ srtp_debug_module_t srtp_mod_aes_icm = {
0, /* debugging is off by default */
"aes icm ossl" /* printable module name */
};
extern const srtp_cipher_type_t srtp_aes_icm;
extern const srtp_cipher_type_t srtp_aes_icm_128;
extern const srtp_cipher_type_t srtp_aes_icm_192;
extern const srtp_cipher_type_t srtp_aes_icm_256;
......@@ -152,17 +152,17 @@ static srtp_err_status_t srtp_aes_icm_openssl_alloc (srtp_cipher_t **c, int key_
/* setup cipher parameters */
switch (key_len) {
case SRTP_AES_128_KEYSIZE_WSALT:
(*c)->algorithm = SRTP_AES_128_ICM;
(*c)->type = &srtp_aes_icm;
(*c)->algorithm = SRTP_AES_ICM_128;
(*c)->type = &srtp_aes_icm_128;
icm->key_size = SRTP_AES_128_KEYSIZE;
break;
case SRTP_AES_192_KEYSIZE_WSALT:
(*c)->algorithm = SRTP_AES_192_ICM;
(*c)->algorithm = SRTP_AES_ICM_192;
(*c)->type = &srtp_aes_icm_192;
icm->key_size = SRTP_AES_192_KEYSIZE;
break;
case SRTP_AES_256_KEYSIZE_WSALT:
(*c)->algorithm = SRTP_AES_256_ICM;
(*c)->algorithm = SRTP_AES_ICM_256;
(*c)->type = &srtp_aes_icm_256;
icm->key_size = SRTP_AES_256_KEYSIZE;
break;
......@@ -316,7 +316,7 @@ static srtp_err_status_t srtp_aes_icm_openssl_encrypt (void *cv, unsigned char *
/*
* Name of this crypto engine
*/
static const char srtp_aes_icm_openssl_description[] = "AES-128 counter mode using openssl";
static const char srtp_aes_icm_128_openssl_description[] = "AES-128 counter mode using openssl";
static const char srtp_aes_icm_192_openssl_description[] = "AES-192 counter mode using openssl";
static const char srtp_aes_icm_256_openssl_description[] = "AES-256 counter mode using openssl";
......@@ -325,40 +325,40 @@ static const char srtp_aes_icm_256_openssl_description[] = "AES-256 counter mode
* KAT values for AES self-test. These
* values came from the legacy libsrtp code.
*/
static const uint8_t srtp_aes_icm_test_case_0_key[SRTP_AES_128_KEYSIZE_WSALT] = {
static const uint8_t srtp_aes_icm_128_test_case_0_key[SRTP_AES_128_KEYSIZE_WSALT] = {
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
};
static uint8_t srtp_aes_icm_test_case_0_nonce[16] = {
static uint8_t srtp_aes_icm_128_test_case_0_nonce[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const uint8_t srtp_aes_icm_test_case_0_plaintext[32] = {
static const uint8_t srtp_aes_icm_128_test_case_0_plaintext[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t srtp_aes_icm_test_case_0_ciphertext[32] = {
static const uint8_t srtp_aes_icm_128_test_case_0_ciphertext[32] = {
0xe0, 0x3e, 0xad, 0x09, 0x35, 0xc9, 0x5e, 0x80,
0xe1, 0x66, 0xb1, 0x6d, 0xd9, 0x2b, 0x4e, 0xb4,
0xd2, 0x35, 0x13, 0x16, 0x2b, 0x02, 0xd0, 0xf7,
0x2a, 0x43, 0xa2, 0xfe, 0x4a, 0x5f, 0x97, 0xab
};
static const srtp_cipher_test_case_t srtp_aes_icm_test_case_0 = {
static const srtp_cipher_test_case_t srtp_aes_icm_128_test_case_0 = {
SRTP_AES_128_KEYSIZE_WSALT, /* octets in key */
srtp_aes_icm_test_case_0_key, /* key */
srtp_aes_icm_test_case_0_nonce, /* packet index */
srtp_aes_icm_128_test_case_0_key, /* key */
srtp_aes_icm_128_test_case_0_nonce, /* packet index */
32, /* octets in plaintext */
srtp_aes_icm_test_case_0_plaintext, /* plaintext */
srtp_aes_icm_128_test_case_0_plaintext, /* plaintext */
32, /* octets in ciphertext */
srtp_aes_icm_test_case_0_ciphertext, /* ciphertext */
srtp_aes_icm_128_test_case_0_ciphertext, /* ciphertext */
0,
NULL,
0,
......@@ -369,7 +369,7 @@ static const srtp_cipher_test_case_t srtp_aes_icm_test_case_0 = {
* KAT values for AES-192-CTR self-test. These
* values came from section 7 of RFC 6188.
*/
static const uint8_t srtp_aes_icm_192_test_case_1_key[SRTP_AES_192_KEYSIZE_WSALT] = {
static const uint8_t srtp_aes_icm_192_test_case_0_key[SRTP_AES_192_KEYSIZE_WSALT] = {
0xea, 0xb2, 0x34, 0x76, 0x4e, 0x51, 0x7b, 0x2d,
0x3d, 0x16, 0x0d, 0x58, 0x7d, 0x8c, 0x86, 0x21,
0x97, 0x40, 0xf6, 0x5f, 0x99, 0xb6, 0xbc, 0xf7,
......@@ -377,33 +377,33 @@ static const uint8_t srtp_aes_icm_192_test_case_1_key[SRTP_AES_192_KEYSIZE_WSALT
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
};
static uint8_t srtp_aes_icm_192_test_case_1_nonce[16] = {
static uint8_t srtp_aes_icm_192_test_case_0_nonce[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const uint8_t srtp_aes_icm_192_test_case_1_plaintext[32] = {
static const uint8_t srtp_aes_icm_192_test_case_0_plaintext[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t srtp_aes_icm_192_test_case_1_ciphertext[32] = {
static const uint8_t srtp_aes_icm_192_test_case_0_ciphertext[32] = {
0x35, 0x09, 0x6c, 0xba, 0x46, 0x10, 0x02, 0x8d,
0xc1, 0xb5, 0x75, 0x03, 0x80, 0x4c, 0xe3, 0x7c,
0x5d, 0xe9, 0x86, 0x29, 0x1d, 0xcc, 0xe1, 0x61,
0xd5, 0x16, 0x5e, 0xc4, 0x56, 0x8f, 0x5c, 0x9a
};
static const srtp_cipher_test_case_t srtp_aes_icm_192_test_case_1 = {
static const srtp_cipher_test_case_t srtp_aes_icm_192_test_case_0 = {
SRTP_AES_192_KEYSIZE_WSALT, /* octets in key */
srtp_aes_icm_192_test_case_1_key, /* key */
srtp_aes_icm_192_test_case_1_nonce, /* packet index */
srtp_aes_icm_192_test_case_0_key, /* key */
srtp_aes_icm_192_test_case_0_nonce, /* packet index */
32, /* octets in plaintext */
srtp_aes_icm_192_test_case_1_plaintext, /* plaintext */
srtp_aes_icm_192_test_case_0_plaintext, /* plaintext */
32, /* octets in ciphertext */
srtp_aes_icm_192_test_case_1_ciphertext, /* ciphertext */
srtp_aes_icm_192_test_case_0_ciphertext, /* ciphertext */
0,
NULL,
0,
......@@ -414,7 +414,7 @@ static const srtp_cipher_test_case_t srtp_aes_icm_192_test_case_1 = {
* KAT values for AES-256-CTR self-test. These
* values came from section 7 of RFC 6188.
*/
static const uint8_t srtp_aes_icm_256_test_case_2_key[SRTP_AES_256_KEYSIZE_WSALT] = {
static const uint8_t srtp_aes_icm_256_test_case_0_key[SRTP_AES_256_KEYSIZE_WSALT] = {
0x57, 0xf8, 0x2f, 0xe3, 0x61, 0x3f, 0xd1, 0x70,
0xa8, 0x5e, 0xc9, 0x3c, 0x40, 0xb1, 0xf0, 0x92,
0x2e, 0xc4, 0xcb, 0x0d, 0xc0, 0x25, 0xb5, 0x82,
......@@ -423,33 +423,33 @@ static const uint8_t srtp_aes_icm_256_test_case_2_key[SRTP_AES_256_KEYSIZE_WSALT
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
};
static uint8_t srtp_aes_icm_256_test_case_2_nonce[16] = {
static uint8_t srtp_aes_icm_256_test_case_0_nonce[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const uint8_t srtp_aes_icm_256_test_case_2_plaintext[32] = {
static const uint8_t srtp_aes_icm_256_test_case_0_plaintext[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t srtp_aes_icm_256_test_case_2_ciphertext[32] = {
static const uint8_t srtp_aes_icm_256_test_case_0_ciphertext[32] = {
0x92, 0xbd, 0xd2, 0x8a, 0x93, 0xc3, 0xf5, 0x25,
0x11, 0xc6, 0x77, 0xd0, 0x8b, 0x55, 0x15, 0xa4,
0x9d, 0xa7, 0x1b, 0x23, 0x78, 0xa8, 0x54, 0xf6,
0x70, 0x50, 0x75, 0x6d, 0xed, 0x16, 0x5b, 0xac
};
static const srtp_cipher_test_case_t srtp_aes_icm_256_test_case_2 = {
static const srtp_cipher_test_case_t srtp_aes_icm_256_test_case_0 = {
SRTP_AES_256_KEYSIZE_WSALT, /* octets in key */
srtp_aes_icm_256_test_case_2_key, /* key */
srtp_aes_icm_256_test_case_2_nonce, /* packet index */
srtp_aes_icm_256_test_case_0_key, /* key */
srtp_aes_icm_256_test_case_0_nonce, /* packet index */
32, /* octets in plaintext */
srtp_aes_icm_256_test_case_2_plaintext, /* plaintext */
srtp_aes_icm_256_test_case_0_plaintext, /* plaintext */
32, /* octets in ciphertext */
srtp_aes_icm_256_test_case_2_ciphertext, /* ciphertext */
srtp_aes_icm_256_test_case_0_ciphertext, /* ciphertext */
0,
NULL,
0,
......@@ -460,7 +460,7 @@ static const srtp_cipher_test_case_t srtp_aes_icm_256_test_case_2 = {
* This is the function table for this crypto engine.
* note: the encrypt function is identical to the decrypt function
*/
const srtp_cipher_type_t srtp_aes_icm = {
const srtp_cipher_type_t srtp_aes_icm_128 = {
srtp_aes_icm_openssl_alloc,
srtp_aes_icm_openssl_dealloc,
srtp_aes_icm_openssl_context_init,
......@@ -469,9 +469,9 @@ const srtp_cipher_type_t srtp_aes_icm = {
srtp_aes_icm_openssl_encrypt,
srtp_aes_icm_openssl_set_iv,
0, /* get_tag */
srtp_aes_icm_openssl_description,
&srtp_aes_icm_test_case_0,
SRTP_AES_ICM
srtp_aes_icm_128_openssl_description,
&srtp_aes_icm_128_test_case_0,
SRTP_AES_ICM_128
};
/*
......@@ -488,8 +488,8 @@ const srtp_cipher_type_t srtp_aes_icm_192 = {
srtp_aes_icm_openssl_set_iv,
0, /* get_tag */
srtp_aes_icm_192_openssl_description,
&srtp_aes_icm_192_test_case_1,
SRTP_AES_192_ICM
&srtp_aes_icm_192_test_case_0,
SRTP_AES_ICM_192
};
/*
......@@ -506,7 +506,7 @@ const srtp_cipher_type_t srtp_aes_icm_256 = {
srtp_aes_icm_openssl_set_iv,
0, /* get_tag */
srtp_aes_icm_256_openssl_description,
&srtp_aes_icm_256_test_case_2,
SRTP_AES_256_ICM
&srtp_aes_icm_256_test_case_0,
SRTP_AES_ICM_256
};
......@@ -261,7 +261,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
return status;
}
if (c->algorithm == SRTP_AES_128_GCM || c->algorithm == SRTP_AES_256_GCM) {
if (c->algorithm == SRTP_AES_GCM_128 || c->algorithm == SRTP_AES_GCM_256) {
debug_print(srtp_mod_cipher, "IV: %s",
srtp_octet_string_hex_string(test_case->idx, 12));
......@@ -286,7 +286,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
return status;
}
if (c->algorithm == SRTP_AES_128_GCM || c->algorithm == SRTP_AES_256_GCM) {
if (c->algorithm == SRTP_AES_GCM_128 || c->algorithm == SRTP_AES_GCM_256) {
/*
* Get the GCM tag
*/
......@@ -361,7 +361,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
return status;
}
if (c->algorithm == SRTP_AES_128_GCM || c->algorithm == SRTP_AES_256_GCM) {
if (c->algorithm == SRTP_AES_GCM_128 || c->algorithm == SRTP_AES_GCM_256) {
/*
* Set the AAD
*/
......@@ -491,7 +491,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
return status;
}
if (c->algorithm == SRTP_AES_128_GCM || c->algorithm == SRTP_AES_256_GCM) {
if (c->algorithm == SRTP_AES_GCM_128 || c->algorithm == SRTP_AES_GCM_256) {
/*
* Set the AAD
*/
......@@ -512,7 +512,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
srtp_cipher_dealloc(c);
return status;
}
if (c->algorithm == SRTP_AES_128_GCM || c->algorithm == SRTP_AES_256_GCM) {
if (c->algorithm == SRTP_AES_GCM_128 || c->algorithm == SRTP_AES_GCM_256) {
/*
* Get the GCM tag
*/
......@@ -540,7 +540,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
srtp_cipher_dealloc(c);
return status;
}
if (c->algorithm == SRTP_AES_128_GCM || c->algorithm == SRTP_AES_256_GCM) {
if (c->algorithm == SRTP_AES_GCM_128 || c->algorithm == SRTP_AES_GCM_256) {
/*
* Set the AAD
*/
......
/*
* math.h
*
* crypto math operations and data types
*
* David A. McGrew
* Cisco Systems, Inc.
*/
/*
*
* Copyright (c) 2001-2006 Cisco Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* Neither the name of the Cisco Systems, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef MATH_H
#define MATH_H
#include "datatypes.h"
#ifdef __cplusplus
extern "C" {
#endif
unsigned char
v32_weight(v32_t a);
unsigned char
v32_distance(v32_t x, v32_t y);
unsigned int
v32_dot_product(v32_t a, v32_t b);
char *
v16_bit_string(v16_t x);
char *
v32_bit_string(v32_t x);
char *
v64_bit_string(const v64_t *x);
char *
octet_hex_string(uint8_t x);
char *
v16_hex_string(v16_t x);
char *
v32_hex_string(v32_t x);
char *
v64_hex_string(const v64_t *x);
int
hex_char_to_nibble(uint8_t c);
int
is_hex_string(char *s);
v16_t
hex_string_to_v16(char *s);
v32_t
hex_string_to_v32(char *s);
v64_t
hex_string_to_v64(char *s);
/* the matrix A[] is stored in column format, i.e., A[i] is
the ith column of the matrix */
uint8_t
A_times_x_plus_b(uint8_t A[8], uint8_t x, uint8_t b);
void
v16_copy_octet_string(v16_t *x, const uint8_t s[2]);
void
v32_copy_octet_string(v32_t *x, const uint8_t s[4]);
void
v64_copy_octet_string(v64_t *x, const uint8_t s[8]);
void
v128_add(v128_t *z, v128_t *x, v128_t *y);
int
octet_string_is_eq(uint8_t *a, uint8_t *b, int len);
/*
* the matrix A[] is stored in column format, i.e., A[i] is the ith
* column of the matrix
*/