aes_cbc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /*
  2. * aes_cbc.c
  3. *
  4. * AES Cipher Block Chaining Mode
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. /*
  10. *
  11. * Copyright (c) 2001-2006, 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. #include "aes_cbc.h"
  45. #include "alloc.h"
  46. debug_module_t mod_aes_cbc = {
  47. 0, /* debugging is off by default */
  48. "aes cbc" /* printable module name */
  49. };
  50. err_status_t
  51. aes_cbc_alloc(cipher_t **c, int key_len, int tlen) {
  52. extern cipher_type_t aes_cbc;
  53. uint8_t *pointer;
  54. int tmp;
  55. debug_print(mod_aes_cbc,
  56. "allocating cipher with key length %d", key_len);
  57. if (key_len != 16 && key_len != 24 && key_len != 32)
  58. return err_status_bad_param;
  59. /* allocate memory a cipher of type aes_cbc */
  60. tmp = (sizeof(aes_cbc_ctx_t) + sizeof(cipher_t));
  61. pointer = (uint8_t*)crypto_alloc(tmp);
  62. if (pointer == NULL)
  63. return err_status_alloc_fail;
  64. /* set pointers */
  65. *c = (cipher_t *)pointer;
  66. (*c)->type = &aes_cbc;
  67. (*c)->state = pointer + sizeof(cipher_t);
  68. /* increment ref_count */
  69. aes_cbc.ref_count++;
  70. /* set key size */
  71. (*c)->key_len = key_len;
  72. return err_status_ok;
  73. }
  74. err_status_t
  75. aes_cbc_dealloc(cipher_t *c) {
  76. extern cipher_type_t aes_cbc;
  77. /* zeroize entire state*/
  78. octet_string_set_to_zero((uint8_t *)c,
  79. sizeof(aes_cbc_ctx_t) + sizeof(cipher_t));
  80. /* free memory */
  81. crypto_free(c);
  82. /* decrement ref_count */
  83. aes_cbc.ref_count--;
  84. return err_status_ok;
  85. }
  86. err_status_t
  87. aes_cbc_context_init(aes_cbc_ctx_t *c, const uint8_t *key, int key_len) {
  88. debug_print(mod_aes_cbc,
  89. "key: %s", octet_string_hex_string(key, key_len));
  90. /*
  91. * Save the key until we have the IV later. We don't
  92. * know the direction until the IV is set.
  93. */
  94. c->key_len = (key_len <= 32 ? key_len : 32);
  95. memcpy(c->key, key, c->key_len);
  96. return err_status_ok;
  97. }
  98. err_status_t
  99. aes_cbc_set_iv(aes_cbc_ctx_t *c, void *iv, int direction) {
  100. err_status_t status;
  101. int i;
  102. /* v128_t *input = iv; */
  103. uint8_t *input = (uint8_t*) iv;
  104. /* set state and 'previous' block to iv */
  105. for (i=0; i < 16; i++)
  106. c->previous.v8[i] = c->state.v8[i] = input[i];
  107. debug_print(mod_aes_cbc, "setting iv: %s", v128_hex_string(&c->state));
  108. /* expand key for the appropriate direction */
  109. switch (direction) {
  110. case (direction_encrypt):
  111. status = aes_expand_encryption_key(c->key, c->key_len, &c->expanded_key);
  112. memset(c->key, 0, 32);
  113. if (status)
  114. return status;
  115. break;
  116. case (direction_decrypt):
  117. status = aes_expand_decryption_key(c->key, c->key_len, &c->expanded_key);
  118. memset(c->key, 0, 32);
  119. if (status)
  120. return status;
  121. break;
  122. default:
  123. return err_status_bad_param;
  124. }
  125. return err_status_ok;
  126. }
  127. err_status_t
  128. aes_cbc_encrypt(aes_cbc_ctx_t *c,
  129. unsigned char *data,
  130. unsigned int *bytes_in_data) {
  131. int i;
  132. unsigned char *input = data; /* pointer to data being read */
  133. unsigned char *output = data; /* pointer to data being written */
  134. int bytes_to_encr = *bytes_in_data;
  135. /*
  136. * verify that we're 16-octet aligned
  137. */
  138. if (*bytes_in_data & 0xf)
  139. return err_status_bad_param;
  140. /*
  141. * note that we assume that the initialization vector has already
  142. * been set, e.g. by calling aes_cbc_set_iv()
  143. */
  144. debug_print(mod_aes_cbc, "iv: %s",
  145. v128_hex_string(&c->state));
  146. /*
  147. * loop over plaintext blocks, exoring state into plaintext then
  148. * encrypting and writing to output
  149. */
  150. while (bytes_to_encr > 0) {
  151. /* exor plaintext into state */
  152. for (i=0; i < 16; i++)
  153. c->state.v8[i] ^= *input++;
  154. debug_print(mod_aes_cbc, "inblock: %s",
  155. v128_hex_string(&c->state));
  156. aes_encrypt(&c->state, &c->expanded_key);
  157. debug_print(mod_aes_cbc, "outblock: %s",
  158. v128_hex_string(&c->state));
  159. /* copy ciphertext to output */
  160. for (i=0; i < 16; i++)
  161. *output++ = c->state.v8[i];
  162. bytes_to_encr -= 16;
  163. }
  164. return err_status_ok;
  165. }
  166. err_status_t
  167. aes_cbc_decrypt(aes_cbc_ctx_t *c,
  168. unsigned char *data,
  169. unsigned int *bytes_in_data) {
  170. int i;
  171. v128_t state, previous;
  172. unsigned char *input = data; /* pointer to data being read */
  173. unsigned char *output = data; /* pointer to data being written */
  174. int bytes_to_encr = *bytes_in_data;
  175. uint8_t tmp;
  176. /*
  177. * verify that we're 16-octet aligned
  178. */
  179. if (*bytes_in_data & 0x0f)
  180. return err_status_bad_param;
  181. /* set 'previous' block to iv*/
  182. for (i=0; i < 16; i++) {
  183. previous.v8[i] = c->previous.v8[i];
  184. }
  185. debug_print(mod_aes_cbc, "iv: %s",
  186. v128_hex_string(&previous));
  187. /*
  188. * loop over ciphertext blocks, decrypting then exoring with state
  189. * then writing plaintext to output
  190. */
  191. while (bytes_to_encr > 0) {
  192. /* set state to ciphertext input block */
  193. for (i=0; i < 16; i++) {
  194. state.v8[i] = *input++;
  195. }
  196. debug_print(mod_aes_cbc, "inblock: %s",
  197. v128_hex_string(&state));
  198. /* decrypt state */
  199. aes_decrypt(&state, &c->expanded_key);
  200. debug_print(mod_aes_cbc, "outblock: %s",
  201. v128_hex_string(&state));
  202. /*
  203. * exor previous ciphertext block out of plaintext, and write new
  204. * plaintext block to output, while copying old ciphertext block
  205. * to the 'previous' block
  206. */
  207. for (i=0; i < 16; i++) {
  208. tmp = *output;
  209. *output++ = state.v8[i] ^ previous.v8[i];
  210. previous.v8[i] = tmp;
  211. }
  212. bytes_to_encr -= 16;
  213. }
  214. return err_status_ok;
  215. }
  216. err_status_t
  217. aes_cbc_nist_encrypt(aes_cbc_ctx_t *c,
  218. unsigned char *data,
  219. unsigned int *bytes_in_data) {
  220. int i;
  221. unsigned char *pad_start;
  222. int num_pad_bytes;
  223. err_status_t status;
  224. /*
  225. * determine the number of padding bytes that we need to add -
  226. * this value is always between 1 and 16, inclusive.
  227. */
  228. num_pad_bytes = 16 - (*bytes_in_data & 0xf);
  229. pad_start = data;
  230. pad_start += *bytes_in_data;
  231. *pad_start++ = 0xa0;
  232. for (i=0; i < num_pad_bytes; i++)
  233. *pad_start++ = 0x00;
  234. /*
  235. * increment the data size
  236. */
  237. *bytes_in_data += num_pad_bytes;
  238. /*
  239. * now cbc encrypt the padded data
  240. */
  241. status = aes_cbc_encrypt(c, data, bytes_in_data);
  242. if (status)
  243. return status;
  244. return err_status_ok;
  245. }
  246. err_status_t
  247. aes_cbc_nist_decrypt(aes_cbc_ctx_t *c,
  248. unsigned char *data,
  249. unsigned int *bytes_in_data) {
  250. unsigned char *pad_end;
  251. int num_pad_bytes;
  252. err_status_t status;
  253. /*
  254. * cbc decrypt the padded data
  255. */
  256. status = aes_cbc_decrypt(c, data, bytes_in_data);
  257. if (status)
  258. return status;
  259. /*
  260. * determine the number of padding bytes in the decrypted plaintext
  261. * - this value is always between 1 and 16, inclusive.
  262. */
  263. num_pad_bytes = 1;
  264. pad_end = data + (*bytes_in_data - 1);
  265. while (*pad_end != 0xa0) { /* note: should check padding correctness */
  266. pad_end--;
  267. num_pad_bytes++;
  268. }
  269. /* decrement data size */
  270. *bytes_in_data -= num_pad_bytes;
  271. return err_status_ok;
  272. }
  273. char
  274. aes_cbc_description[] = "aes cipher block chaining (cbc) mode";
  275. /*
  276. * Test case 0 is derived from FIPS 197 Appendix C; it uses an
  277. * all-zero IV, so that the first block encryption matches the test
  278. * case in that appendix. This property provides a check of the base
  279. * AES encryption and decryption algorithms; if CBC fails on some
  280. * particular platform, then you should print out AES intermediate
  281. * data and compare with the detailed info provided in that appendix.
  282. *
  283. */
  284. uint8_t aes_cbc_test_case_0_key[16] = {
  285. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  286. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  287. };
  288. uint8_t aes_cbc_test_case_0_plaintext[64] = {
  289. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  290. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  291. };
  292. uint8_t aes_cbc_test_case_0_ciphertext[80] = {
  293. 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30,
  294. 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a,
  295. 0x03, 0x35, 0xed, 0x27, 0x67, 0xf2, 0x6d, 0xf1,
  296. 0x64, 0x83, 0x2e, 0x23, 0x44, 0x38, 0x70, 0x8b
  297. };
  298. uint8_t aes_cbc_test_case_0_iv[16] = {
  299. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  300. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  301. };
  302. cipher_test_case_t aes_cbc_test_case_0 = {
  303. 16, /* octets in key */
  304. aes_cbc_test_case_0_key, /* key */
  305. aes_cbc_test_case_0_iv, /* initialization vector */
  306. 16, /* octets in plaintext */
  307. aes_cbc_test_case_0_plaintext, /* plaintext */
  308. 32, /* octets in ciphertext */
  309. aes_cbc_test_case_0_ciphertext, /* ciphertext */
  310. 0,
  311. NULL,
  312. 0,
  313. NULL /* pointer to next testcase */
  314. };
  315. /*
  316. * this test case is taken directly from Appendix F.2 of NIST Special
  317. * Publication SP 800-38A
  318. */
  319. uint8_t aes_cbc_test_case_1_key[16] = {
  320. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  321. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
  322. };
  323. uint8_t aes_cbc_test_case_1_plaintext[64] = {
  324. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  325. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  326. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  327. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
  328. 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
  329. 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
  330. 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
  331. 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
  332. };
  333. uint8_t aes_cbc_test_case_1_ciphertext[80] = {
  334. 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
  335. 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
  336. 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
  337. 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
  338. 0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b,
  339. 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
  340. 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09,
  341. 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7,
  342. 0x39, 0x34, 0x07, 0x03, 0x36, 0xd0, 0x77, 0x99,
  343. 0xe0, 0xc4, 0x2f, 0xdd, 0xa8, 0xdf, 0x4c, 0xa3
  344. };
  345. uint8_t aes_cbc_test_case_1_iv[16] = {
  346. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  347. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  348. };
  349. cipher_test_case_t aes_cbc_test_case_1 = {
  350. 16, /* octets in key */
  351. aes_cbc_test_case_1_key, /* key */
  352. aes_cbc_test_case_1_iv, /* initialization vector */
  353. 64, /* octets in plaintext */
  354. aes_cbc_test_case_1_plaintext, /* plaintext */
  355. 80, /* octets in ciphertext */
  356. aes_cbc_test_case_1_ciphertext, /* ciphertext */
  357. 0,
  358. NULL,
  359. 0,
  360. &aes_cbc_test_case_0 /* pointer to next testcase */
  361. };
  362. /*
  363. * Test case 2 is like test case 0, but for 256-bit keys. (FIPS 197
  364. * appendix C.3).
  365. */
  366. uint8_t aes_cbc_test_case_2_key[32] = {
  367. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  368. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  369. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  370. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  371. };
  372. uint8_t aes_cbc_test_case_2_plaintext[64] = {
  373. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  374. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  375. };
  376. uint8_t aes_cbc_test_case_2_ciphertext[80] = {
  377. 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf,
  378. 0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89,
  379. 0x72, 0x72, 0x6e, 0xe7, 0x71, 0x39, 0xbf, 0x11,
  380. 0xe5, 0x40, 0xe2, 0x7c, 0x54, 0x65, 0x1d, 0xee
  381. };
  382. uint8_t aes_cbc_test_case_2_iv[16] = {
  383. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  384. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  385. };
  386. cipher_test_case_t aes_cbc_test_case_2 = {
  387. 32, /* octets in key */
  388. aes_cbc_test_case_2_key, /* key */
  389. aes_cbc_test_case_2_iv, /* initialization vector */
  390. 16, /* octets in plaintext */
  391. aes_cbc_test_case_2_plaintext, /* plaintext */
  392. 32, /* octets in ciphertext */
  393. aes_cbc_test_case_2_ciphertext, /* ciphertext */
  394. 0,
  395. NULL,
  396. 0,
  397. &aes_cbc_test_case_1 /* pointer to next testcase */
  398. };
  399. /*
  400. * this test case is taken directly from Appendix F.2 of NIST Special
  401. * Publication SP 800-38A
  402. */
  403. uint8_t aes_cbc_test_case_3_key[32] = {
  404. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  405. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  406. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  407. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  408. };
  409. uint8_t aes_cbc_test_case_3_plaintext[64] = {
  410. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  411. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  412. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  413. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
  414. 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
  415. 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
  416. 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
  417. 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
  418. };
  419. uint8_t aes_cbc_test_case_3_ciphertext[80] = {
  420. 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba,
  421. 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6,
  422. 0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d,
  423. 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d,
  424. 0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf,
  425. 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61,
  426. 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc,
  427. 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b,
  428. 0xfb, 0x98, 0x20, 0x2c, 0x45, 0xb2, 0xe4, 0xa0,
  429. 0x63, 0xc4, 0x68, 0xba, 0x84, 0x39, 0x16, 0x5a
  430. };
  431. uint8_t aes_cbc_test_case_3_iv[16] = {
  432. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  433. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  434. };
  435. cipher_test_case_t aes_cbc_test_case_3 = {
  436. 32, /* octets in key */
  437. aes_cbc_test_case_3_key, /* key */
  438. aes_cbc_test_case_3_iv, /* initialization vector */
  439. 64, /* octets in plaintext */
  440. aes_cbc_test_case_3_plaintext, /* plaintext */
  441. 80, /* octets in ciphertext */
  442. aes_cbc_test_case_3_ciphertext, /* ciphertext */
  443. 0,
  444. NULL,
  445. 0,
  446. &aes_cbc_test_case_2 /* pointer to next testcase */
  447. };
  448. cipher_type_t aes_cbc = {
  449. (cipher_alloc_func_t) aes_cbc_alloc,
  450. (cipher_dealloc_func_t) aes_cbc_dealloc,
  451. (cipher_init_func_t) aes_cbc_context_init,
  452. (cipher_set_aad_func_t) 0,
  453. (cipher_encrypt_func_t) aes_cbc_nist_encrypt,
  454. (cipher_decrypt_func_t) aes_cbc_nist_decrypt,
  455. (cipher_set_iv_func_t) aes_cbc_set_iv,
  456. (cipher_get_tag_func_t) 0,
  457. (char *) aes_cbc_description,
  458. (int) 0, /* instance count */
  459. (cipher_test_case_t *) &aes_cbc_test_case_3,
  460. (debug_module_t *) &mod_aes_cbc,
  461. (cipher_type_id_t) AES_CBC
  462. };