Coverage Report

Created: 2025-11-07 06:36

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