aes_gcm_ossl.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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-2017, 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. #ifdef HAVE_CONFIG_H
  46. #include <config.h>
  47. #endif
  48. #include <openssl/evp.h>
  49. #include "aes_gcm.h"
  50. #include "alloc.h"
  51. #include "err.h" /* for srtp_debug */
  52. #include "crypto_types.h"
  53. #include "cipher_types.h"
  54. srtp_debug_module_t srtp_mod_aes_gcm = {
  55. 0, /* debugging is off by default */
  56. "aes gcm" /* printable module name */
  57. };
  58. /*
  59. * For now we only support 8 and 16 octet tags. The spec allows for
  60. * optional 12 byte tag, which may be supported in the future.
  61. */
  62. #define GCM_AUTH_TAG_LEN 16
  63. #define GCM_AUTH_TAG_LEN_8 8
  64. /*
  65. * This function allocates a new instance of this crypto engine.
  66. * The key_len parameter should be one of 28 or 44 for
  67. * AES-128-GCM or AES-256-GCM respectively. Note that the
  68. * key length includes the 14 byte salt value that is used when
  69. * initializing the KDF.
  70. */
  71. static srtp_err_status_t srtp_aes_gcm_openssl_alloc(srtp_cipher_t **c,
  72. int key_len,
  73. int tlen)
  74. {
  75. srtp_aes_gcm_ctx_t *gcm;
  76. debug_print(srtp_mod_aes_gcm, "allocating cipher with key length %d",
  77. key_len);
  78. debug_print(srtp_mod_aes_gcm, "allocating cipher with tag length %d", tlen);
  79. /*
  80. * Verify the key_len is valid for one of: AES-128/256
  81. */
  82. if (key_len != SRTP_AES_GCM_128_KEY_LEN_WSALT &&
  83. key_len != SRTP_AES_GCM_256_KEY_LEN_WSALT) {
  84. return (srtp_err_status_bad_param);
  85. }
  86. if (tlen != GCM_AUTH_TAG_LEN && tlen != GCM_AUTH_TAG_LEN_8) {
  87. return (srtp_err_status_bad_param);
  88. }
  89. /* allocate memory a cipher of type aes_gcm */
  90. *c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
  91. if (*c == NULL) {
  92. return (srtp_err_status_alloc_fail);
  93. }
  94. gcm = (srtp_aes_gcm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_gcm_ctx_t));
  95. if (gcm == NULL) {
  96. srtp_crypto_free(*c);
  97. *c = NULL;
  98. return (srtp_err_status_alloc_fail);
  99. }
  100. gcm->ctx = EVP_CIPHER_CTX_new();
  101. if (gcm->ctx == NULL) {
  102. srtp_crypto_free(gcm);
  103. srtp_crypto_free(*c);
  104. *c = NULL;
  105. return srtp_err_status_alloc_fail;
  106. }
  107. /* set pointers */
  108. (*c)->state = gcm;
  109. /* setup cipher attributes */
  110. switch (key_len) {
  111. case SRTP_AES_GCM_128_KEY_LEN_WSALT:
  112. (*c)->type = &srtp_aes_gcm_128;
  113. (*c)->algorithm = SRTP_AES_GCM_128;
  114. gcm->key_size = SRTP_AES_128_KEY_LEN;
  115. gcm->tag_len = tlen;
  116. break;
  117. case SRTP_AES_GCM_256_KEY_LEN_WSALT:
  118. (*c)->type = &srtp_aes_gcm_256;
  119. (*c)->algorithm = SRTP_AES_GCM_256;
  120. gcm->key_size = SRTP_AES_256_KEY_LEN;
  121. gcm->tag_len = tlen;
  122. break;
  123. }
  124. /* set key size */
  125. (*c)->key_len = key_len;
  126. return (srtp_err_status_ok);
  127. }
  128. /*
  129. * This function deallocates a GCM session
  130. */
  131. static srtp_err_status_t srtp_aes_gcm_openssl_dealloc(srtp_cipher_t *c)
  132. {
  133. srtp_aes_gcm_ctx_t *ctx;
  134. ctx = (srtp_aes_gcm_ctx_t *)c->state;
  135. if (ctx) {
  136. EVP_CIPHER_CTX_free(ctx->ctx);
  137. /* zeroize the key material */
  138. octet_string_set_to_zero(ctx, sizeof(srtp_aes_gcm_ctx_t));
  139. srtp_crypto_free(ctx);
  140. }
  141. /* free memory */
  142. srtp_crypto_free(c);
  143. return (srtp_err_status_ok);
  144. }
  145. /*
  146. * aes_gcm_openssl_context_init(...) initializes the aes_gcm_context
  147. * using the value in key[].
  148. *
  149. * the key is the secret key
  150. */
  151. static srtp_err_status_t srtp_aes_gcm_openssl_context_init(void *cv,
  152. const uint8_t *key)
  153. {
  154. srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
  155. const EVP_CIPHER *evp;
  156. c->dir = srtp_direction_any;
  157. debug_print(srtp_mod_aes_gcm, "key: %s",
  158. srtp_octet_string_hex_string(key, c->key_size));
  159. switch (c->key_size) {
  160. case SRTP_AES_256_KEY_LEN:
  161. evp = EVP_aes_256_gcm();
  162. break;
  163. case SRTP_AES_128_KEY_LEN:
  164. evp = EVP_aes_128_gcm();
  165. break;
  166. default:
  167. return (srtp_err_status_bad_param);
  168. break;
  169. }
  170. EVP_CIPHER_CTX_cleanup(c->ctx);
  171. if (!EVP_CipherInit_ex(c->ctx, evp, NULL, key, NULL, 0)) {
  172. return (srtp_err_status_init_fail);
  173. }
  174. return (srtp_err_status_ok);
  175. }
  176. /*
  177. * aes_gcm_openssl_set_iv(c, iv) sets the counter value to the exor of iv with
  178. * the offset
  179. */
  180. static srtp_err_status_t srtp_aes_gcm_openssl_set_iv(
  181. void *cv,
  182. uint8_t *iv,
  183. srtp_cipher_direction_t direction)
  184. {
  185. srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
  186. if (direction != srtp_direction_encrypt &&
  187. direction != srtp_direction_decrypt) {
  188. return (srtp_err_status_bad_param);
  189. }
  190. c->dir = direction;
  191. debug_print(srtp_mod_aes_gcm, "setting iv: %s",
  192. srtp_octet_string_hex_string(iv, 12));
  193. if (!EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_IVLEN, 12, 0)) {
  194. return (srtp_err_status_init_fail);
  195. }
  196. if (!EVP_CipherInit_ex(c->ctx, NULL, NULL, NULL, iv,
  197. (c->dir == srtp_direction_encrypt ? 1 : 0))) {
  198. return (srtp_err_status_init_fail);
  199. }
  200. return (srtp_err_status_ok);
  201. }
  202. /*
  203. * This function processes the AAD
  204. *
  205. * Parameters:
  206. * c Crypto context
  207. * aad Additional data to process for AEAD cipher suites
  208. * aad_len length of aad buffer
  209. */
  210. static srtp_err_status_t srtp_aes_gcm_openssl_set_aad(void *cv,
  211. const uint8_t *aad,
  212. uint32_t aad_len)
  213. {
  214. srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
  215. int rv;
  216. debug_print(srtp_mod_aes_gcm, "setting AAD: %s",
  217. srtp_octet_string_hex_string(aad, aad_len));
  218. /*
  219. * Set dummy tag, OpenSSL requires the Tag to be set before
  220. * processing AAD
  221. */
  222. /*
  223. * OpenSSL never write to address pointed by the last parameter of
  224. * EVP_CIPHER_CTX_ctrl while EVP_CTRL_GCM_SET_TAG (in reality,
  225. * OpenSSL copy its content to the context), so we can make
  226. * aad read-only in this function and all its wrappers.
  227. */
  228. unsigned char dummy_tag[GCM_AUTH_TAG_LEN];
  229. memset(dummy_tag, 0x0, GCM_AUTH_TAG_LEN);
  230. EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_TAG, c->tag_len, &dummy_tag);
  231. rv = EVP_Cipher(c->ctx, NULL, aad, aad_len);
  232. if (rv != aad_len) {
  233. return (srtp_err_status_algo_fail);
  234. } else {
  235. return (srtp_err_status_ok);
  236. }
  237. }
  238. /*
  239. * This function encrypts a buffer using AES GCM mode
  240. *
  241. * Parameters:
  242. * c Crypto context
  243. * buf data to encrypt
  244. * enc_len length of encrypt buffer
  245. */
  246. static srtp_err_status_t srtp_aes_gcm_openssl_encrypt(void *cv,
  247. unsigned char *buf,
  248. unsigned int *enc_len)
  249. {
  250. srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
  251. if (c->dir != srtp_direction_encrypt && c->dir != srtp_direction_decrypt) {
  252. return (srtp_err_status_bad_param);
  253. }
  254. /*
  255. * Encrypt the data
  256. */
  257. EVP_Cipher(c->ctx, buf, buf, *enc_len);
  258. return (srtp_err_status_ok);
  259. }
  260. /*
  261. * This function calculates and returns the GCM tag for a given context.
  262. * This should be called after encrypting the data. The *len value
  263. * is increased by the tag size. The caller must ensure that *buf has
  264. * enough room to accept the appended tag.
  265. *
  266. * Parameters:
  267. * c Crypto context
  268. * buf data to encrypt
  269. * len length of encrypt buffer
  270. */
  271. static srtp_err_status_t srtp_aes_gcm_openssl_get_tag(void *cv,
  272. uint8_t *buf,
  273. uint32_t *len)
  274. {
  275. srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
  276. /*
  277. * Calculate the tag
  278. */
  279. EVP_Cipher(c->ctx, NULL, NULL, 0);
  280. /*
  281. * Retreive the tag
  282. */
  283. EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_GET_TAG, c->tag_len, buf);
  284. /*
  285. * Increase encryption length by desired tag size
  286. */
  287. *len = c->tag_len;
  288. return (srtp_err_status_ok);
  289. }
  290. /*
  291. * This function decrypts a buffer using AES GCM mode
  292. *
  293. * Parameters:
  294. * c Crypto context
  295. * buf data to encrypt
  296. * enc_len length of encrypt buffer
  297. */
  298. static srtp_err_status_t srtp_aes_gcm_openssl_decrypt(void *cv,
  299. unsigned char *buf,
  300. unsigned int *enc_len)
  301. {
  302. srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
  303. if (c->dir != srtp_direction_encrypt && c->dir != srtp_direction_decrypt) {
  304. return (srtp_err_status_bad_param);
  305. }
  306. /*
  307. * Set the tag before decrypting
  308. */
  309. EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_TAG, c->tag_len,
  310. buf + (*enc_len - c->tag_len));
  311. EVP_Cipher(c->ctx, buf, buf, *enc_len - c->tag_len);
  312. /*
  313. * Check the tag
  314. */
  315. if (EVP_Cipher(c->ctx, NULL, NULL, 0)) {
  316. return (srtp_err_status_auth_fail);
  317. }
  318. /*
  319. * Reduce the buffer size by the tag length since the tag
  320. * is not part of the original payload
  321. */
  322. *enc_len -= c->tag_len;
  323. return (srtp_err_status_ok);
  324. }
  325. /*
  326. * Name of this crypto engine
  327. */
  328. static const char srtp_aes_gcm_128_openssl_description[] =
  329. "AES-128 GCM using openssl";
  330. static const char srtp_aes_gcm_256_openssl_description[] =
  331. "AES-256 GCM using openssl";
  332. /*
  333. * KAT values for AES self-test. These
  334. * values we're derived from independent test code
  335. * using OpenSSL.
  336. */
  337. /* clang-format off */
  338. static const uint8_t srtp_aes_gcm_test_case_0_key[SRTP_AES_GCM_128_KEY_LEN_WSALT] = {
  339. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  340. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  341. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  342. 0x09, 0x0a, 0x0b, 0x0c,
  343. };
  344. /* clang-format on */
  345. /* clang-format off */
  346. static uint8_t srtp_aes_gcm_test_case_0_iv[12] = {
  347. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  348. 0xde, 0xca, 0xf8, 0x88
  349. };
  350. /* clang-format on */
  351. /* clang-format off */
  352. static const uint8_t srtp_aes_gcm_test_case_0_plaintext[60] = {
  353. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  354. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  355. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  356. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  357. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  358. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  359. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  360. 0xba, 0x63, 0x7b, 0x39
  361. };
  362. /* clang-format off */
  363. static const uint8_t srtp_aes_gcm_test_case_0_aad[20] = {
  364. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  365. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  366. 0xab, 0xad, 0xda, 0xd2
  367. };
  368. /* clang-format on */
  369. /* clang-format off */
  370. static const uint8_t srtp_aes_gcm_test_case_0_ciphertext[76] = {
  371. 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
  372. 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
  373. 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
  374. 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
  375. 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
  376. 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
  377. 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
  378. 0x3d, 0x58, 0xe0, 0x91,
  379. /* the last 16 bytes are the tag */
  380. 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
  381. 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47,
  382. };
  383. /* clang-format on */
  384. static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_0a = {
  385. SRTP_AES_GCM_128_KEY_LEN_WSALT, /* octets in key */
  386. srtp_aes_gcm_test_case_0_key, /* key */
  387. srtp_aes_gcm_test_case_0_iv, /* packet index */
  388. 60, /* octets in plaintext */
  389. srtp_aes_gcm_test_case_0_plaintext, /* plaintext */
  390. 68, /* octets in ciphertext */
  391. srtp_aes_gcm_test_case_0_ciphertext, /* ciphertext + tag */
  392. 20, /* octets in AAD */
  393. srtp_aes_gcm_test_case_0_aad, /* AAD */
  394. GCM_AUTH_TAG_LEN_8, /* */
  395. NULL /* pointer to next testcase */
  396. };
  397. static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_0 = {
  398. SRTP_AES_GCM_128_KEY_LEN_WSALT, /* octets in key */
  399. srtp_aes_gcm_test_case_0_key, /* key */
  400. srtp_aes_gcm_test_case_0_iv, /* packet index */
  401. 60, /* octets in plaintext */
  402. srtp_aes_gcm_test_case_0_plaintext, /* plaintext */
  403. 76, /* octets in ciphertext */
  404. srtp_aes_gcm_test_case_0_ciphertext, /* ciphertext + tag */
  405. 20, /* octets in AAD */
  406. srtp_aes_gcm_test_case_0_aad, /* AAD */
  407. GCM_AUTH_TAG_LEN, /* */
  408. &srtp_aes_gcm_test_case_0a /* pointer to next testcase */
  409. };
  410. /* clang-format off */
  411. static const uint8_t srtp_aes_gcm_test_case_1_key[SRTP_AES_GCM_256_KEY_LEN_WSALT] = {
  412. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  413. 0xa5, 0x59, 0x09, 0xc5, 0x54, 0x66, 0x93, 0x1c,
  414. 0xaf, 0xf5, 0x26, 0x9a, 0x21, 0xd5, 0x14, 0xb2,
  415. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  416. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  417. 0x09, 0x0a, 0x0b, 0x0c,
  418. };
  419. /* clang-format on */
  420. /* clang-format off */
  421. static uint8_t srtp_aes_gcm_test_case_1_iv[12] = {
  422. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  423. 0xde, 0xca, 0xf8, 0x88
  424. };
  425. /* clang-format on */
  426. /* clang-format off */
  427. static const uint8_t srtp_aes_gcm_test_case_1_plaintext[60] = {
  428. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  429. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  430. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  431. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  432. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  433. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  434. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  435. 0xba, 0x63, 0x7b, 0x39
  436. };
  437. /* clang-format on */
  438. /* clang-format off */
  439. static const uint8_t srtp_aes_gcm_test_case_1_aad[20] = {
  440. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  441. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  442. 0xab, 0xad, 0xda, 0xd2
  443. };
  444. /* clang-format on */
  445. /* clang-format off */
  446. static const uint8_t srtp_aes_gcm_test_case_1_ciphertext[76] = {
  447. 0x0b, 0x11, 0xcf, 0xaf, 0x68, 0x4d, 0xae, 0x46,
  448. 0xc7, 0x90, 0xb8, 0x8e, 0xb7, 0x6a, 0x76, 0x2a,
  449. 0x94, 0x82, 0xca, 0xab, 0x3e, 0x39, 0xd7, 0x86,
  450. 0x1b, 0xc7, 0x93, 0xed, 0x75, 0x7f, 0x23, 0x5a,
  451. 0xda, 0xfd, 0xd3, 0xe2, 0x0e, 0x80, 0x87, 0xa9,
  452. 0x6d, 0xd7, 0xe2, 0x6a, 0x7d, 0x5f, 0xb4, 0x80,
  453. 0xef, 0xef, 0xc5, 0x29, 0x12, 0xd1, 0xaa, 0x10,
  454. 0x09, 0xc9, 0x86, 0xc1,
  455. /* the last 16 bytes are the tag */
  456. 0x45, 0xbc, 0x03, 0xe6, 0xe1, 0xac, 0x0a, 0x9f,
  457. 0x81, 0xcb, 0x8e, 0x5b, 0x46, 0x65, 0x63, 0x1d,
  458. };
  459. /* clang-format on */
  460. static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_1a = {
  461. SRTP_AES_GCM_256_KEY_LEN_WSALT, /* octets in key */
  462. srtp_aes_gcm_test_case_1_key, /* key */
  463. srtp_aes_gcm_test_case_1_iv, /* packet index */
  464. 60, /* octets in plaintext */
  465. srtp_aes_gcm_test_case_1_plaintext, /* plaintext */
  466. 68, /* octets in ciphertext */
  467. srtp_aes_gcm_test_case_1_ciphertext, /* ciphertext + tag */
  468. 20, /* octets in AAD */
  469. srtp_aes_gcm_test_case_1_aad, /* AAD */
  470. GCM_AUTH_TAG_LEN_8, /* */
  471. NULL /* pointer to next testcase */
  472. };
  473. static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_1 = {
  474. SRTP_AES_GCM_256_KEY_LEN_WSALT, /* octets in key */
  475. srtp_aes_gcm_test_case_1_key, /* key */
  476. srtp_aes_gcm_test_case_1_iv, /* packet index */
  477. 60, /* octets in plaintext */
  478. srtp_aes_gcm_test_case_1_plaintext, /* plaintext */
  479. 76, /* octets in ciphertext */
  480. srtp_aes_gcm_test_case_1_ciphertext, /* ciphertext + tag */
  481. 20, /* octets in AAD */
  482. srtp_aes_gcm_test_case_1_aad, /* AAD */
  483. GCM_AUTH_TAG_LEN, /* */
  484. &srtp_aes_gcm_test_case_1a /* pointer to next testcase */
  485. };
  486. /*
  487. * This is the vector function table for this crypto engine.
  488. */
  489. const srtp_cipher_type_t srtp_aes_gcm_128 = {
  490. srtp_aes_gcm_openssl_alloc,
  491. srtp_aes_gcm_openssl_dealloc,
  492. srtp_aes_gcm_openssl_context_init,
  493. srtp_aes_gcm_openssl_set_aad,
  494. srtp_aes_gcm_openssl_encrypt,
  495. srtp_aes_gcm_openssl_decrypt,
  496. srtp_aes_gcm_openssl_set_iv,
  497. srtp_aes_gcm_openssl_get_tag,
  498. srtp_aes_gcm_128_openssl_description,
  499. &srtp_aes_gcm_test_case_0,
  500. SRTP_AES_GCM_128
  501. };
  502. /*
  503. * This is the vector function table for this crypto engine.
  504. */
  505. const srtp_cipher_type_t srtp_aes_gcm_256 = {
  506. srtp_aes_gcm_openssl_alloc,
  507. srtp_aes_gcm_openssl_dealloc,
  508. srtp_aes_gcm_openssl_context_init,
  509. srtp_aes_gcm_openssl_set_aad,
  510. srtp_aes_gcm_openssl_encrypt,
  511. srtp_aes_gcm_openssl_decrypt,
  512. srtp_aes_gcm_openssl_set_iv,
  513. srtp_aes_gcm_openssl_get_tag,
  514. srtp_aes_gcm_256_openssl_description,
  515. &srtp_aes_gcm_test_case_1,
  516. SRTP_AES_GCM_256
  517. };