kmac_prov.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /*
  2. * Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. /*
  10. * See SP800-185 "Appendix A - KMAC, .... in Terms of Keccak[c]"
  11. *
  12. * Inputs are:
  13. * K = Key (len(K) < 2^2040 bits)
  14. * X = Input
  15. * L = Output length (0 <= L < 2^2040 bits)
  16. * S = Customization String Default="" (len(S) < 2^2040 bits)
  17. *
  18. * KMAC128(K, X, L, S)
  19. * {
  20. * newX = bytepad(encode_string(K), 168) || X || right_encode(L).
  21. * T = bytepad(encode_string("KMAC") || encode_string(S), 168).
  22. * return KECCAK[256](T || newX || 00, L).
  23. * }
  24. *
  25. * KMAC256(K, X, L, S)
  26. * {
  27. * newX = bytepad(encode_string(K), 136) || X || right_encode(L).
  28. * T = bytepad(encode_string("KMAC") || encode_string(S), 136).
  29. * return KECCAK[512](T || newX || 00, L).
  30. * }
  31. *
  32. * KMAC128XOF(K, X, L, S)
  33. * {
  34. * newX = bytepad(encode_string(K), 168) || X || right_encode(0).
  35. * T = bytepad(encode_string("KMAC") || encode_string(S), 168).
  36. * return KECCAK[256](T || newX || 00, L).
  37. * }
  38. *
  39. * KMAC256XOF(K, X, L, S)
  40. * {
  41. * newX = bytepad(encode_string(K), 136) || X || right_encode(0).
  42. * T = bytepad(encode_string("KMAC") || encode_string(S), 136).
  43. * return KECCAK[512](T || newX || 00, L).
  44. * }
  45. *
  46. */
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #include <openssl/core_dispatch.h>
  50. #include <openssl/core_names.h>
  51. #include <openssl/params.h>
  52. #include <openssl/evp.h>
  53. #include <openssl/err.h>
  54. #include <openssl/proverr.h>
  55. #include "prov/implementations.h"
  56. #include "prov/provider_ctx.h"
  57. #include "prov/provider_util.h"
  58. #include "prov/providercommon.h"
  59. #include "internal/cryptlib.h" /* ossl_assert */
  60. /*
  61. * Forward declaration of everything implemented here. This is not strictly
  62. * necessary for the compiler, but provides an assurance that the signatures
  63. * of the functions in the dispatch table are correct.
  64. */
  65. static OSSL_FUNC_mac_newctx_fn kmac128_new;
  66. static OSSL_FUNC_mac_newctx_fn kmac256_new;
  67. static OSSL_FUNC_mac_dupctx_fn kmac_dup;
  68. static OSSL_FUNC_mac_freectx_fn kmac_free;
  69. static OSSL_FUNC_mac_gettable_ctx_params_fn kmac_gettable_ctx_params;
  70. static OSSL_FUNC_mac_get_ctx_params_fn kmac_get_ctx_params;
  71. static OSSL_FUNC_mac_settable_ctx_params_fn kmac_settable_ctx_params;
  72. static OSSL_FUNC_mac_set_ctx_params_fn kmac_set_ctx_params;
  73. static OSSL_FUNC_mac_init_fn kmac_init;
  74. static OSSL_FUNC_mac_update_fn kmac_update;
  75. static OSSL_FUNC_mac_final_fn kmac_final;
  76. #define KMAC_MAX_BLOCKSIZE ((1600 - 128*2) / 8) /* 168 */
  77. /* Length encoding will be a 1 byte size + length in bits (2 bytes max) */
  78. #define KMAC_MAX_ENCODED_HEADER_LEN 3
  79. /*
  80. * Restrict the maximum length of the customisation string. This must not
  81. * exceed 64 bits = 8k bytes.
  82. */
  83. #define KMAC_MAX_CUSTOM 256
  84. /* Maximum size of encoded custom string */
  85. #define KMAC_MAX_CUSTOM_ENCODED (KMAC_MAX_CUSTOM + KMAC_MAX_ENCODED_HEADER_LEN)
  86. /* Maximum key size in bytes = 2040 / 8 */
  87. #define KMAC_MAX_KEY 255
  88. /*
  89. * Maximum Encoded Key size will be padded to a multiple of the blocksize
  90. * i.e KMAC_MAX_KEY + KMAC_MAX_ENCODED_LEN = 258
  91. * Padded to a multiple of KMAC_MAX_BLOCKSIZE
  92. */
  93. #define KMAC_MAX_KEY_ENCODED (KMAC_MAX_BLOCKSIZE * 2)
  94. /* Fixed value of encode_string("KMAC") */
  95. static const unsigned char kmac_string[] = {
  96. 0x01, 0x20, 0x4B, 0x4D, 0x41, 0x43
  97. };
  98. #define KMAC_FLAG_XOF_MODE 1
  99. struct kmac_data_st {
  100. void *provctx;
  101. EVP_MD_CTX *ctx;
  102. PROV_DIGEST digest;
  103. size_t out_len;
  104. size_t key_len;
  105. size_t custom_len;
  106. /* If xof_mode = 1 then we use right_encode(0) */
  107. int xof_mode;
  108. /* key and custom are stored in encoded form */
  109. unsigned char key[KMAC_MAX_KEY_ENCODED];
  110. unsigned char custom[KMAC_MAX_CUSTOM_ENCODED];
  111. };
  112. static int encode_string(unsigned char *out, size_t *out_len,
  113. const unsigned char *in, size_t in_len);
  114. static int right_encode(unsigned char *out, size_t *out_len, size_t bits);
  115. static int bytepad(unsigned char *out, size_t *out_len,
  116. const unsigned char *in1, size_t in1_len,
  117. const unsigned char *in2, size_t in2_len,
  118. size_t w);
  119. static int kmac_bytepad_encode_key(unsigned char *out, size_t *out_len,
  120. const unsigned char *in, size_t in_len,
  121. size_t w);
  122. static void kmac_free(void *vmacctx)
  123. {
  124. struct kmac_data_st *kctx = vmacctx;
  125. if (kctx != NULL) {
  126. EVP_MD_CTX_free(kctx->ctx);
  127. ossl_prov_digest_reset(&kctx->digest);
  128. OPENSSL_cleanse(kctx->key, kctx->key_len);
  129. OPENSSL_cleanse(kctx->custom, kctx->custom_len);
  130. OPENSSL_free(kctx);
  131. }
  132. }
  133. /*
  134. * We have KMAC implemented as a hash, which we can use instead of
  135. * reimplementing the EVP functionality with direct use of
  136. * keccak_mac_init() and friends.
  137. */
  138. static struct kmac_data_st *kmac_new(void *provctx)
  139. {
  140. struct kmac_data_st *kctx;
  141. if (!ossl_prov_is_running())
  142. return NULL;
  143. if ((kctx = OPENSSL_zalloc(sizeof(*kctx))) == NULL
  144. || (kctx->ctx = EVP_MD_CTX_new()) == NULL) {
  145. kmac_free(kctx);
  146. return NULL;
  147. }
  148. kctx->provctx = provctx;
  149. return kctx;
  150. }
  151. static void *kmac_fetch_new(void *provctx, const OSSL_PARAM *params)
  152. {
  153. struct kmac_data_st *kctx = kmac_new(provctx);
  154. if (kctx == NULL)
  155. return 0;
  156. if (!ossl_prov_digest_load_from_params(&kctx->digest, params,
  157. PROV_LIBCTX_OF(provctx))) {
  158. kmac_free(kctx);
  159. return 0;
  160. }
  161. kctx->out_len = EVP_MD_size(ossl_prov_digest_md(&kctx->digest));
  162. return kctx;
  163. }
  164. static void *kmac128_new(void *provctx)
  165. {
  166. static const OSSL_PARAM kmac128_params[] = {
  167. OSSL_PARAM_utf8_string("digest", OSSL_DIGEST_NAME_KECCAK_KMAC128,
  168. sizeof(OSSL_DIGEST_NAME_KECCAK_KMAC128)),
  169. OSSL_PARAM_END
  170. };
  171. return kmac_fetch_new(provctx, kmac128_params);
  172. }
  173. static void *kmac256_new(void *provctx)
  174. {
  175. static const OSSL_PARAM kmac256_params[] = {
  176. OSSL_PARAM_utf8_string("digest", OSSL_DIGEST_NAME_KECCAK_KMAC256,
  177. sizeof(OSSL_DIGEST_NAME_KECCAK_KMAC256)),
  178. OSSL_PARAM_END
  179. };
  180. return kmac_fetch_new(provctx, kmac256_params);
  181. }
  182. static void *kmac_dup(void *vsrc)
  183. {
  184. struct kmac_data_st *src = vsrc;
  185. struct kmac_data_st *dst;
  186. if (!ossl_prov_is_running())
  187. return NULL;
  188. dst = kmac_new(src->provctx);
  189. if (dst == NULL)
  190. return NULL;
  191. if (!EVP_MD_CTX_copy(dst->ctx, src->ctx)
  192. || !ossl_prov_digest_copy(&dst->digest, &src->digest)) {
  193. kmac_free(dst);
  194. return NULL;
  195. }
  196. dst->out_len = src->out_len;
  197. dst->key_len = src->key_len;
  198. dst->custom_len = src->custom_len;
  199. dst->xof_mode = src->xof_mode;
  200. memcpy(dst->key, src->key, src->key_len);
  201. memcpy(dst->custom, src->custom, dst->custom_len);
  202. return dst;
  203. }
  204. static size_t kmac_size(void *vmacctx)
  205. {
  206. struct kmac_data_st *kctx = vmacctx;
  207. return kctx->out_len;
  208. }
  209. static int kmac_setkey(struct kmac_data_st *kctx, const unsigned char *key,
  210. size_t keylen)
  211. {
  212. const EVP_MD *digest = ossl_prov_digest_md(&kctx->digest);
  213. int w = EVP_MD_block_size(digest);
  214. if (keylen < 4 || keylen > KMAC_MAX_KEY) {
  215. ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
  216. return 0;
  217. }
  218. if (w < 0) {
  219. ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH);
  220. return 0;
  221. }
  222. if (!kmac_bytepad_encode_key(kctx->key, &kctx->key_len,
  223. key, keylen, (size_t)w))
  224. return 0;
  225. return 1;
  226. }
  227. /*
  228. * The init() assumes that any ctrl methods are set beforehand for
  229. * md, key and custom. Setting the fields afterwards will have no
  230. * effect on the output mac.
  231. */
  232. static int kmac_init(void *vmacctx, const unsigned char *key,
  233. size_t keylen, const OSSL_PARAM params[])
  234. {
  235. struct kmac_data_st *kctx = vmacctx;
  236. EVP_MD_CTX *ctx = kctx->ctx;
  237. unsigned char *out;
  238. size_t out_len, block_len;
  239. int res, t;
  240. if (!ossl_prov_is_running() || !kmac_set_ctx_params(kctx, params))
  241. return 0;
  242. if (key != NULL) {
  243. if (!kmac_setkey(kctx, key, keylen))
  244. return 0;
  245. } else if (kctx->key_len == 0) {
  246. /* Check key has been set */
  247. ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
  248. return 0;
  249. }
  250. if (!EVP_DigestInit_ex(kctx->ctx, ossl_prov_digest_md(&kctx->digest),
  251. NULL))
  252. return 0;
  253. t = EVP_MD_block_size(ossl_prov_digest_md(&kctx->digest));
  254. if (t < 0) {
  255. ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH);
  256. return 0;
  257. }
  258. block_len = t;
  259. /* Set default custom string if it is not already set */
  260. if (kctx->custom_len == 0) {
  261. const OSSL_PARAM cparams[] = {
  262. OSSL_PARAM_octet_string(OSSL_MAC_PARAM_CUSTOM, "", 0),
  263. OSSL_PARAM_END
  264. };
  265. (void)kmac_set_ctx_params(kctx, cparams);
  266. }
  267. if (!bytepad(NULL, &out_len, kmac_string, sizeof(kmac_string),
  268. kctx->custom, kctx->custom_len, block_len)) {
  269. ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
  270. return 0;
  271. }
  272. out = OPENSSL_malloc(out_len);
  273. if (out == NULL) {
  274. ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
  275. return 0;
  276. }
  277. res = bytepad(out, NULL, kmac_string, sizeof(kmac_string),
  278. kctx->custom, kctx->custom_len, block_len)
  279. && EVP_DigestUpdate(ctx, out, out_len)
  280. && EVP_DigestUpdate(ctx, kctx->key, kctx->key_len);
  281. OPENSSL_free(out);
  282. return res;
  283. }
  284. static int kmac_update(void *vmacctx, const unsigned char *data,
  285. size_t datalen)
  286. {
  287. struct kmac_data_st *kctx = vmacctx;
  288. return EVP_DigestUpdate(kctx->ctx, data, datalen);
  289. }
  290. static int kmac_final(void *vmacctx, unsigned char *out, size_t *outl,
  291. size_t outsize)
  292. {
  293. struct kmac_data_st *kctx = vmacctx;
  294. EVP_MD_CTX *ctx = kctx->ctx;
  295. size_t lbits, len;
  296. unsigned char encoded_outlen[KMAC_MAX_ENCODED_HEADER_LEN];
  297. int ok;
  298. if (!ossl_prov_is_running())
  299. return 0;
  300. /* KMAC XOF mode sets the encoded length to 0 */
  301. lbits = (kctx->xof_mode ? 0 : (kctx->out_len * 8));
  302. ok = right_encode(encoded_outlen, &len, lbits)
  303. && EVP_DigestUpdate(ctx, encoded_outlen, len)
  304. && EVP_DigestFinalXOF(ctx, out, kctx->out_len);
  305. *outl = kctx->out_len;
  306. return ok;
  307. }
  308. static const OSSL_PARAM known_gettable_ctx_params[] = {
  309. OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),
  310. OSSL_PARAM_END
  311. };
  312. static const OSSL_PARAM *kmac_gettable_ctx_params(ossl_unused void *ctx,
  313. ossl_unused void *provctx)
  314. {
  315. return known_gettable_ctx_params;
  316. }
  317. static int kmac_get_ctx_params(void *vmacctx, OSSL_PARAM params[])
  318. {
  319. OSSL_PARAM *p;
  320. if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL)
  321. return OSSL_PARAM_set_size_t(p, kmac_size(vmacctx));
  322. return 1;
  323. }
  324. static const OSSL_PARAM known_settable_ctx_params[] = {
  325. OSSL_PARAM_int(OSSL_MAC_PARAM_XOF, NULL),
  326. OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),
  327. OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0),
  328. OSSL_PARAM_octet_string(OSSL_MAC_PARAM_CUSTOM, NULL, 0),
  329. OSSL_PARAM_END
  330. };
  331. static const OSSL_PARAM *kmac_settable_ctx_params(ossl_unused void *ctx,
  332. ossl_unused void *provctx)
  333. {
  334. return known_settable_ctx_params;
  335. }
  336. /*
  337. * The following params can be set any time before final():
  338. * - "outlen" or "size": The requested output length.
  339. * - "xof": If set, this indicates that right_encoded(0)
  340. * is part of the digested data, otherwise it
  341. * uses right_encoded(requested output length).
  342. *
  343. * All other params should be set before init().
  344. */
  345. static int kmac_set_ctx_params(void *vmacctx, const OSSL_PARAM *params)
  346. {
  347. struct kmac_data_st *kctx = vmacctx;
  348. const OSSL_PARAM *p;
  349. if (params == NULL)
  350. return 1;
  351. if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_XOF)) != NULL
  352. && !OSSL_PARAM_get_int(p, &kctx->xof_mode))
  353. return 0;
  354. if (((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_SIZE)) != NULL)
  355. && !OSSL_PARAM_get_size_t(p, &kctx->out_len))
  356. return 0;
  357. if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL
  358. && !kmac_setkey(kctx, p->data, p->data_size))
  359. return 0;
  360. if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_CUSTOM))
  361. != NULL) {
  362. if (p->data_size > KMAC_MAX_CUSTOM) {
  363. ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_CUSTOM_LENGTH);
  364. return 0;
  365. }
  366. if (!encode_string(kctx->custom, &kctx->custom_len,
  367. p->data, p->data_size))
  368. return 0;
  369. }
  370. return 1;
  371. }
  372. /*
  373. * Encoding/Padding Methods.
  374. */
  375. /* Returns the number of bytes required to store 'bits' into a byte array */
  376. static unsigned int get_encode_size(size_t bits)
  377. {
  378. unsigned int cnt = 0, sz = sizeof(size_t);
  379. while (bits && (cnt < sz)) {
  380. ++cnt;
  381. bits >>= 8;
  382. }
  383. /* If bits is zero 1 byte is required */
  384. if (cnt == 0)
  385. cnt = 1;
  386. return cnt;
  387. }
  388. /*
  389. * Convert an integer into bytes . The number of bytes is appended
  390. * to the end of the buffer. Returns an array of bytes 'out' of size
  391. * *out_len.
  392. *
  393. * e.g if bits = 32, out[2] = { 0x20, 0x01 }
  394. *
  395. */
  396. static int right_encode(unsigned char *out, size_t *out_len, size_t bits)
  397. {
  398. unsigned int len = get_encode_size(bits);
  399. int i;
  400. /* The length is constrained to a single byte: 2040/8 = 255 */
  401. if (len > 0xFF) {
  402. ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE);
  403. return 0;
  404. }
  405. /* MSB's are at the start of the bytes array */
  406. for (i = len - 1; i >= 0; --i) {
  407. out[i] = (unsigned char)(bits & 0xFF);
  408. bits >>= 8;
  409. }
  410. /* Tack the length onto the end */
  411. out[len] = (unsigned char)len;
  412. /* The Returned length includes the tacked on byte */
  413. *out_len = len + 1;
  414. return 1;
  415. }
  416. /*
  417. * Encodes a string with a left encoded length added. Note that the
  418. * in_len is converted to bits (*8).
  419. *
  420. * e.g- in="KMAC" gives out[6] = { 0x01, 0x20, 0x4B, 0x4D, 0x41, 0x43 }
  421. * len bits K M A C
  422. */
  423. static int encode_string(unsigned char *out, size_t *out_len,
  424. const unsigned char *in, size_t in_len)
  425. {
  426. if (in == NULL) {
  427. *out_len = 0;
  428. } else {
  429. size_t i, bits, len;
  430. bits = 8 * in_len;
  431. len = get_encode_size(bits);
  432. if (len > 0xFF) {
  433. ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE);
  434. return 0;
  435. }
  436. out[0] = (unsigned char)len;
  437. for (i = len; i > 0; --i) {
  438. out[i] = (bits & 0xFF);
  439. bits >>= 8;
  440. }
  441. memcpy(out + len + 1, in, in_len);
  442. *out_len = (1 + len + in_len);
  443. }
  444. return 1;
  445. }
  446. /*
  447. * Returns a zero padded encoding of the inputs in1 and an optional
  448. * in2 (can be NULL). The padded output must be a multiple of the blocksize 'w'.
  449. * The value of w is in bytes (< 256).
  450. *
  451. * The returned output is:
  452. * zero_padded(multiple of w, (left_encode(w) || in1 [|| in2])
  453. */
  454. static int bytepad(unsigned char *out, size_t *out_len,
  455. const unsigned char *in1, size_t in1_len,
  456. const unsigned char *in2, size_t in2_len, size_t w)
  457. {
  458. int len;
  459. unsigned char *p = out;
  460. int sz = w;
  461. if (out == NULL) {
  462. if (out_len == NULL) {
  463. ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER);
  464. return 0;
  465. }
  466. sz = 2 + in1_len + (in2 != NULL ? in2_len : 0);
  467. *out_len = (sz + w - 1) / w * w;
  468. return 1;
  469. }
  470. if (!ossl_assert(w <= 255))
  471. return 0;
  472. /* Left encoded w */
  473. *p++ = 1;
  474. *p++ = (unsigned char)w;
  475. /* || in1 */
  476. memcpy(p, in1, in1_len);
  477. p += in1_len;
  478. /* [ || in2 ] */
  479. if (in2 != NULL && in2_len > 0) {
  480. memcpy(p, in2, in2_len);
  481. p += in2_len;
  482. }
  483. /* Figure out the pad size (divisible by w) */
  484. len = p - out;
  485. sz = (len + w - 1) / w * w;
  486. /* zero pad the end of the buffer */
  487. if (sz != len)
  488. memset(p, 0, sz - len);
  489. if (out_len != NULL)
  490. *out_len = sz;
  491. return 1;
  492. }
  493. /*
  494. * Returns out = bytepad(encode_string(in), w)
  495. */
  496. static int kmac_bytepad_encode_key(unsigned char *out, size_t *out_len,
  497. const unsigned char *in, size_t in_len,
  498. size_t w)
  499. {
  500. unsigned char tmp[KMAC_MAX_KEY + KMAC_MAX_ENCODED_HEADER_LEN];
  501. size_t tmp_len;
  502. if (!encode_string(tmp, &tmp_len, in, in_len))
  503. return 0;
  504. return bytepad(out, out_len, tmp, tmp_len, NULL, 0, w);
  505. }
  506. const OSSL_DISPATCH ossl_kmac128_functions[] = {
  507. { OSSL_FUNC_MAC_NEWCTX, (void (*)(void))kmac128_new },
  508. { OSSL_FUNC_MAC_DUPCTX, (void (*)(void))kmac_dup },
  509. { OSSL_FUNC_MAC_FREECTX, (void (*)(void))kmac_free },
  510. { OSSL_FUNC_MAC_INIT, (void (*)(void))kmac_init },
  511. { OSSL_FUNC_MAC_UPDATE, (void (*)(void))kmac_update },
  512. { OSSL_FUNC_MAC_FINAL, (void (*)(void))kmac_final },
  513. { OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS,
  514. (void (*)(void))kmac_gettable_ctx_params },
  515. { OSSL_FUNC_MAC_GET_CTX_PARAMS, (void (*)(void))kmac_get_ctx_params },
  516. { OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS,
  517. (void (*)(void))kmac_settable_ctx_params },
  518. { OSSL_FUNC_MAC_SET_CTX_PARAMS, (void (*)(void))kmac_set_ctx_params },
  519. { 0, NULL }
  520. };
  521. const OSSL_DISPATCH ossl_kmac256_functions[] = {
  522. { OSSL_FUNC_MAC_NEWCTX, (void (*)(void))kmac256_new },
  523. { OSSL_FUNC_MAC_DUPCTX, (void (*)(void))kmac_dup },
  524. { OSSL_FUNC_MAC_FREECTX, (void (*)(void))kmac_free },
  525. { OSSL_FUNC_MAC_INIT, (void (*)(void))kmac_init },
  526. { OSSL_FUNC_MAC_UPDATE, (void (*)(void))kmac_update },
  527. { OSSL_FUNC_MAC_FINAL, (void (*)(void))kmac_final },
  528. { OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS,
  529. (void (*)(void))kmac_gettable_ctx_params },
  530. { OSSL_FUNC_MAC_GET_CTX_PARAMS, (void (*)(void))kmac_get_ctx_params },
  531. { OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS,
  532. (void (*)(void))kmac_settable_ctx_params },
  533. { OSSL_FUNC_MAC_SET_CTX_PARAMS, (void (*)(void))kmac_set_ctx_params },
  534. { 0, NULL }
  535. };