1*b077aed3SPierre Pronchery /*
2*b077aed3SPierre Pronchery * Copyright 2018-2022 The OpenSSL Project Authors. All Rights Reserved.
3*b077aed3SPierre Pronchery *
4*b077aed3SPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use
5*b077aed3SPierre Pronchery * this file except in compliance with the License. You can obtain a copy
6*b077aed3SPierre Pronchery * in the file LICENSE in the source distribution or at
7*b077aed3SPierre Pronchery * https://www.openssl.org/source/license.html
8*b077aed3SPierre Pronchery */
9*b077aed3SPierre Pronchery
10*b077aed3SPierre Pronchery /*
11*b077aed3SPierre Pronchery * HMAC low level APIs are deprecated for public use, but still ok for internal
12*b077aed3SPierre Pronchery * use.
13*b077aed3SPierre Pronchery */
14*b077aed3SPierre Pronchery #include "internal/deprecated.h"
15*b077aed3SPierre Pronchery
16*b077aed3SPierre Pronchery #include <string.h>
17*b077aed3SPierre Pronchery
18*b077aed3SPierre Pronchery #include <openssl/core_dispatch.h>
19*b077aed3SPierre Pronchery #include <openssl/core_names.h>
20*b077aed3SPierre Pronchery #include <openssl/params.h>
21*b077aed3SPierre Pronchery #include <openssl/evp.h>
22*b077aed3SPierre Pronchery #include <openssl/hmac.h>
23*b077aed3SPierre Pronchery
24*b077aed3SPierre Pronchery #include "prov/implementations.h"
25*b077aed3SPierre Pronchery #include "prov/provider_ctx.h"
26*b077aed3SPierre Pronchery #include "prov/provider_util.h"
27*b077aed3SPierre Pronchery #include "prov/providercommon.h"
28*b077aed3SPierre Pronchery
29*b077aed3SPierre Pronchery /*
30*b077aed3SPierre Pronchery * Forward declaration of everything implemented here. This is not strictly
31*b077aed3SPierre Pronchery * necessary for the compiler, but provides an assurance that the signatures
32*b077aed3SPierre Pronchery * of the functions in the dispatch table are correct.
33*b077aed3SPierre Pronchery */
34*b077aed3SPierre Pronchery static OSSL_FUNC_mac_newctx_fn hmac_new;
35*b077aed3SPierre Pronchery static OSSL_FUNC_mac_dupctx_fn hmac_dup;
36*b077aed3SPierre Pronchery static OSSL_FUNC_mac_freectx_fn hmac_free;
37*b077aed3SPierre Pronchery static OSSL_FUNC_mac_gettable_ctx_params_fn hmac_gettable_ctx_params;
38*b077aed3SPierre Pronchery static OSSL_FUNC_mac_get_ctx_params_fn hmac_get_ctx_params;
39*b077aed3SPierre Pronchery static OSSL_FUNC_mac_settable_ctx_params_fn hmac_settable_ctx_params;
40*b077aed3SPierre Pronchery static OSSL_FUNC_mac_set_ctx_params_fn hmac_set_ctx_params;
41*b077aed3SPierre Pronchery static OSSL_FUNC_mac_init_fn hmac_init;
42*b077aed3SPierre Pronchery static OSSL_FUNC_mac_update_fn hmac_update;
43*b077aed3SPierre Pronchery static OSSL_FUNC_mac_final_fn hmac_final;
44*b077aed3SPierre Pronchery
45*b077aed3SPierre Pronchery /* local HMAC context structure */
46*b077aed3SPierre Pronchery
47*b077aed3SPierre Pronchery /* typedef EVP_MAC_IMPL */
48*b077aed3SPierre Pronchery struct hmac_data_st {
49*b077aed3SPierre Pronchery void *provctx;
50*b077aed3SPierre Pronchery HMAC_CTX *ctx; /* HMAC context */
51*b077aed3SPierre Pronchery PROV_DIGEST digest;
52*b077aed3SPierre Pronchery unsigned char *key;
53*b077aed3SPierre Pronchery size_t keylen;
54*b077aed3SPierre Pronchery /* Length of full TLS record including the MAC and any padding */
55*b077aed3SPierre Pronchery size_t tls_data_size;
56*b077aed3SPierre Pronchery unsigned char tls_header[13];
57*b077aed3SPierre Pronchery int tls_header_set;
58*b077aed3SPierre Pronchery unsigned char tls_mac_out[EVP_MAX_MD_SIZE];
59*b077aed3SPierre Pronchery size_t tls_mac_out_size;
60*b077aed3SPierre Pronchery };
61*b077aed3SPierre Pronchery
62*b077aed3SPierre Pronchery /* Defined in ssl/s3_cbc.c */
63*b077aed3SPierre Pronchery int ssl3_cbc_digest_record(const EVP_MD *md,
64*b077aed3SPierre Pronchery unsigned char *md_out,
65*b077aed3SPierre Pronchery size_t *md_out_size,
66*b077aed3SPierre Pronchery const unsigned char header[13],
67*b077aed3SPierre Pronchery const unsigned char *data,
68*b077aed3SPierre Pronchery size_t data_size,
69*b077aed3SPierre Pronchery size_t data_plus_mac_plus_padding_size,
70*b077aed3SPierre Pronchery const unsigned char *mac_secret,
71*b077aed3SPierre Pronchery size_t mac_secret_length, char is_sslv3);
72*b077aed3SPierre Pronchery
hmac_new(void * provctx)73*b077aed3SPierre Pronchery static void *hmac_new(void *provctx)
74*b077aed3SPierre Pronchery {
75*b077aed3SPierre Pronchery struct hmac_data_st *macctx;
76*b077aed3SPierre Pronchery
77*b077aed3SPierre Pronchery if (!ossl_prov_is_running())
78*b077aed3SPierre Pronchery return NULL;
79*b077aed3SPierre Pronchery
80*b077aed3SPierre Pronchery if ((macctx = OPENSSL_zalloc(sizeof(*macctx))) == NULL
81*b077aed3SPierre Pronchery || (macctx->ctx = HMAC_CTX_new()) == NULL) {
82*b077aed3SPierre Pronchery OPENSSL_free(macctx);
83*b077aed3SPierre Pronchery return NULL;
84*b077aed3SPierre Pronchery }
85*b077aed3SPierre Pronchery macctx->provctx = provctx;
86*b077aed3SPierre Pronchery
87*b077aed3SPierre Pronchery return macctx;
88*b077aed3SPierre Pronchery }
89*b077aed3SPierre Pronchery
hmac_free(void * vmacctx)90*b077aed3SPierre Pronchery static void hmac_free(void *vmacctx)
91*b077aed3SPierre Pronchery {
92*b077aed3SPierre Pronchery struct hmac_data_st *macctx = vmacctx;
93*b077aed3SPierre Pronchery
94*b077aed3SPierre Pronchery if (macctx != NULL) {
95*b077aed3SPierre Pronchery HMAC_CTX_free(macctx->ctx);
96*b077aed3SPierre Pronchery ossl_prov_digest_reset(&macctx->digest);
97*b077aed3SPierre Pronchery OPENSSL_secure_clear_free(macctx->key, macctx->keylen);
98*b077aed3SPierre Pronchery OPENSSL_free(macctx);
99*b077aed3SPierre Pronchery }
100*b077aed3SPierre Pronchery }
101*b077aed3SPierre Pronchery
hmac_dup(void * vsrc)102*b077aed3SPierre Pronchery static void *hmac_dup(void *vsrc)
103*b077aed3SPierre Pronchery {
104*b077aed3SPierre Pronchery struct hmac_data_st *src = vsrc;
105*b077aed3SPierre Pronchery struct hmac_data_st *dst;
106*b077aed3SPierre Pronchery HMAC_CTX *ctx;
107*b077aed3SPierre Pronchery
108*b077aed3SPierre Pronchery if (!ossl_prov_is_running())
109*b077aed3SPierre Pronchery return NULL;
110*b077aed3SPierre Pronchery dst = hmac_new(src->provctx);
111*b077aed3SPierre Pronchery if (dst == NULL)
112*b077aed3SPierre Pronchery return NULL;
113*b077aed3SPierre Pronchery
114*b077aed3SPierre Pronchery ctx = dst->ctx;
115*b077aed3SPierre Pronchery *dst = *src;
116*b077aed3SPierre Pronchery dst->ctx = ctx;
117*b077aed3SPierre Pronchery dst->key = NULL;
118*b077aed3SPierre Pronchery memset(&dst->digest, 0, sizeof(dst->digest));
119*b077aed3SPierre Pronchery
120*b077aed3SPierre Pronchery if (!HMAC_CTX_copy(dst->ctx, src->ctx)
121*b077aed3SPierre Pronchery || !ossl_prov_digest_copy(&dst->digest, &src->digest)) {
122*b077aed3SPierre Pronchery hmac_free(dst);
123*b077aed3SPierre Pronchery return NULL;
124*b077aed3SPierre Pronchery }
125*b077aed3SPierre Pronchery if (src->key != NULL) {
126*b077aed3SPierre Pronchery /* There is no "secure" OPENSSL_memdup */
127*b077aed3SPierre Pronchery dst->key = OPENSSL_secure_malloc(src->keylen > 0 ? src->keylen : 1);
128*b077aed3SPierre Pronchery if (dst->key == NULL) {
129*b077aed3SPierre Pronchery hmac_free(dst);
130*b077aed3SPierre Pronchery return 0;
131*b077aed3SPierre Pronchery }
132*b077aed3SPierre Pronchery memcpy(dst->key, src->key, src->keylen);
133*b077aed3SPierre Pronchery }
134*b077aed3SPierre Pronchery return dst;
135*b077aed3SPierre Pronchery }
136*b077aed3SPierre Pronchery
hmac_size(struct hmac_data_st * macctx)137*b077aed3SPierre Pronchery static size_t hmac_size(struct hmac_data_st *macctx)
138*b077aed3SPierre Pronchery {
139*b077aed3SPierre Pronchery return HMAC_size(macctx->ctx);
140*b077aed3SPierre Pronchery }
141*b077aed3SPierre Pronchery
hmac_block_size(struct hmac_data_st * macctx)142*b077aed3SPierre Pronchery static int hmac_block_size(struct hmac_data_st *macctx)
143*b077aed3SPierre Pronchery {
144*b077aed3SPierre Pronchery const EVP_MD *md = ossl_prov_digest_md(&macctx->digest);
145*b077aed3SPierre Pronchery
146*b077aed3SPierre Pronchery if (md == NULL)
147*b077aed3SPierre Pronchery return 0;
148*b077aed3SPierre Pronchery return EVP_MD_block_size(md);
149*b077aed3SPierre Pronchery }
150*b077aed3SPierre Pronchery
hmac_setkey(struct hmac_data_st * macctx,const unsigned char * key,size_t keylen)151*b077aed3SPierre Pronchery static int hmac_setkey(struct hmac_data_st *macctx,
152*b077aed3SPierre Pronchery const unsigned char *key, size_t keylen)
153*b077aed3SPierre Pronchery {
154*b077aed3SPierre Pronchery const EVP_MD *digest;
155*b077aed3SPierre Pronchery
156*b077aed3SPierre Pronchery if (macctx->key != NULL)
157*b077aed3SPierre Pronchery OPENSSL_secure_clear_free(macctx->key, macctx->keylen);
158*b077aed3SPierre Pronchery /* Keep a copy of the key in case we need it for TLS HMAC */
159*b077aed3SPierre Pronchery macctx->key = OPENSSL_secure_malloc(keylen > 0 ? keylen : 1);
160*b077aed3SPierre Pronchery if (macctx->key == NULL)
161*b077aed3SPierre Pronchery return 0;
162*b077aed3SPierre Pronchery memcpy(macctx->key, key, keylen);
163*b077aed3SPierre Pronchery macctx->keylen = keylen;
164*b077aed3SPierre Pronchery
165*b077aed3SPierre Pronchery digest = ossl_prov_digest_md(&macctx->digest);
166*b077aed3SPierre Pronchery /* HMAC_Init_ex doesn't tolerate all zero params, so we must be careful */
167*b077aed3SPierre Pronchery if (key != NULL || (macctx->tls_data_size == 0 && digest != NULL))
168*b077aed3SPierre Pronchery return HMAC_Init_ex(macctx->ctx, key, keylen, digest,
169*b077aed3SPierre Pronchery ossl_prov_digest_engine(&macctx->digest));
170*b077aed3SPierre Pronchery return 1;
171*b077aed3SPierre Pronchery }
172*b077aed3SPierre Pronchery
hmac_init(void * vmacctx,const unsigned char * key,size_t keylen,const OSSL_PARAM params[])173*b077aed3SPierre Pronchery static int hmac_init(void *vmacctx, const unsigned char *key,
174*b077aed3SPierre Pronchery size_t keylen, const OSSL_PARAM params[])
175*b077aed3SPierre Pronchery {
176*b077aed3SPierre Pronchery struct hmac_data_st *macctx = vmacctx;
177*b077aed3SPierre Pronchery
178*b077aed3SPierre Pronchery if (!ossl_prov_is_running() || !hmac_set_ctx_params(macctx, params))
179*b077aed3SPierre Pronchery return 0;
180*b077aed3SPierre Pronchery
181*b077aed3SPierre Pronchery if (key != NULL)
182*b077aed3SPierre Pronchery return hmac_setkey(macctx, key, keylen);
183*b077aed3SPierre Pronchery
184*b077aed3SPierre Pronchery /* Just reinit the HMAC context */
185*b077aed3SPierre Pronchery return HMAC_Init_ex(macctx->ctx, NULL, 0, NULL, NULL);
186*b077aed3SPierre Pronchery }
187*b077aed3SPierre Pronchery
hmac_update(void * vmacctx,const unsigned char * data,size_t datalen)188*b077aed3SPierre Pronchery static int hmac_update(void *vmacctx, const unsigned char *data,
189*b077aed3SPierre Pronchery size_t datalen)
190*b077aed3SPierre Pronchery {
191*b077aed3SPierre Pronchery struct hmac_data_st *macctx = vmacctx;
192*b077aed3SPierre Pronchery
193*b077aed3SPierre Pronchery if (macctx->tls_data_size > 0) {
194*b077aed3SPierre Pronchery /* We're doing a TLS HMAC */
195*b077aed3SPierre Pronchery if (!macctx->tls_header_set) {
196*b077aed3SPierre Pronchery /* We expect the first update call to contain the TLS header */
197*b077aed3SPierre Pronchery if (datalen != sizeof(macctx->tls_header))
198*b077aed3SPierre Pronchery return 0;
199*b077aed3SPierre Pronchery memcpy(macctx->tls_header, data, datalen);
200*b077aed3SPierre Pronchery macctx->tls_header_set = 1;
201*b077aed3SPierre Pronchery return 1;
202*b077aed3SPierre Pronchery }
203*b077aed3SPierre Pronchery /* macctx->tls_data_size is datalen plus the padding length */
204*b077aed3SPierre Pronchery if (macctx->tls_data_size < datalen)
205*b077aed3SPierre Pronchery return 0;
206*b077aed3SPierre Pronchery
207*b077aed3SPierre Pronchery return ssl3_cbc_digest_record(ossl_prov_digest_md(&macctx->digest),
208*b077aed3SPierre Pronchery macctx->tls_mac_out,
209*b077aed3SPierre Pronchery &macctx->tls_mac_out_size,
210*b077aed3SPierre Pronchery macctx->tls_header,
211*b077aed3SPierre Pronchery data,
212*b077aed3SPierre Pronchery datalen,
213*b077aed3SPierre Pronchery macctx->tls_data_size,
214*b077aed3SPierre Pronchery macctx->key,
215*b077aed3SPierre Pronchery macctx->keylen,
216*b077aed3SPierre Pronchery 0);
217*b077aed3SPierre Pronchery }
218*b077aed3SPierre Pronchery
219*b077aed3SPierre Pronchery return HMAC_Update(macctx->ctx, data, datalen);
220*b077aed3SPierre Pronchery }
221*b077aed3SPierre Pronchery
hmac_final(void * vmacctx,unsigned char * out,size_t * outl,size_t outsize)222*b077aed3SPierre Pronchery static int hmac_final(void *vmacctx, unsigned char *out, size_t *outl,
223*b077aed3SPierre Pronchery size_t outsize)
224*b077aed3SPierre Pronchery {
225*b077aed3SPierre Pronchery unsigned int hlen;
226*b077aed3SPierre Pronchery struct hmac_data_st *macctx = vmacctx;
227*b077aed3SPierre Pronchery
228*b077aed3SPierre Pronchery if (!ossl_prov_is_running())
229*b077aed3SPierre Pronchery return 0;
230*b077aed3SPierre Pronchery if (macctx->tls_data_size > 0) {
231*b077aed3SPierre Pronchery if (macctx->tls_mac_out_size == 0)
232*b077aed3SPierre Pronchery return 0;
233*b077aed3SPierre Pronchery if (outl != NULL)
234*b077aed3SPierre Pronchery *outl = macctx->tls_mac_out_size;
235*b077aed3SPierre Pronchery memcpy(out, macctx->tls_mac_out, macctx->tls_mac_out_size);
236*b077aed3SPierre Pronchery return 1;
237*b077aed3SPierre Pronchery }
238*b077aed3SPierre Pronchery if (!HMAC_Final(macctx->ctx, out, &hlen))
239*b077aed3SPierre Pronchery return 0;
240*b077aed3SPierre Pronchery *outl = hlen;
241*b077aed3SPierre Pronchery return 1;
242*b077aed3SPierre Pronchery }
243*b077aed3SPierre Pronchery
244*b077aed3SPierre Pronchery static const OSSL_PARAM known_gettable_ctx_params[] = {
245*b077aed3SPierre Pronchery OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL),
246*b077aed3SPierre Pronchery OSSL_PARAM_size_t(OSSL_MAC_PARAM_BLOCK_SIZE, NULL),
247*b077aed3SPierre Pronchery OSSL_PARAM_END
248*b077aed3SPierre Pronchery };
hmac_gettable_ctx_params(ossl_unused void * ctx,ossl_unused void * provctx)249*b077aed3SPierre Pronchery static const OSSL_PARAM *hmac_gettable_ctx_params(ossl_unused void *ctx,
250*b077aed3SPierre Pronchery ossl_unused void *provctx)
251*b077aed3SPierre Pronchery {
252*b077aed3SPierre Pronchery return known_gettable_ctx_params;
253*b077aed3SPierre Pronchery }
254*b077aed3SPierre Pronchery
hmac_get_ctx_params(void * vmacctx,OSSL_PARAM params[])255*b077aed3SPierre Pronchery static int hmac_get_ctx_params(void *vmacctx, OSSL_PARAM params[])
256*b077aed3SPierre Pronchery {
257*b077aed3SPierre Pronchery struct hmac_data_st *macctx = vmacctx;
258*b077aed3SPierre Pronchery OSSL_PARAM *p;
259*b077aed3SPierre Pronchery
260*b077aed3SPierre Pronchery if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL
261*b077aed3SPierre Pronchery && !OSSL_PARAM_set_size_t(p, hmac_size(macctx)))
262*b077aed3SPierre Pronchery return 0;
263*b077aed3SPierre Pronchery
264*b077aed3SPierre Pronchery if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_BLOCK_SIZE)) != NULL
265*b077aed3SPierre Pronchery && !OSSL_PARAM_set_int(p, hmac_block_size(macctx)))
266*b077aed3SPierre Pronchery return 0;
267*b077aed3SPierre Pronchery
268*b077aed3SPierre Pronchery return 1;
269*b077aed3SPierre Pronchery }
270*b077aed3SPierre Pronchery
271*b077aed3SPierre Pronchery static const OSSL_PARAM known_settable_ctx_params[] = {
272*b077aed3SPierre Pronchery OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_DIGEST, NULL, 0),
273*b077aed3SPierre Pronchery OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_PROPERTIES, NULL, 0),
274*b077aed3SPierre Pronchery OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0),
275*b077aed3SPierre Pronchery OSSL_PARAM_int(OSSL_MAC_PARAM_DIGEST_NOINIT, NULL),
276*b077aed3SPierre Pronchery OSSL_PARAM_int(OSSL_MAC_PARAM_DIGEST_ONESHOT, NULL),
277*b077aed3SPierre Pronchery OSSL_PARAM_size_t(OSSL_MAC_PARAM_TLS_DATA_SIZE, NULL),
278*b077aed3SPierre Pronchery OSSL_PARAM_END
279*b077aed3SPierre Pronchery };
hmac_settable_ctx_params(ossl_unused void * ctx,ossl_unused void * provctx)280*b077aed3SPierre Pronchery static const OSSL_PARAM *hmac_settable_ctx_params(ossl_unused void *ctx,
281*b077aed3SPierre Pronchery ossl_unused void *provctx)
282*b077aed3SPierre Pronchery {
283*b077aed3SPierre Pronchery return known_settable_ctx_params;
284*b077aed3SPierre Pronchery }
285*b077aed3SPierre Pronchery
set_flag(const OSSL_PARAM params[],const char * key,int mask,int * flags)286*b077aed3SPierre Pronchery static int set_flag(const OSSL_PARAM params[], const char *key, int mask,
287*b077aed3SPierre Pronchery int *flags)
288*b077aed3SPierre Pronchery {
289*b077aed3SPierre Pronchery const OSSL_PARAM *p = OSSL_PARAM_locate_const(params, key);
290*b077aed3SPierre Pronchery int flag = 0;
291*b077aed3SPierre Pronchery
292*b077aed3SPierre Pronchery if (p != NULL) {
293*b077aed3SPierre Pronchery if (!OSSL_PARAM_get_int(p, &flag))
294*b077aed3SPierre Pronchery return 0;
295*b077aed3SPierre Pronchery if (flag == 0)
296*b077aed3SPierre Pronchery *flags &= ~mask;
297*b077aed3SPierre Pronchery else
298*b077aed3SPierre Pronchery *flags |= mask;
299*b077aed3SPierre Pronchery }
300*b077aed3SPierre Pronchery return 1;
301*b077aed3SPierre Pronchery }
302*b077aed3SPierre Pronchery
303*b077aed3SPierre Pronchery /*
304*b077aed3SPierre Pronchery * ALL parameters should be set before init().
305*b077aed3SPierre Pronchery */
hmac_set_ctx_params(void * vmacctx,const OSSL_PARAM params[])306*b077aed3SPierre Pronchery static int hmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[])
307*b077aed3SPierre Pronchery {
308*b077aed3SPierre Pronchery struct hmac_data_st *macctx = vmacctx;
309*b077aed3SPierre Pronchery OSSL_LIB_CTX *ctx = PROV_LIBCTX_OF(macctx->provctx);
310*b077aed3SPierre Pronchery const OSSL_PARAM *p;
311*b077aed3SPierre Pronchery int flags = 0;
312*b077aed3SPierre Pronchery
313*b077aed3SPierre Pronchery if (params == NULL)
314*b077aed3SPierre Pronchery return 1;
315*b077aed3SPierre Pronchery
316*b077aed3SPierre Pronchery if (!ossl_prov_digest_load_from_params(&macctx->digest, params, ctx))
317*b077aed3SPierre Pronchery return 0;
318*b077aed3SPierre Pronchery
319*b077aed3SPierre Pronchery if (!set_flag(params, OSSL_MAC_PARAM_DIGEST_NOINIT, EVP_MD_CTX_FLAG_NO_INIT,
320*b077aed3SPierre Pronchery &flags))
321*b077aed3SPierre Pronchery return 0;
322*b077aed3SPierre Pronchery if (!set_flag(params, OSSL_MAC_PARAM_DIGEST_ONESHOT, EVP_MD_CTX_FLAG_ONESHOT,
323*b077aed3SPierre Pronchery &flags))
324*b077aed3SPierre Pronchery return 0;
325*b077aed3SPierre Pronchery if (flags)
326*b077aed3SPierre Pronchery HMAC_CTX_set_flags(macctx->ctx, flags);
327*b077aed3SPierre Pronchery
328*b077aed3SPierre Pronchery if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL) {
329*b077aed3SPierre Pronchery if (p->data_type != OSSL_PARAM_OCTET_STRING)
330*b077aed3SPierre Pronchery return 0;
331*b077aed3SPierre Pronchery if (!hmac_setkey(macctx, p->data, p->data_size))
332*b077aed3SPierre Pronchery return 0;
333*b077aed3SPierre Pronchery }
334*b077aed3SPierre Pronchery
335*b077aed3SPierre Pronchery if ((p = OSSL_PARAM_locate_const(params,
336*b077aed3SPierre Pronchery OSSL_MAC_PARAM_TLS_DATA_SIZE)) != NULL) {
337*b077aed3SPierre Pronchery if (!OSSL_PARAM_get_size_t(p, &macctx->tls_data_size))
338*b077aed3SPierre Pronchery return 0;
339*b077aed3SPierre Pronchery }
340*b077aed3SPierre Pronchery return 1;
341*b077aed3SPierre Pronchery }
342*b077aed3SPierre Pronchery
343*b077aed3SPierre Pronchery const OSSL_DISPATCH ossl_hmac_functions[] = {
344*b077aed3SPierre Pronchery { OSSL_FUNC_MAC_NEWCTX, (void (*)(void))hmac_new },
345*b077aed3SPierre Pronchery { OSSL_FUNC_MAC_DUPCTX, (void (*)(void))hmac_dup },
346*b077aed3SPierre Pronchery { OSSL_FUNC_MAC_FREECTX, (void (*)(void))hmac_free },
347*b077aed3SPierre Pronchery { OSSL_FUNC_MAC_INIT, (void (*)(void))hmac_init },
348*b077aed3SPierre Pronchery { OSSL_FUNC_MAC_UPDATE, (void (*)(void))hmac_update },
349*b077aed3SPierre Pronchery { OSSL_FUNC_MAC_FINAL, (void (*)(void))hmac_final },
350*b077aed3SPierre Pronchery { OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS,
351*b077aed3SPierre Pronchery (void (*)(void))hmac_gettable_ctx_params },
352*b077aed3SPierre Pronchery { OSSL_FUNC_MAC_GET_CTX_PARAMS, (void (*)(void))hmac_get_ctx_params },
353*b077aed3SPierre Pronchery { OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS,
354*b077aed3SPierre Pronchery (void (*)(void))hmac_settable_ctx_params },
355*b077aed3SPierre Pronchery { OSSL_FUNC_MAC_SET_CTX_PARAMS, (void (*)(void))hmac_set_ctx_params },
356*b077aed3SPierre Pronchery { 0, NULL }
357*b077aed3SPierre Pronchery };
358