modes_internal_test.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. /*
  2. * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /* Internal tests for the modes module */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <openssl/aes.h>
  13. #include <openssl/modes.h>
  14. #include "../crypto/modes/modes_lcl.h"
  15. #include "testutil.h"
  16. #include "internal/nelem.h"
  17. typedef struct {
  18. size_t size;
  19. const unsigned char *data;
  20. } SIZED_DATA;
  21. /**********************************************************************
  22. *
  23. * Test of cts128
  24. *
  25. ***/
  26. /* cts128 test vectors from RFC 3962 */
  27. static const unsigned char cts128_test_key[16] = "chicken teriyaki";
  28. static const unsigned char cts128_test_input[64] =
  29. "I would like the" " General Gau's C"
  30. "hicken, please, " "and wonton soup.";
  31. static const unsigned char cts128_test_iv[] =
  32. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  33. static const unsigned char vector_17[17] = {
  34. 0xc6, 0x35, 0x35, 0x68, 0xf2, 0xbf, 0x8c, 0xb4,
  35. 0xd8, 0xa5, 0x80, 0x36, 0x2d, 0xa7, 0xff, 0x7f,
  36. 0x97
  37. };
  38. static const unsigned char vector_31[31] = {
  39. 0xfc, 0x00, 0x78, 0x3e, 0x0e, 0xfd, 0xb2, 0xc1,
  40. 0xd4, 0x45, 0xd4, 0xc8, 0xef, 0xf7, 0xed, 0x22,
  41. 0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
  42. 0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5
  43. };
  44. static const unsigned char vector_32[32] = {
  45. 0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0xd5,
  46. 0xbe, 0x7f, 0xcb, 0xcc, 0x98, 0xeb, 0xf5, 0xa8,
  47. 0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
  48. 0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5, 0x84
  49. };
  50. static const unsigned char vector_47[47] = {
  51. 0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
  52. 0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5, 0x84,
  53. 0xb3, 0xff, 0xfd, 0x94, 0x0c, 0x16, 0xa1, 0x8c,
  54. 0x1b, 0x55, 0x49, 0xd2, 0xf8, 0x38, 0x02, 0x9e,
  55. 0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0xd5,
  56. 0xbe, 0x7f, 0xcb, 0xcc, 0x98, 0xeb, 0xf5
  57. };
  58. static const unsigned char vector_48[48] = {
  59. 0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
  60. 0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5, 0x84,
  61. 0x9d, 0xad, 0x8b, 0xbb, 0x96, 0xc4, 0xcd, 0xc0,
  62. 0x3b, 0xc1, 0x03, 0xe1, 0xa1, 0x94, 0xbb, 0xd8,
  63. 0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0xd5,
  64. 0xbe, 0x7f, 0xcb, 0xcc, 0x98, 0xeb, 0xf5, 0xa8
  65. };
  66. static const unsigned char vector_64[64] = {
  67. 0x97, 0x68, 0x72, 0x68, 0xd6, 0xec, 0xcc, 0xc0,
  68. 0xc0, 0x7b, 0x25, 0xe2, 0x5e, 0xcf, 0xe5, 0x84,
  69. 0x39, 0x31, 0x25, 0x23, 0xa7, 0x86, 0x62, 0xd5,
  70. 0xbe, 0x7f, 0xcb, 0xcc, 0x98, 0xeb, 0xf5, 0xa8,
  71. 0x48, 0x07, 0xef, 0xe8, 0x36, 0xee, 0x89, 0xa5,
  72. 0x26, 0x73, 0x0d, 0xbc, 0x2f, 0x7b, 0xc8, 0x40,
  73. 0x9d, 0xad, 0x8b, 0xbb, 0x96, 0xc4, 0xcd, 0xc0,
  74. 0x3b, 0xc1, 0x03, 0xe1, 0xa1, 0x94, 0xbb, 0xd8
  75. };
  76. #define CTS128_TEST_VECTOR(len) \
  77. { \
  78. sizeof(vector_##len), vector_##len \
  79. }
  80. static const SIZED_DATA aes_cts128_vectors[] = {
  81. CTS128_TEST_VECTOR(17),
  82. CTS128_TEST_VECTOR(31),
  83. CTS128_TEST_VECTOR(32),
  84. CTS128_TEST_VECTOR(47),
  85. CTS128_TEST_VECTOR(48),
  86. CTS128_TEST_VECTOR(64),
  87. };
  88. static AES_KEY *cts128_encrypt_key_schedule(void)
  89. {
  90. static int init_key = 1;
  91. static AES_KEY ks;
  92. if (init_key) {
  93. AES_set_encrypt_key(cts128_test_key, 128, &ks);
  94. init_key = 0;
  95. }
  96. return &ks;
  97. }
  98. static AES_KEY *cts128_decrypt_key_schedule(void)
  99. {
  100. static int init_key = 1;
  101. static AES_KEY ks;
  102. if (init_key) {
  103. AES_set_decrypt_key(cts128_test_key, 128, &ks);
  104. init_key = 0;
  105. }
  106. return &ks;
  107. }
  108. typedef struct {
  109. const char *case_name;
  110. size_t (*last_blocks_correction)(const unsigned char *in,
  111. unsigned char *out, size_t len);
  112. size_t (*encrypt_block)(const unsigned char *in,
  113. unsigned char *out, size_t len,
  114. const void *key, unsigned char ivec[16],
  115. block128_f block);
  116. size_t (*encrypt_stream)(const unsigned char *in, unsigned char *out,
  117. size_t len, const void *key,
  118. unsigned char ivec[16], cbc128_f cbc);
  119. size_t (*decrypt_block)(const unsigned char *in,
  120. unsigned char *out, size_t len,
  121. const void *key, unsigned char ivec[16],
  122. block128_f block);
  123. size_t (*decrypt_stream)(const unsigned char *in, unsigned char *out,
  124. size_t len, const void *key,
  125. unsigned char ivec[16], cbc128_f cbc);
  126. } CTS128_FIXTURE;
  127. static size_t last_blocks_correction(const unsigned char *in,
  128. unsigned char *out, size_t len)
  129. {
  130. size_t tail;
  131. memcpy(out, in, len);
  132. if ((tail = len % 16) == 0)
  133. tail = 16;
  134. tail += 16;
  135. return tail;
  136. }
  137. static size_t last_blocks_correction_nist(const unsigned char *in,
  138. unsigned char *out, size_t len)
  139. {
  140. size_t tail;
  141. if ((tail = len % 16) == 0)
  142. tail = 16;
  143. len -= 16 + tail;
  144. memcpy(out, in, len);
  145. /* flip two last blocks */
  146. memcpy(out + len, in + len + 16, tail);
  147. memcpy(out + len + tail, in + len, 16);
  148. len += 16 + tail;
  149. tail = 16;
  150. return tail;
  151. }
  152. static int execute_cts128(const CTS128_FIXTURE *fixture, int num)
  153. {
  154. const unsigned char *test_iv = cts128_test_iv;
  155. size_t test_iv_len = sizeof(cts128_test_iv);
  156. const unsigned char *orig_vector = aes_cts128_vectors[num].data;
  157. size_t len = aes_cts128_vectors[num].size;
  158. const unsigned char *test_input = cts128_test_input;
  159. const AES_KEY *encrypt_key_schedule = cts128_encrypt_key_schedule();
  160. const AES_KEY *decrypt_key_schedule = cts128_decrypt_key_schedule();
  161. unsigned char iv[16];
  162. /* The largest test inputs are = 64 bytes. */
  163. unsigned char cleartext[64], ciphertext[64], vector[64];
  164. size_t tail, size;
  165. TEST_info("%s_vector_%lu", fixture->case_name, (unsigned long)len);
  166. tail = fixture->last_blocks_correction(orig_vector, vector, len);
  167. /* test block-based encryption */
  168. memcpy(iv, test_iv, test_iv_len);
  169. if (!TEST_size_t_eq(fixture->encrypt_block(test_input, ciphertext, len,
  170. encrypt_key_schedule, iv,
  171. (block128_f)AES_encrypt), len)
  172. || !TEST_mem_eq(ciphertext, len, vector, len)
  173. || !TEST_mem_eq(iv, sizeof(iv), vector + len - tail, sizeof(iv)))
  174. return 0;
  175. /* test block-based decryption */
  176. memcpy(iv, test_iv, test_iv_len);
  177. size = fixture->decrypt_block(ciphertext, cleartext, len,
  178. decrypt_key_schedule, iv,
  179. (block128_f)AES_decrypt);
  180. if (!TEST_true(len == size || len + 16 == size)
  181. || !TEST_mem_eq(cleartext, len, test_input, len)
  182. || !TEST_mem_eq(iv, sizeof(iv), vector + len - tail, sizeof(iv)))
  183. return 0;
  184. /* test streamed encryption */
  185. memcpy(iv, test_iv, test_iv_len);
  186. if (!TEST_size_t_eq(fixture->encrypt_stream(test_input, ciphertext, len,
  187. encrypt_key_schedule, iv,
  188. (cbc128_f) AES_cbc_encrypt),
  189. len)
  190. || !TEST_mem_eq(ciphertext, len, vector, len)
  191. || !TEST_mem_eq(iv, sizeof(iv), vector + len - tail, sizeof(iv)))
  192. return 0;
  193. /* test streamed decryption */
  194. memcpy(iv, test_iv, test_iv_len);
  195. if (!TEST_size_t_eq(fixture->decrypt_stream(ciphertext, cleartext, len,
  196. decrypt_key_schedule, iv,
  197. (cbc128_f)AES_cbc_encrypt),
  198. len)
  199. || !TEST_mem_eq(cleartext, len, test_input, len)
  200. || !TEST_mem_eq(iv, sizeof(iv), vector + len - tail, sizeof(iv)))
  201. return 0;
  202. return 1;
  203. }
  204. static int test_aes_cts128(int idx)
  205. {
  206. static const CTS128_FIXTURE fixture_cts128 = {
  207. "aes_cts128", last_blocks_correction,
  208. CRYPTO_cts128_encrypt_block, CRYPTO_cts128_encrypt,
  209. CRYPTO_cts128_decrypt_block, CRYPTO_cts128_decrypt
  210. };
  211. return execute_cts128(&fixture_cts128, idx);
  212. }
  213. static int test_aes_cts128_nist(int idx)
  214. {
  215. static const CTS128_FIXTURE fixture_cts128_nist = {
  216. "aes_cts128_nist", last_blocks_correction_nist,
  217. CRYPTO_nistcts128_encrypt_block, CRYPTO_nistcts128_encrypt,
  218. CRYPTO_nistcts128_decrypt_block, CRYPTO_nistcts128_decrypt
  219. };
  220. return execute_cts128(&fixture_cts128_nist, idx);
  221. }
  222. /*
  223. *
  224. * Test of gcm128
  225. *
  226. */
  227. /* Test Case 1 */
  228. static const u8 K1[16], P1[] = { 0 }, A1[] = { 0 }, IV1[12], C1[] = { 0 };
  229. static const u8 T1[] = {
  230. 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61,
  231. 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a
  232. };
  233. /* Test Case 2 */
  234. # define K2 K1
  235. # define A2 A1
  236. # define IV2 IV1
  237. static const u8 P2[16];
  238. static const u8 C2[] = {
  239. 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92,
  240. 0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78
  241. };
  242. static const u8 T2[] = {
  243. 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd,
  244. 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf
  245. };
  246. /* Test Case 3 */
  247. # define A3 A2
  248. static const u8 K3[] = {
  249. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  250. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
  251. };
  252. static const u8 P3[] = {
  253. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  254. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  255. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  256. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  257. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  258. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  259. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  260. 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55
  261. };
  262. static const u8 IV3[] = {
  263. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  264. 0xde, 0xca, 0xf8, 0x88
  265. };
  266. static const u8 C3[] = {
  267. 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
  268. 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
  269. 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
  270. 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
  271. 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
  272. 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
  273. 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
  274. 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85
  275. };
  276. static const u8 T3[] = {
  277. 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6,
  278. 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4
  279. };
  280. /* Test Case 4 */
  281. # define K4 K3
  282. # define IV4 IV3
  283. static const u8 P4[] = {
  284. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  285. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  286. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  287. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  288. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  289. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  290. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  291. 0xba, 0x63, 0x7b, 0x39
  292. };
  293. static const u8 A4[] = {
  294. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  295. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  296. 0xab, 0xad, 0xda, 0xd2
  297. };
  298. static const u8 C4[] = {
  299. 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
  300. 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
  301. 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
  302. 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
  303. 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
  304. 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
  305. 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
  306. 0x3d, 0x58, 0xe0, 0x91
  307. };
  308. static const u8 T4[] = {
  309. 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
  310. 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47
  311. };
  312. /* Test Case 5 */
  313. # define K5 K4
  314. # define P5 P4
  315. # define A5 A4
  316. static const u8 IV5[] = {
  317. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad
  318. };
  319. static const u8 C5[] = {
  320. 0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a,
  321. 0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55,
  322. 0x69, 0x9b, 0x2a, 0x71, 0x4f, 0xcd, 0xc6, 0xf8,
  323. 0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23,
  324. 0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2,
  325. 0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42,
  326. 0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07,
  327. 0xc2, 0x3f, 0x45, 0x98
  328. };
  329. static const u8 T5[] = {
  330. 0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85,
  331. 0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb
  332. };
  333. /* Test Case 6 */
  334. # define K6 K5
  335. # define P6 P5
  336. # define A6 A5
  337. static const u8 IV6[] = {
  338. 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
  339. 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
  340. 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
  341. 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
  342. 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
  343. 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
  344. 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
  345. 0xa6, 0x37, 0xb3, 0x9b
  346. };
  347. static const u8 C6[] = {
  348. 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6,
  349. 0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94,
  350. 0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8,
  351. 0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7,
  352. 0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90,
  353. 0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f,
  354. 0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03,
  355. 0x4c, 0x34, 0xae, 0xe5
  356. };
  357. static const u8 T6[] = {
  358. 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa,
  359. 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50
  360. };
  361. /* Test Case 7 */
  362. static const u8 K7[24], P7[] = { 0 }, A7[] = { 0 }, IV7[12], C7[] = { 0 };
  363. static const u8 T7[] = {
  364. 0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b,
  365. 0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35
  366. };
  367. /* Test Case 8 */
  368. # define K8 K7
  369. # define IV8 IV7
  370. # define A8 A7
  371. static const u8 P8[16];
  372. static const u8 C8[] = {
  373. 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41,
  374. 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00
  375. };
  376. static const u8 T8[] = {
  377. 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab,
  378. 0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb
  379. };
  380. /* Test Case 9 */
  381. # define A9 A8
  382. static const u8 K9[] = {
  383. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  384. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  385. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c
  386. };
  387. static const u8 P9[] = {
  388. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  389. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  390. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  391. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  392. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  393. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  394. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  395. 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55
  396. };
  397. static const u8 IV9[] = {
  398. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  399. 0xde, 0xca, 0xf8, 0x88
  400. };
  401. static const u8 C9[] = {
  402. 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
  403. 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
  404. 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
  405. 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
  406. 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
  407. 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
  408. 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
  409. 0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56
  410. };
  411. static const u8 T9[] = {
  412. 0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf,
  413. 0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14
  414. };
  415. /* Test Case 10 */
  416. # define K10 K9
  417. # define IV10 IV9
  418. static const u8 P10[] = {
  419. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  420. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  421. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  422. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  423. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  424. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  425. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  426. 0xba, 0x63, 0x7b, 0x39
  427. };
  428. static const u8 A10[] = {
  429. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  430. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  431. 0xab, 0xad, 0xda, 0xd2
  432. };
  433. static const u8 C10[] = {
  434. 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
  435. 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
  436. 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
  437. 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
  438. 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
  439. 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
  440. 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
  441. 0xcc, 0xda, 0x27, 0x10
  442. };
  443. static const u8 T10[] = {
  444. 0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f,
  445. 0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c
  446. };
  447. /* Test Case 11 */
  448. # define K11 K10
  449. # define P11 P10
  450. # define A11 A10
  451. static const u8 IV11[] = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad };
  452. static const u8 C11[] = {
  453. 0x0f, 0x10, 0xf5, 0x99, 0xae, 0x14, 0xa1, 0x54,
  454. 0xed, 0x24, 0xb3, 0x6e, 0x25, 0x32, 0x4d, 0xb8,
  455. 0xc5, 0x66, 0x63, 0x2e, 0xf2, 0xbb, 0xb3, 0x4f,
  456. 0x83, 0x47, 0x28, 0x0f, 0xc4, 0x50, 0x70, 0x57,
  457. 0xfd, 0xdc, 0x29, 0xdf, 0x9a, 0x47, 0x1f, 0x75,
  458. 0xc6, 0x65, 0x41, 0xd4, 0xd4, 0xda, 0xd1, 0xc9,
  459. 0xe9, 0x3a, 0x19, 0xa5, 0x8e, 0x8b, 0x47, 0x3f,
  460. 0xa0, 0xf0, 0x62, 0xf7
  461. };
  462. static const u8 T11[] = {
  463. 0x65, 0xdc, 0xc5, 0x7f, 0xcf, 0x62, 0x3a, 0x24,
  464. 0x09, 0x4f, 0xcc, 0xa4, 0x0d, 0x35, 0x33, 0xf8
  465. };
  466. /* Test Case 12 */
  467. # define K12 K11
  468. # define P12 P11
  469. # define A12 A11
  470. static const u8 IV12[] = {
  471. 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
  472. 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
  473. 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
  474. 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
  475. 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
  476. 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
  477. 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
  478. 0xa6, 0x37, 0xb3, 0x9b
  479. };
  480. static const u8 C12[] = {
  481. 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
  482. 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
  483. 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
  484. 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
  485. 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
  486. 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
  487. 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
  488. 0xe9, 0xb7, 0x37, 0x3b
  489. };
  490. static const u8 T12[] = {
  491. 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
  492. 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9
  493. };
  494. /* Test Case 13 */
  495. static const u8 K13[32], P13[] = { 0 }, A13[] = { 0 }, IV13[12], C13[] = { 0 };
  496. static const u8 T13[] = {
  497. 0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9,
  498. 0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b
  499. };
  500. /* Test Case 14 */
  501. # define K14 K13
  502. # define A14 A13
  503. static const u8 P14[16], IV14[12];
  504. static const u8 C14[] = {
  505. 0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e,
  506. 0x07, 0x4e, 0xc5, 0xd3, 0xba, 0xf3, 0x9d, 0x18
  507. };
  508. static const u8 T14[] = {
  509. 0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0,
  510. 0x26, 0x5b, 0x98, 0xb5, 0xd4, 0x8a, 0xb9, 0x19
  511. };
  512. /* Test Case 15 */
  513. # define A15 A14
  514. static const u8 K15[] = {
  515. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  516. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  517. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  518. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
  519. };
  520. static const u8 P15[] = {
  521. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  522. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  523. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  524. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  525. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  526. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  527. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  528. 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55
  529. };
  530. static const u8 IV15[] = {
  531. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  532. 0xde, 0xca, 0xf8, 0x88
  533. };
  534. static const u8 C15[] = {
  535. 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
  536. 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
  537. 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
  538. 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
  539. 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
  540. 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
  541. 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
  542. 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad
  543. };
  544. static const u8 T15[] = {
  545. 0xb0, 0x94, 0xda, 0xc5, 0xd9, 0x34, 0x71, 0xbd,
  546. 0xec, 0x1a, 0x50, 0x22, 0x70, 0xe3, 0xcc, 0x6c
  547. };
  548. /* Test Case 16 */
  549. # define K16 K15
  550. # define IV16 IV15
  551. static const u8 P16[] = {
  552. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  553. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  554. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  555. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  556. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  557. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  558. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  559. 0xba, 0x63, 0x7b, 0x39
  560. };
  561. static const u8 A16[] = {
  562. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  563. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  564. 0xab, 0xad, 0xda, 0xd2
  565. };
  566. static const u8 C16[] = {
  567. 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
  568. 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
  569. 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
  570. 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
  571. 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
  572. 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
  573. 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
  574. 0xbc, 0xc9, 0xf6, 0x62
  575. };
  576. static const u8 T16[] = {
  577. 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
  578. 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b
  579. };
  580. /* Test Case 17 */
  581. # define K17 K16
  582. # define P17 P16
  583. # define A17 A16
  584. static const u8 IV17[] = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad };
  585. static const u8 C17[] = {
  586. 0xc3, 0x76, 0x2d, 0xf1, 0xca, 0x78, 0x7d, 0x32,
  587. 0xae, 0x47, 0xc1, 0x3b, 0xf1, 0x98, 0x44, 0xcb,
  588. 0xaf, 0x1a, 0xe1, 0x4d, 0x0b, 0x97, 0x6a, 0xfa,
  589. 0xc5, 0x2f, 0xf7, 0xd7, 0x9b, 0xba, 0x9d, 0xe0,
  590. 0xfe, 0xb5, 0x82, 0xd3, 0x39, 0x34, 0xa4, 0xf0,
  591. 0x95, 0x4c, 0xc2, 0x36, 0x3b, 0xc7, 0x3f, 0x78,
  592. 0x62, 0xac, 0x43, 0x0e, 0x64, 0xab, 0xe4, 0x99,
  593. 0xf4, 0x7c, 0x9b, 0x1f
  594. };
  595. static const u8 T17[] = {
  596. 0x3a, 0x33, 0x7d, 0xbf, 0x46, 0xa7, 0x92, 0xc4,
  597. 0x5e, 0x45, 0x49, 0x13, 0xfe, 0x2e, 0xa8, 0xf2
  598. };
  599. /* Test Case 18 */
  600. # define K18 K17
  601. # define P18 P17
  602. # define A18 A17
  603. static const u8 IV18[] = {
  604. 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
  605. 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
  606. 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
  607. 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
  608. 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
  609. 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
  610. 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
  611. 0xa6, 0x37, 0xb3, 0x9b
  612. };
  613. static const u8 C18[] = {
  614. 0x5a, 0x8d, 0xef, 0x2f, 0x0c, 0x9e, 0x53, 0xf1,
  615. 0xf7, 0x5d, 0x78, 0x53, 0x65, 0x9e, 0x2a, 0x20,
  616. 0xee, 0xb2, 0xb2, 0x2a, 0xaf, 0xde, 0x64, 0x19,
  617. 0xa0, 0x58, 0xab, 0x4f, 0x6f, 0x74, 0x6b, 0xf4,
  618. 0x0f, 0xc0, 0xc3, 0xb7, 0x80, 0xf2, 0x44, 0x45,
  619. 0x2d, 0xa3, 0xeb, 0xf1, 0xc5, 0xd8, 0x2c, 0xde,
  620. 0xa2, 0x41, 0x89, 0x97, 0x20, 0x0e, 0xf8, 0x2e,
  621. 0x44, 0xae, 0x7e, 0x3f
  622. };
  623. static const u8 T18[] = {
  624. 0xa4, 0x4a, 0x82, 0x66, 0xee, 0x1c, 0x8e, 0xb0,
  625. 0xc8, 0xb5, 0xd4, 0xcf, 0x5a, 0xe9, 0xf1, 0x9a
  626. };
  627. /* Test Case 19 */
  628. # define K19 K1
  629. # define P19 P1
  630. # define IV19 IV1
  631. # define C19 C1
  632. static const u8 A19[] = {
  633. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  634. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  635. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  636. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  637. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  638. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  639. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  640. 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55,
  641. 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
  642. 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
  643. 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
  644. 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
  645. 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
  646. 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
  647. 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
  648. 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad
  649. };
  650. static const u8 T19[] = {
  651. 0x5f, 0xea, 0x79, 0x3a, 0x2d, 0x6f, 0x97, 0x4d,
  652. 0x37, 0xe6, 0x8e, 0x0c, 0xb8, 0xff, 0x94, 0x92
  653. };
  654. /* Test Case 20 */
  655. # define K20 K1
  656. # define A20 A1
  657. /* this results in 0xff in counter LSB */
  658. static const u8 IV20[64] = { 0xff, 0xff, 0xff, 0xff };
  659. static const u8 P20[288];
  660. static const u8 C20[] = {
  661. 0x56, 0xb3, 0x37, 0x3c, 0xa9, 0xef, 0x6e, 0x4a,
  662. 0x2b, 0x64, 0xfe, 0x1e, 0x9a, 0x17, 0xb6, 0x14,
  663. 0x25, 0xf1, 0x0d, 0x47, 0xa7, 0x5a, 0x5f, 0xce,
  664. 0x13, 0xef, 0xc6, 0xbc, 0x78, 0x4a, 0xf2, 0x4f,
  665. 0x41, 0x41, 0xbd, 0xd4, 0x8c, 0xf7, 0xc7, 0x70,
  666. 0x88, 0x7a, 0xfd, 0x57, 0x3c, 0xca, 0x54, 0x18,
  667. 0xa9, 0xae, 0xff, 0xcd, 0x7c, 0x5c, 0xed, 0xdf,
  668. 0xc6, 0xa7, 0x83, 0x97, 0xb9, 0xa8, 0x5b, 0x49,
  669. 0x9d, 0xa5, 0x58, 0x25, 0x72, 0x67, 0xca, 0xab,
  670. 0x2a, 0xd0, 0xb2, 0x3c, 0xa4, 0x76, 0xa5, 0x3c,
  671. 0xb1, 0x7f, 0xb4, 0x1c, 0x4b, 0x8b, 0x47, 0x5c,
  672. 0xb4, 0xf3, 0xf7, 0x16, 0x50, 0x94, 0xc2, 0x29,
  673. 0xc9, 0xe8, 0xc4, 0xdc, 0x0a, 0x2a, 0x5f, 0xf1,
  674. 0x90, 0x3e, 0x50, 0x15, 0x11, 0x22, 0x13, 0x76,
  675. 0xa1, 0xcd, 0xb8, 0x36, 0x4c, 0x50, 0x61, 0xa2,
  676. 0x0c, 0xae, 0x74, 0xbc, 0x4a, 0xcd, 0x76, 0xce,
  677. 0xb0, 0xab, 0xc9, 0xfd, 0x32, 0x17, 0xef, 0x9f,
  678. 0x8c, 0x90, 0xbe, 0x40, 0x2d, 0xdf, 0x6d, 0x86,
  679. 0x97, 0xf4, 0xf8, 0x80, 0xdf, 0xf1, 0x5b, 0xfb,
  680. 0x7a, 0x6b, 0x28, 0x24, 0x1e, 0xc8, 0xfe, 0x18,
  681. 0x3c, 0x2d, 0x59, 0xe3, 0xf9, 0xdf, 0xff, 0x65,
  682. 0x3c, 0x71, 0x26, 0xf0, 0xac, 0xb9, 0xe6, 0x42,
  683. 0x11, 0xf4, 0x2b, 0xae, 0x12, 0xaf, 0x46, 0x2b,
  684. 0x10, 0x70, 0xbe, 0xf1, 0xab, 0x5e, 0x36, 0x06,
  685. 0x87, 0x2c, 0xa1, 0x0d, 0xee, 0x15, 0xb3, 0x24,
  686. 0x9b, 0x1a, 0x1b, 0x95, 0x8f, 0x23, 0x13, 0x4c,
  687. 0x4b, 0xcc, 0xb7, 0xd0, 0x32, 0x00, 0xbc, 0xe4,
  688. 0x20, 0xa2, 0xf8, 0xeb, 0x66, 0xdc, 0xf3, 0x64,
  689. 0x4d, 0x14, 0x23, 0xc1, 0xb5, 0x69, 0x90, 0x03,
  690. 0xc1, 0x3e, 0xce, 0xf4, 0xbf, 0x38, 0xa3, 0xb6,
  691. 0x0e, 0xed, 0xc3, 0x40, 0x33, 0xba, 0xc1, 0x90,
  692. 0x27, 0x83, 0xdc, 0x6d, 0x89, 0xe2, 0xe7, 0x74,
  693. 0x18, 0x8a, 0x43, 0x9c, 0x7e, 0xbc, 0xc0, 0x67,
  694. 0x2d, 0xbd, 0xa4, 0xdd, 0xcf, 0xb2, 0x79, 0x46,
  695. 0x13, 0xb0, 0xbe, 0x41, 0x31, 0x5e, 0xf7, 0x78,
  696. 0x70, 0x8a, 0x70, 0xee, 0x7d, 0x75, 0x16, 0x5c
  697. };
  698. static const u8 T20[] = {
  699. 0x8b, 0x30, 0x7f, 0x6b, 0x33, 0x28, 0x6d, 0x0a,
  700. 0xb0, 0x26, 0xa9, 0xed, 0x3f, 0xe1, 0xe8, 0x5f
  701. };
  702. #define GCM128_TEST_VECTOR(n) \
  703. { \
  704. {sizeof(K##n), K##n}, \
  705. {sizeof(IV##n), IV##n}, \
  706. {sizeof(A##n), A##n}, \
  707. {sizeof(P##n), P##n}, \
  708. {sizeof(C##n), C##n}, \
  709. {sizeof(T##n), T##n} \
  710. }
  711. static struct gcm128_data {
  712. const SIZED_DATA K;
  713. const SIZED_DATA IV;
  714. const SIZED_DATA A;
  715. const SIZED_DATA P;
  716. const SIZED_DATA C;
  717. const SIZED_DATA T;
  718. } gcm128_vectors[] = {
  719. GCM128_TEST_VECTOR(1),
  720. GCM128_TEST_VECTOR(2),
  721. GCM128_TEST_VECTOR(3),
  722. GCM128_TEST_VECTOR(4),
  723. GCM128_TEST_VECTOR(5),
  724. GCM128_TEST_VECTOR(6),
  725. GCM128_TEST_VECTOR(7),
  726. GCM128_TEST_VECTOR(8),
  727. GCM128_TEST_VECTOR(9),
  728. GCM128_TEST_VECTOR(10),
  729. GCM128_TEST_VECTOR(11),
  730. GCM128_TEST_VECTOR(12),
  731. GCM128_TEST_VECTOR(13),
  732. GCM128_TEST_VECTOR(14),
  733. GCM128_TEST_VECTOR(15),
  734. GCM128_TEST_VECTOR(16),
  735. GCM128_TEST_VECTOR(17),
  736. GCM128_TEST_VECTOR(18),
  737. GCM128_TEST_VECTOR(19),
  738. GCM128_TEST_VECTOR(20)
  739. };
  740. static int test_gcm128(int idx)
  741. {
  742. unsigned char out[512];
  743. SIZED_DATA K = gcm128_vectors[idx].K;
  744. SIZED_DATA IV = gcm128_vectors[idx].IV;
  745. SIZED_DATA A = gcm128_vectors[idx].A;
  746. SIZED_DATA P = gcm128_vectors[idx].P;
  747. SIZED_DATA C = gcm128_vectors[idx].C;
  748. SIZED_DATA T = gcm128_vectors[idx].T;
  749. GCM128_CONTEXT ctx;
  750. AES_KEY key;
  751. /* Size 1 inputs are special-cased to signal NULL. */
  752. if (A.size == 1)
  753. A.data = NULL;
  754. if (P.size == 1)
  755. P.data = NULL;
  756. if (C.size == 1)
  757. C.data = NULL;
  758. AES_set_encrypt_key(K.data, K.size * 8, &key);
  759. CRYPTO_gcm128_init(&ctx, &key, (block128_f)AES_encrypt);
  760. CRYPTO_gcm128_setiv(&ctx, IV.data, IV.size);
  761. memset(out, 0, P.size);
  762. if (A.data != NULL)
  763. CRYPTO_gcm128_aad(&ctx, A.data, A.size);
  764. if (P.data != NULL)
  765. CRYPTO_gcm128_encrypt( &ctx, P.data, out, P.size);
  766. if (!TEST_false(CRYPTO_gcm128_finish(&ctx, T.data, 16))
  767. || (C.data != NULL
  768. && !TEST_mem_eq(out, P.size, C.data, P.size)))
  769. return 0;
  770. CRYPTO_gcm128_setiv(&ctx, IV.data, IV.size);
  771. memset(out, 0, P.size);
  772. if (A.data != NULL)
  773. CRYPTO_gcm128_aad(&ctx, A.data, A.size);
  774. if (C.data != NULL)
  775. CRYPTO_gcm128_decrypt(&ctx, C.data, out, P.size);
  776. if (!TEST_false(CRYPTO_gcm128_finish(&ctx, T.data, 16))
  777. || (P.data != NULL
  778. && !TEST_mem_eq(out, P.size, P.data, P.size)))
  779. return 0;
  780. return 1;
  781. }
  782. int setup_tests(void)
  783. {
  784. ADD_ALL_TESTS(test_aes_cts128, OSSL_NELEM(aes_cts128_vectors));
  785. ADD_ALL_TESTS(test_aes_cts128_nist, OSSL_NELEM(aes_cts128_vectors));
  786. ADD_ALL_TESTS(test_gcm128, OSSL_NELEM(gcm128_vectors));
  787. return 1;
  788. }