Path: blob/main/crypto/openssl/providers/implementations/macs/kmac_prov.c
48383 views
/*1* Copyright 2018-2024 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89/*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 = Input15* 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*/4748#include <stdlib.h>49#include <string.h>50#include <openssl/core_dispatch.h>51#include <openssl/core_names.h>52#include <openssl/params.h>53#include <openssl/evp.h>54#include <openssl/err.h>55#include <openssl/proverr.h>56#include <openssl/fips_names.h>57#include "prov/securitycheck.h"58#include "prov/implementations.h"59#include "prov/provider_ctx.h"60#include "prov/provider_util.h"61#include "prov/providercommon.h"62#include "internal/cryptlib.h" /* ossl_assert */6364/*65* Forward declaration of everything implemented here. This is not strictly66* necessary for the compiler, but provides an assurance that the signatures67* of the functions in the dispatch table are correct.68*/69static OSSL_FUNC_mac_newctx_fn kmac128_new;70static OSSL_FUNC_mac_newctx_fn kmac256_new;71static OSSL_FUNC_mac_dupctx_fn kmac_dup;72static OSSL_FUNC_mac_freectx_fn kmac_free;73static OSSL_FUNC_mac_gettable_ctx_params_fn kmac_gettable_ctx_params;74static OSSL_FUNC_mac_get_ctx_params_fn kmac_get_ctx_params;75static OSSL_FUNC_mac_settable_ctx_params_fn kmac_settable_ctx_params;76static OSSL_FUNC_mac_set_ctx_params_fn kmac_set_ctx_params;77static OSSL_FUNC_mac_init_fn kmac_init;78static OSSL_FUNC_mac_update_fn kmac_update;79static OSSL_FUNC_mac_final_fn kmac_final;8081#define KMAC_MAX_BLOCKSIZE ((1600 - 128 * 2) / 8) /* 168 */8283/*84* Length encoding will be a 1 byte size + length in bits (3 bytes max)85* This gives a range of 0..0XFFFFFF bits = 2097151 bytes).86*/87#define KMAC_MAX_OUTPUT_LEN (0xFFFFFF / 8)88#define KMAC_MAX_ENCODED_HEADER_LEN (1 + 3)8990/*91* Restrict the maximum length of the customisation string. This must not92* exceed 64 bits = 8k bytes.93*/94#define KMAC_MAX_CUSTOM 5129596/* Maximum size of encoded custom string */97#define KMAC_MAX_CUSTOM_ENCODED (KMAC_MAX_CUSTOM + KMAC_MAX_ENCODED_HEADER_LEN)9899/* Maximum key size in bytes = 512 (4096 bits) */100#define KMAC_MAX_KEY 512101#define KMAC_MIN_KEY 4102103/*104* Maximum Encoded Key size will be padded to a multiple of the blocksize105* i.e KMAC_MAX_KEY + KMAC_MAX_ENCODED_HEADER_LEN = 512 + 4106* Padded to a multiple of KMAC_MAX_BLOCKSIZE107*/108#define KMAC_MAX_KEY_ENCODED (KMAC_MAX_BLOCKSIZE * 4)109110/* Fixed value of encode_string("KMAC") */111static const unsigned char kmac_string[] = {1120x01, 0x20, 0x4B, 0x4D, 0x41, 0x43113};114115#define KMAC_FLAG_XOF_MODE 1116117struct kmac_data_st {118void *provctx;119EVP_MD_CTX *ctx;120PROV_DIGEST digest;121size_t out_len;122size_t key_len;123size_t custom_len;124/* If xof_mode = 1 then we use right_encode(0) */125int xof_mode;126/* key and custom are stored in encoded form */127unsigned char key[KMAC_MAX_KEY_ENCODED];128unsigned char custom[KMAC_MAX_CUSTOM_ENCODED];129#ifdef FIPS_MODULE130/*131* 'internal' is set to 1 if KMAC is used inside another algorithm such as a132* KDF. In this case it is the parent algorithm that is responsible for133* performing any conditional FIPS indicator related checks for KMAC.134*/135int internal;136#endif137OSSL_FIPS_IND_DECLARE138};139140static int encode_string(unsigned char *out, size_t out_max_len, size_t *out_len,141const unsigned char *in, size_t in_len);142static int right_encode(unsigned char *out, size_t out_max_len, size_t *out_len,143size_t bits);144static int bytepad(unsigned char *out, size_t *out_len,145const unsigned char *in1, size_t in1_len,146const unsigned char *in2, size_t in2_len,147size_t w);148static int kmac_bytepad_encode_key(unsigned char *out, size_t out_max_len,149size_t *out_len,150const unsigned char *in, size_t in_len,151size_t w);152153static void kmac_free(void *vmacctx)154{155struct kmac_data_st *kctx = vmacctx;156157if (kctx != NULL) {158EVP_MD_CTX_free(kctx->ctx);159ossl_prov_digest_reset(&kctx->digest);160OPENSSL_cleanse(kctx->key, kctx->key_len);161OPENSSL_cleanse(kctx->custom, kctx->custom_len);162OPENSSL_free(kctx);163}164}165166/*167* We have KMAC implemented as a hash, which we can use instead of168* reimplementing the EVP functionality with direct use of169* keccak_mac_init() and friends.170*/171static struct kmac_data_st *kmac_new(void *provctx)172{173struct kmac_data_st *kctx;174175if (!ossl_prov_is_running())176return NULL;177178if ((kctx = OPENSSL_zalloc(sizeof(*kctx))) == NULL179|| (kctx->ctx = EVP_MD_CTX_new()) == NULL) {180kmac_free(kctx);181return NULL;182}183kctx->provctx = provctx;184OSSL_FIPS_IND_INIT(kctx)185return kctx;186}187188static void *kmac_fetch_new(void *provctx, const OSSL_PARAM *params)189{190struct kmac_data_st *kctx = kmac_new(provctx);191int md_size;192193if (kctx == NULL)194return 0;195if (!ossl_prov_digest_load_from_params(&kctx->digest, params,196PROV_LIBCTX_OF(provctx))) {197kmac_free(kctx);198return 0;199}200201md_size = EVP_MD_get_size(ossl_prov_digest_md(&kctx->digest));202if (md_size <= 0) {203kmac_free(kctx);204return 0;205}206kctx->out_len = (size_t)md_size;207return kctx;208}209210static void *kmac128_new(void *provctx)211{212static const OSSL_PARAM kmac128_params[] = {213OSSL_PARAM_utf8_string("digest", OSSL_DIGEST_NAME_KECCAK_KMAC128,214sizeof(OSSL_DIGEST_NAME_KECCAK_KMAC128)),215OSSL_PARAM_END216};217return kmac_fetch_new(provctx, kmac128_params);218}219220static void *kmac256_new(void *provctx)221{222static const OSSL_PARAM kmac256_params[] = {223OSSL_PARAM_utf8_string("digest", OSSL_DIGEST_NAME_KECCAK_KMAC256,224sizeof(OSSL_DIGEST_NAME_KECCAK_KMAC256)),225OSSL_PARAM_END226};227return kmac_fetch_new(provctx, kmac256_params);228}229230static void *kmac_dup(void *vsrc)231{232struct kmac_data_st *src = vsrc;233struct kmac_data_st *dst;234235if (!ossl_prov_is_running())236return NULL;237238dst = kmac_new(src->provctx);239if (dst == NULL)240return NULL;241242if (!EVP_MD_CTX_copy(dst->ctx, src->ctx)243|| !ossl_prov_digest_copy(&dst->digest, &src->digest)) {244kmac_free(dst);245return NULL;246}247#ifdef FIPS_MODULE248dst->internal = src->internal;249#endif250dst->out_len = src->out_len;251dst->key_len = src->key_len;252dst->custom_len = src->custom_len;253dst->xof_mode = src->xof_mode;254memcpy(dst->key, src->key, src->key_len);255memcpy(dst->custom, src->custom, dst->custom_len);256OSSL_FIPS_IND_COPY(dst, src)257258return dst;259}260261static int kmac_setkey(struct kmac_data_st *kctx, const unsigned char *key,262size_t keylen)263{264const EVP_MD *digest = ossl_prov_digest_md(&kctx->digest);265int w = EVP_MD_get_block_size(digest);266267if (keylen < KMAC_MIN_KEY || keylen > KMAC_MAX_KEY) {268ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);269return 0;270}271#ifdef FIPS_MODULE272/*273* Only do the key check if KMAC is fetched directly.274* Other algorithms that embed KMAC such as SSKDF will ignore this check.275*/276if (!kctx->internal) {277int approved = ossl_mac_check_key_size(keylen);278279if (!approved) {280if (!OSSL_FIPS_IND_ON_UNAPPROVED(kctx, OSSL_FIPS_IND_SETTABLE1,281PROV_LIBCTX_OF(kctx->provctx),282"KMAC", "Key size",283ossl_fips_config_kmac_key_check)) {284ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);285return 0;286}287}288}289#endif290if (w <= 0) {291ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH);292return 0;293}294if (!kmac_bytepad_encode_key(kctx->key, sizeof(kctx->key), &kctx->key_len,295key, keylen, (size_t)w))296return 0;297return 1;298}299300/*301* The init() assumes that any ctrl methods are set beforehand for302* md, key and custom. Setting the fields afterwards will have no303* effect on the output mac.304*/305static int kmac_init(void *vmacctx, const unsigned char *key,306size_t keylen, const OSSL_PARAM params[])307{308struct kmac_data_st *kctx = vmacctx;309EVP_MD_CTX *ctx = kctx->ctx;310unsigned char *out;311size_t out_len, block_len;312int res, t;313314if (!ossl_prov_is_running() || !kmac_set_ctx_params(kctx, params))315return 0;316317if (key != NULL) {318if (!kmac_setkey(kctx, key, keylen))319return 0;320} else if (kctx->key_len == 0) {321/* Check key has been set */322ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);323return 0;324}325if (!EVP_DigestInit_ex(kctx->ctx, ossl_prov_digest_md(&kctx->digest),326NULL))327return 0;328329t = EVP_MD_get_block_size(ossl_prov_digest_md(&kctx->digest));330if (t <= 0) {331ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH);332return 0;333}334block_len = t;335336/* Set default custom string if it is not already set */337if (kctx->custom_len == 0) {338const OSSL_PARAM cparams[] = {339OSSL_PARAM_octet_string(OSSL_MAC_PARAM_CUSTOM, "", 0),340OSSL_PARAM_END341};342(void)kmac_set_ctx_params(kctx, cparams);343}344345if (!bytepad(NULL, &out_len, kmac_string, sizeof(kmac_string),346kctx->custom, kctx->custom_len, block_len)) {347ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);348return 0;349}350out = OPENSSL_malloc(out_len);351if (out == NULL)352return 0;353res = bytepad(out, NULL, kmac_string, sizeof(kmac_string),354kctx->custom, kctx->custom_len, block_len)355&& EVP_DigestUpdate(ctx, out, out_len)356&& EVP_DigestUpdate(ctx, kctx->key, kctx->key_len);357OPENSSL_free(out);358return res;359}360361static int kmac_update(void *vmacctx, const unsigned char *data,362size_t datalen)363{364struct kmac_data_st *kctx = vmacctx;365366return EVP_DigestUpdate(kctx->ctx, data, datalen);367}368369static int kmac_final(void *vmacctx, unsigned char *out, size_t *outl,370size_t outsize)371{372struct kmac_data_st *kctx = vmacctx;373EVP_MD_CTX *ctx = kctx->ctx;374size_t lbits, len;375unsigned char encoded_outlen[KMAC_MAX_ENCODED_HEADER_LEN];376int ok;377378if (!ossl_prov_is_running())379return 0;380381/* KMAC XOF mode sets the encoded length to 0 */382lbits = (kctx->xof_mode ? 0 : (kctx->out_len * 8));383384ok = right_encode(encoded_outlen, sizeof(encoded_outlen), &len, lbits)385&& EVP_DigestUpdate(ctx, encoded_outlen, len)386&& EVP_DigestFinalXOF(ctx, out, kctx->out_len);387*outl = kctx->out_len;388return ok;389}390391static const OSSL_PARAM known_gettable_ctx_params[] = {392OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),393OSSL_PARAM_size_t(OSSL_MAC_PARAM_BLOCK_SIZE, NULL),394OSSL_FIPS_IND_GETTABLE_CTX_PARAM()395OSSL_PARAM_END396};397static const OSSL_PARAM *kmac_gettable_ctx_params(ossl_unused void *ctx,398ossl_unused void *provctx)399{400return known_gettable_ctx_params;401}402403static int kmac_get_ctx_params(void *vmacctx, OSSL_PARAM params[])404{405struct kmac_data_st *kctx = vmacctx;406OSSL_PARAM *p;407int sz;408409if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL410&& !OSSL_PARAM_set_size_t(p, kctx->out_len))411return 0;412413if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_BLOCK_SIZE)) != NULL) {414sz = EVP_MD_block_size(ossl_prov_digest_md(&kctx->digest));415if (!OSSL_PARAM_set_int(p, sz))416return 0;417}418419if (!OSSL_FIPS_IND_GET_CTX_PARAM(kctx, params))420return 0;421422return 1;423}424425static const OSSL_PARAM known_settable_ctx_params[] = {426OSSL_PARAM_int(OSSL_MAC_PARAM_XOF, NULL),427OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),428OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0),429OSSL_PARAM_octet_string(OSSL_MAC_PARAM_CUSTOM, NULL, 0),430OSSL_FIPS_IND_SETTABLE_CTX_PARAM(OSSL_MAC_PARAM_FIPS_NO_SHORT_MAC)431OSSL_FIPS_IND_SETTABLE_CTX_PARAM(OSSL_MAC_PARAM_FIPS_KEY_CHECK)432OSSL_PARAM_END433};434static const OSSL_PARAM *kmac_settable_ctx_params(ossl_unused void *ctx,435ossl_unused void *provctx)436{437return known_settable_ctx_params;438}439440/*441* The following params can be set any time before final():442* - "outlen" or "size": The requested output length.443* - "xof": If set, this indicates that right_encoded(0)444* is part of the digested data, otherwise it445* uses right_encoded(requested output length).446*447* All other params should be set before init().448*/449static int kmac_set_ctx_params(void *vmacctx, const OSSL_PARAM *params)450{451struct kmac_data_st *kctx = vmacctx;452const OSSL_PARAM *p;453454if (ossl_param_is_empty(params))455return 1;456457if (!OSSL_FIPS_IND_SET_CTX_PARAM(kctx, OSSL_FIPS_IND_SETTABLE0, params,458OSSL_MAC_PARAM_FIPS_NO_SHORT_MAC))459return 0;460if (!OSSL_FIPS_IND_SET_CTX_PARAM(kctx, OSSL_FIPS_IND_SETTABLE1, params,461OSSL_MAC_PARAM_FIPS_KEY_CHECK))462return 0;463464if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_XOF)) != NULL465&& !OSSL_PARAM_get_int(p, &kctx->xof_mode))466return 0;467if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_SIZE)) != NULL) {468size_t sz = 0;469470if (!OSSL_PARAM_get_size_t(p, &sz))471return 0;472if (sz > KMAC_MAX_OUTPUT_LEN) {473ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_OUTPUT_LENGTH);474return 0;475}476#ifdef FIPS_MODULE477/* SP 800-185 8.4.2 mandates a minimum of 32 bits of output */478if (sz < 32 / 8) {479if (!OSSL_FIPS_IND_ON_UNAPPROVED(kctx, OSSL_FIPS_IND_SETTABLE0,480PROV_LIBCTX_OF(kctx->provctx),481"KMAC", "length",482ossl_fips_config_no_short_mac)) {483ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_OUTPUT_LENGTH);484return 0;485}486}487#endif488kctx->out_len = sz;489}490if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL491&& !kmac_setkey(kctx, p->data, p->data_size))492return 0;493if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_CUSTOM))494!= NULL) {495if (p->data_size > KMAC_MAX_CUSTOM) {496ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_CUSTOM_LENGTH);497return 0;498}499if (!encode_string(kctx->custom, sizeof(kctx->custom), &kctx->custom_len,500p->data, p->data_size))501return 0;502}503return 1;504}505506/* Encoding/Padding Methods. */507508/* Returns the number of bytes required to store 'bits' into a byte array */509static unsigned int get_encode_size(size_t bits)510{511unsigned int cnt = 0, sz = sizeof(size_t);512513while (bits && (cnt < sz)) {514++cnt;515bits >>= 8;516}517/* If bits is zero 1 byte is required */518if (cnt == 0)519cnt = 1;520return cnt;521}522523/*524* Convert an integer into bytes . The number of bytes is appended525* to the end of the buffer. Returns an array of bytes 'out' of size526* *out_len.527*528* e.g if bits = 32, out[2] = { 0x20, 0x01 }529*/530static int right_encode(unsigned char *out, size_t out_max_len, size_t *out_len,531size_t bits)532{533unsigned int len = get_encode_size(bits);534int i;535536if (len >= out_max_len) {537ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE);538return 0;539}540541/* MSB's are at the start of the bytes array */542for (i = len - 1; i >= 0; --i) {543out[i] = (unsigned char)(bits & 0xFF);544bits >>= 8;545}546/* Tack the length onto the end */547out[len] = (unsigned char)len;548549/* The Returned length includes the tacked on byte */550*out_len = len + 1;551return 1;552}553554/*555* Encodes a string with a left encoded length added. Note that the556* in_len is converted to bits (*8).557*558* e.g- in="KMAC" gives out[6] = { 0x01, 0x20, 0x4B, 0x4D, 0x41, 0x43 }559* len bits K M A C560*/561static int encode_string(unsigned char *out, size_t out_max_len, size_t *out_len,562const unsigned char *in, size_t in_len)563{564if (in == NULL) {565*out_len = 0;566} else {567size_t i, bits, len, sz;568569bits = 8 * in_len;570len = get_encode_size(bits);571sz = 1 + len + in_len;572573if (sz > out_max_len) {574ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE);575return 0;576}577578out[0] = (unsigned char)len;579for (i = len; i > 0; --i) {580out[i] = (bits & 0xFF);581bits >>= 8;582}583memcpy(out + len + 1, in, in_len);584*out_len = sz;585}586return 1;587}588589/*590* Returns a zero padded encoding of the inputs in1 and an optional591* in2 (can be NULL). The padded output must be a multiple of the blocksize 'w'.592* The value of w is in bytes (< 256).593*594* The returned output is:595* zero_padded(multiple of w, (left_encode(w) || in1 [|| in2])596*/597static int bytepad(unsigned char *out, size_t *out_len,598const unsigned char *in1, size_t in1_len,599const unsigned char *in2, size_t in2_len, size_t w)600{601int len;602unsigned char *p = out;603int sz = w;604605if (out == NULL) {606if (out_len == NULL) {607ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER);608return 0;609}610sz = 2 + in1_len + (in2 != NULL ? in2_len : 0);611*out_len = (sz + w - 1) / w * w;612return 1;613}614615if (!ossl_assert(w <= 255))616return 0;617618/* Left encoded w */619*p++ = 1;620*p++ = (unsigned char)w;621/* || in1 */622memcpy(p, in1, in1_len);623p += in1_len;624/* [ || in2 ] */625if (in2 != NULL && in2_len > 0) {626memcpy(p, in2, in2_len);627p += in2_len;628}629/* Figure out the pad size (divisible by w) */630len = p - out;631sz = (len + w - 1) / w * w;632/* zero pad the end of the buffer */633if (sz != len)634memset(p, 0, sz - len);635if (out_len != NULL)636*out_len = sz;637return 1;638}639640/* Returns out = bytepad(encode_string(in), w) */641static int kmac_bytepad_encode_key(unsigned char *out, size_t out_max_len,642size_t *out_len,643const unsigned char *in, size_t in_len,644size_t w)645{646unsigned char tmp[KMAC_MAX_KEY + KMAC_MAX_ENCODED_HEADER_LEN];647size_t tmp_len;648649if (!encode_string(tmp, sizeof(tmp), &tmp_len, in, in_len))650return 0;651if (!bytepad(NULL, out_len, tmp, tmp_len, NULL, 0, w))652return 0;653if (!ossl_assert(*out_len <= out_max_len))654return 0;655return bytepad(out, NULL, tmp, tmp_len, NULL, 0, w);656}657658#define IMPLEMENT_KMAC_TABLE(size, funcname, newname) \659const OSSL_DISPATCH ossl_kmac##size##_##funcname[] = \660{ \661{ OSSL_FUNC_MAC_NEWCTX, (void (*)(void))kmac##size##_##newname }, \662{ OSSL_FUNC_MAC_DUPCTX, (void (*)(void))kmac_dup }, \663{ OSSL_FUNC_MAC_FREECTX, (void (*)(void))kmac_free }, \664{ OSSL_FUNC_MAC_INIT, (void (*)(void))kmac_init }, \665{ OSSL_FUNC_MAC_UPDATE, (void (*)(void))kmac_update }, \666{ OSSL_FUNC_MAC_FINAL, (void (*)(void))kmac_final }, \667{ OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS, \668(void (*)(void))kmac_gettable_ctx_params }, \669{ OSSL_FUNC_MAC_GET_CTX_PARAMS, (void (*)(void))kmac_get_ctx_params }, \670{ OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS, \671(void (*)(void))kmac_settable_ctx_params }, \672{ OSSL_FUNC_MAC_SET_CTX_PARAMS, (void (*)(void))kmac_set_ctx_params }, \673OSSL_DISPATCH_END \674}675676#define KMAC_TABLE(size) IMPLEMENT_KMAC_TABLE(size, functions, new)677678KMAC_TABLE(128);679KMAC_TABLE(256);680681#ifdef FIPS_MODULE682# define KMAC_INTERNAL_TABLE(size) \683static OSSL_FUNC_mac_newctx_fn kmac##size##_internal_new; \684static void *kmac##size##_internal_new(void *provctx) \685{ \686struct kmac_data_st *macctx = kmac##size##_new(provctx); \687\688if (macctx != NULL) \689macctx->internal = 1; \690return macctx; \691} \692IMPLEMENT_KMAC_TABLE(size, internal_functions, internal_new)693694KMAC_INTERNAL_TABLE(128);695KMAC_INTERNAL_TABLE(256);696#endif /* FIPS_MODULE */697698699