Coverage Report

Created: 2026-02-22 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/providers/implementations/rands/drbg_hmac.c
Line
Count
Source
1
/*
2
 * Copyright 2011-2025 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
#include <stdlib.h>
11
#include <string.h>
12
#include <openssl/crypto.h>
13
#include <openssl/err.h>
14
#include <openssl/rand.h>
15
#include <openssl/proverr.h>
16
#include "internal/cryptlib.h"
17
#include "internal/thread_once.h"
18
#include "prov/providercommon.h"
19
#include "prov/implementations.h"
20
#include "prov/provider_ctx.h"
21
#include "prov/hmac_drbg.h"
22
#include "prov/drbg.h"
23
#include "crypto/evp.h"
24
#include "crypto/evp/evp_local.h"
25
#include "internal/fips.h"
26
#include "internal/provider.h"
27
28
#define drbg_hmac_get_ctx_params_st drbg_get_ctx_params_st
29
#define drbg_hmac_set_ctx_params_st drbg_set_ctx_params_st
30
31
#include "providers/implementations/rands/drbg_hmac.inc"
32
33
static OSSL_FUNC_rand_newctx_fn drbg_hmac_new_wrapper;
34
static OSSL_FUNC_rand_freectx_fn drbg_hmac_free;
35
static OSSL_FUNC_rand_instantiate_fn drbg_hmac_instantiate_wrapper;
36
static OSSL_FUNC_rand_uninstantiate_fn drbg_hmac_uninstantiate_wrapper;
37
static OSSL_FUNC_rand_generate_fn drbg_hmac_generate_wrapper;
38
static OSSL_FUNC_rand_reseed_fn drbg_hmac_reseed_wrapper;
39
static OSSL_FUNC_rand_settable_ctx_params_fn drbg_hmac_settable_ctx_params;
40
static OSSL_FUNC_rand_set_ctx_params_fn drbg_hmac_set_ctx_params;
41
static OSSL_FUNC_rand_gettable_ctx_params_fn drbg_hmac_gettable_ctx_params;
42
static OSSL_FUNC_rand_get_ctx_params_fn drbg_hmac_get_ctx_params;
43
static OSSL_FUNC_rand_verify_zeroization_fn drbg_hmac_verify_zeroization;
44
45
static int drbg_hmac_set_ctx_params_locked(PROV_DRBG *drbg,
46
    const struct drbg_set_ctx_params_st *p);
47
48
/*
49
 * Called twice by SP800-90Ar1 10.1.2.2 HMAC_DRBG_Update_Process.
50
 *
51
 * hmac is an object that holds the input/output Key and Value (K and V).
52
 * inbyte is 0x00 on the first call and 0x01 on the second call.
53
 * in1, in2, in3 are optional inputs that can be NULL.
54
 * in1len, in2len, in3len are the lengths of the input buffers.
55
 *
56
 * The returned K,V is:
57
 *   hmac->K = HMAC(hmac->K, hmac->V || inbyte || [in1] || [in2] || [in3])
58
 *   hmac->V = HMAC(hmac->K, hmac->V)
59
 *
60
 * Returns zero if an error occurs otherwise it returns 1.
61
 */
62
static int do_hmac(PROV_DRBG_HMAC *hmac, unsigned char inbyte,
63
    const unsigned char *in1, size_t in1len,
64
    const unsigned char *in2, size_t in2len,
65
    const unsigned char *in3, size_t in3len)
66
0
{
67
0
    EVP_MAC_CTX *ctx = hmac->ctx;
68
69
0
    if (!EVP_MAC_init(ctx, hmac->K, hmac->blocklen, NULL)
70
        /* K = HMAC(K, V || inbyte || [in1] || [in2] || [in3]) */
71
0
        || !EVP_MAC_update(ctx, hmac->V, hmac->blocklen)
72
0
        || !EVP_MAC_update(ctx, &inbyte, 1)
73
0
        || !(in1 == NULL || in1len == 0 || EVP_MAC_update(ctx, in1, in1len))
74
0
        || !(in2 == NULL || in2len == 0 || EVP_MAC_update(ctx, in2, in2len))
75
0
        || !(in3 == NULL || in3len == 0 || EVP_MAC_update(ctx, in3, in3len))
76
0
        || !EVP_MAC_final(ctx, hmac->K, NULL, sizeof(hmac->K)))
77
0
        return 0;
78
79
    /* V = HMAC(K, V) */
80
0
    return EVP_MAC_init(ctx, hmac->K, hmac->blocklen, NULL)
81
0
        && EVP_MAC_update(ctx, hmac->V, hmac->blocklen)
82
0
        && EVP_MAC_final(ctx, hmac->V, NULL, sizeof(hmac->V));
83
0
}
84
85
/*
86
 * SP800-90Ar1 10.1.2.2 HMAC_DRBG_Update_Process
87
 *
88
 *
89
 * Updates the drbg objects Key(K) and Value(V) using the following algorithm:
90
 *   K,V = do_hmac(hmac, 0, in1, in2, in3)
91
 *   if (any input is not NULL)
92
 *     K,V = do_hmac(hmac, 1, in1, in2, in3)
93
 *
94
 * where in1, in2, in3 are optional input buffers that can be NULL.
95
 *       in1len, in2len, in3len are the lengths of the input buffers.
96
 *
97
 * Returns zero if an error occurs otherwise it returns 1.
98
 */
99
static int drbg_hmac_update(PROV_DRBG_HMAC *hmac,
100
    const unsigned char *in1, size_t in1len,
101
    const unsigned char *in2, size_t in2len,
102
    const unsigned char *in3, size_t in3len)
103
0
{
104
    /* (Steps 1-2) K = HMAC(K, V||0x00||provided_data). V = HMAC(K,V) */
105
0
    if (!do_hmac(hmac, 0x00, in1, in1len, in2, in2len, in3, in3len))
106
0
        return 0;
107
    /* (Step 3) If provided_data == NULL then return (K,V) */
108
0
    if (in1len == 0 && in2len == 0 && in3len == 0)
109
0
        return 1;
110
    /* (Steps 4-5) K = HMAC(K, V||0x01||provided_data). V = HMAC(K,V) */
111
0
    return do_hmac(hmac, 0x01, in1, in1len, in2, in2len, in3, in3len);
112
0
}
113
114
/*
115
 * SP800-90Ar1 10.1.2.3 HMAC_DRBG_Instantiate_Process:
116
 *
117
 * This sets the drbg Key (K) to all zeros, and Value (V) to all 1's.
118
 * and then calls (K,V) = drbg_hmac_update() with input parameters:
119
 *   ent = entropy data (Can be NULL) of length ent_len.
120
 *   nonce = nonce data (Can be NULL) of length nonce_len.
121
 *   pstr = personalization data (Can be NULL) of length pstr_len.
122
 *
123
 * Returns zero if an error occurs otherwise it returns 1.
124
 */
125
int ossl_drbg_hmac_init(PROV_DRBG_HMAC *hmac,
126
    const unsigned char *ent, size_t ent_len,
127
    const unsigned char *nonce, size_t nonce_len,
128
    const unsigned char *pstr, size_t pstr_len)
129
0
{
130
0
    if (hmac->ctx == NULL) {
131
0
        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MAC);
132
0
        return 0;
133
0
    }
134
135
    /* (Step 2) Key = 0x00 00...00 */
136
0
    memset(hmac->K, 0x00, hmac->blocklen);
137
    /* (Step 3) V = 0x01 01...01 */
138
0
    memset(hmac->V, 0x01, hmac->blocklen);
139
    /* (Step 4) (K,V) = HMAC_DRBG_Update(entropy||nonce||pers string, K, V) */
140
0
    return drbg_hmac_update(hmac, ent, ent_len, nonce, nonce_len, pstr,
141
0
        pstr_len);
142
0
}
143
static int drbg_hmac_instantiate(PROV_DRBG *drbg,
144
    const unsigned char *ent, size_t ent_len,
145
    const unsigned char *nonce, size_t nonce_len,
146
    const unsigned char *pstr, size_t pstr_len)
147
0
{
148
0
    return ossl_drbg_hmac_init((PROV_DRBG_HMAC *)drbg->data, ent, ent_len,
149
0
        nonce, nonce_len, pstr, pstr_len);
150
0
}
151
152
static int drbg_hmac_instantiate_wrapper(void *vdrbg, unsigned int strength,
153
    int prediction_resistance,
154
    const unsigned char *pstr,
155
    size_t pstr_len,
156
    const OSSL_PARAM params[])
157
0
{
158
0
    PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
159
0
    struct drbg_set_ctx_params_st p;
160
0
    int ret = 0;
161
162
0
    if (drbg == NULL || !drbg_hmac_set_ctx_params_decoder(params, &p))
163
0
        return 0;
164
165
0
    if (drbg->lock != NULL && !CRYPTO_THREAD_write_lock(drbg->lock))
166
0
        return 0;
167
168
0
    if (!ossl_prov_is_running()
169
0
        || !drbg_hmac_set_ctx_params_locked(drbg, &p))
170
0
        goto err;
171
0
    ret = ossl_prov_drbg_instantiate(drbg, strength, prediction_resistance,
172
0
        pstr, pstr_len);
173
0
err:
174
0
    if (drbg->lock != NULL)
175
0
        CRYPTO_THREAD_unlock(drbg->lock);
176
0
    return ret;
177
0
}
178
179
/*
180
 * SP800-90Ar1 10.1.2.4 HMAC_DRBG_Reseed_Process:
181
 *
182
 * Reseeds the drbg's Key (K) and Value (V) by calling
183
 * (K,V) = drbg_hmac_update() with the following input parameters:
184
 *   ent = entropy input data (Can be NULL) of length ent_len.
185
 *   adin = additional input data (Can be NULL) of length adin_len.
186
 *
187
 * Returns zero if an error occurs otherwise it returns 1.
188
 */
189
static int drbg_hmac_reseed(PROV_DRBG *drbg,
190
    const unsigned char *ent, size_t ent_len,
191
    const unsigned char *adin, size_t adin_len)
192
0
{
193
0
    PROV_DRBG_HMAC *hmac = (PROV_DRBG_HMAC *)drbg->data;
194
195
    /* (Step 2) (K,V) = HMAC_DRBG_Update(entropy||additional_input, K, V) */
196
0
    return drbg_hmac_update(hmac, ent, ent_len, adin, adin_len, NULL, 0);
197
0
}
198
199
static int drbg_hmac_reseed_wrapper(void *vdrbg, int prediction_resistance,
200
    const unsigned char *ent, size_t ent_len,
201
    const unsigned char *adin, size_t adin_len)
202
0
{
203
0
    PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
204
205
0
    return ossl_prov_drbg_reseed(drbg, prediction_resistance, ent, ent_len,
206
0
        adin, adin_len);
207
0
}
208
209
/*
210
 * SP800-90Ar1 10.1.2.5 HMAC_DRBG_Generate_Process:
211
 *
212
 * Generates pseudo random bytes and updates the internal K,V for the drbg.
213
 * out is a buffer to fill with outlen bytes of pseudo random data.
214
 * adin is an additional_input string of size adin_len that may be NULL.
215
 *
216
 * Returns zero if an error occurs otherwise it returns 1.
217
 */
218
int ossl_drbg_hmac_generate(PROV_DRBG_HMAC *hmac,
219
    unsigned char *out, size_t outlen,
220
    const unsigned char *adin, size_t adin_len)
221
0
{
222
0
    EVP_MAC_CTX *ctx = hmac->ctx;
223
0
    const unsigned char *temp = hmac->V;
224
225
    /* (Step 2) if adin != NULL then (K,V) = HMAC_DRBG_Update(adin, K, V) */
226
0
    if (adin != NULL
227
0
        && adin_len > 0
228
0
        && !drbg_hmac_update(hmac, adin, adin_len, NULL, 0, NULL, 0))
229
0
        return 0;
230
231
    /*
232
     * (Steps 3-5) temp = NULL
233
     *             while (len(temp) < outlen) {
234
     *                 V = HMAC(K, V)
235
     *                 temp = temp || V
236
     *             }
237
     */
238
0
    for (;;) {
239
0
        if (!EVP_MAC_init(ctx, hmac->K, hmac->blocklen, NULL)
240
0
            || !EVP_MAC_update(ctx, temp, hmac->blocklen))
241
0
            return 0;
242
243
0
        if (outlen > hmac->blocklen) {
244
0
            if (!EVP_MAC_final(ctx, out, NULL, outlen))
245
0
                return 0;
246
0
            temp = out;
247
0
        } else {
248
0
            if (!EVP_MAC_final(ctx, hmac->V, NULL, sizeof(hmac->V)))
249
0
                return 0;
250
0
            memcpy(out, hmac->V, outlen);
251
0
            break;
252
0
        }
253
0
        out += hmac->blocklen;
254
0
        outlen -= hmac->blocklen;
255
0
    }
256
    /* (Step 6) (K,V) = HMAC_DRBG_Update(adin, K, V) */
257
0
    if (!drbg_hmac_update(hmac, adin, adin_len, NULL, 0, NULL, 0))
258
0
        return 0;
259
260
0
    return 1;
261
0
}
262
263
static int drbg_hmac_generate(PROV_DRBG *drbg,
264
    unsigned char *out, size_t outlen,
265
    const unsigned char *adin, size_t adin_len)
266
0
{
267
0
    return ossl_drbg_hmac_generate((PROV_DRBG_HMAC *)drbg->data, out, outlen,
268
0
        adin, adin_len);
269
0
}
270
271
static int drbg_hmac_generate_wrapper(void *vdrbg,
272
    unsigned char *out, size_t outlen, unsigned int strength,
273
    int prediction_resistance, const unsigned char *adin, size_t adin_len)
274
0
{
275
0
    PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
276
277
0
    return ossl_prov_drbg_generate(drbg, out, outlen, strength,
278
0
        prediction_resistance, adin, adin_len);
279
0
}
280
281
static int drbg_hmac_uninstantiate(PROV_DRBG *drbg)
282
0
{
283
0
    PROV_DRBG_HMAC *hmac = (PROV_DRBG_HMAC *)drbg->data;
284
285
0
    OPENSSL_cleanse(hmac->K, sizeof(hmac->K));
286
0
    OPENSSL_cleanse(hmac->V, sizeof(hmac->V));
287
0
    return ossl_prov_drbg_uninstantiate(drbg);
288
0
}
289
290
static int drbg_hmac_uninstantiate_wrapper(void *vdrbg)
291
0
{
292
0
    PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
293
0
    int ret;
294
295
0
    if (drbg->lock != NULL && !CRYPTO_THREAD_write_lock(drbg->lock))
296
0
        return 0;
297
298
0
    ret = drbg_hmac_uninstantiate(drbg);
299
300
0
    if (drbg->lock != NULL)
301
0
        CRYPTO_THREAD_unlock(drbg->lock);
302
303
0
    return ret;
304
0
}
305
306
static int drbg_hmac_verify_zeroization(void *vdrbg)
307
0
{
308
0
    PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
309
0
    PROV_DRBG_HMAC *hmac = (PROV_DRBG_HMAC *)drbg->data;
310
0
    int ret = 0;
311
312
0
    if (drbg->lock != NULL && !CRYPTO_THREAD_read_lock(drbg->lock))
313
0
        return 0;
314
315
0
    PROV_DRBG_VERIFY_ZEROIZATION(hmac->K);
316
0
    PROV_DRBG_VERIFY_ZEROIZATION(hmac->V);
317
318
0
    ret = 1;
319
0
err:
320
0
    if (drbg->lock != NULL)
321
0
        CRYPTO_THREAD_unlock(drbg->lock);
322
0
    return ret;
323
0
}
324
325
static int drbg_hmac_new(PROV_DRBG *drbg)
326
0
{
327
0
    PROV_DRBG_HMAC *hmac;
328
329
0
    hmac = OPENSSL_secure_zalloc(sizeof(*hmac));
330
0
    if (hmac == NULL)
331
0
        return 0;
332
333
0
    OSSL_FIPS_IND_INIT(drbg)
334
335
0
    drbg->data = hmac;
336
    /* See SP800-57 Part1 Rev4 5.6.1 Table 3 */
337
0
    drbg->max_entropylen = DRBG_MAX_LENGTH;
338
0
    drbg->max_noncelen = DRBG_MAX_LENGTH;
339
0
    drbg->max_perslen = DRBG_MAX_LENGTH;
340
0
    drbg->max_adinlen = DRBG_MAX_LENGTH;
341
342
    /* Maximum number of bits per request = 2^19  = 2^16 bytes */
343
0
    drbg->max_request = 1 << 16;
344
0
    return 1;
345
0
}
346
347
static void *drbg_hmac_new_wrapper(void *provctx, void *parent,
348
    const OSSL_DISPATCH *parent_dispatch)
349
0
{
350
#ifdef FIPS_MODULE
351
    if (!ossl_deferred_self_test(PROV_LIBCTX_OF(provctx),
352
            ST_ID_DRBG_HMAC))
353
        return NULL;
354
#endif
355
356
0
    return ossl_rand_drbg_new(provctx, parent, parent_dispatch,
357
0
        &drbg_hmac_new, &drbg_hmac_free,
358
0
        &drbg_hmac_instantiate, &drbg_hmac_uninstantiate,
359
0
        &drbg_hmac_reseed, &drbg_hmac_generate);
360
0
}
361
362
static void drbg_hmac_free(void *vdrbg)
363
0
{
364
0
    PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
365
0
    PROV_DRBG_HMAC *hmac;
366
367
0
    if (drbg != NULL && (hmac = (PROV_DRBG_HMAC *)drbg->data) != NULL) {
368
0
        EVP_MAC_CTX_free(hmac->ctx);
369
0
        ossl_prov_digest_reset(&hmac->digest);
370
0
        OPENSSL_secure_clear_free(hmac, sizeof(*hmac));
371
0
    }
372
0
    ossl_rand_drbg_free(drbg);
373
0
}
374
375
static int drbg_hmac_get_ctx_params(void *vdrbg, OSSL_PARAM params[])
376
0
{
377
0
    PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
378
0
    PROV_DRBG_HMAC *hmac;
379
0
    const EVP_MD *md;
380
0
    struct drbg_get_ctx_params_st p;
381
0
    int ret = 0, complete = 0;
382
383
0
    if (drbg == NULL || !drbg_hmac_get_ctx_params_decoder(params, &p))
384
0
        return 0;
385
386
0
    if (!ossl_drbg_get_ctx_params_no_lock(drbg, &p, params, &complete))
387
0
        return 0;
388
389
0
    if (complete)
390
0
        return 1;
391
392
0
    hmac = (PROV_DRBG_HMAC *)drbg->data;
393
394
0
    if (drbg->lock != NULL && !CRYPTO_THREAD_read_lock(drbg->lock))
395
0
        return 0;
396
397
0
    if (p.digest != NULL) {
398
0
        md = ossl_prov_digest_md(&hmac->digest);
399
0
        if (md == NULL
400
0
            || !OSSL_PARAM_set_utf8_string(p.digest, EVP_MD_get0_name(md)))
401
0
            goto err;
402
0
    }
403
404
0
    ret = ossl_drbg_get_ctx_params(drbg, &p);
405
0
err:
406
0
    if (drbg->lock != NULL)
407
0
        CRYPTO_THREAD_unlock(drbg->lock);
408
409
0
    return ret;
410
0
}
411
412
static const OSSL_PARAM *drbg_hmac_gettable_ctx_params(ossl_unused void *vctx,
413
    ossl_unused void *p_ctx)
414
0
{
415
0
    return drbg_hmac_get_ctx_params_list;
416
0
}
417
418
static int drbg_fetch_algs_from_prov(const struct drbg_set_ctx_params_st *p,
419
    OSSL_LIB_CTX *libctx,
420
    EVP_MAC_CTX **macctx,
421
    EVP_MD **digest)
422
0
{
423
0
    OSSL_PROVIDER *prov = NULL;
424
0
    EVP_MD *md = NULL;
425
0
    int ret = 0;
426
427
0
    if (macctx == NULL || digest == NULL)
428
0
        return 0;
429
430
0
    if (p->prov == NULL || p->prov->data_type != OSSL_PARAM_UTF8_STRING)
431
0
        return 0;
432
0
    if ((prov = ossl_provider_find(libctx, (const char *)p->prov->data, 1)) == NULL)
433
0
        return 0;
434
435
0
    if (p->digest != NULL) {
436
0
        if (p->digest->data_type != OSSL_PARAM_UTF8_STRING)
437
0
            goto done;
438
439
0
        md = evp_digest_fetch_from_prov(prov, (const char *)p->digest->data, NULL);
440
0
        if (md) {
441
0
            EVP_MD_free(*digest);
442
0
            *digest = md;
443
0
        } else {
444
0
            goto done;
445
0
        }
446
0
        if (!ossl_prov_macctx_load(macctx, NULL, NULL, p->digest,
447
0
                p->propq, "HMAC", NULL, NULL, libctx))
448
0
            goto done;
449
0
    }
450
451
0
    ret = 1;
452
453
0
done:
454
0
    ossl_provider_free(prov);
455
0
    return ret;
456
0
}
457
458
static int drbg_hmac_set_ctx_params_locked(PROV_DRBG *ctx, const struct drbg_set_ctx_params_st *p)
459
0
{
460
0
    PROV_DRBG_HMAC *hmac = (PROV_DRBG_HMAC *)ctx->data;
461
0
    OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx);
462
0
    EVP_MD *prov_md = NULL;
463
0
    const EVP_MD *md;
464
0
    int md_size;
465
466
0
    if (!OSSL_FIPS_IND_SET_CTX_FROM_PARAM(ctx, OSSL_FIPS_IND_SETTABLE0, p->ind_d))
467
0
        return 0;
468
469
    /* try to fetch mac and digest from provider */
470
0
    (void)ERR_set_mark();
471
0
    if (!drbg_fetch_algs_from_prov(p, libctx, &hmac->ctx, &prov_md)) {
472
0
        (void)ERR_pop_to_mark();
473
0
        if (p->digest != NULL) {
474
            /* fall back to full implementation search */
475
0
            if (!ossl_prov_digest_load(&hmac->digest, p->digest, p->propq,
476
0
                    libctx))
477
0
                return 0;
478
479
0
            if (!ossl_prov_macctx_load(&hmac->ctx, NULL, NULL, p->digest,
480
0
                    p->propq, "HMAC", NULL, NULL, libctx))
481
0
                return 0;
482
0
        }
483
0
    } else {
484
0
        (void)ERR_clear_last_mark();
485
0
        if (prov_md)
486
0
            ossl_prov_digest_set_md(&hmac->digest, prov_md);
487
0
    }
488
489
0
    md = ossl_prov_digest_md(&hmac->digest);
490
0
    if (md != NULL && !ossl_drbg_verify_digest(ctx, libctx, md))
491
0
        return 0; /* Error already raised for us */
492
493
0
    if (md != NULL && hmac->ctx != NULL) {
494
        /* These are taken from SP 800-90 10.1 Table 2 */
495
0
        md_size = EVP_MD_get_size(md);
496
0
        if (md_size <= 0)
497
0
            return 0;
498
0
        hmac->blocklen = (size_t)md_size;
499
        /* See SP800-57 Part1 Rev4 5.6.1 Table 3 */
500
0
        ctx->strength = 64 * (int)(hmac->blocklen >> 3);
501
0
        if (ctx->strength > 256)
502
0
            ctx->strength = 256;
503
0
        ctx->seedlen = hmac->blocklen;
504
0
        ctx->min_entropylen = ctx->strength / 8;
505
0
        ctx->min_noncelen = ctx->min_entropylen / 2;
506
0
    }
507
508
0
    return ossl_drbg_set_ctx_params(ctx, p);
509
0
}
510
511
static int drbg_hmac_set_ctx_params(void *vctx, const OSSL_PARAM params[])
512
0
{
513
0
    PROV_DRBG *drbg = (PROV_DRBG *)vctx;
514
0
    struct drbg_set_ctx_params_st p;
515
0
    int ret;
516
517
0
    if (drbg == NULL || !drbg_hmac_set_ctx_params_decoder(params, &p))
518
0
        return 0;
519
520
0
    if (drbg->lock != NULL && !CRYPTO_THREAD_write_lock(drbg->lock))
521
0
        return 0;
522
523
0
    ret = drbg_hmac_set_ctx_params_locked(drbg, &p);
524
525
0
    if (drbg->lock != NULL)
526
0
        CRYPTO_THREAD_unlock(drbg->lock);
527
528
0
    return ret;
529
0
}
530
531
static const OSSL_PARAM *drbg_hmac_settable_ctx_params(ossl_unused void *vctx,
532
    ossl_unused void *p_ctx)
533
0
{
534
0
    return drbg_hmac_set_ctx_params_list;
535
0
}
536
537
const OSSL_DISPATCH ossl_drbg_ossl_hmac_functions[] = {
538
    { OSSL_FUNC_RAND_NEWCTX, (void (*)(void))drbg_hmac_new_wrapper },
539
    { OSSL_FUNC_RAND_FREECTX, (void (*)(void))drbg_hmac_free },
540
    { OSSL_FUNC_RAND_INSTANTIATE,
541
        (void (*)(void))drbg_hmac_instantiate_wrapper },
542
    { OSSL_FUNC_RAND_UNINSTANTIATE,
543
        (void (*)(void))drbg_hmac_uninstantiate_wrapper },
544
    { OSSL_FUNC_RAND_GENERATE, (void (*)(void))drbg_hmac_generate_wrapper },
545
    { OSSL_FUNC_RAND_RESEED, (void (*)(void))drbg_hmac_reseed_wrapper },
546
    { OSSL_FUNC_RAND_ENABLE_LOCKING, (void (*)(void))ossl_drbg_enable_locking },
547
    { OSSL_FUNC_RAND_LOCK, (void (*)(void))ossl_drbg_lock },
548
    { OSSL_FUNC_RAND_UNLOCK, (void (*)(void))ossl_drbg_unlock },
549
    { OSSL_FUNC_RAND_SETTABLE_CTX_PARAMS,
550
        (void (*)(void))drbg_hmac_settable_ctx_params },
551
    { OSSL_FUNC_RAND_SET_CTX_PARAMS, (void (*)(void))drbg_hmac_set_ctx_params },
552
    { OSSL_FUNC_RAND_GETTABLE_CTX_PARAMS,
553
        (void (*)(void))drbg_hmac_gettable_ctx_params },
554
    { OSSL_FUNC_RAND_GET_CTX_PARAMS, (void (*)(void))drbg_hmac_get_ctx_params },
555
    { OSSL_FUNC_RAND_VERIFY_ZEROIZATION,
556
        (void (*)(void))drbg_hmac_verify_zeroization },
557
    { OSSL_FUNC_RAND_GET_SEED, (void (*)(void))ossl_drbg_get_seed },
558
    { OSSL_FUNC_RAND_CLEAR_SEED, (void (*)(void))ossl_drbg_clear_seed },
559
    OSSL_DISPATCH_END
560
};