| Index: srtp/crypto/cipher/aes_icm.c
|
| diff --git a/srtp/crypto/cipher/aes_icm.c b/srtp/crypto/cipher/aes_icm.c
|
| index 1fcd6d83a2f7cbed11471e1dd44e49ba5253fa3a..3ce8c44466289f8bb176ac27048d5f86c43d0dfc 100644
|
| --- a/srtp/crypto/cipher/aes_icm.c
|
| +++ b/srtp/crypto/cipher/aes_icm.c
|
| @@ -9,7 +9,7 @@
|
|
|
| /*
|
| *
|
| - * Copyright (c) 2001-2006, Cisco Systems, Inc.
|
| + * Copyright (c) 2001-2006,2013 Cisco Systems, Inc.
|
| * All rights reserved.
|
| *
|
| * Redistribution and use in source and binary forms, with or without
|
| @@ -43,6 +43,9 @@
|
| *
|
| */
|
|
|
| +#ifdef HAVE_CONFIG_H
|
| + #include <config.h>
|
| +#endif
|
|
|
| #define ALIGN_32 0
|
|
|
| @@ -118,6 +121,17 @@ aes_icm_alloc_ismacryp(cipher_t **c, int key_len, int forIsmacryp) {
|
|
|
| /* set pointers */
|
| *c = (cipher_t *)pointer;
|
| + switch (key_len) {
|
| + case 46:
|
| + (*c)->algorithm = AES_256_ICM;
|
| + break;
|
| + case 38:
|
| + (*c)->algorithm = AES_192_ICM;
|
| + break;
|
| + default:
|
| + (*c)->algorithm = AES_128_ICM;
|
| + break;
|
| + }
|
| (*c)->type = &aes_icm;
|
| (*c)->state = pointer + sizeof(cipher_t);
|
|
|
| @@ -174,17 +188,18 @@ aes_icm_context_init(aes_icm_ctx_t *c, const uint8_t *key, int key_len) {
|
| else
|
| return err_status_bad_param;
|
|
|
| - /*
|
| + /*
|
| * set counter and initial values to 'offset' value, being careful not to
|
| - * go past the end of the key buffer.
|
| + * go past the end of the key buffer
|
| */
|
| v128_set_to_zero(&c->counter);
|
| v128_set_to_zero(&c->offset);
|
|
|
| - /* force last two octets of the offset to be left zero
|
| - * (for srtp compatibility) */
|
| copy_len = key_len - base_key_len;
|
| -
|
| + /* force last two octets of the offset to be left zero (for srtp compatibility) */
|
| + if (copy_len > 14)
|
| + copy_len = 14;
|
| +
|
| memcpy(&c->counter, key + base_key_len, copy_len);
|
| memcpy(&c->offset, key + base_key_len, copy_len);
|
|
|
| @@ -271,7 +286,7 @@ aes_icm_set_octet(aes_icm_ctx_t *c,
|
| */
|
|
|
| err_status_t
|
| -aes_icm_set_iv(aes_icm_ctx_t *c, void *iv) {
|
| +aes_icm_set_iv(aes_icm_ctx_t *c, void *iv, int direction) {
|
| v128_t *nonce = (v128_t *) iv;
|
|
|
| debug_print(mod_aes_icm,
|
| @@ -464,6 +479,10 @@ aes_icm_output(aes_icm_ctx_t *c, uint8_t *buffer, int num_octets_to_output) {
|
| return aes_icm_encrypt(c, buffer, &len);
|
| }
|
|
|
| +uint16_t
|
| +aes_icm_bytes_encrypted(aes_icm_ctx_t *c) {
|
| + return htons(c->counter.v16[7]);
|
| +}
|
|
|
| char
|
| aes_icm_description[] = "aes integer counter mode";
|
| @@ -502,6 +521,9 @@ cipher_test_case_t aes_icm_test_case_0 = {
|
| aes_icm_test_case_0_plaintext, /* plaintext */
|
| 32, /* octets in ciphertext */
|
| aes_icm_test_case_0_ciphertext, /* ciphertext */
|
| + 0,
|
| + NULL,
|
| + 0,
|
| NULL /* pointer to next testcase */
|
| };
|
|
|
| @@ -541,6 +563,9 @@ cipher_test_case_t aes_icm_test_case_1 = {
|
| aes_icm_test_case_1_plaintext, /* plaintext */
|
| 32, /* octets in ciphertext */
|
| aes_icm_test_case_1_ciphertext, /* ciphertext */
|
| + 0,
|
| + NULL,
|
| + 0,
|
| &aes_icm_test_case_0 /* pointer to next testcase */
|
| };
|
|
|
| @@ -554,9 +579,11 @@ cipher_type_t aes_icm = {
|
| (cipher_alloc_func_t) aes_icm_alloc,
|
| (cipher_dealloc_func_t) aes_icm_dealloc,
|
| (cipher_init_func_t) aes_icm_context_init,
|
| + (cipher_set_aad_func_t) 0,
|
| (cipher_encrypt_func_t) aes_icm_encrypt,
|
| (cipher_decrypt_func_t) aes_icm_encrypt,
|
| (cipher_set_iv_func_t) aes_icm_set_iv,
|
| + (cipher_get_tag_func_t) 0,
|
| (char *) aes_icm_description,
|
| (int) 0, /* instance count */
|
| (cipher_test_case_t *) &aes_icm_test_case_1,
|
|
|