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_ ...@@ -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 * Verify the key_len is valid for one of: AES-128/256
*/ */
if (key_len != SRTP_AES_128_GCM_KEYSIZE_WSALT && if (key_len != SRTP_AES_GCM_128_KEYSIZE_WSALT &&
key_len != SRTP_AES_256_GCM_KEYSIZE_WSALT) { key_len != SRTP_AES_GCM_256_KEYSIZE_WSALT) {
return (srtp_err_status_bad_param); 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_ ...@@ -131,15 +131,15 @@ static srtp_err_status_t srtp_aes_gcm_openssl_alloc (srtp_cipher_t **c, int key_
/* setup cipher attributes */ /* setup cipher attributes */
switch (key_len) { 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)->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->key_size = SRTP_AES_128_KEYSIZE;
gcm->tag_len = tlen; gcm->tag_len = tlen;
break; break;
case SRTP_AES_256_GCM_KEYSIZE_WSALT: case SRTP_AES_GCM_256_KEYSIZE_WSALT:
(*c)->type = &srtp_aes_gcm_256_openssl; (*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->key_size = SRTP_AES_256_KEYSIZE;
gcm->tag_len = tlen; gcm->tag_len = tlen;
break; break;
...@@ -386,7 +386,7 @@ static const char srtp_aes_gcm_256_openssl_description[] = "AES-256 GCM using op ...@@ -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 * values we're derived from independent test code
* using OpenSSL. * 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, 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 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] = { ...@@ -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 = { 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_key, /* key */
srtp_aes_gcm_test_case_0_iv, /* packet index */ srtp_aes_gcm_test_case_0_iv, /* packet index */
60, /* octets in plaintext */ 60, /* octets in plaintext */
...@@ -444,7 +444,7 @@ static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_0a = { ...@@ -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 = { 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_key, /* key */
srtp_aes_gcm_test_case_0_iv, /* packet index */ srtp_aes_gcm_test_case_0_iv, /* packet index */
60, /* octets in plaintext */ 60, /* octets in plaintext */
...@@ -457,7 +457,7 @@ static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_0 = { ...@@ -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 */ &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, 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
0xa5, 0x59, 0x09, 0xc5, 0x54, 0x66, 0x93, 0x1c, 0xa5, 0x59, 0x09, 0xc5, 0x54, 0x66, 0x93, 0x1c,
0xaf, 0xf5, 0x26, 0x9a, 0x21, 0xd5, 0x14, 0xb2, 0xaf, 0xf5, 0x26, 0x9a, 0x21, 0xd5, 0x14, 0xb2,
...@@ -504,7 +504,7 @@ static const uint8_t srtp_aes_gcm_test_case_1_ciphertext[76] = { ...@@ -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 = { 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_key, /* key */
srtp_aes_gcm_test_case_1_iv, /* packet index */ srtp_aes_gcm_test_case_1_iv, /* packet index */
60, /* octets in plaintext */ 60, /* octets in plaintext */
...@@ -518,7 +518,7 @@ static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_1a = { ...@@ -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 = { 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_key, /* key */
srtp_aes_gcm_test_case_1_iv, /* packet index */ srtp_aes_gcm_test_case_1_iv, /* packet index */
60, /* octets in plaintext */ 60, /* octets in plaintext */
...@@ -545,7 +545,7 @@ const srtp_cipher_type_t srtp_aes_gcm_128_openssl = { ...@@ -545,7 +545,7 @@ const srtp_cipher_type_t srtp_aes_gcm_128_openssl = {
srtp_aes_gcm_openssl_get_tag, srtp_aes_gcm_openssl_get_tag,
srtp_aes_gcm_128_openssl_description, srtp_aes_gcm_128_openssl_description,
&srtp_aes_gcm_test_case_0, &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 = { ...@@ -562,6 +562,6 @@ const srtp_cipher_type_t srtp_aes_gcm_256_openssl = {
srtp_aes_gcm_openssl_get_tag, srtp_aes_gcm_openssl_get_tag,
srtp_aes_gcm_256_openssl_description, srtp_aes_gcm_256_openssl_description,
&srtp_aes_gcm_test_case_1, &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 = { ...@@ -57,6 +57,8 @@ srtp_debug_module_t srtp_mod_aes_icm = {
0, /* debugging is off by default */ 0, /* debugging is off by default */
"aes icm" /* printable module name */ "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: * integer counter mode works as follows:
...@@ -94,7 +96,6 @@ srtp_debug_module_t srtp_mod_aes_icm = { ...@@ -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) 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; srtp_aes_icm_ctx_t *icm;
debug_print(srtp_mod_aes_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 ...@@ -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 * has not broken anything. Don't know what would be the
* effect of skipping this check for srtp in general. * 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; 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 ...@@ -126,17 +127,15 @@ static srtp_err_status_t srtp_aes_icm_alloc (srtp_cipher_t **c, int key_len, int
/* set pointers */ /* set pointers */
(*c)->state = icm; (*c)->state = icm;
(*c)->type = &srtp_aes_icm;
switch (key_len) { switch (key_len) {
case 46: case 46:
(*c)->algorithm = SRTP_AES_256_ICM; (*c)->algorithm = SRTP_AES_ICM_256;
break; (*c)->type = &srtp_aes_icm_256;
case 38:
(*c)->algorithm = SRTP_AES_192_ICM;
break; break;
default: default:
(*c)->algorithm = SRTP_AES_128_ICM; (*c)->algorithm = SRTP_AES_ICM_128;
(*c)->type = &srtp_aes_icm_128;
break; break;
} }
...@@ -402,49 +401,50 @@ static srtp_err_status_t srtp_aes_icm_encrypt (void *cv, ...@@ -402,49 +401,50 @@ static srtp_err_status_t srtp_aes_icm_encrypt (void *cv,
return srtp_err_status_ok; 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, 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd 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,
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,
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, 0xe0, 0x3e, 0xad, 0x09, 0x35, 0xc9, 0x5e, 0x80,
0xe1, 0x66, 0xb1, 0x6d, 0xd9, 0x2b, 0x4e, 0xb4, 0xe1, 0x66, 0xb1, 0x6d, 0xd9, 0x2b, 0x4e, 0xb4,
0xd2, 0x35, 0x13, 0x16, 0x2b, 0x02, 0xd0, 0xf7, 0xd2, 0x35, 0x13, 0x16, 0x2b, 0x02, 0xd0, 0xf7,
0x2a, 0x43, 0xa2, 0xfe, 0x4a, 0x5f, 0x97, 0xab 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 */ 30, /* octets in key */
srtp_aes_icm_test_case_0_key, /* key */ srtp_aes_icm_128_test_case_0_key, /* key */
srtp_aes_icm_test_case_0_nonce, /* packet index */ srtp_aes_icm_128_test_case_0_nonce, /* packet index */
32, /* octets in plaintext */ 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 */ 32, /* octets in ciphertext */
srtp_aes_icm_test_case_0_ciphertext, /* ciphertext */ srtp_aes_icm_128_test_case_0_ciphertext, /* ciphertext */
0, 0,
NULL, NULL,
0, 0,
NULL /* pointer to next testcase */ 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, 0x57, 0xf8, 0x2f, 0xe3, 0x61, 0x3f, 0xd1, 0x70,
0xa8, 0x5e, 0xc9, 0x3c, 0x40, 0xb1, 0xf0, 0x92, 0xa8, 0x5e, 0xc9, 0x3c, 0x40, 0xb1, 0xf0, 0x92,
0x2e, 0xc4, 0xcb, 0x0d, 0xc0, 0x25, 0xb5, 0x82, 0x2e, 0xc4, 0xcb, 0x0d, 0xc0, 0x25, 0xb5, 0x82,
...@@ -453,37 +453,37 @@ static const uint8_t srtp_aes_icm_test_case_1_key[46] = { ...@@ -453,37 +453,37 @@ static const uint8_t srtp_aes_icm_test_case_1_key[46] = {
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd 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,
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,
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, 0x92, 0xbd, 0xd2, 0x8a, 0x93, 0xc3, 0xf5, 0x25,
0x11, 0xc6, 0x77, 0xd0, 0x8b, 0x55, 0x15, 0xa4, 0x11, 0xc6, 0x77, 0xd0, 0x8b, 0x55, 0x15, 0xa4,
0x9d, 0xa7, 0x1b, 0x23, 0x78, 0xa8, 0x54, 0xf6, 0x9d, 0xa7, 0x1b, 0x23, 0x78, 0xa8, 0x54, 0xf6,
0x70, 0x50, 0x75, 0x6d, 0xed, 0x16, 0x5b, 0xac 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 */ 46, /* octets in key */
srtp_aes_icm_test_case_1_key, /* key */ srtp_aes_icm_256_test_case_0_key, /* key */
srtp_aes_icm_test_case_1_nonce, /* packet index */ srtp_aes_icm_256_test_case_0_nonce, /* packet index */
32, /* octets in plaintext */ 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 */ 32, /* octets in ciphertext */
srtp_aes_icm_test_case_1_ciphertext, /* ciphertext */ srtp_aes_icm_256_test_case_0_ciphertext, /* ciphertext */
0, 0,
NULL, NULL,
0, 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 = { ...@@ -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 * 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_alloc,
srtp_aes_icm_dealloc, srtp_aes_icm_dealloc,
srtp_aes_icm_context_init, srtp_aes_icm_context_init,
...@@ -501,8 +501,21 @@ const srtp_cipher_type_t srtp_aes_icm = { ...@@ -501,8 +501,21 @@ const srtp_cipher_type_t srtp_aes_icm = {
srtp_aes_icm_encrypt, srtp_aes_icm_encrypt,
srtp_aes_icm_set_iv, srtp_aes_icm_set_iv,
0, /* get_tag */ 0, /* get_tag */
srtp_aes_icm_description, srtp_aes_icm_128_description,
&srtp_aes_icm_test_case_1, &srtp_aes_icm_128_test_case_0,
SRTP_AES_ICM 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
};
This diff is collapsed.
...@@ -261,7 +261,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt ...@@ -261,7 +261,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
return status; 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", debug_print(srtp_mod_cipher, "IV: %s",
srtp_octet_string_hex_string(test_case->idx, 12)); 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 ...@@ -286,7 +286,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
return status; 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 * Get the GCM tag
*/ */
...@@ -361,7 +361,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt ...@@ -361,7 +361,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
return status; 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 * Set the AAD
*/ */
...@@ -491,7 +491,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt ...@@ -491,7 +491,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
return status; 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 * Set the AAD
*/ */
...@@ -512,7 +512,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt ...@@ -512,7 +512,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
srtp_cipher_dealloc(c); srtp_cipher_dealloc(c);
return status; 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 * Get the GCM tag
*/ */
...@@ -540,7 +540,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt ...@@ -540,7 +540,7 @@ srtp_err_status_t srtp_cipher_type_test (const srtp_cipher_type_t *ct, const srt
srtp_cipher_dealloc(c); srtp_cipher_dealloc(c);
return status; 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 * 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
*/
uint8_t
A_times_x_plus_b(uint8_t A[8], uint8_t x, uint8_t b);
#if 0
#if WORDS_BIGENDIAN
#define _v128_add(z, x, y) { \
uint64_t tmp; \
\
tmp = x->v32[3] + y->v32[3]; \
z->v32[3] = (uint32_t) tmp; \
\
tmp = x->v32[2] + y->v32[2] + (tmp >> 32); \
z->v32[2] = (uint32_t) tmp; \
\
tmp = x->v32[1] + y->v32[1] + (tmp >> 32); \
z->v32[1] = (uint32_t) tmp; \
\
tmp = x->v32[0] + y->v32[0] + (tmp >> 32); \
z->v32[0] = (uint32_t) tmp; \
}
#else /* assume little endian architecture */
#define _v128_add(z, x, y) { \
uint64_t tmp; \
\
tmp = htonl(x->v32[3]) + htonl(y->v32[3]); \
z->v32[3] = ntohl((uint32_t) tmp); \
\
tmp = htonl(x->v32[2]) + htonl(y->v32[2]) \
+ htonl(tmp >> 32); \
z->v32[2] = ntohl((uint32_t) tmp); \
\
tmp = htonl(x->v32[1]) + htonl(y->v32[1]) \
+ htonl(tmp >> 32); \
z->v32[1] = ntohl((uint32_t) tmp); \
\
tmp = htonl(x->v32[0]) + htonl(y->v32[0]) \
+ htonl(tmp >> 32); \
z->v32[0] = ntohl((uint32_t) tmp); \
}
#endif /* WORDS_BIGENDIAN */
#endif
#ifdef DATATYPES_USE_MACROS /* little functions are really macros */
#define v128_set_to_zero(z) _v128_set_to_zero(z)
#define v128_copy(z, x) _v128_copy(z, x)
#define v128_xor(z, x, y) _v128_xor(z, x, y)
#define v128_and(z, x, y) _v128_and(z, x, y)
#define v128_or(z, x, y) _v128_or(z, x, y)
#define v128_complement(x) _v128_complement(x)
#define v128_is_eq(x, y) _v128_is_eq(x, y)
#define v128_xor_eq(x, y) _v128_xor_eq(x, y)
#define v128_get_bit(x, i) _v128_get_bit(x, i)
#define v128_set_bit(x, i) _v128_set_bit(x, i)
#define v128_clear_bit(x, i) _v128_clear_bit(x, i)
#define v128_set_bit_to(x, i, y) _v128_set_bit_to(x, i, y)
#else
void
v128_set_to_zero(v128_t *x);
int
v128_is_eq(const v128_t *x, const v128_t *y);
void
v128_copy(v128_t *x, const v128_t *y);
void
v128_xor(v128_t *z, v128_t *x, v128_t *y);
void
v128_and(v128_t *z, v128_t *x, v128_t *y);
void
v128_or(v128_t *z, v128_t *x, v128_t *y);
void