2018-11-09 12:00:05 +08:00
|
|
|
/*
|
2024-09-05 15:35:49 +08:00
|
|
|
* Copyright 2018-2024 The OpenSSL Project Authors. All Rights Reserved.
|
2018-11-09 12:00:05 +08:00
|
|
|
*
|
2018-12-06 20:42:17 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2018-11-09 12:00:05 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See SP800-185 "Appendix A - KMAC, .... in Terms of Keccak[c]"
|
|
|
|
*
|
|
|
|
* Inputs are:
|
|
|
|
* K = Key (len(K) < 2^2040 bits)
|
|
|
|
* X = Input
|
|
|
|
* L = Output length (0 <= L < 2^2040 bits)
|
|
|
|
* S = Customization String Default="" (len(S) < 2^2040 bits)
|
|
|
|
*
|
|
|
|
* KMAC128(K, X, L, S)
|
|
|
|
* {
|
|
|
|
* newX = bytepad(encode_string(K), 168) || X || right_encode(L).
|
2018-12-07 11:13:49 +08:00
|
|
|
* T = bytepad(encode_string("KMAC") || encode_string(S), 168).
|
2018-11-09 12:00:05 +08:00
|
|
|
* return KECCAK[256](T || newX || 00, L).
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* KMAC256(K, X, L, S)
|
|
|
|
* {
|
|
|
|
* newX = bytepad(encode_string(K), 136) || X || right_encode(L).
|
2018-12-07 11:13:49 +08:00
|
|
|
* T = bytepad(encode_string("KMAC") || encode_string(S), 136).
|
2018-11-09 12:00:05 +08:00
|
|
|
* return KECCAK[512](T || newX || 00, L).
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* KMAC128XOF(K, X, L, S)
|
|
|
|
* {
|
|
|
|
* newX = bytepad(encode_string(K), 168) || X || right_encode(0).
|
2018-12-07 11:13:49 +08:00
|
|
|
* T = bytepad(encode_string("KMAC") || encode_string(S), 168).
|
2018-11-09 12:00:05 +08:00
|
|
|
* return KECCAK[256](T || newX || 00, L).
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* KMAC256XOF(K, X, L, S)
|
|
|
|
* {
|
|
|
|
* newX = bytepad(encode_string(K), 136) || X || right_encode(0).
|
2018-12-07 11:13:49 +08:00
|
|
|
* T = bytepad(encode_string("KMAC") || encode_string(S), 136).
|
2018-11-09 12:00:05 +08:00
|
|
|
* return KECCAK[512](T || newX || 00, L).
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2019-06-02 14:46:35 +08:00
|
|
|
#include <string.h>
|
2020-06-21 07:21:19 +08:00
|
|
|
#include <openssl/core_dispatch.h>
|
2019-06-02 14:46:35 +08:00
|
|
|
#include <openssl/core_names.h>
|
|
|
|
#include <openssl/params.h>
|
2018-11-09 12:00:05 +08:00
|
|
|
#include <openssl/evp.h>
|
2019-06-02 14:46:35 +08:00
|
|
|
#include <openssl/err.h>
|
2021-02-06 00:40:42 +08:00
|
|
|
#include <openssl/proverr.h>
|
2024-07-17 11:56:08 +08:00
|
|
|
#include <openssl/fips_names.h>
|
2024-08-12 17:31:10 +08:00
|
|
|
#include "prov/securitycheck.h"
|
2019-10-04 21:20:48 +08:00
|
|
|
#include "prov/implementations.h"
|
2019-10-04 21:25:59 +08:00
|
|
|
#include "prov/provider_ctx.h"
|
|
|
|
#include "prov/provider_util.h"
|
2020-09-07 11:03:07 +08:00
|
|
|
#include "prov/providercommon.h"
|
2021-04-13 10:24:25 +08:00
|
|
|
#include "internal/cryptlib.h" /* ossl_assert */
|
2019-06-02 14:46:35 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Forward declaration of everything implemented here. This is not strictly
|
|
|
|
* necessary for the compiler, but provides an assurance that the signatures
|
|
|
|
* of the functions in the dispatch table are correct.
|
|
|
|
*/
|
2020-06-21 07:19:16 +08:00
|
|
|
static OSSL_FUNC_mac_newctx_fn kmac128_new;
|
|
|
|
static OSSL_FUNC_mac_newctx_fn kmac256_new;
|
|
|
|
static OSSL_FUNC_mac_dupctx_fn kmac_dup;
|
|
|
|
static OSSL_FUNC_mac_freectx_fn kmac_free;
|
|
|
|
static OSSL_FUNC_mac_gettable_ctx_params_fn kmac_gettable_ctx_params;
|
|
|
|
static OSSL_FUNC_mac_get_ctx_params_fn kmac_get_ctx_params;
|
|
|
|
static OSSL_FUNC_mac_settable_ctx_params_fn kmac_settable_ctx_params;
|
|
|
|
static OSSL_FUNC_mac_set_ctx_params_fn kmac_set_ctx_params;
|
|
|
|
static OSSL_FUNC_mac_init_fn kmac_init;
|
|
|
|
static OSSL_FUNC_mac_update_fn kmac_update;
|
|
|
|
static OSSL_FUNC_mac_final_fn kmac_final;
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2021-05-01 12:49:25 +08:00
|
|
|
#define KMAC_MAX_BLOCKSIZE ((1600 - 128 * 2) / 8) /* 168 */
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2021-05-01 12:49:25 +08:00
|
|
|
/*
|
|
|
|
* Length encoding will be a 1 byte size + length in bits (3 bytes max)
|
|
|
|
* This gives a range of 0..0XFFFFFF bits = 2097151 bytes).
|
|
|
|
*/
|
|
|
|
#define KMAC_MAX_OUTPUT_LEN (0xFFFFFF / 8)
|
|
|
|
#define KMAC_MAX_ENCODED_HEADER_LEN (1 + 3)
|
2018-11-09 12:00:05 +08:00
|
|
|
|
|
|
|
/*
|
2021-04-09 14:20:15 +08:00
|
|
|
* Restrict the maximum length of the customisation string. This must not
|
|
|
|
* exceed 64 bits = 8k bytes.
|
2018-11-09 12:00:05 +08:00
|
|
|
*/
|
2022-12-15 16:57:09 +08:00
|
|
|
#define KMAC_MAX_CUSTOM 512
|
2018-11-09 12:00:05 +08:00
|
|
|
|
|
|
|
/* Maximum size of encoded custom string */
|
|
|
|
#define KMAC_MAX_CUSTOM_ENCODED (KMAC_MAX_CUSTOM + KMAC_MAX_ENCODED_HEADER_LEN)
|
|
|
|
|
2022-12-15 16:57:09 +08:00
|
|
|
/* Maximum key size in bytes = 512 (4096 bits) */
|
|
|
|
#define KMAC_MAX_KEY 512
|
2021-05-01 12:49:25 +08:00
|
|
|
#define KMAC_MIN_KEY 4
|
2018-11-09 12:00:05 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Maximum Encoded Key size will be padded to a multiple of the blocksize
|
2022-12-15 16:57:09 +08:00
|
|
|
* i.e KMAC_MAX_KEY + KMAC_MAX_ENCODED_HEADER_LEN = 512 + 4
|
2018-11-09 12:00:05 +08:00
|
|
|
* Padded to a multiple of KMAC_MAX_BLOCKSIZE
|
|
|
|
*/
|
2022-12-15 16:57:09 +08:00
|
|
|
#define KMAC_MAX_KEY_ENCODED (KMAC_MAX_BLOCKSIZE * 4)
|
2018-11-09 12:00:05 +08:00
|
|
|
|
|
|
|
/* Fixed value of encode_string("KMAC") */
|
|
|
|
static const unsigned char kmac_string[] = {
|
|
|
|
0x01, 0x20, 0x4B, 0x4D, 0x41, 0x43
|
|
|
|
};
|
|
|
|
|
|
|
|
#define KMAC_FLAG_XOF_MODE 1
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
struct kmac_data_st {
|
|
|
|
void *provctx;
|
2018-11-09 12:00:05 +08:00
|
|
|
EVP_MD_CTX *ctx;
|
2019-09-05 11:55:04 +08:00
|
|
|
PROV_DIGEST digest;
|
2018-11-09 12:00:05 +08:00
|
|
|
size_t out_len;
|
2021-04-09 14:20:15 +08:00
|
|
|
size_t key_len;
|
|
|
|
size_t custom_len;
|
2018-11-09 12:00:05 +08:00
|
|
|
/* If xof_mode = 1 then we use right_encode(0) */
|
|
|
|
int xof_mode;
|
|
|
|
/* key and custom are stored in encoded form */
|
|
|
|
unsigned char key[KMAC_MAX_KEY_ENCODED];
|
|
|
|
unsigned char custom[KMAC_MAX_CUSTOM_ENCODED];
|
2024-08-05 13:25:35 +08:00
|
|
|
#ifdef FIPS_MODULE
|
|
|
|
/*
|
|
|
|
* 'internal' is set to 1 if KMAC is used inside another algorithm such as a
|
|
|
|
* KDF. In this case it is the parent algorithm that is responsible for
|
|
|
|
* performing any conditional FIPS indicator related checks for KMAC.
|
|
|
|
*/
|
|
|
|
int internal;
|
|
|
|
#endif
|
2024-07-17 11:56:08 +08:00
|
|
|
OSSL_FIPS_IND_DECLARE
|
2018-11-09 12:00:05 +08:00
|
|
|
};
|
|
|
|
|
2021-05-01 12:49:25 +08:00
|
|
|
static int encode_string(unsigned char *out, size_t out_max_len, size_t *out_len,
|
2021-04-09 14:20:15 +08:00
|
|
|
const unsigned char *in, size_t in_len);
|
2021-05-01 12:49:25 +08:00
|
|
|
static int right_encode(unsigned char *out, size_t out_max_len, size_t *out_len,
|
|
|
|
size_t bits);
|
2021-04-09 14:20:15 +08:00
|
|
|
static int bytepad(unsigned char *out, size_t *out_len,
|
|
|
|
const unsigned char *in1, size_t in1_len,
|
|
|
|
const unsigned char *in2, size_t in2_len,
|
|
|
|
size_t w);
|
2021-05-01 12:49:25 +08:00
|
|
|
static int kmac_bytepad_encode_key(unsigned char *out, size_t out_max_len,
|
|
|
|
size_t *out_len,
|
2021-04-09 14:20:15 +08:00
|
|
|
const unsigned char *in, size_t in_len,
|
|
|
|
size_t w);
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
static void kmac_free(void *vmacctx)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2019-06-02 14:46:35 +08:00
|
|
|
struct kmac_data_st *kctx = vmacctx;
|
|
|
|
|
2018-11-09 12:00:05 +08:00
|
|
|
if (kctx != NULL) {
|
|
|
|
EVP_MD_CTX_free(kctx->ctx);
|
2019-09-05 11:55:04 +08:00
|
|
|
ossl_prov_digest_reset(&kctx->digest);
|
2018-11-09 12:00:05 +08:00
|
|
|
OPENSSL_cleanse(kctx->key, kctx->key_len);
|
|
|
|
OPENSSL_cleanse(kctx->custom, kctx->custom_len);
|
|
|
|
OPENSSL_free(kctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
/*
|
|
|
|
* We have KMAC implemented as a hash, which we can use instead of
|
|
|
|
* reimplementing the EVP functionality with direct use of
|
|
|
|
* keccak_mac_init() and friends.
|
|
|
|
*/
|
2019-09-05 11:55:04 +08:00
|
|
|
static struct kmac_data_st *kmac_new(void *provctx)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2019-09-05 11:55:04 +08:00
|
|
|
struct kmac_data_st *kctx;
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2020-09-07 11:03:07 +08:00
|
|
|
if (!ossl_prov_is_running())
|
|
|
|
return NULL;
|
|
|
|
|
2018-11-09 12:00:05 +08:00
|
|
|
if ((kctx = OPENSSL_zalloc(sizeof(*kctx))) == NULL
|
|
|
|
|| (kctx->ctx = EVP_MD_CTX_new()) == NULL) {
|
|
|
|
kmac_free(kctx);
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-06-02 14:46:35 +08:00
|
|
|
kctx->provctx = provctx;
|
2024-07-17 11:56:08 +08:00
|
|
|
OSSL_FIPS_IND_INIT(kctx)
|
2018-11-09 12:00:05 +08:00
|
|
|
return kctx;
|
|
|
|
}
|
|
|
|
|
2019-09-05 11:55:04 +08:00
|
|
|
static void *kmac_fetch_new(void *provctx, const OSSL_PARAM *params)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2019-09-05 11:55:04 +08:00
|
|
|
struct kmac_data_st *kctx = kmac_new(provctx);
|
2024-03-23 04:21:46 +08:00
|
|
|
int md_size;
|
2019-09-05 11:55:04 +08:00
|
|
|
|
|
|
|
if (kctx == NULL)
|
|
|
|
return 0;
|
|
|
|
if (!ossl_prov_digest_load_from_params(&kctx->digest, params,
|
2020-10-15 17:55:50 +08:00
|
|
|
PROV_LIBCTX_OF(provctx))) {
|
2019-09-08 16:39:11 +08:00
|
|
|
kmac_free(kctx);
|
2019-09-05 11:55:04 +08:00
|
|
|
return 0;
|
2019-09-08 16:39:11 +08:00
|
|
|
}
|
2019-09-05 11:55:04 +08:00
|
|
|
|
2024-03-23 04:21:46 +08:00
|
|
|
md_size = EVP_MD_get_size(ossl_prov_digest_md(&kctx->digest));
|
|
|
|
if (md_size <= 0) {
|
|
|
|
kmac_free(kctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
kctx->out_len = (size_t)md_size;
|
2019-09-05 11:55:04 +08:00
|
|
|
return kctx;
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
static void *kmac128_new(void *provctx)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2019-09-05 11:55:04 +08:00
|
|
|
static const OSSL_PARAM kmac128_params[] = {
|
|
|
|
OSSL_PARAM_utf8_string("digest", OSSL_DIGEST_NAME_KECCAK_KMAC128,
|
|
|
|
sizeof(OSSL_DIGEST_NAME_KECCAK_KMAC128)),
|
|
|
|
OSSL_PARAM_END
|
|
|
|
};
|
|
|
|
return kmac_fetch_new(provctx, kmac128_params);
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
static void *kmac256_new(void *provctx)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2019-09-05 11:55:04 +08:00
|
|
|
static const OSSL_PARAM kmac256_params[] = {
|
|
|
|
OSSL_PARAM_utf8_string("digest", OSSL_DIGEST_NAME_KECCAK_KMAC256,
|
|
|
|
sizeof(OSSL_DIGEST_NAME_KECCAK_KMAC256)),
|
|
|
|
OSSL_PARAM_END
|
|
|
|
};
|
|
|
|
return kmac_fetch_new(provctx, kmac256_params);
|
2019-06-02 14:46:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *kmac_dup(void *vsrc)
|
|
|
|
{
|
|
|
|
struct kmac_data_st *src = vsrc;
|
2020-09-07 11:03:07 +08:00
|
|
|
struct kmac_data_st *dst;
|
|
|
|
|
|
|
|
if (!ossl_prov_is_running())
|
|
|
|
return NULL;
|
2018-12-19 07:36:40 +08:00
|
|
|
|
2020-09-07 11:03:07 +08:00
|
|
|
dst = kmac_new(src->provctx);
|
2019-06-02 14:46:35 +08:00
|
|
|
if (dst == NULL)
|
2018-12-19 07:36:40 +08:00
|
|
|
return NULL;
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
if (!EVP_MD_CTX_copy(dst->ctx, src->ctx)
|
2019-09-05 11:55:04 +08:00
|
|
|
|| !ossl_prov_digest_copy(&dst->digest, &src->digest)) {
|
2019-06-02 14:46:35 +08:00
|
|
|
kmac_free(dst);
|
2018-12-19 07:36:40 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2024-08-05 13:25:35 +08:00
|
|
|
#ifdef FIPS_MODULE
|
|
|
|
dst->internal = src->internal;
|
|
|
|
#endif
|
2019-06-02 14:46:35 +08:00
|
|
|
dst->out_len = src->out_len;
|
|
|
|
dst->key_len = src->key_len;
|
|
|
|
dst->custom_len = src->custom_len;
|
|
|
|
dst->xof_mode = src->xof_mode;
|
|
|
|
memcpy(dst->key, src->key, src->key_len);
|
|
|
|
memcpy(dst->custom, src->custom, dst->custom_len);
|
2024-07-17 11:56:08 +08:00
|
|
|
OSSL_FIPS_IND_COPY(dst, src)
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
return dst;
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2021-02-25 11:54:13 +08:00
|
|
|
static int kmac_setkey(struct kmac_data_st *kctx, const unsigned char *key,
|
|
|
|
size_t keylen)
|
|
|
|
{
|
|
|
|
const EVP_MD *digest = ossl_prov_digest_md(&kctx->digest);
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
int w = EVP_MD_get_block_size(digest);
|
2021-02-25 11:54:13 +08:00
|
|
|
|
2021-05-01 12:49:25 +08:00
|
|
|
if (keylen < KMAC_MIN_KEY || keylen > KMAC_MAX_KEY) {
|
2021-02-25 11:54:13 +08:00
|
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
|
|
|
|
return 0;
|
|
|
|
}
|
2024-08-05 13:25:35 +08:00
|
|
|
#ifdef FIPS_MODULE
|
|
|
|
/*
|
|
|
|
* Only do the key check if KMAC is fetched directly.
|
|
|
|
* Other algorithms that embed KMAC such as SSKDF will ignore this check.
|
|
|
|
*/
|
|
|
|
if (!kctx->internal) {
|
|
|
|
int approved = ossl_mac_check_key_size(keylen);
|
|
|
|
|
|
|
|
if (!approved) {
|
|
|
|
if (!OSSL_FIPS_IND_ON_UNAPPROVED(kctx, OSSL_FIPS_IND_SETTABLE1,
|
|
|
|
PROV_LIBCTX_OF(kctx->provctx),
|
|
|
|
"KMAC", "Key size",
|
2024-08-12 17:31:10 +08:00
|
|
|
ossl_fips_config_kmac_key_check)) {
|
2024-08-05 13:25:35 +08:00
|
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2023-08-09 22:05:03 +08:00
|
|
|
if (w <= 0) {
|
2021-04-09 14:20:15 +08:00
|
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH);
|
|
|
|
return 0;
|
|
|
|
}
|
2021-05-01 12:49:25 +08:00
|
|
|
if (!kmac_bytepad_encode_key(kctx->key, sizeof(kctx->key), &kctx->key_len,
|
2021-04-09 14:20:15 +08:00
|
|
|
key, keylen, (size_t)w))
|
2021-02-25 11:54:13 +08:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-11-09 12:00:05 +08:00
|
|
|
/*
|
|
|
|
* The init() assumes that any ctrl methods are set beforehand for
|
|
|
|
* md, key and custom. Setting the fields afterwards will have no
|
|
|
|
* effect on the output mac.
|
|
|
|
*/
|
2021-02-25 11:54:13 +08:00
|
|
|
static int kmac_init(void *vmacctx, const unsigned char *key,
|
|
|
|
size_t keylen, const OSSL_PARAM params[])
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2019-06-02 14:46:35 +08:00
|
|
|
struct kmac_data_st *kctx = vmacctx;
|
2018-11-09 12:00:05 +08:00
|
|
|
EVP_MD_CTX *ctx = kctx->ctx;
|
2021-04-09 14:20:15 +08:00
|
|
|
unsigned char *out;
|
|
|
|
size_t out_len, block_len;
|
|
|
|
int res, t;
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2021-02-25 11:54:13 +08:00
|
|
|
if (!ossl_prov_is_running() || !kmac_set_ctx_params(kctx, params))
|
2020-09-07 11:03:07 +08:00
|
|
|
return 0;
|
2021-04-09 14:20:15 +08:00
|
|
|
|
2021-02-25 11:54:13 +08:00
|
|
|
if (key != NULL) {
|
|
|
|
if (!kmac_setkey(kctx, key, keylen))
|
|
|
|
return 0;
|
|
|
|
} else if (kctx->key_len == 0) {
|
|
|
|
/* Check key has been set */
|
2021-02-06 01:51:37 +08:00
|
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
|
2018-11-09 12:00:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2019-09-05 11:55:04 +08:00
|
|
|
if (!EVP_DigestInit_ex(kctx->ctx, ossl_prov_digest_md(&kctx->digest),
|
|
|
|
NULL))
|
2018-11-09 12:00:05 +08:00
|
|
|
return 0;
|
|
|
|
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
t = EVP_MD_get_block_size(ossl_prov_digest_md(&kctx->digest));
|
2023-08-09 22:05:03 +08:00
|
|
|
if (t <= 0) {
|
2021-04-09 14:20:15 +08:00
|
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH);
|
2020-04-27 07:04:05 +08:00
|
|
|
return 0;
|
2021-04-09 14:20:15 +08:00
|
|
|
}
|
|
|
|
block_len = t;
|
2018-11-09 12:00:05 +08:00
|
|
|
|
|
|
|
/* Set default custom string if it is not already set */
|
2019-06-02 14:46:35 +08:00
|
|
|
if (kctx->custom_len == 0) {
|
2021-02-25 11:54:13 +08:00
|
|
|
const OSSL_PARAM cparams[] = {
|
2019-06-02 14:46:35 +08:00
|
|
|
OSSL_PARAM_octet_string(OSSL_MAC_PARAM_CUSTOM, "", 0),
|
|
|
|
OSSL_PARAM_END
|
|
|
|
};
|
2021-02-25 11:54:13 +08:00
|
|
|
(void)kmac_set_ctx_params(kctx, cparams);
|
2019-06-02 14:46:35 +08:00
|
|
|
}
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2021-04-09 14:20:15 +08:00
|
|
|
if (!bytepad(NULL, &out_len, kmac_string, sizeof(kmac_string),
|
|
|
|
kctx->custom, kctx->custom_len, block_len)) {
|
|
|
|
ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
out = OPENSSL_malloc(out_len);
|
2022-09-29 19:57:34 +08:00
|
|
|
if (out == NULL)
|
2021-04-09 14:20:15 +08:00
|
|
|
return 0;
|
|
|
|
res = bytepad(out, NULL, kmac_string, sizeof(kmac_string),
|
|
|
|
kctx->custom, kctx->custom_len, block_len)
|
|
|
|
&& EVP_DigestUpdate(ctx, out, out_len)
|
|
|
|
&& EVP_DigestUpdate(ctx, kctx->key, kctx->key_len);
|
|
|
|
OPENSSL_free(out);
|
|
|
|
return res;
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
static int kmac_update(void *vmacctx, const unsigned char *data,
|
2018-11-09 12:00:05 +08:00
|
|
|
size_t datalen)
|
|
|
|
{
|
2019-06-02 14:46:35 +08:00
|
|
|
struct kmac_data_st *kctx = vmacctx;
|
|
|
|
|
2018-11-09 12:00:05 +08:00
|
|
|
return EVP_DigestUpdate(kctx->ctx, data, datalen);
|
|
|
|
}
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
static int kmac_final(void *vmacctx, unsigned char *out, size_t *outl,
|
|
|
|
size_t outsize)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2019-06-02 14:46:35 +08:00
|
|
|
struct kmac_data_st *kctx = vmacctx;
|
2018-11-09 12:00:05 +08:00
|
|
|
EVP_MD_CTX *ctx = kctx->ctx;
|
2021-04-09 14:20:15 +08:00
|
|
|
size_t lbits, len;
|
2018-11-09 12:00:05 +08:00
|
|
|
unsigned char encoded_outlen[KMAC_MAX_ENCODED_HEADER_LEN];
|
2019-06-02 14:46:35 +08:00
|
|
|
int ok;
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2020-09-07 11:03:07 +08:00
|
|
|
if (!ossl_prov_is_running())
|
|
|
|
return 0;
|
|
|
|
|
2018-11-09 12:00:05 +08:00
|
|
|
/* KMAC XOF mode sets the encoded length to 0 */
|
|
|
|
lbits = (kctx->xof_mode ? 0 : (kctx->out_len * 8));
|
|
|
|
|
2021-05-01 12:49:25 +08:00
|
|
|
ok = right_encode(encoded_outlen, sizeof(encoded_outlen), &len, lbits)
|
2019-06-02 14:46:35 +08:00
|
|
|
&& EVP_DigestUpdate(ctx, encoded_outlen, len)
|
|
|
|
&& EVP_DigestFinalXOF(ctx, out, kctx->out_len);
|
2020-08-05 13:26:48 +08:00
|
|
|
*outl = kctx->out_len;
|
2019-06-02 14:46:35 +08:00
|
|
|
return ok;
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
static const OSSL_PARAM known_gettable_ctx_params[] = {
|
2019-08-22 18:50:00 +08:00
|
|
|
OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),
|
2021-05-24 12:22:17 +08:00
|
|
|
OSSL_PARAM_size_t(OSSL_MAC_PARAM_BLOCK_SIZE, NULL),
|
2024-07-17 11:56:08 +08:00
|
|
|
OSSL_FIPS_IND_GETTABLE_CTX_PARAM()
|
2019-06-02 14:46:35 +08:00
|
|
|
OSSL_PARAM_END
|
|
|
|
};
|
2021-02-23 09:02:49 +08:00
|
|
|
static const OSSL_PARAM *kmac_gettable_ctx_params(ossl_unused void *ctx,
|
|
|
|
ossl_unused void *provctx)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2019-06-02 14:46:35 +08:00
|
|
|
return known_gettable_ctx_params;
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2019-08-16 15:04:29 +08:00
|
|
|
static int kmac_get_ctx_params(void *vmacctx, OSSL_PARAM params[])
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2021-05-24 12:22:17 +08:00
|
|
|
struct kmac_data_st *kctx = vmacctx;
|
2019-06-02 14:46:35 +08:00
|
|
|
OSSL_PARAM *p;
|
2021-05-24 12:22:17 +08:00
|
|
|
int sz;
|
|
|
|
|
|
|
|
if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL
|
|
|
|
&& !OSSL_PARAM_set_size_t(p, kctx->out_len))
|
|
|
|
return 0;
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2021-05-24 12:22:17 +08:00
|
|
|
if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_BLOCK_SIZE)) != NULL) {
|
|
|
|
sz = EVP_MD_block_size(ossl_prov_digest_md(&kctx->digest));
|
|
|
|
if (!OSSL_PARAM_set_int(p, sz))
|
|
|
|
return 0;
|
|
|
|
}
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2024-07-17 11:56:08 +08:00
|
|
|
if (!OSSL_FIPS_IND_GET_CTX_PARAM(kctx, params))
|
|
|
|
return 0;
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
return 1;
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
static const OSSL_PARAM known_settable_ctx_params[] = {
|
|
|
|
OSSL_PARAM_int(OSSL_MAC_PARAM_XOF, NULL),
|
|
|
|
OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),
|
|
|
|
OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0),
|
|
|
|
OSSL_PARAM_octet_string(OSSL_MAC_PARAM_CUSTOM, NULL, 0),
|
2024-08-05 13:25:35 +08:00
|
|
|
OSSL_FIPS_IND_SETTABLE_CTX_PARAM(OSSL_MAC_PARAM_FIPS_NO_SHORT_MAC)
|
|
|
|
OSSL_FIPS_IND_SETTABLE_CTX_PARAM(OSSL_MAC_PARAM_FIPS_KEY_CHECK)
|
2019-06-02 14:46:35 +08:00
|
|
|
OSSL_PARAM_END
|
|
|
|
};
|
2021-02-23 09:02:49 +08:00
|
|
|
static const OSSL_PARAM *kmac_settable_ctx_params(ossl_unused void *ctx,
|
|
|
|
ossl_unused void *provctx)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2019-06-02 14:46:35 +08:00
|
|
|
return known_settable_ctx_params;
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
/*
|
|
|
|
* The following params can be set any time before final():
|
|
|
|
* - "outlen" or "size": The requested output length.
|
|
|
|
* - "xof": If set, this indicates that right_encoded(0)
|
|
|
|
* is part of the digested data, otherwise it
|
|
|
|
* uses right_encoded(requested output length).
|
|
|
|
*
|
|
|
|
* All other params should be set before init().
|
|
|
|
*/
|
2019-08-16 15:04:29 +08:00
|
|
|
static int kmac_set_ctx_params(void *vmacctx, const OSSL_PARAM *params)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
2019-06-02 14:46:35 +08:00
|
|
|
struct kmac_data_st *kctx = vmacctx;
|
|
|
|
const OSSL_PARAM *p;
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2024-09-20 08:34:08 +08:00
|
|
|
if (ossl_param_is_empty(params))
|
2021-03-10 16:37:07 +08:00
|
|
|
return 1;
|
|
|
|
|
2024-07-17 11:56:08 +08:00
|
|
|
if (!OSSL_FIPS_IND_SET_CTX_PARAM(kctx, OSSL_FIPS_IND_SETTABLE0, params,
|
2024-08-05 13:25:35 +08:00
|
|
|
OSSL_MAC_PARAM_FIPS_NO_SHORT_MAC))
|
|
|
|
return 0;
|
|
|
|
if (!OSSL_FIPS_IND_SET_CTX_PARAM(kctx, OSSL_FIPS_IND_SETTABLE1, params,
|
|
|
|
OSSL_MAC_PARAM_FIPS_KEY_CHECK))
|
|
|
|
return 0;
|
2024-07-17 11:56:08 +08:00
|
|
|
|
2019-06-02 14:46:35 +08:00
|
|
|
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_XOF)) != NULL
|
|
|
|
&& !OSSL_PARAM_get_int(p, &kctx->xof_mode))
|
|
|
|
return 0;
|
2021-05-01 12:49:25 +08:00
|
|
|
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_SIZE)) != NULL) {
|
|
|
|
size_t sz = 0;
|
|
|
|
|
|
|
|
if (!OSSL_PARAM_get_size_t(p, &sz))
|
|
|
|
return 0;
|
|
|
|
if (sz > KMAC_MAX_OUTPUT_LEN) {
|
|
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_OUTPUT_LENGTH);
|
|
|
|
return 0;
|
|
|
|
}
|
2024-07-17 11:56:08 +08:00
|
|
|
#ifdef FIPS_MODULE
|
|
|
|
/* SP 800-185 8.4.2 mandates a minimum of 32 bits of output */
|
|
|
|
if (sz < 32 / 8) {
|
|
|
|
if (!OSSL_FIPS_IND_ON_UNAPPROVED(kctx, OSSL_FIPS_IND_SETTABLE0,
|
|
|
|
PROV_LIBCTX_OF(kctx->provctx),
|
|
|
|
"KMAC", "length",
|
2024-08-12 17:31:10 +08:00
|
|
|
ossl_fips_config_no_short_mac)) {
|
2024-07-17 11:56:08 +08:00
|
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_OUTPUT_LENGTH);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-05-01 12:49:25 +08:00
|
|
|
kctx->out_len = sz;
|
|
|
|
}
|
2021-02-25 11:54:13 +08:00
|
|
|
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL
|
|
|
|
&& !kmac_setkey(kctx, p->data, p->data_size))
|
|
|
|
return 0;
|
2019-06-02 14:46:35 +08:00
|
|
|
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_CUSTOM))
|
|
|
|
!= NULL) {
|
|
|
|
if (p->data_size > KMAC_MAX_CUSTOM) {
|
|
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_CUSTOM_LENGTH);
|
|
|
|
return 0;
|
|
|
|
}
|
2021-05-01 12:49:25 +08:00
|
|
|
if (!encode_string(kctx->custom, sizeof(kctx->custom), &kctx->custom_len,
|
2019-06-02 14:46:35 +08:00
|
|
|
p->data, p->data_size))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2021-05-01 12:49:25 +08:00
|
|
|
/* Encoding/Padding Methods. */
|
2018-11-09 12:00:05 +08:00
|
|
|
|
|
|
|
/* Returns the number of bytes required to store 'bits' into a byte array */
|
|
|
|
static unsigned int get_encode_size(size_t bits)
|
|
|
|
{
|
|
|
|
unsigned int cnt = 0, sz = sizeof(size_t);
|
|
|
|
|
|
|
|
while (bits && (cnt < sz)) {
|
|
|
|
++cnt;
|
|
|
|
bits >>= 8;
|
|
|
|
}
|
|
|
|
/* If bits is zero 1 byte is required */
|
|
|
|
if (cnt == 0)
|
|
|
|
cnt = 1;
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert an integer into bytes . The number of bytes is appended
|
|
|
|
* to the end of the buffer. Returns an array of bytes 'out' of size
|
|
|
|
* *out_len.
|
|
|
|
*
|
|
|
|
* e.g if bits = 32, out[2] = { 0x20, 0x01 }
|
|
|
|
*/
|
2021-05-01 12:49:25 +08:00
|
|
|
static int right_encode(unsigned char *out, size_t out_max_len, size_t *out_len,
|
|
|
|
size_t bits)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
|
|
|
unsigned int len = get_encode_size(bits);
|
|
|
|
int i;
|
|
|
|
|
2021-05-01 12:49:25 +08:00
|
|
|
if (len >= out_max_len) {
|
2021-04-09 14:20:15 +08:00
|
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE);
|
2018-11-09 12:00:05 +08:00
|
|
|
return 0;
|
2021-04-09 14:20:15 +08:00
|
|
|
}
|
2018-11-09 12:00:05 +08:00
|
|
|
|
|
|
|
/* MSB's are at the start of the bytes array */
|
|
|
|
for (i = len - 1; i >= 0; --i) {
|
|
|
|
out[i] = (unsigned char)(bits & 0xFF);
|
|
|
|
bits >>= 8;
|
|
|
|
}
|
|
|
|
/* Tack the length onto the end */
|
|
|
|
out[len] = (unsigned char)len;
|
|
|
|
|
|
|
|
/* The Returned length includes the tacked on byte */
|
|
|
|
*out_len = len + 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Encodes a string with a left encoded length added. Note that the
|
|
|
|
* in_len is converted to bits (*8).
|
|
|
|
*
|
|
|
|
* e.g- in="KMAC" gives out[6] = { 0x01, 0x20, 0x4B, 0x4D, 0x41, 0x43 }
|
|
|
|
* len bits K M A C
|
|
|
|
*/
|
2021-05-01 12:49:25 +08:00
|
|
|
static int encode_string(unsigned char *out, size_t out_max_len, size_t *out_len,
|
2021-04-09 14:20:15 +08:00
|
|
|
const unsigned char *in, size_t in_len)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
|
|
|
if (in == NULL) {
|
|
|
|
*out_len = 0;
|
|
|
|
} else {
|
2021-05-01 12:49:25 +08:00
|
|
|
size_t i, bits, len, sz;
|
2018-11-09 12:00:05 +08:00
|
|
|
|
|
|
|
bits = 8 * in_len;
|
|
|
|
len = get_encode_size(bits);
|
2021-05-01 12:49:25 +08:00
|
|
|
sz = 1 + len + in_len;
|
|
|
|
|
|
|
|
if (sz > out_max_len) {
|
2021-04-09 14:20:15 +08:00
|
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE);
|
2018-11-09 12:00:05 +08:00
|
|
|
return 0;
|
2021-04-09 14:20:15 +08:00
|
|
|
}
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2021-04-13 10:24:25 +08:00
|
|
|
out[0] = (unsigned char)len;
|
2018-11-09 12:00:05 +08:00
|
|
|
for (i = len; i > 0; --i) {
|
|
|
|
out[i] = (bits & 0xFF);
|
|
|
|
bits >>= 8;
|
|
|
|
}
|
|
|
|
memcpy(out + len + 1, in, in_len);
|
2021-05-01 12:49:25 +08:00
|
|
|
*out_len = sz;
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a zero padded encoding of the inputs in1 and an optional
|
|
|
|
* in2 (can be NULL). The padded output must be a multiple of the blocksize 'w'.
|
|
|
|
* The value of w is in bytes (< 256).
|
|
|
|
*
|
|
|
|
* The returned output is:
|
|
|
|
* zero_padded(multiple of w, (left_encode(w) || in1 [|| in2])
|
|
|
|
*/
|
2021-04-09 14:20:15 +08:00
|
|
|
static int bytepad(unsigned char *out, size_t *out_len,
|
|
|
|
const unsigned char *in1, size_t in1_len,
|
|
|
|
const unsigned char *in2, size_t in2_len, size_t w)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
unsigned char *p = out;
|
|
|
|
int sz = w;
|
|
|
|
|
2021-04-09 14:20:15 +08:00
|
|
|
if (out == NULL) {
|
|
|
|
if (out_len == NULL) {
|
|
|
|
ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
sz = 2 + in1_len + (in2 != NULL ? in2_len : 0);
|
|
|
|
*out_len = (sz + w - 1) / w * w;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-04-13 10:24:25 +08:00
|
|
|
if (!ossl_assert(w <= 255))
|
|
|
|
return 0;
|
|
|
|
|
2018-11-09 12:00:05 +08:00
|
|
|
/* Left encoded w */
|
|
|
|
*p++ = 1;
|
2021-04-13 10:24:25 +08:00
|
|
|
*p++ = (unsigned char)w;
|
2018-11-09 12:00:05 +08:00
|
|
|
/* || in1 */
|
|
|
|
memcpy(p, in1, in1_len);
|
|
|
|
p += in1_len;
|
|
|
|
/* [ || in2 ] */
|
|
|
|
if (in2 != NULL && in2_len > 0) {
|
|
|
|
memcpy(p, in2, in2_len);
|
|
|
|
p += in2_len;
|
|
|
|
}
|
|
|
|
/* Figure out the pad size (divisible by w) */
|
|
|
|
len = p - out;
|
2021-04-09 14:20:15 +08:00
|
|
|
sz = (len + w - 1) / w * w;
|
2018-11-09 12:00:05 +08:00
|
|
|
/* zero pad the end of the buffer */
|
2021-04-09 14:20:15 +08:00
|
|
|
if (sz != len)
|
|
|
|
memset(p, 0, sz - len);
|
|
|
|
if (out_len != NULL)
|
|
|
|
*out_len = sz;
|
2018-11-09 12:00:05 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-05-01 12:49:25 +08:00
|
|
|
/* Returns out = bytepad(encode_string(in), w) */
|
|
|
|
static int kmac_bytepad_encode_key(unsigned char *out, size_t out_max_len,
|
|
|
|
size_t *out_len,
|
2021-04-09 14:20:15 +08:00
|
|
|
const unsigned char *in, size_t in_len,
|
|
|
|
size_t w)
|
2018-11-09 12:00:05 +08:00
|
|
|
{
|
|
|
|
unsigned char tmp[KMAC_MAX_KEY + KMAC_MAX_ENCODED_HEADER_LEN];
|
2021-04-09 14:20:15 +08:00
|
|
|
size_t tmp_len;
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2021-05-01 12:49:25 +08:00
|
|
|
if (!encode_string(tmp, sizeof(tmp), &tmp_len, in, in_len))
|
2018-11-09 12:00:05 +08:00
|
|
|
return 0;
|
2021-05-01 12:49:25 +08:00
|
|
|
if (!bytepad(NULL, out_len, tmp, tmp_len, NULL, 0, w))
|
|
|
|
return 0;
|
|
|
|
if (!ossl_assert(*out_len <= out_max_len))
|
|
|
|
return 0;
|
|
|
|
return bytepad(out, NULL, tmp, tmp_len, NULL, 0, w);
|
2018-11-09 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2024-08-05 13:25:35 +08:00
|
|
|
#define IMPLEMENT_KMAC_TABLE(size, funcname, newname) \
|
|
|
|
const OSSL_DISPATCH ossl_kmac##size##_##funcname[] = \
|
|
|
|
{ \
|
|
|
|
{ OSSL_FUNC_MAC_NEWCTX, (void (*)(void))kmac##size##_##newname }, \
|
|
|
|
{ OSSL_FUNC_MAC_DUPCTX, (void (*)(void))kmac_dup }, \
|
|
|
|
{ OSSL_FUNC_MAC_FREECTX, (void (*)(void))kmac_free }, \
|
|
|
|
{ OSSL_FUNC_MAC_INIT, (void (*)(void))kmac_init }, \
|
|
|
|
{ OSSL_FUNC_MAC_UPDATE, (void (*)(void))kmac_update }, \
|
|
|
|
{ OSSL_FUNC_MAC_FINAL, (void (*)(void))kmac_final }, \
|
|
|
|
{ OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS, \
|
|
|
|
(void (*)(void))kmac_gettable_ctx_params }, \
|
|
|
|
{ OSSL_FUNC_MAC_GET_CTX_PARAMS, (void (*)(void))kmac_get_ctx_params }, \
|
|
|
|
{ OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS, \
|
|
|
|
(void (*)(void))kmac_settable_ctx_params }, \
|
|
|
|
{ OSSL_FUNC_MAC_SET_CTX_PARAMS, (void (*)(void))kmac_set_ctx_params }, \
|
|
|
|
OSSL_DISPATCH_END \
|
|
|
|
}
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2024-08-05 13:25:35 +08:00
|
|
|
#define KMAC_TABLE(size) IMPLEMENT_KMAC_TABLE(size, functions, new)
|
|
|
|
|
|
|
|
KMAC_TABLE(128);
|
|
|
|
KMAC_TABLE(256);
|
|
|
|
|
|
|
|
#ifdef FIPS_MODULE
|
|
|
|
# define KMAC_INTERNAL_TABLE(size) \
|
|
|
|
static OSSL_FUNC_mac_newctx_fn kmac##size##_internal_new; \
|
|
|
|
static void *kmac##size##_internal_new(void *provctx) \
|
|
|
|
{ \
|
|
|
|
struct kmac_data_st *macctx = kmac##size##_new(provctx); \
|
|
|
|
\
|
|
|
|
if (macctx != NULL) \
|
|
|
|
macctx->internal = 1; \
|
|
|
|
return macctx; \
|
|
|
|
} \
|
|
|
|
IMPLEMENT_KMAC_TABLE(size, internal_functions, internal_new)
|
|
|
|
|
|
|
|
KMAC_INTERNAL_TABLE(128);
|
|
|
|
KMAC_INTERNAL_TABLE(256);
|
|
|
|
#endif /* FIPS_MODULE */
|