2
0

aes_gcm_ossl.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /*
  2. * aes_gcm_ossl.c
  3. *
  4. * AES Galois Counter Mode
  5. *
  6. * John A. Foley
  7. * Cisco Systems, Inc.
  8. *
  9. */
  10. /*
  11. *
  12. * Copyright (c) 2013, Cisco Systems, Inc.
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions
  17. * are met:
  18. *
  19. * Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. *
  22. * Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials provided
  25. * with the distribution.
  26. *
  27. * Neither the name of the Cisco Systems, Inc. nor the names of its
  28. * contributors may be used to endorse or promote products derived
  29. * from this software without specific prior written permission.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  34. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  35. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  36. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  37. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  38. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42. * OF THE POSSIBILITY OF SUCH DAMAGE.
  43. *
  44. */
  45. #include <openssl/evp.h>
  46. #include "aes_icm_ossl.h"
  47. #include "aes_gcm_ossl.h"
  48. #include "alloc.h"
  49. #include "crypto_types.h"
  50. debug_module_t mod_aes_gcm = {
  51. 0, /* debugging is off by default */
  52. "aes gcm" /* printable module name */
  53. };
  54. /*
  55. * The following are the global singleton instances for the
  56. * 128-bit and 256-bit GCM ciphers.
  57. */
  58. extern cipher_type_t aes_gcm_128_openssl;
  59. extern cipher_type_t aes_gcm_256_openssl;
  60. /*
  61. * For now we only support 8 and 16 octet tags. The spec allows for
  62. * optional 12 byte tag, which may be supported in the future.
  63. */
  64. #define GCM_AUTH_TAG_LEN 16
  65. #define GCM_AUTH_TAG_LEN_8 8
  66. /*
  67. * This function allocates a new instance of this crypto engine.
  68. * The key_len parameter should be one of 28 or 44 for
  69. * AES-128-GCM or AES-256-GCM respectively. Note that the
  70. * key length includes the 14 byte salt value that is used when
  71. * initializing the KDF.
  72. */
  73. err_status_t aes_gcm_openssl_alloc (cipher_t **c, int key_len, int tlen)
  74. {
  75. aes_gcm_ctx_t *gcm;
  76. int tmp;
  77. uint8_t *allptr;
  78. debug_print(mod_aes_gcm, "allocating cipher with key length %d", key_len);
  79. debug_print(mod_aes_gcm, "allocating cipher with tag length %d", tlen);
  80. /*
  81. * Verify the key_len is valid for one of: AES-128/256
  82. */
  83. if (key_len != AES_128_GCM_KEYSIZE_WSALT &&
  84. key_len != AES_256_GCM_KEYSIZE_WSALT) {
  85. return (err_status_bad_param);
  86. }
  87. if (tlen != GCM_AUTH_TAG_LEN &&
  88. tlen != GCM_AUTH_TAG_LEN_8) {
  89. return (err_status_bad_param);
  90. }
  91. /* allocate memory a cipher of type aes_gcm */
  92. tmp = sizeof(cipher_t) + sizeof(aes_gcm_ctx_t);
  93. allptr = crypto_alloc(tmp);
  94. if (allptr == NULL) {
  95. return (err_status_alloc_fail);
  96. }
  97. /* set pointers */
  98. *c = (cipher_t*)allptr;
  99. (*c)->state = allptr + sizeof(cipher_t);
  100. gcm = (aes_gcm_ctx_t *)(*c)->state;
  101. /* increment ref_count */
  102. switch (key_len) {
  103. case AES_128_GCM_KEYSIZE_WSALT:
  104. (*c)->type = &aes_gcm_128_openssl;
  105. (*c)->algorithm = AES_128_GCM;
  106. aes_gcm_128_openssl.ref_count++;
  107. ((aes_gcm_ctx_t*)(*c)->state)->key_size = AES_128_KEYSIZE;
  108. ((aes_gcm_ctx_t*)(*c)->state)->tag_len = tlen;
  109. break;
  110. case AES_256_GCM_KEYSIZE_WSALT:
  111. (*c)->type = &aes_gcm_256_openssl;
  112. (*c)->algorithm = AES_256_GCM;
  113. aes_gcm_256_openssl.ref_count++;
  114. ((aes_gcm_ctx_t*)(*c)->state)->key_size = AES_256_KEYSIZE;
  115. ((aes_gcm_ctx_t*)(*c)->state)->tag_len = tlen;
  116. break;
  117. }
  118. /* set key size */
  119. (*c)->key_len = key_len;
  120. EVP_CIPHER_CTX_init(&gcm->ctx);
  121. return (err_status_ok);
  122. }
  123. /*
  124. * This function deallocates a GCM session
  125. */
  126. err_status_t aes_gcm_openssl_dealloc (cipher_t *c)
  127. {
  128. aes_gcm_ctx_t *ctx;
  129. ctx = (aes_gcm_ctx_t*)c->state;
  130. if (ctx) {
  131. EVP_CIPHER_CTX_cleanup(&ctx->ctx);
  132. /* decrement ref_count for the appropriate engine */
  133. switch (ctx->key_size) {
  134. case AES_256_KEYSIZE:
  135. aes_gcm_256_openssl.ref_count--;
  136. break;
  137. case AES_128_KEYSIZE:
  138. aes_gcm_128_openssl.ref_count--;
  139. break;
  140. default:
  141. return (err_status_dealloc_fail);
  142. break;
  143. }
  144. }
  145. /* zeroize entire state*/
  146. octet_string_set_to_zero((uint8_t*)c, sizeof(cipher_t) + sizeof(aes_gcm_ctx_t));
  147. /* free memory */
  148. crypto_free(c);
  149. return (err_status_ok);
  150. }
  151. /*
  152. * aes_gcm_openssl_context_init(...) initializes the aes_gcm_context
  153. * using the value in key[].
  154. *
  155. * the key is the secret key
  156. */
  157. err_status_t aes_gcm_openssl_context_init (aes_gcm_ctx_t *c, const uint8_t *key)
  158. {
  159. c->dir = direction_any;
  160. /* copy key to be used later when CiscoSSL crypto context is created */
  161. v128_copy_octet_string((v128_t*)&c->key, key);
  162. if (c->key_size == AES_256_KEYSIZE) {
  163. debug_print(mod_aes_gcm, "Copying last 16 bytes of key: %s",
  164. v128_hex_string((v128_t*)(key + AES_128_KEYSIZE)));
  165. v128_copy_octet_string(((v128_t*)(&c->key.v8)) + 1,
  166. key + AES_128_KEYSIZE);
  167. }
  168. debug_print(mod_aes_gcm, "key: %s", v128_hex_string((v128_t*)&c->key));
  169. EVP_CIPHER_CTX_cleanup(&c->ctx);
  170. return (err_status_ok);
  171. }
  172. /*
  173. * aes_gcm_openssl_set_iv(c, iv) sets the counter value to the exor of iv with
  174. * the offset
  175. */
  176. err_status_t aes_gcm_openssl_set_iv (aes_gcm_ctx_t *c, void *iv,
  177. int direction)
  178. {
  179. const EVP_CIPHER *evp;
  180. v128_t *nonce = iv;
  181. if (direction != direction_encrypt && direction != direction_decrypt) {
  182. return (err_status_bad_param);
  183. }
  184. c->dir = direction;
  185. debug_print(mod_aes_gcm, "setting iv: %s", v128_hex_string(nonce));
  186. switch (c->key_size) {
  187. case AES_256_KEYSIZE:
  188. evp = EVP_aes_256_gcm();
  189. break;
  190. case AES_128_KEYSIZE:
  191. evp = EVP_aes_128_gcm();
  192. break;
  193. default:
  194. return (err_status_bad_param);
  195. break;
  196. }
  197. if (!EVP_CipherInit_ex(&c->ctx, evp, NULL, (const unsigned char*)&c->key.v8,
  198. NULL, (c->dir == direction_encrypt ? 1 : 0))) {
  199. return (err_status_init_fail);
  200. }
  201. /* set IV len and the IV value, the followiong 3 calls are required */
  202. if (!EVP_CIPHER_CTX_ctrl(&c->ctx, EVP_CTRL_GCM_SET_IVLEN, 12, 0)) {
  203. return (err_status_init_fail);
  204. }
  205. if (!EVP_CIPHER_CTX_ctrl(&c->ctx, EVP_CTRL_GCM_SET_IV_FIXED, -1, iv)) {
  206. return (err_status_init_fail);
  207. }
  208. if (!EVP_CIPHER_CTX_ctrl(&c->ctx, EVP_CTRL_GCM_IV_GEN, 0, iv)) {
  209. return (err_status_init_fail);
  210. }
  211. return (err_status_ok);
  212. }
  213. /*
  214. * This function processes the AAD
  215. *
  216. * Parameters:
  217. * c Crypto context
  218. * aad Additional data to process for AEAD cipher suites
  219. * aad_len length of aad buffer
  220. */
  221. err_status_t aes_gcm_openssl_set_aad (aes_gcm_ctx_t *c, unsigned char *aad,
  222. unsigned int aad_len)
  223. {
  224. int rv;
  225. /*
  226. * Set dummy tag, OpenSSL requires the Tag to be set before
  227. * processing AAD
  228. */
  229. EVP_CIPHER_CTX_ctrl(&c->ctx, EVP_CTRL_GCM_SET_TAG, c->tag_len, aad);
  230. rv = EVP_Cipher(&c->ctx, NULL, aad, aad_len);
  231. if (rv != aad_len) {
  232. return (err_status_algo_fail);
  233. } else {
  234. return (err_status_ok);
  235. }
  236. }
  237. /*
  238. * This function encrypts a buffer using AES GCM mode
  239. *
  240. * Parameters:
  241. * c Crypto context
  242. * buf data to encrypt
  243. * enc_len length of encrypt buffer
  244. */
  245. err_status_t aes_gcm_openssl_encrypt (aes_gcm_ctx_t *c, unsigned char *buf,
  246. unsigned int *enc_len)
  247. {
  248. if (c->dir != direction_encrypt && c->dir != direction_decrypt) {
  249. return (err_status_bad_param);
  250. }
  251. /*
  252. * Encrypt the data
  253. */
  254. EVP_Cipher(&c->ctx, buf, buf, *enc_len);
  255. return (err_status_ok);
  256. }
  257. /*
  258. * This function calculates and returns the GCM tag for a given context.
  259. * This should be called after encrypting the data. The *len value
  260. * is increased by the tag size. The caller must ensure that *buf has
  261. * enough room to accept the appended tag.
  262. *
  263. * Parameters:
  264. * c Crypto context
  265. * buf data to encrypt
  266. * len length of encrypt buffer
  267. */
  268. err_status_t aes_gcm_openssl_get_tag (aes_gcm_ctx_t *c, unsigned char *buf,
  269. int *len)
  270. {
  271. /*
  272. * Calculate the tag
  273. */
  274. EVP_Cipher(&c->ctx, NULL, NULL, 0);
  275. /*
  276. * Retreive the tag
  277. */
  278. EVP_CIPHER_CTX_ctrl(&c->ctx, EVP_CTRL_GCM_GET_TAG, c->tag_len, buf);
  279. /*
  280. * Increase encryption length by desired tag size
  281. */
  282. *len = c->tag_len;
  283. return (err_status_ok);
  284. }
  285. /*
  286. * This function decrypts a buffer using AES GCM mode
  287. *
  288. * Parameters:
  289. * c Crypto context
  290. * buf data to encrypt
  291. * enc_len length of encrypt buffer
  292. */
  293. err_status_t aes_gcm_openssl_decrypt (aes_gcm_ctx_t *c, unsigned char *buf,
  294. unsigned int *enc_len)
  295. {
  296. if (c->dir != direction_encrypt && c->dir != direction_decrypt) {
  297. return (err_status_bad_param);
  298. }
  299. /*
  300. * Set the tag before decrypting
  301. */
  302. EVP_CIPHER_CTX_ctrl(&c->ctx, EVP_CTRL_GCM_SET_TAG, c->tag_len,
  303. buf + (*enc_len - c->tag_len));
  304. EVP_Cipher(&c->ctx, buf, buf, *enc_len - c->tag_len);
  305. /*
  306. * Check the tag
  307. */
  308. if (EVP_Cipher(&c->ctx, NULL, NULL, 0)) {
  309. return (err_status_auth_fail);
  310. }
  311. /*
  312. * Reduce the buffer size by the tag length since the tag
  313. * is not part of the original payload
  314. */
  315. *enc_len -= c->tag_len;
  316. return (err_status_ok);
  317. }
  318. /*
  319. * Name of this crypto engine
  320. */
  321. char aes_gcm_128_openssl_description[] = "AES-128 GCM using openssl";
  322. char aes_gcm_256_openssl_description[] = "AES-256 GCM using openssl";
  323. /*
  324. * KAT values for AES self-test. These
  325. * values we're derived from independent test code
  326. * using OpenSSL.
  327. */
  328. uint8_t aes_gcm_test_case_0_key[AES_128_GCM_KEYSIZE_WSALT] = {
  329. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  330. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  331. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  332. 0x09, 0x0a, 0x0b, 0x0c,
  333. };
  334. uint8_t aes_gcm_test_case_0_iv[12] = {
  335. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  336. 0xde, 0xca, 0xf8, 0x88
  337. };
  338. uint8_t aes_gcm_test_case_0_plaintext[60] = {
  339. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  340. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  341. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  342. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  343. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  344. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  345. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  346. 0xba, 0x63, 0x7b, 0x39
  347. };
  348. uint8_t aes_gcm_test_case_0_aad[20] = {
  349. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  350. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  351. 0xab, 0xad, 0xda, 0xd2
  352. };
  353. uint8_t aes_gcm_test_case_0_ciphertext[76] = {
  354. 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
  355. 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
  356. 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
  357. 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
  358. 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
  359. 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
  360. 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
  361. 0x3d, 0x58, 0xe0, 0x91,
  362. /* the last 16 bytes are the tag */
  363. 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
  364. 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47,
  365. };
  366. cipher_test_case_t aes_gcm_test_case_0a = {
  367. AES_128_GCM_KEYSIZE_WSALT, /* octets in key */
  368. aes_gcm_test_case_0_key, /* key */
  369. aes_gcm_test_case_0_iv, /* packet index */
  370. 60, /* octets in plaintext */
  371. aes_gcm_test_case_0_plaintext, /* plaintext */
  372. 68, /* octets in ciphertext */
  373. aes_gcm_test_case_0_ciphertext, /* ciphertext + tag */
  374. 20, /* octets in AAD */
  375. aes_gcm_test_case_0_aad, /* AAD */
  376. GCM_AUTH_TAG_LEN_8,
  377. NULL /* pointer to next testcase */
  378. };
  379. cipher_test_case_t aes_gcm_test_case_0 = {
  380. AES_128_GCM_KEYSIZE_WSALT, /* octets in key */
  381. aes_gcm_test_case_0_key, /* key */
  382. aes_gcm_test_case_0_iv, /* packet index */
  383. 60, /* octets in plaintext */
  384. aes_gcm_test_case_0_plaintext, /* plaintext */
  385. 76, /* octets in ciphertext */
  386. aes_gcm_test_case_0_ciphertext, /* ciphertext + tag */
  387. 20, /* octets in AAD */
  388. aes_gcm_test_case_0_aad, /* AAD */
  389. GCM_AUTH_TAG_LEN,
  390. &aes_gcm_test_case_0a /* pointer to next testcase */
  391. };
  392. uint8_t aes_gcm_test_case_1_key[AES_256_GCM_KEYSIZE_WSALT] = {
  393. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  394. 0xa5, 0x59, 0x09, 0xc5, 0x54, 0x66, 0x93, 0x1c,
  395. 0xaf, 0xf5, 0x26, 0x9a, 0x21, 0xd5, 0x14, 0xb2,
  396. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  397. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  398. 0x09, 0x0a, 0x0b, 0x0c,
  399. };
  400. uint8_t aes_gcm_test_case_1_iv[12] = {
  401. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  402. 0xde, 0xca, 0xf8, 0x88
  403. };
  404. uint8_t aes_gcm_test_case_1_plaintext[60] = {
  405. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  406. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  407. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  408. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  409. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  410. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  411. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  412. 0xba, 0x63, 0x7b, 0x39
  413. };
  414. uint8_t aes_gcm_test_case_1_aad[20] = {
  415. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  416. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  417. 0xab, 0xad, 0xda, 0xd2
  418. };
  419. uint8_t aes_gcm_test_case_1_ciphertext[76] = {
  420. 0x0b, 0x11, 0xcf, 0xaf, 0x68, 0x4d, 0xae, 0x46,
  421. 0xc7, 0x90, 0xb8, 0x8e, 0xb7, 0x6a, 0x76, 0x2a,
  422. 0x94, 0x82, 0xca, 0xab, 0x3e, 0x39, 0xd7, 0x86,
  423. 0x1b, 0xc7, 0x93, 0xed, 0x75, 0x7f, 0x23, 0x5a,
  424. 0xda, 0xfd, 0xd3, 0xe2, 0x0e, 0x80, 0x87, 0xa9,
  425. 0x6d, 0xd7, 0xe2, 0x6a, 0x7d, 0x5f, 0xb4, 0x80,
  426. 0xef, 0xef, 0xc5, 0x29, 0x12, 0xd1, 0xaa, 0x10,
  427. 0x09, 0xc9, 0x86, 0xc1,
  428. /* the last 16 bytes are the tag */
  429. 0x45, 0xbc, 0x03, 0xe6, 0xe1, 0xac, 0x0a, 0x9f,
  430. 0x81, 0xcb, 0x8e, 0x5b, 0x46, 0x65, 0x63, 0x1d,
  431. };
  432. cipher_test_case_t aes_gcm_test_case_1a = {
  433. AES_256_GCM_KEYSIZE_WSALT, /* octets in key */
  434. aes_gcm_test_case_1_key, /* key */
  435. aes_gcm_test_case_1_iv, /* packet index */
  436. 60, /* octets in plaintext */
  437. aes_gcm_test_case_1_plaintext, /* plaintext */
  438. 68, /* octets in ciphertext */
  439. aes_gcm_test_case_1_ciphertext, /* ciphertext + tag */
  440. 20, /* octets in AAD */
  441. aes_gcm_test_case_1_aad, /* AAD */
  442. GCM_AUTH_TAG_LEN_8,
  443. NULL /* pointer to next testcase */
  444. };
  445. cipher_test_case_t aes_gcm_test_case_1 = {
  446. AES_256_GCM_KEYSIZE_WSALT, /* octets in key */
  447. aes_gcm_test_case_1_key, /* key */
  448. aes_gcm_test_case_1_iv, /* packet index */
  449. 60, /* octets in plaintext */
  450. aes_gcm_test_case_1_plaintext, /* plaintext */
  451. 76, /* octets in ciphertext */
  452. aes_gcm_test_case_1_ciphertext, /* ciphertext + tag */
  453. 20, /* octets in AAD */
  454. aes_gcm_test_case_1_aad, /* AAD */
  455. GCM_AUTH_TAG_LEN,
  456. &aes_gcm_test_case_1a /* pointer to next testcase */
  457. };
  458. /*
  459. * This is the vector function table for this crypto engine.
  460. */
  461. cipher_type_t aes_gcm_128_openssl = {
  462. (cipher_alloc_func_t) aes_gcm_openssl_alloc,
  463. (cipher_dealloc_func_t) aes_gcm_openssl_dealloc,
  464. (cipher_init_func_t) aes_gcm_openssl_context_init,
  465. (cipher_set_aad_func_t) aes_gcm_openssl_set_aad,
  466. (cipher_encrypt_func_t) aes_gcm_openssl_encrypt,
  467. (cipher_decrypt_func_t) aes_gcm_openssl_decrypt,
  468. (cipher_set_iv_func_t) aes_gcm_openssl_set_iv,
  469. (cipher_get_tag_func_t) aes_gcm_openssl_get_tag,
  470. (char*) aes_gcm_128_openssl_description,
  471. (int) 0, /* instance count */
  472. (cipher_test_case_t*) &aes_gcm_test_case_0,
  473. (debug_module_t*) &mod_aes_gcm,
  474. (cipher_type_id_t) AES_128_GCM
  475. };
  476. /*
  477. * This is the vector function table for this crypto engine.
  478. */
  479. cipher_type_t aes_gcm_256_openssl = {
  480. (cipher_alloc_func_t) aes_gcm_openssl_alloc,
  481. (cipher_dealloc_func_t) aes_gcm_openssl_dealloc,
  482. (cipher_init_func_t) aes_gcm_openssl_context_init,
  483. (cipher_set_aad_func_t) aes_gcm_openssl_set_aad,
  484. (cipher_encrypt_func_t) aes_gcm_openssl_encrypt,
  485. (cipher_decrypt_func_t) aes_gcm_openssl_decrypt,
  486. (cipher_set_iv_func_t) aes_gcm_openssl_set_iv,
  487. (cipher_get_tag_func_t) aes_gcm_openssl_get_tag,
  488. (char*) aes_gcm_256_openssl_description,
  489. (int) 0, /* instance count */
  490. (cipher_test_case_t*) &aes_gcm_test_case_1,
  491. (debug_module_t*) &mod_aes_gcm,
  492. (cipher_type_id_t) AES_256_GCM
  493. };