aes_icm.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /*
  2. * aes_icm.c
  3. *
  4. * AES Integer Counter Mode
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. /*
  10. *
  11. * Copyright (c) 2001-2006,2013 Cisco Systems, Inc.
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *
  18. * Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. *
  21. * Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials provided
  24. * with the distribution.
  25. *
  26. * Neither the name of the Cisco Systems, Inc. nor the names of its
  27. * contributors may be used to endorse or promote products derived
  28. * from this software without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  33. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  34. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  35. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  36. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  37. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  41. * OF THE POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. */
  44. #define ALIGN_32 0
  45. #include "aes_icm.h"
  46. #include "alloc.h"
  47. debug_module_t mod_aes_icm = {
  48. 0, /* debugging is off by default */
  49. "aes icm" /* printable module name */
  50. };
  51. /*
  52. * integer counter mode works as follows:
  53. *
  54. * 16 bits
  55. * <----->
  56. * +------+------+------+------+------+------+------+------+
  57. * | nonce | pakcet index | ctr |---+
  58. * +------+------+------+------+------+------+------+------+ |
  59. * |
  60. * +------+------+------+------+------+------+------+------+ v
  61. * | salt |000000|->(+)
  62. * +------+------+------+------+------+------+------+------+ |
  63. * |
  64. * +---------+
  65. * | encrypt |
  66. * +---------+
  67. * |
  68. * +------+------+------+------+------+------+------+------+ |
  69. * | keystream block |<--+
  70. * +------+------+------+------+------+------+------+------+
  71. *
  72. * All fields are big-endian
  73. *
  74. * ctr is the block counter, which increments from zero for
  75. * each packet (16 bits wide)
  76. *
  77. * packet index is distinct for each packet (48 bits wide)
  78. *
  79. * nonce can be distinct across many uses of the same key, or
  80. * can be a fixed value per key, or can be per-packet randomness
  81. * (64 bits)
  82. *
  83. */
  84. err_status_t
  85. aes_icm_alloc_ismacryp(cipher_t **c, int key_len, int forIsmacryp) {
  86. extern cipher_type_t aes_icm;
  87. uint8_t *pointer;
  88. int tmp;
  89. debug_print(mod_aes_icm,
  90. "allocating cipher with key length %d", key_len);
  91. /*
  92. * Ismacryp, for example, uses 16 byte key + 8 byte
  93. * salt so this function is called with key_len = 24.
  94. * The check for key_len = 30/38/46 does not apply. Our usage
  95. * of aes functions with key_len = values other than 30
  96. * has not broken anything. Don't know what would be the
  97. * effect of skipping this check for srtp in general.
  98. */
  99. if (!(forIsmacryp && key_len > 16 && key_len < 30) &&
  100. key_len != 30 && key_len != 38 && key_len != 46)
  101. return err_status_bad_param;
  102. /* allocate memory a cipher of type aes_icm */
  103. tmp = (sizeof(aes_icm_ctx_t) + sizeof(cipher_t));
  104. pointer = (uint8_t*)crypto_alloc(tmp);
  105. if (pointer == NULL)
  106. return err_status_alloc_fail;
  107. /* set pointers */
  108. *c = (cipher_t *)pointer;
  109. switch (key_len) {
  110. case 46:
  111. (*c)->algorithm = AES_256_ICM;
  112. break;
  113. case 38:
  114. (*c)->algorithm = AES_192_ICM;
  115. break;
  116. default:
  117. (*c)->algorithm = AES_128_ICM;
  118. break;
  119. }
  120. (*c)->type = &aes_icm;
  121. (*c)->state = pointer + sizeof(cipher_t);
  122. /* increment ref_count */
  123. aes_icm.ref_count++;
  124. /* set key size */
  125. (*c)->key_len = key_len;
  126. return err_status_ok;
  127. }
  128. err_status_t aes_icm_alloc(cipher_t **c, int key_len, int forIsmacryp) {
  129. return aes_icm_alloc_ismacryp(c, key_len, 0);
  130. }
  131. err_status_t
  132. aes_icm_dealloc(cipher_t *c) {
  133. extern cipher_type_t aes_icm;
  134. /* zeroize entire state*/
  135. octet_string_set_to_zero((uint8_t *)c,
  136. sizeof(aes_icm_ctx_t) + sizeof(cipher_t));
  137. /* free memory */
  138. crypto_free(c);
  139. /* decrement ref_count */
  140. aes_icm.ref_count--;
  141. return err_status_ok;
  142. }
  143. /*
  144. * aes_icm_context_init(...) initializes the aes_icm_context
  145. * using the value in key[].
  146. *
  147. * the key is the secret key
  148. *
  149. * the salt is unpredictable (but not necessarily secret) data which
  150. * randomizes the starting point in the keystream
  151. */
  152. err_status_t
  153. aes_icm_context_init(aes_icm_ctx_t *c, const uint8_t *key, int key_len) {
  154. err_status_t status;
  155. int base_key_len, copy_len;
  156. if (key_len > 16 && key_len < 30) /* Ismacryp */
  157. base_key_len = 16;
  158. else if (key_len == 30 || key_len == 38 || key_len == 46)
  159. base_key_len = key_len - 14;
  160. else
  161. return err_status_bad_param;
  162. /*
  163. * set counter and initial values to 'offset' value, being careful not to
  164. * go past the end of the key buffer
  165. */
  166. v128_set_to_zero(&c->counter);
  167. v128_set_to_zero(&c->offset);
  168. copy_len = key_len - base_key_len;
  169. /* force last two octets of the offset to be left zero (for srtp compatibility) */
  170. if (copy_len > 14)
  171. copy_len = 14;
  172. memcpy(&c->counter, key + base_key_len, copy_len);
  173. memcpy(&c->offset, key + base_key_len, copy_len);
  174. debug_print(mod_aes_icm,
  175. "key: %s", octet_string_hex_string(key, base_key_len));
  176. debug_print(mod_aes_icm,
  177. "offset: %s", v128_hex_string(&c->offset));
  178. /* expand key */
  179. status = aes_expand_encryption_key(key, base_key_len, &c->expanded_key);
  180. if (status) {
  181. v128_set_to_zero(&c->counter);
  182. v128_set_to_zero(&c->offset);
  183. return status;
  184. }
  185. /* indicate that the keystream_buffer is empty */
  186. c->bytes_in_buffer = 0;
  187. return err_status_ok;
  188. }
  189. /*
  190. * aes_icm_set_octet(c, i) sets the counter of the context which it is
  191. * passed so that the next octet of keystream that will be generated
  192. * is the ith octet
  193. */
  194. err_status_t
  195. aes_icm_set_octet(aes_icm_ctx_t *c,
  196. uint64_t octet_num) {
  197. #ifdef NO_64BIT_MATH
  198. int tail_num = low32(octet_num) & 0x0f;
  199. /* 64-bit right-shift 4 */
  200. uint64_t block_num = make64(high32(octet_num) >> 4,
  201. ((high32(octet_num) & 0x0f)<<(32-4)) |
  202. (low32(octet_num) >> 4));
  203. #else
  204. int tail_num = (int)(octet_num % 16);
  205. uint64_t block_num = octet_num / 16;
  206. #endif
  207. /* set counter value */
  208. /* FIX - There's no way this is correct */
  209. c->counter.v64[0] = c->offset.v64[0];
  210. #ifdef NO_64BIT_MATH
  211. c->counter.v64[0] = make64(high32(c->offset.v64[0]) ^ high32(block_num),
  212. low32(c->offset.v64[0]) ^ low32(block_num));
  213. #else
  214. c->counter.v64[0] = c->offset.v64[0] ^ block_num;
  215. #endif
  216. debug_print(mod_aes_icm,
  217. "set_octet: %s", v128_hex_string(&c->counter));
  218. /* fill keystream buffer, if needed */
  219. if (tail_num) {
  220. v128_copy(&c->keystream_buffer, &c->counter);
  221. aes_encrypt(&c->keystream_buffer, &c->expanded_key);
  222. c->bytes_in_buffer = sizeof(v128_t);
  223. debug_print(mod_aes_icm, "counter: %s",
  224. v128_hex_string(&c->counter));
  225. debug_print(mod_aes_icm, "ciphertext: %s",
  226. v128_hex_string(&c->keystream_buffer));
  227. /* indicate number of bytes in keystream_buffer */
  228. c->bytes_in_buffer = sizeof(v128_t) - tail_num;
  229. } else {
  230. /* indicate that keystream_buffer is empty */
  231. c->bytes_in_buffer = 0;
  232. }
  233. return err_status_ok;
  234. }
  235. /*
  236. * aes_icm_set_iv(c, iv) sets the counter value to the exor of iv with
  237. * the offset
  238. */
  239. err_status_t
  240. aes_icm_set_iv(aes_icm_ctx_t *c, void *iv, int direction) {
  241. v128_t nonce;
  242. /* set nonce (for alignment) */
  243. v128_copy_octet_string(&nonce, iv);
  244. debug_print(mod_aes_icm,
  245. "setting iv: %s", v128_hex_string(&nonce));
  246. v128_xor(&c->counter, &c->offset, &nonce);
  247. debug_print(mod_aes_icm,
  248. "set_counter: %s", v128_hex_string(&c->counter));
  249. /* indicate that the keystream_buffer is empty */
  250. c->bytes_in_buffer = 0;
  251. return err_status_ok;
  252. }
  253. /*
  254. * aes_icm_advance(...) refills the keystream_buffer and
  255. * advances the block index of the sicm_context forward by one
  256. *
  257. * this is an internal, hopefully inlined function
  258. */
  259. static inline void
  260. aes_icm_advance_ismacryp(aes_icm_ctx_t *c, uint8_t forIsmacryp) {
  261. /* fill buffer with new keystream */
  262. v128_copy(&c->keystream_buffer, &c->counter);
  263. aes_encrypt(&c->keystream_buffer, &c->expanded_key);
  264. c->bytes_in_buffer = sizeof(v128_t);
  265. debug_print(mod_aes_icm, "counter: %s",
  266. v128_hex_string(&c->counter));
  267. debug_print(mod_aes_icm, "ciphertext: %s",
  268. v128_hex_string(&c->keystream_buffer));
  269. /* clock counter forward */
  270. if (forIsmacryp) {
  271. uint32_t temp;
  272. //alex's clock counter forward
  273. temp = ntohl(c->counter.v32[3]);
  274. c->counter.v32[3] = htonl(++temp);
  275. } else {
  276. if (!++(c->counter.v8[15]))
  277. ++(c->counter.v8[14]);
  278. }
  279. }
  280. static inline void aes_icm_advance(aes_icm_ctx_t *c) {
  281. aes_icm_advance_ismacryp(c, 0);
  282. }
  283. /*e
  284. * icm_encrypt deals with the following cases:
  285. *
  286. * bytes_to_encr < bytes_in_buffer
  287. * - add keystream into data
  288. *
  289. * bytes_to_encr > bytes_in_buffer
  290. * - add keystream into data until keystream_buffer is depleted
  291. * - loop over blocks, filling keystream_buffer and then
  292. * adding keystream into data
  293. * - fill buffer then add in remaining (< 16) bytes of keystream
  294. */
  295. err_status_t
  296. aes_icm_encrypt_ismacryp(aes_icm_ctx_t *c,
  297. unsigned char *buf, unsigned int *enc_len,
  298. int forIsmacryp) {
  299. unsigned int bytes_to_encr = *enc_len;
  300. unsigned int i;
  301. uint32_t *b;
  302. /* check that there's enough segment left but not for ismacryp*/
  303. if (!forIsmacryp && (bytes_to_encr + htons(c->counter.v16[7])) > 0xffff)
  304. return err_status_terminus;
  305. debug_print(mod_aes_icm, "block index: %d",
  306. htons(c->counter.v16[7]));
  307. if (bytes_to_encr <= (unsigned int)c->bytes_in_buffer) {
  308. /* deal with odd case of small bytes_to_encr */
  309. for (i = (sizeof(v128_t) - c->bytes_in_buffer);
  310. i < (sizeof(v128_t) - c->bytes_in_buffer + bytes_to_encr); i++)
  311. {
  312. *buf++ ^= c->keystream_buffer.v8[i];
  313. }
  314. c->bytes_in_buffer -= bytes_to_encr;
  315. /* return now to avoid the main loop */
  316. return err_status_ok;
  317. } else {
  318. /* encrypt bytes until the remaining data is 16-byte aligned */
  319. for (i=(sizeof(v128_t) - c->bytes_in_buffer); i < sizeof(v128_t); i++)
  320. *buf++ ^= c->keystream_buffer.v8[i];
  321. bytes_to_encr -= c->bytes_in_buffer;
  322. c->bytes_in_buffer = 0;
  323. }
  324. /* now loop over entire 16-byte blocks of keystream */
  325. for (i=0; i < (bytes_to_encr/sizeof(v128_t)); i++) {
  326. /* fill buffer with new keystream */
  327. aes_icm_advance_ismacryp(c, forIsmacryp);
  328. /*
  329. * add keystream into the data buffer (this would be a lot faster
  330. * if we could assume 32-bit alignment!)
  331. */
  332. #if ALIGN_32
  333. b = (uint32_t *)buf;
  334. *b++ ^= c->keystream_buffer.v32[0];
  335. *b++ ^= c->keystream_buffer.v32[1];
  336. *b++ ^= c->keystream_buffer.v32[2];
  337. *b++ ^= c->keystream_buffer.v32[3];
  338. buf = (uint8_t *)b;
  339. #else
  340. if ((((unsigned long) buf) & 0x03) != 0) {
  341. *buf++ ^= c->keystream_buffer.v8[0];
  342. *buf++ ^= c->keystream_buffer.v8[1];
  343. *buf++ ^= c->keystream_buffer.v8[2];
  344. *buf++ ^= c->keystream_buffer.v8[3];
  345. *buf++ ^= c->keystream_buffer.v8[4];
  346. *buf++ ^= c->keystream_buffer.v8[5];
  347. *buf++ ^= c->keystream_buffer.v8[6];
  348. *buf++ ^= c->keystream_buffer.v8[7];
  349. *buf++ ^= c->keystream_buffer.v8[8];
  350. *buf++ ^= c->keystream_buffer.v8[9];
  351. *buf++ ^= c->keystream_buffer.v8[10];
  352. *buf++ ^= c->keystream_buffer.v8[11];
  353. *buf++ ^= c->keystream_buffer.v8[12];
  354. *buf++ ^= c->keystream_buffer.v8[13];
  355. *buf++ ^= c->keystream_buffer.v8[14];
  356. *buf++ ^= c->keystream_buffer.v8[15];
  357. } else {
  358. b = (uint32_t *)buf;
  359. *b++ ^= c->keystream_buffer.v32[0];
  360. *b++ ^= c->keystream_buffer.v32[1];
  361. *b++ ^= c->keystream_buffer.v32[2];
  362. *b++ ^= c->keystream_buffer.v32[3];
  363. buf = (uint8_t *)b;
  364. }
  365. #endif /* #if ALIGN_32 */
  366. }
  367. /* if there is a tail end of the data, process it */
  368. if ((bytes_to_encr & 0xf) != 0) {
  369. /* fill buffer with new keystream */
  370. aes_icm_advance_ismacryp(c, forIsmacryp);
  371. for (i=0; i < (bytes_to_encr & 0xf); i++)
  372. *buf++ ^= c->keystream_buffer.v8[i];
  373. /* reset the keystream buffer size to right value */
  374. c->bytes_in_buffer = sizeof(v128_t) - i;
  375. } else {
  376. /* no tail, so just reset the keystream buffer size to zero */
  377. c->bytes_in_buffer = 0;
  378. }
  379. return err_status_ok;
  380. }
  381. err_status_t
  382. aes_icm_encrypt(aes_icm_ctx_t *c, unsigned char *buf, unsigned int *enc_len) {
  383. return aes_icm_encrypt_ismacryp(c, buf, enc_len, 0);
  384. }
  385. err_status_t
  386. aes_icm_output(aes_icm_ctx_t *c, uint8_t *buffer, int num_octets_to_output) {
  387. unsigned int len = num_octets_to_output;
  388. /* zeroize the buffer */
  389. octet_string_set_to_zero(buffer, num_octets_to_output);
  390. /* exor keystream into buffer */
  391. return aes_icm_encrypt(c, buffer, &len);
  392. }
  393. uint16_t
  394. aes_icm_bytes_encrypted(aes_icm_ctx_t *c) {
  395. return htons(c->counter.v16[7]);
  396. }
  397. char
  398. aes_icm_description[] = "aes integer counter mode";
  399. uint8_t aes_icm_test_case_0_key[30] = {
  400. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  401. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
  402. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  403. 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
  404. };
  405. uint8_t aes_icm_test_case_0_nonce[16] = {
  406. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  407. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  408. };
  409. uint8_t aes_icm_test_case_0_plaintext[32] = {
  410. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  411. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  412. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  413. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  414. };
  415. uint8_t aes_icm_test_case_0_ciphertext[32] = {
  416. 0xe0, 0x3e, 0xad, 0x09, 0x35, 0xc9, 0x5e, 0x80,
  417. 0xe1, 0x66, 0xb1, 0x6d, 0xd9, 0x2b, 0x4e, 0xb4,
  418. 0xd2, 0x35, 0x13, 0x16, 0x2b, 0x02, 0xd0, 0xf7,
  419. 0x2a, 0x43, 0xa2, 0xfe, 0x4a, 0x5f, 0x97, 0xab
  420. };
  421. cipher_test_case_t aes_icm_test_case_0 = {
  422. 30, /* octets in key */
  423. aes_icm_test_case_0_key, /* key */
  424. aes_icm_test_case_0_nonce, /* packet index */
  425. 32, /* octets in plaintext */
  426. aes_icm_test_case_0_plaintext, /* plaintext */
  427. 32, /* octets in ciphertext */
  428. aes_icm_test_case_0_ciphertext, /* ciphertext */
  429. 0,
  430. NULL,
  431. 0,
  432. NULL /* pointer to next testcase */
  433. };
  434. uint8_t aes_icm_test_case_1_key[46] = {
  435. 0x57, 0xf8, 0x2f, 0xe3, 0x61, 0x3f, 0xd1, 0x70,
  436. 0xa8, 0x5e, 0xc9, 0x3c, 0x40, 0xb1, 0xf0, 0x92,
  437. 0x2e, 0xc4, 0xcb, 0x0d, 0xc0, 0x25, 0xb5, 0x82,
  438. 0x72, 0x14, 0x7c, 0xc4, 0x38, 0x94, 0x4a, 0x98,
  439. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  440. 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
  441. };
  442. uint8_t aes_icm_test_case_1_nonce[16] = {
  443. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  444. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  445. };
  446. uint8_t aes_icm_test_case_1_plaintext[32] = {
  447. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  448. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  449. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  450. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  451. };
  452. uint8_t aes_icm_test_case_1_ciphertext[32] = {
  453. 0x92, 0xbd, 0xd2, 0x8a, 0x93, 0xc3, 0xf5, 0x25,
  454. 0x11, 0xc6, 0x77, 0xd0, 0x8b, 0x55, 0x15, 0xa4,
  455. 0x9d, 0xa7, 0x1b, 0x23, 0x78, 0xa8, 0x54, 0xf6,
  456. 0x70, 0x50, 0x75, 0x6d, 0xed, 0x16, 0x5b, 0xac
  457. };
  458. cipher_test_case_t aes_icm_test_case_1 = {
  459. 46, /* octets in key */
  460. aes_icm_test_case_1_key, /* key */
  461. aes_icm_test_case_1_nonce, /* packet index */
  462. 32, /* octets in plaintext */
  463. aes_icm_test_case_1_plaintext, /* plaintext */
  464. 32, /* octets in ciphertext */
  465. aes_icm_test_case_1_ciphertext, /* ciphertext */
  466. 0,
  467. NULL,
  468. 0,
  469. &aes_icm_test_case_0 /* pointer to next testcase */
  470. };
  471. /*
  472. * note: the encrypt function is identical to the decrypt function
  473. */
  474. cipher_type_t aes_icm = {
  475. (cipher_alloc_func_t) aes_icm_alloc,
  476. (cipher_dealloc_func_t) aes_icm_dealloc,
  477. (cipher_init_func_t) aes_icm_context_init,
  478. (cipher_set_aad_func_t) 0,
  479. (cipher_encrypt_func_t) aes_icm_encrypt,
  480. (cipher_decrypt_func_t) aes_icm_encrypt,
  481. (cipher_set_iv_func_t) aes_icm_set_iv,
  482. (cipher_get_tag_func_t) 0,
  483. (char *) aes_icm_description,
  484. (int) 0, /* instance count */
  485. (cipher_test_case_t *) &aes_icm_test_case_1,
  486. (debug_module_t *) &mod_aes_icm,
  487. (cipher_type_id_t) AES_ICM
  488. };