/src/openssl36/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 | | /* clang-format off */ |
10 | | |
11 | | /* clang-format on */ |
12 | | |
13 | | #include <stdlib.h> |
14 | | #include <string.h> |
15 | | #include <openssl/crypto.h> |
16 | | #include <openssl/err.h> |
17 | | #include <openssl/rand.h> |
18 | | #include <openssl/proverr.h> |
19 | | #include "internal/cryptlib.h" |
20 | | #include "internal/thread_once.h" |
21 | | #include "prov/providercommon.h" |
22 | | #include "prov/implementations.h" |
23 | | #include "prov/provider_ctx.h" |
24 | | #include "prov/hmac_drbg.h" |
25 | | #include "prov/drbg.h" |
26 | | #include "crypto/evp.h" |
27 | | #include "crypto/evp/evp_local.h" |
28 | | #include "internal/provider.h" |
29 | | |
30 | | static OSSL_FUNC_rand_newctx_fn drbg_hmac_new_wrapper; |
31 | | static OSSL_FUNC_rand_freectx_fn drbg_hmac_free; |
32 | | static OSSL_FUNC_rand_instantiate_fn drbg_hmac_instantiate_wrapper; |
33 | | static OSSL_FUNC_rand_uninstantiate_fn drbg_hmac_uninstantiate_wrapper; |
34 | | static OSSL_FUNC_rand_generate_fn drbg_hmac_generate_wrapper; |
35 | | static OSSL_FUNC_rand_reseed_fn drbg_hmac_reseed_wrapper; |
36 | | static OSSL_FUNC_rand_settable_ctx_params_fn drbg_hmac_settable_ctx_params; |
37 | | static OSSL_FUNC_rand_set_ctx_params_fn drbg_hmac_set_ctx_params; |
38 | | static OSSL_FUNC_rand_gettable_ctx_params_fn drbg_hmac_gettable_ctx_params; |
39 | | static OSSL_FUNC_rand_get_ctx_params_fn drbg_hmac_get_ctx_params; |
40 | | static OSSL_FUNC_rand_verify_zeroization_fn drbg_hmac_verify_zeroization; |
41 | | |
42 | | static int drbg_hmac_set_ctx_params_locked(PROV_DRBG *drbg, const struct drbg_set_ctx_params_st *p); |
43 | | static int drbg_hmac_set_ctx_params_decoder(const OSSL_PARAM params[], |
44 | | struct drbg_set_ctx_params_st *p); |
45 | | |
46 | | /* |
47 | | * Called twice by SP800-90Ar1 10.1.2.2 HMAC_DRBG_Update_Process. |
48 | | * |
49 | | * hmac is an object that holds the input/output Key and Value (K and V). |
50 | | * inbyte is 0x00 on the first call and 0x01 on the second call. |
51 | | * in1, in2, in3 are optional inputs that can be NULL. |
52 | | * in1len, in2len, in3len are the lengths of the input buffers. |
53 | | * |
54 | | * The returned K,V is: |
55 | | * hmac->K = HMAC(hmac->K, hmac->V || inbyte || [in1] || [in2] || [in3]) |
56 | | * hmac->V = HMAC(hmac->K, hmac->V) |
57 | | * |
58 | | * Returns zero if an error occurs otherwise it returns 1. |
59 | | */ |
60 | | static int do_hmac(PROV_DRBG_HMAC *hmac, unsigned char inbyte, |
61 | | const unsigned char *in1, size_t in1len, |
62 | | const unsigned char *in2, size_t in2len, |
63 | | const unsigned char *in3, size_t in3len) |
64 | 2.00k | { |
65 | 2.00k | EVP_MAC_CTX *ctx = hmac->ctx; |
66 | | |
67 | 2.00k | if (!EVP_MAC_init(ctx, hmac->K, hmac->blocklen, NULL) |
68 | | /* K = HMAC(K, V || inbyte || [in1] || [in2] || [in3]) */ |
69 | 1.98k | || !EVP_MAC_update(ctx, hmac->V, hmac->blocklen) |
70 | 1.98k | || !EVP_MAC_update(ctx, &inbyte, 1) |
71 | 1.98k | || !(in1 == NULL || in1len == 0 || EVP_MAC_update(ctx, in1, in1len)) |
72 | 1.98k | || !(in2 == NULL || in2len == 0 || EVP_MAC_update(ctx, in2, in2len)) |
73 | 1.98k | || !(in3 == NULL || in3len == 0 || EVP_MAC_update(ctx, in3, in3len)) |
74 | 1.98k | || !EVP_MAC_final(ctx, hmac->K, NULL, sizeof(hmac->K))) |
75 | 21 | return 0; |
76 | | |
77 | | /* V = HMAC(K, V) */ |
78 | 1.98k | return EVP_MAC_init(ctx, hmac->K, hmac->blocklen, NULL) |
79 | 1.98k | && EVP_MAC_update(ctx, hmac->V, hmac->blocklen) |
80 | 1.98k | && EVP_MAC_final(ctx, hmac->V, NULL, sizeof(hmac->V)); |
81 | 2.00k | } |
82 | | |
83 | | /* |
84 | | * SP800-90Ar1 10.1.2.2 HMAC_DRBG_Update_Process |
85 | | * |
86 | | * |
87 | | * Updates the drbg objects Key(K) and Value(V) using the following algorithm: |
88 | | * K,V = do_hmac(hmac, 0, in1, in2, in3) |
89 | | * if (any input is not NULL) |
90 | | * K,V = do_hmac(hmac, 1, in1, in2, in3) |
91 | | * |
92 | | * where in1, in2, in3 are optional input buffers that can be NULL. |
93 | | * in1len, in2len, in3len are the lengths of the input buffers. |
94 | | * |
95 | | * Returns zero if an error occurs otherwise it returns 1. |
96 | | */ |
97 | | static int drbg_hmac_update(PROV_DRBG_HMAC *hmac, |
98 | | const unsigned char *in1, size_t in1len, |
99 | | const unsigned char *in2, size_t in2len, |
100 | | const unsigned char *in3, size_t in3len) |
101 | 1.25k | { |
102 | | /* (Steps 1-2) K = HMAC(K, V||0x00||provided_data). V = HMAC(K,V) */ |
103 | 1.25k | if (!do_hmac(hmac, 0x00, in1, in1len, in2, in2len, in3, in3len)) |
104 | 21 | return 0; |
105 | | /* (Step 3) If provided_data == NULL then return (K,V) */ |
106 | 1.23k | if (in1len == 0 && in2len == 0 && in3len == 0) |
107 | 482 | return 1; |
108 | | /* (Steps 4-5) K = HMAC(K, V||0x01||provided_data). V = HMAC(K,V) */ |
109 | 749 | return do_hmac(hmac, 0x01, in1, in1len, in2, in2len, in3, in3len); |
110 | 1.23k | } |
111 | | |
112 | | /* |
113 | | * SP800-90Ar1 10.1.2.3 HMAC_DRBG_Instantiate_Process: |
114 | | * |
115 | | * This sets the drbg Key (K) to all zeros, and Value (V) to all 1's. |
116 | | * and then calls (K,V) = drbg_hmac_update() with input parameters: |
117 | | * ent = entropy data (Can be NULL) of length ent_len. |
118 | | * nonce = nonce data (Can be NULL) of length nonce_len. |
119 | | * pstr = personalization data (Can be NULL) of length pstr_len. |
120 | | * |
121 | | * Returns zero if an error occurs otherwise it returns 1. |
122 | | */ |
123 | | int ossl_drbg_hmac_init(PROV_DRBG_HMAC *hmac, |
124 | | const unsigned char *ent, size_t ent_len, |
125 | | const unsigned char *nonce, size_t nonce_len, |
126 | | const unsigned char *pstr, size_t pstr_len) |
127 | 528 | { |
128 | 528 | if (hmac->ctx == NULL) { |
129 | 1 | ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MAC); |
130 | 1 | return 0; |
131 | 1 | } |
132 | | |
133 | | /* (Step 2) Key = 0x00 00...00 */ |
134 | 527 | memset(hmac->K, 0x00, hmac->blocklen); |
135 | | /* (Step 3) V = 0x01 01...01 */ |
136 | 527 | memset(hmac->V, 0x01, hmac->blocklen); |
137 | | /* (Step 4) (K,V) = HMAC_DRBG_Update(entropy||nonce||pers string, K, V) */ |
138 | 527 | return drbg_hmac_update(hmac, ent, ent_len, nonce, nonce_len, pstr, |
139 | 527 | pstr_len); |
140 | 528 | } |
141 | | static int drbg_hmac_instantiate(PROV_DRBG *drbg, |
142 | | const unsigned char *ent, size_t ent_len, |
143 | | const unsigned char *nonce, size_t nonce_len, |
144 | | const unsigned char *pstr, size_t pstr_len) |
145 | 236 | { |
146 | 236 | return ossl_drbg_hmac_init((PROV_DRBG_HMAC *)drbg->data, ent, ent_len, |
147 | 236 | nonce, nonce_len, pstr, pstr_len); |
148 | 236 | } |
149 | | |
150 | | static int drbg_hmac_instantiate_wrapper(void *vdrbg, unsigned int strength, |
151 | | int prediction_resistance, |
152 | | const unsigned char *pstr, |
153 | | size_t pstr_len, |
154 | | const OSSL_PARAM params[]) |
155 | 0 | { |
156 | 0 | PROV_DRBG *drbg = (PROV_DRBG *)vdrbg; |
157 | 0 | struct drbg_set_ctx_params_st p; |
158 | 0 | int ret = 0; |
159 | |
|
160 | 0 | if (drbg == NULL || !drbg_hmac_set_ctx_params_decoder(params, &p)) |
161 | 0 | return 0; |
162 | | |
163 | 0 | if (drbg->lock != NULL && !CRYPTO_THREAD_write_lock(drbg->lock)) |
164 | 0 | return 0; |
165 | | |
166 | 0 | if (!ossl_prov_is_running() |
167 | 0 | || !drbg_hmac_set_ctx_params_locked(drbg, &p)) |
168 | 0 | goto err; |
169 | 0 | ret = ossl_prov_drbg_instantiate(drbg, strength, prediction_resistance, |
170 | 0 | pstr, pstr_len); |
171 | 0 | err: |
172 | 0 | if (drbg->lock != NULL) |
173 | 0 | CRYPTO_THREAD_unlock(drbg->lock); |
174 | 0 | return ret; |
175 | 0 | } |
176 | | |
177 | | /* |
178 | | * SP800-90Ar1 10.1.2.4 HMAC_DRBG_Reseed_Process: |
179 | | * |
180 | | * Reseeds the drbg's Key (K) and Value (V) by calling |
181 | | * (K,V) = drbg_hmac_update() with the following input parameters: |
182 | | * ent = entropy input data (Can be NULL) of length ent_len. |
183 | | * adin = additional input data (Can be NULL) of length adin_len. |
184 | | * |
185 | | * Returns zero if an error occurs otherwise it returns 1. |
186 | | */ |
187 | | static int drbg_hmac_reseed(PROV_DRBG *drbg, |
188 | | const unsigned char *ent, size_t ent_len, |
189 | | const unsigned char *adin, size_t adin_len) |
190 | 243 | { |
191 | 243 | PROV_DRBG_HMAC *hmac = (PROV_DRBG_HMAC *)drbg->data; |
192 | | |
193 | | /* (Step 2) (K,V) = HMAC_DRBG_Update(entropy||additional_input, K, V) */ |
194 | 243 | return drbg_hmac_update(hmac, ent, ent_len, adin, adin_len, NULL, 0); |
195 | 243 | } |
196 | | |
197 | | static int drbg_hmac_reseed_wrapper(void *vdrbg, int prediction_resistance, |
198 | | const unsigned char *ent, size_t ent_len, |
199 | | const unsigned char *adin, size_t adin_len) |
200 | 190 | { |
201 | 190 | PROV_DRBG *drbg = (PROV_DRBG *)vdrbg; |
202 | | |
203 | 190 | return ossl_prov_drbg_reseed(drbg, prediction_resistance, ent, ent_len, |
204 | 190 | adin, adin_len); |
205 | 190 | } |
206 | | |
207 | | /* |
208 | | * SP800-90Ar1 10.1.2.5 HMAC_DRBG_Generate_Process: |
209 | | * |
210 | | * Generates pseudo random bytes and updates the internal K,V for the drbg. |
211 | | * out is a buffer to fill with outlen bytes of pseudo random data. |
212 | | * adin is an additional_input string of size adin_len that may be NULL. |
213 | | * |
214 | | * Returns zero if an error occurs otherwise it returns 1. |
215 | | */ |
216 | | int ossl_drbg_hmac_generate(PROV_DRBG_HMAC *hmac, |
217 | | unsigned char *out, size_t outlen, |
218 | | const unsigned char *adin, size_t adin_len) |
219 | 506 | { |
220 | 506 | EVP_MAC_CTX *ctx = hmac->ctx; |
221 | 506 | const unsigned char *temp = hmac->V; |
222 | | |
223 | | /* (Step 2) if adin != NULL then (K,V) = HMAC_DRBG_Update(adin, K, V) */ |
224 | 506 | if (adin != NULL |
225 | 0 | && adin_len > 0 |
226 | 0 | && !drbg_hmac_update(hmac, adin, adin_len, NULL, 0, NULL, 0)) |
227 | 0 | return 0; |
228 | | |
229 | | /* |
230 | | * (Steps 3-5) temp = NULL |
231 | | * while (len(temp) < outlen) { |
232 | | * V = HMAC(K, V) |
233 | | * temp = temp || V |
234 | | * } |
235 | | */ |
236 | 35.1k | for (;;) { |
237 | 35.1k | if (!EVP_MAC_init(ctx, hmac->K, hmac->blocklen, NULL) |
238 | 35.1k | || !EVP_MAC_update(ctx, temp, hmac->blocklen)) |
239 | 0 | return 0; |
240 | | |
241 | 35.1k | if (outlen > hmac->blocklen) { |
242 | 34.7k | if (!EVP_MAC_final(ctx, out, NULL, outlen)) |
243 | 24 | return 0; |
244 | 34.6k | temp = out; |
245 | 34.6k | } else { |
246 | 482 | if (!EVP_MAC_final(ctx, hmac->V, NULL, sizeof(hmac->V))) |
247 | 0 | return 0; |
248 | 482 | memcpy(out, hmac->V, outlen); |
249 | 482 | break; |
250 | 482 | } |
251 | 34.6k | out += hmac->blocklen; |
252 | 34.6k | outlen -= hmac->blocklen; |
253 | 34.6k | } |
254 | | /* (Step 6) (K,V) = HMAC_DRBG_Update(adin, K, V) */ |
255 | 482 | if (!drbg_hmac_update(hmac, adin, adin_len, NULL, 0, NULL, 0)) |
256 | 0 | return 0; |
257 | | |
258 | 482 | return 1; |
259 | 482 | } |
260 | | |
261 | | static int drbg_hmac_generate(PROV_DRBG *drbg, |
262 | | unsigned char *out, size_t outlen, |
263 | | const unsigned char *adin, size_t adin_len) |
264 | 214 | { |
265 | 214 | return ossl_drbg_hmac_generate((PROV_DRBG_HMAC *)drbg->data, out, outlen, |
266 | 214 | adin, adin_len); |
267 | 214 | } |
268 | | |
269 | | static int drbg_hmac_generate_wrapper(void *vdrbg, |
270 | | unsigned char *out, size_t outlen, unsigned int strength, |
271 | | int prediction_resistance, const unsigned char *adin, size_t adin_len) |
272 | 236 | { |
273 | 236 | PROV_DRBG *drbg = (PROV_DRBG *)vdrbg; |
274 | | |
275 | 236 | return ossl_prov_drbg_generate(drbg, out, outlen, strength, |
276 | 236 | prediction_resistance, adin, adin_len); |
277 | 236 | } |
278 | | |
279 | | static int drbg_hmac_uninstantiate(PROV_DRBG *drbg) |
280 | 0 | { |
281 | 0 | PROV_DRBG_HMAC *hmac = (PROV_DRBG_HMAC *)drbg->data; |
282 | |
|
283 | 0 | OPENSSL_cleanse(hmac->K, sizeof(hmac->K)); |
284 | 0 | OPENSSL_cleanse(hmac->V, sizeof(hmac->V)); |
285 | 0 | return ossl_prov_drbg_uninstantiate(drbg); |
286 | 0 | } |
287 | | |
288 | | static int drbg_hmac_uninstantiate_wrapper(void *vdrbg) |
289 | 0 | { |
290 | 0 | PROV_DRBG *drbg = (PROV_DRBG *)vdrbg; |
291 | 0 | int ret; |
292 | |
|
293 | 0 | if (drbg->lock != NULL && !CRYPTO_THREAD_write_lock(drbg->lock)) |
294 | 0 | return 0; |
295 | | |
296 | 0 | ret = drbg_hmac_uninstantiate(drbg); |
297 | |
|
298 | 0 | if (drbg->lock != NULL) |
299 | 0 | CRYPTO_THREAD_unlock(drbg->lock); |
300 | |
|
301 | 0 | return ret; |
302 | 0 | } |
303 | | |
304 | | static int drbg_hmac_verify_zeroization(void *vdrbg) |
305 | 0 | { |
306 | 0 | PROV_DRBG *drbg = (PROV_DRBG *)vdrbg; |
307 | 0 | PROV_DRBG_HMAC *hmac = (PROV_DRBG_HMAC *)drbg->data; |
308 | 0 | int ret = 0; |
309 | |
|
310 | 0 | if (drbg->lock != NULL && !CRYPTO_THREAD_read_lock(drbg->lock)) |
311 | 0 | return 0; |
312 | | |
313 | 0 | PROV_DRBG_VERIFY_ZEROIZATION(hmac->K); |
314 | 0 | PROV_DRBG_VERIFY_ZEROIZATION(hmac->V); |
315 | |
|
316 | 0 | ret = 1; |
317 | 0 | err: |
318 | 0 | if (drbg->lock != NULL) |
319 | 0 | CRYPTO_THREAD_unlock(drbg->lock); |
320 | 0 | return ret; |
321 | 0 | } |
322 | | |
323 | | static int drbg_hmac_new(PROV_DRBG *drbg) |
324 | 357 | { |
325 | 357 | PROV_DRBG_HMAC *hmac; |
326 | | |
327 | 357 | hmac = OPENSSL_secure_zalloc(sizeof(*hmac)); |
328 | 357 | if (hmac == NULL) |
329 | 0 | return 0; |
330 | | |
331 | 357 | OSSL_FIPS_IND_INIT(drbg) |
332 | | |
333 | 357 | drbg->data = hmac; |
334 | | /* See SP800-57 Part1 Rev4 5.6.1 Table 3 */ |
335 | 357 | drbg->max_entropylen = DRBG_MAX_LENGTH; |
336 | 357 | drbg->max_noncelen = DRBG_MAX_LENGTH; |
337 | 357 | drbg->max_perslen = DRBG_MAX_LENGTH; |
338 | 357 | drbg->max_adinlen = DRBG_MAX_LENGTH; |
339 | | |
340 | | /* Maximum number of bits per request = 2^19 = 2^16 bytes */ |
341 | 357 | drbg->max_request = 1 << 16; |
342 | 357 | return 1; |
343 | 357 | } |
344 | | |
345 | | static void *drbg_hmac_new_wrapper(void *provctx, void *parent, |
346 | | const OSSL_DISPATCH *parent_dispatch) |
347 | 357 | { |
348 | 357 | return ossl_rand_drbg_new(provctx, parent, parent_dispatch, |
349 | 357 | &drbg_hmac_new, &drbg_hmac_free, |
350 | 357 | &drbg_hmac_instantiate, &drbg_hmac_uninstantiate, |
351 | 357 | &drbg_hmac_reseed, &drbg_hmac_generate); |
352 | 357 | } |
353 | | |
354 | | static void drbg_hmac_free(void *vdrbg) |
355 | 357 | { |
356 | 357 | PROV_DRBG *drbg = (PROV_DRBG *)vdrbg; |
357 | 357 | PROV_DRBG_HMAC *hmac; |
358 | | |
359 | 357 | if (drbg != NULL && (hmac = (PROV_DRBG_HMAC *)drbg->data) != NULL) { |
360 | 357 | EVP_MAC_CTX_free(hmac->ctx); |
361 | 357 | ossl_prov_digest_reset(&hmac->digest); |
362 | 357 | OPENSSL_secure_clear_free(hmac, sizeof(*hmac)); |
363 | 357 | } |
364 | 357 | ossl_rand_drbg_free(drbg); |
365 | 357 | } |
366 | | |
367 | | #define drbg_hmac_get_ctx_params_st drbg_get_ctx_params_st |
368 | | |
369 | | /* clang-format off */ |
370 | | /* Machine generated by util/perl/OpenSSL/paramnames.pm */ |
371 | | #ifndef drbg_hmac_get_ctx_params_list |
372 | | static const OSSL_PARAM drbg_hmac_get_ctx_params_list[] = { |
373 | | OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_MAC, NULL, 0), |
374 | | OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_DIGEST, NULL, 0), |
375 | | OSSL_PARAM_int(OSSL_RAND_PARAM_STATE, NULL), |
376 | | OSSL_PARAM_uint(OSSL_RAND_PARAM_STRENGTH, NULL), |
377 | | OSSL_PARAM_size_t(OSSL_RAND_PARAM_MAX_REQUEST, NULL), |
378 | | OSSL_PARAM_size_t(OSSL_DRBG_PARAM_MIN_ENTROPYLEN, NULL), |
379 | | OSSL_PARAM_size_t(OSSL_DRBG_PARAM_MAX_ENTROPYLEN, NULL), |
380 | | OSSL_PARAM_size_t(OSSL_DRBG_PARAM_MIN_NONCELEN, NULL), |
381 | | OSSL_PARAM_size_t(OSSL_DRBG_PARAM_MAX_NONCELEN, NULL), |
382 | | OSSL_PARAM_size_t(OSSL_DRBG_PARAM_MAX_PERSLEN, NULL), |
383 | | OSSL_PARAM_size_t(OSSL_DRBG_PARAM_MAX_ADINLEN, NULL), |
384 | | OSSL_PARAM_uint(OSSL_DRBG_PARAM_RESEED_COUNTER, NULL), |
385 | | OSSL_PARAM_time_t(OSSL_DRBG_PARAM_RESEED_TIME, NULL), |
386 | | OSSL_PARAM_uint(OSSL_DRBG_PARAM_RESEED_REQUESTS, NULL), |
387 | | OSSL_PARAM_uint64(OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL, NULL), |
388 | | # if defined(FIPS_MODULE) |
389 | | OSSL_PARAM_int(OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR, NULL), |
390 | | # endif |
391 | | OSSL_PARAM_END |
392 | | }; |
393 | | #endif |
394 | | |
395 | | #ifndef drbg_hmac_get_ctx_params_st |
396 | | struct drbg_hmac_get_ctx_params_st { |
397 | | OSSL_PARAM *digest; |
398 | | # if defined(FIPS_MODULE) |
399 | | OSSL_PARAM *ind; |
400 | | # endif |
401 | | OSSL_PARAM *mac; |
402 | | OSSL_PARAM *maxadlen; |
403 | | OSSL_PARAM *maxentlen; |
404 | | OSSL_PARAM *maxnonlen; |
405 | | OSSL_PARAM *maxperlen; |
406 | | OSSL_PARAM *maxreq; |
407 | | OSSL_PARAM *minentlen; |
408 | | OSSL_PARAM *minnonlen; |
409 | | OSSL_PARAM *reseed_cnt; |
410 | | OSSL_PARAM *reseed_int; |
411 | | OSSL_PARAM *reseed_req; |
412 | | OSSL_PARAM *reseed_time; |
413 | | OSSL_PARAM *state; |
414 | | OSSL_PARAM *str; |
415 | | }; |
416 | | #endif |
417 | | |
418 | | #ifndef drbg_hmac_get_ctx_params_decoder |
419 | | static int drbg_hmac_get_ctx_params_decoder |
420 | | (const OSSL_PARAM *p, struct drbg_hmac_get_ctx_params_st *r) |
421 | 60 | { |
422 | 60 | const char *s; |
423 | | |
424 | 60 | memset(r, 0, sizeof(*r)); |
425 | 60 | if (p != NULL) |
426 | 120 | for (; (s = p->key) != NULL; p++) |
427 | 60 | switch(s[0]) { |
428 | 0 | default: |
429 | 0 | break; |
430 | 0 | case 'd': |
431 | 0 | if (ossl_likely(strcmp("igest", s + 1) == 0)) { |
432 | | /* OSSL_DRBG_PARAM_DIGEST */ |
433 | 0 | if (ossl_unlikely(r->digest != NULL)) { |
434 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
435 | 0 | "param %s is repeated", s); |
436 | 0 | return 0; |
437 | 0 | } |
438 | 0 | r->digest = (OSSL_PARAM *)p; |
439 | 0 | } |
440 | 0 | break; |
441 | 0 | case 'f': |
442 | | # if defined(FIPS_MODULE) |
443 | | if (ossl_likely(strcmp("ips-indicator", s + 1) == 0)) { |
444 | | /* OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR */ |
445 | | if (ossl_unlikely(r->ind != NULL)) { |
446 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
447 | | "param %s is repeated", s); |
448 | | return 0; |
449 | | } |
450 | | r->ind = (OSSL_PARAM *)p; |
451 | | } |
452 | | # endif |
453 | 0 | break; |
454 | 60 | case 'm': |
455 | 60 | switch(s[1]) { |
456 | 0 | default: |
457 | 0 | break; |
458 | 60 | case 'a': |
459 | 60 | switch(s[2]) { |
460 | 0 | default: |
461 | 0 | break; |
462 | 0 | case 'c': |
463 | 0 | switch(s[3]) { |
464 | 0 | default: |
465 | 0 | break; |
466 | 0 | case '\0': |
467 | 0 | if (ossl_unlikely(r->mac != NULL)) { |
468 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
469 | 0 | "param %s is repeated", s); |
470 | 0 | return 0; |
471 | 0 | } |
472 | 0 | r->mac = (OSSL_PARAM *)p; |
473 | 0 | } |
474 | 0 | break; |
475 | 60 | case 'x': |
476 | 60 | switch(s[3]) { |
477 | 0 | default: |
478 | 0 | break; |
479 | 60 | case '_': |
480 | 60 | switch(s[4]) { |
481 | 0 | default: |
482 | 0 | break; |
483 | 0 | case 'a': |
484 | 0 | if (ossl_likely(strcmp("dinlen", s + 5) == 0)) { |
485 | | /* OSSL_DRBG_PARAM_MAX_ADINLEN */ |
486 | 0 | if (ossl_unlikely(r->maxadlen != NULL)) { |
487 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
488 | 0 | "param %s is repeated", s); |
489 | 0 | return 0; |
490 | 0 | } |
491 | 0 | r->maxadlen = (OSSL_PARAM *)p; |
492 | 0 | } |
493 | 0 | break; |
494 | 0 | case 'e': |
495 | 0 | if (ossl_likely(strcmp("ntropylen", s + 5) == 0)) { |
496 | | /* OSSL_DRBG_PARAM_MAX_ENTROPYLEN */ |
497 | 0 | if (ossl_unlikely(r->maxentlen != NULL)) { |
498 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
499 | 0 | "param %s is repeated", s); |
500 | 0 | return 0; |
501 | 0 | } |
502 | 0 | r->maxentlen = (OSSL_PARAM *)p; |
503 | 0 | } |
504 | 0 | break; |
505 | 0 | case 'n': |
506 | 0 | if (ossl_likely(strcmp("oncelen", s + 5) == 0)) { |
507 | | /* OSSL_DRBG_PARAM_MAX_NONCELEN */ |
508 | 0 | if (ossl_unlikely(r->maxnonlen != NULL)) { |
509 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
510 | 0 | "param %s is repeated", s); |
511 | 0 | return 0; |
512 | 0 | } |
513 | 0 | r->maxnonlen = (OSSL_PARAM *)p; |
514 | 0 | } |
515 | 0 | break; |
516 | 0 | case 'p': |
517 | 0 | if (ossl_likely(strcmp("erslen", s + 5) == 0)) { |
518 | | /* OSSL_DRBG_PARAM_MAX_PERSLEN */ |
519 | 0 | if (ossl_unlikely(r->maxperlen != NULL)) { |
520 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
521 | 0 | "param %s is repeated", s); |
522 | 0 | return 0; |
523 | 0 | } |
524 | 0 | r->maxperlen = (OSSL_PARAM *)p; |
525 | 0 | } |
526 | 0 | break; |
527 | 60 | case 'r': |
528 | 60 | if (ossl_likely(strcmp("equest", s + 5) == 0)) { |
529 | | /* OSSL_RAND_PARAM_MAX_REQUEST */ |
530 | 60 | if (ossl_unlikely(r->maxreq != NULL)) { |
531 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
532 | 0 | "param %s is repeated", s); |
533 | 0 | return 0; |
534 | 0 | } |
535 | 60 | r->maxreq = (OSSL_PARAM *)p; |
536 | 60 | } |
537 | 60 | } |
538 | 60 | } |
539 | 60 | } |
540 | 60 | break; |
541 | 60 | case 'i': |
542 | 0 | switch(s[2]) { |
543 | 0 | default: |
544 | 0 | break; |
545 | 0 | case 'n': |
546 | 0 | switch(s[3]) { |
547 | 0 | default: |
548 | 0 | break; |
549 | 0 | case '_': |
550 | 0 | switch(s[4]) { |
551 | 0 | default: |
552 | 0 | break; |
553 | 0 | case 'e': |
554 | 0 | if (ossl_likely(strcmp("ntropylen", s + 5) == 0)) { |
555 | | /* OSSL_DRBG_PARAM_MIN_ENTROPYLEN */ |
556 | 0 | if (ossl_unlikely(r->minentlen != NULL)) { |
557 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
558 | 0 | "param %s is repeated", s); |
559 | 0 | return 0; |
560 | 0 | } |
561 | 0 | r->minentlen = (OSSL_PARAM *)p; |
562 | 0 | } |
563 | 0 | break; |
564 | 0 | case 'n': |
565 | 0 | if (ossl_likely(strcmp("oncelen", s + 5) == 0)) { |
566 | | /* OSSL_DRBG_PARAM_MIN_NONCELEN */ |
567 | 0 | if (ossl_unlikely(r->minnonlen != NULL)) { |
568 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
569 | 0 | "param %s is repeated", s); |
570 | 0 | return 0; |
571 | 0 | } |
572 | 0 | r->minnonlen = (OSSL_PARAM *)p; |
573 | 0 | } |
574 | 0 | } |
575 | 0 | } |
576 | 0 | } |
577 | 60 | } |
578 | 60 | break; |
579 | 60 | case 'r': |
580 | 0 | switch(s[1]) { |
581 | 0 | default: |
582 | 0 | break; |
583 | 0 | case 'e': |
584 | 0 | switch(s[2]) { |
585 | 0 | default: |
586 | 0 | break; |
587 | 0 | case 's': |
588 | 0 | switch(s[3]) { |
589 | 0 | default: |
590 | 0 | break; |
591 | 0 | case 'e': |
592 | 0 | switch(s[4]) { |
593 | 0 | default: |
594 | 0 | break; |
595 | 0 | case 'e': |
596 | 0 | switch(s[5]) { |
597 | 0 | default: |
598 | 0 | break; |
599 | 0 | case 'd': |
600 | 0 | switch(s[6]) { |
601 | 0 | default: |
602 | 0 | break; |
603 | 0 | case '_': |
604 | 0 | switch(s[7]) { |
605 | 0 | default: |
606 | 0 | break; |
607 | 0 | case 'c': |
608 | 0 | if (ossl_likely(strcmp("ounter", s + 8) == 0)) { |
609 | | /* OSSL_DRBG_PARAM_RESEED_COUNTER */ |
610 | 0 | if (ossl_unlikely(r->reseed_cnt != NULL)) { |
611 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
612 | 0 | "param %s is repeated", s); |
613 | 0 | return 0; |
614 | 0 | } |
615 | 0 | r->reseed_cnt = (OSSL_PARAM *)p; |
616 | 0 | } |
617 | 0 | break; |
618 | 0 | case 'r': |
619 | 0 | if (ossl_likely(strcmp("equests", s + 8) == 0)) { |
620 | | /* OSSL_DRBG_PARAM_RESEED_REQUESTS */ |
621 | 0 | if (ossl_unlikely(r->reseed_req != NULL)) { |
622 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
623 | 0 | "param %s is repeated", s); |
624 | 0 | return 0; |
625 | 0 | } |
626 | 0 | r->reseed_req = (OSSL_PARAM *)p; |
627 | 0 | } |
628 | 0 | break; |
629 | 0 | case 't': |
630 | 0 | switch(s[8]) { |
631 | 0 | default: |
632 | 0 | break; |
633 | 0 | case 'i': |
634 | 0 | switch(s[9]) { |
635 | 0 | default: |
636 | 0 | break; |
637 | 0 | case 'm': |
638 | 0 | switch(s[10]) { |
639 | 0 | default: |
640 | 0 | break; |
641 | 0 | case 'e': |
642 | 0 | switch(s[11]) { |
643 | 0 | default: |
644 | 0 | break; |
645 | 0 | case '_': |
646 | 0 | if (ossl_likely(strcmp("interval", s + 12) == 0)) { |
647 | | /* OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL */ |
648 | 0 | if (ossl_unlikely(r->reseed_int != NULL)) { |
649 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
650 | 0 | "param %s is repeated", s); |
651 | 0 | return 0; |
652 | 0 | } |
653 | 0 | r->reseed_int = (OSSL_PARAM *)p; |
654 | 0 | } |
655 | 0 | break; |
656 | 0 | case '\0': |
657 | 0 | if (ossl_unlikely(r->reseed_time != NULL)) { |
658 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
659 | 0 | "param %s is repeated", s); |
660 | 0 | return 0; |
661 | 0 | } |
662 | 0 | r->reseed_time = (OSSL_PARAM *)p; |
663 | 0 | } |
664 | 0 | } |
665 | 0 | } |
666 | 0 | } |
667 | 0 | } |
668 | 0 | } |
669 | 0 | } |
670 | 0 | } |
671 | 0 | } |
672 | 0 | } |
673 | 0 | } |
674 | 0 | break; |
675 | 0 | case 's': |
676 | 0 | switch(s[1]) { |
677 | 0 | default: |
678 | 0 | break; |
679 | 0 | case 't': |
680 | 0 | switch(s[2]) { |
681 | 0 | default: |
682 | 0 | break; |
683 | 0 | case 'a': |
684 | 0 | if (ossl_likely(strcmp("te", s + 3) == 0)) { |
685 | | /* OSSL_RAND_PARAM_STATE */ |
686 | 0 | if (ossl_unlikely(r->state != NULL)) { |
687 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
688 | 0 | "param %s is repeated", s); |
689 | 0 | return 0; |
690 | 0 | } |
691 | 0 | r->state = (OSSL_PARAM *)p; |
692 | 0 | } |
693 | 0 | break; |
694 | 0 | case 'r': |
695 | 0 | if (ossl_likely(strcmp("ength", s + 3) == 0)) { |
696 | | /* OSSL_RAND_PARAM_STRENGTH */ |
697 | 0 | if (ossl_unlikely(r->str != NULL)) { |
698 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
699 | 0 | "param %s is repeated", s); |
700 | 0 | return 0; |
701 | 0 | } |
702 | 0 | r->str = (OSSL_PARAM *)p; |
703 | 0 | } |
704 | 0 | } |
705 | 0 | } |
706 | 60 | } |
707 | 60 | return 1; |
708 | 60 | } |
709 | | #endif |
710 | | /* End of machine generated */ |
711 | | /* clang-format on */ |
712 | | |
713 | | static int drbg_hmac_get_ctx_params(void *vdrbg, OSSL_PARAM params[]) |
714 | 60 | { |
715 | 60 | PROV_DRBG *drbg = (PROV_DRBG *)vdrbg; |
716 | 60 | PROV_DRBG_HMAC *hmac; |
717 | 60 | const char *name; |
718 | 60 | const EVP_MD *md; |
719 | 60 | struct drbg_get_ctx_params_st p; |
720 | 60 | int ret = 0, complete = 0; |
721 | | |
722 | 60 | if (drbg == NULL || !drbg_hmac_get_ctx_params_decoder(params, &p)) |
723 | 0 | return 0; |
724 | | |
725 | 60 | if (!ossl_drbg_get_ctx_params_no_lock(drbg, &p, params, &complete)) |
726 | 0 | return 0; |
727 | | |
728 | 60 | if (complete) |
729 | 60 | return 1; |
730 | | |
731 | 0 | hmac = (PROV_DRBG_HMAC *)drbg->data; |
732 | |
|
733 | 0 | if (drbg->lock != NULL && !CRYPTO_THREAD_read_lock(drbg->lock)) |
734 | 0 | return 0; |
735 | | |
736 | 0 | if (p.mac != NULL) { |
737 | 0 | if (hmac->ctx == NULL) |
738 | 0 | goto err; |
739 | 0 | name = EVP_MAC_get0_name(EVP_MAC_CTX_get0_mac(hmac->ctx)); |
740 | 0 | if (!OSSL_PARAM_set_utf8_string(p.mac, name)) |
741 | 0 | goto err; |
742 | 0 | } |
743 | | |
744 | 0 | if (p.digest != NULL) { |
745 | 0 | md = ossl_prov_digest_md(&hmac->digest); |
746 | 0 | if (md == NULL |
747 | 0 | || !OSSL_PARAM_set_utf8_string(p.digest, EVP_MD_get0_name(md))) |
748 | 0 | goto err; |
749 | 0 | } |
750 | | |
751 | 0 | ret = ossl_drbg_get_ctx_params(drbg, &p); |
752 | 0 | err: |
753 | 0 | if (drbg->lock != NULL) |
754 | 0 | CRYPTO_THREAD_unlock(drbg->lock); |
755 | |
|
756 | 0 | return ret; |
757 | 0 | } |
758 | | |
759 | | static const OSSL_PARAM *drbg_hmac_gettable_ctx_params(ossl_unused void *vctx, |
760 | | ossl_unused void *p_ctx) |
761 | 0 | { |
762 | 0 | return drbg_hmac_get_ctx_params_list; |
763 | 0 | } |
764 | | |
765 | | static int drbg_fetch_algs_from_prov(const struct drbg_set_ctx_params_st *p, |
766 | | OSSL_LIB_CTX *libctx, |
767 | | EVP_MAC_CTX **macctx, |
768 | | EVP_MD **digest) |
769 | 105 | { |
770 | 105 | OSSL_PROVIDER *prov = NULL; |
771 | 105 | EVP_MD *md = NULL; |
772 | 105 | EVP_MAC *mac = NULL; |
773 | 105 | int ret = 0; |
774 | | |
775 | 105 | if (macctx == NULL || digest == NULL) |
776 | 0 | return 0; |
777 | | |
778 | 105 | if (p->prov == NULL || p->prov->data_type != OSSL_PARAM_UTF8_STRING) |
779 | 0 | return 0; |
780 | 105 | if ((prov = ossl_provider_find(libctx, (const char *)p->prov->data, 1)) == NULL) |
781 | 93 | return 0; |
782 | | |
783 | 12 | if (p->digest != NULL) { |
784 | 12 | if (p->digest->data_type != OSSL_PARAM_UTF8_STRING) |
785 | 0 | goto done; |
786 | | |
787 | 12 | md = evp_digest_fetch_from_prov(prov, (const char *)p->digest->data, NULL); |
788 | 12 | if (md) { |
789 | 4 | EVP_MD_free(*digest); |
790 | 4 | *digest = md; |
791 | 8 | } else { |
792 | 8 | goto done; |
793 | 8 | } |
794 | 12 | } |
795 | | |
796 | 4 | if (p->mac == NULL) { |
797 | 0 | ret = 1; |
798 | 0 | goto done; |
799 | 0 | } |
800 | | |
801 | 4 | if (p->mac->data_type != OSSL_PARAM_UTF8_STRING) |
802 | 0 | goto done; |
803 | | |
804 | 4 | EVP_MAC_CTX_free(*macctx); |
805 | 4 | *macctx = NULL; |
806 | | |
807 | 4 | mac = evp_mac_fetch_from_prov(prov, (const char *)p->mac->data, NULL); |
808 | 4 | if (mac) { |
809 | 3 | *macctx = EVP_MAC_CTX_new(mac); |
810 | | /* The context holds on to the MAC */ |
811 | 3 | EVP_MAC_free(mac); |
812 | 3 | ret = 1; |
813 | 3 | } |
814 | | |
815 | 12 | done: |
816 | 12 | ossl_provider_free(prov); |
817 | 12 | return ret; |
818 | 4 | } |
819 | | |
820 | | static int drbg_hmac_set_ctx_params_locked(PROV_DRBG *ctx, const struct drbg_set_ctx_params_st *p) |
821 | 177 | { |
822 | 177 | PROV_DRBG_HMAC *hmac = (PROV_DRBG_HMAC *)ctx->data; |
823 | 177 | OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx); |
824 | 177 | EVP_MD *prov_md = NULL; |
825 | 177 | const EVP_MD *md; |
826 | 177 | int md_size; |
827 | | |
828 | 177 | if (!OSSL_FIPS_IND_SET_CTX_FROM_PARAM(ctx, OSSL_FIPS_IND_SETTABLE0, p->ind_d)) |
829 | 0 | return 0; |
830 | | |
831 | | /* try to fetch mac and digest from provider */ |
832 | 177 | (void)ERR_set_mark(); |
833 | 177 | if (!drbg_fetch_algs_from_prov(p, libctx, &hmac->ctx, &prov_md)) { |
834 | 174 | (void)ERR_pop_to_mark(); |
835 | | /* fall back to full implementation search */ |
836 | 174 | if (!ossl_prov_digest_load(&hmac->digest, p->digest, p->propq, |
837 | 174 | p->engine, libctx)) |
838 | 36 | return 0; |
839 | | |
840 | 138 | if (!ossl_prov_macctx_load(&hmac->ctx, p->mac, NULL, p->digest, |
841 | 138 | p->propq, p->engine, |
842 | 138 | NULL, NULL, NULL, libctx)) |
843 | 22 | return 0; |
844 | 138 | } else { |
845 | 3 | (void)ERR_clear_last_mark(); |
846 | 3 | if (prov_md) |
847 | 3 | ossl_prov_digest_set_md(&hmac->digest, prov_md); |
848 | 3 | } |
849 | | |
850 | 119 | md = ossl_prov_digest_md(&hmac->digest); |
851 | 119 | if (md != NULL && !ossl_drbg_verify_digest(ctx, libctx, md)) |
852 | 3 | return 0; /* Error already raised for us */ |
853 | | |
854 | 116 | if (md != NULL && hmac->ctx != NULL) { |
855 | | /* These are taken from SP 800-90 10.1 Table 2 */ |
856 | 116 | md_size = EVP_MD_get_size(md); |
857 | 116 | if (md_size <= 0) |
858 | 3 | return 0; |
859 | 113 | hmac->blocklen = (size_t)md_size; |
860 | | /* See SP800-57 Part1 Rev4 5.6.1 Table 3 */ |
861 | 113 | ctx->strength = 64 * (int)(hmac->blocklen >> 3); |
862 | 113 | if (ctx->strength > 256) |
863 | 12 | ctx->strength = 256; |
864 | 113 | ctx->seedlen = hmac->blocklen; |
865 | 113 | ctx->min_entropylen = ctx->strength / 8; |
866 | 113 | ctx->min_noncelen = ctx->min_entropylen / 2; |
867 | 113 | } |
868 | | |
869 | 113 | return ossl_drbg_set_ctx_params(ctx, p); |
870 | 116 | } |
871 | | |
872 | | #define drbg_hmac_set_ctx_params_st drbg_set_ctx_params_st |
873 | | |
874 | | /* clang-format off */ |
875 | | /* Machine generated by util/perl/OpenSSL/paramnames.pm */ |
876 | | #ifndef drbg_hmac_set_ctx_params_list |
877 | | static const OSSL_PARAM drbg_hmac_set_ctx_params_list[] = { |
878 | | OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_PROPERTIES, NULL, 0), |
879 | | OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_DIGEST, NULL, 0), |
880 | | OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_MAC, NULL, 0), |
881 | | OSSL_PARAM_utf8_string(OSSL_PROV_PARAM_CORE_PROV_NAME, NULL, 0), |
882 | | OSSL_PARAM_uint(OSSL_DRBG_PARAM_RESEED_REQUESTS, NULL), |
883 | | OSSL_PARAM_uint64(OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL, NULL), |
884 | | # if defined(FIPS_MODULE) |
885 | | OSSL_PARAM_int(OSSL_KDF_PARAM_FIPS_DIGEST_CHECK, NULL), |
886 | | # endif |
887 | | OSSL_PARAM_END |
888 | | }; |
889 | | #endif |
890 | | |
891 | | #ifndef drbg_hmac_set_ctx_params_st |
892 | | struct drbg_hmac_set_ctx_params_st { |
893 | | OSSL_PARAM *digest; |
894 | | OSSL_PARAM *engine; |
895 | | # if defined(FIPS_MODULE) |
896 | | OSSL_PARAM *ind_d; |
897 | | # endif |
898 | | OSSL_PARAM *mac; |
899 | | OSSL_PARAM *propq; |
900 | | OSSL_PARAM *prov; |
901 | | OSSL_PARAM *reseed_req; |
902 | | OSSL_PARAM *reseed_time; |
903 | | }; |
904 | | #endif |
905 | | |
906 | | #ifndef drbg_hmac_set_ctx_params_decoder |
907 | | static int drbg_hmac_set_ctx_params_decoder |
908 | | (const OSSL_PARAM *p, struct drbg_hmac_set_ctx_params_st *r) |
909 | 105 | { |
910 | 105 | const char *s; |
911 | | |
912 | 105 | memset(r, 0, sizeof(*r)); |
913 | 105 | if (p != NULL) |
914 | 735 | for (; (s = p->key) != NULL; p++) |
915 | 630 | switch(s[0]) { |
916 | 0 | default: |
917 | 0 | break; |
918 | 105 | case 'd': |
919 | 105 | switch(s[1]) { |
920 | 0 | default: |
921 | 0 | break; |
922 | 105 | case 'i': |
923 | 105 | switch(s[2]) { |
924 | 0 | default: |
925 | 0 | break; |
926 | 105 | case 'g': |
927 | 105 | switch(s[3]) { |
928 | 0 | default: |
929 | 0 | break; |
930 | 105 | case 'e': |
931 | 105 | switch(s[4]) { |
932 | 0 | default: |
933 | 0 | break; |
934 | 105 | case 's': |
935 | 105 | switch(s[5]) { |
936 | 0 | default: |
937 | 0 | break; |
938 | 105 | case 't': |
939 | 105 | switch(s[6]) { |
940 | 0 | default: |
941 | 0 | break; |
942 | 0 | case '-': |
943 | | # if defined(FIPS_MODULE) |
944 | | if (ossl_likely(strcmp("check", s + 7) == 0)) { |
945 | | /* OSSL_KDF_PARAM_FIPS_DIGEST_CHECK */ |
946 | | if (ossl_unlikely(r->ind_d != NULL)) { |
947 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
948 | | "param %s is repeated", s); |
949 | | return 0; |
950 | | } |
951 | | r->ind_d = (OSSL_PARAM *)p; |
952 | | } |
953 | | # endif |
954 | 0 | break; |
955 | 105 | case '\0': |
956 | 105 | if (ossl_unlikely(r->digest != NULL)) { |
957 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
958 | 0 | "param %s is repeated", s); |
959 | 0 | return 0; |
960 | 0 | } |
961 | 105 | r->digest = (OSSL_PARAM *)p; |
962 | 105 | } |
963 | 105 | } |
964 | 105 | } |
965 | 105 | } |
966 | 105 | } |
967 | 105 | } |
968 | 105 | break; |
969 | 105 | case 'e': |
970 | 0 | if (ossl_likely(strcmp("ngine", s + 1) == 0)) { |
971 | | /* OSSL_ALG_PARAM_ENGINE */ |
972 | 0 | if (ossl_unlikely(r->engine != NULL)) { |
973 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
974 | 0 | "param %s is repeated", s); |
975 | 0 | return 0; |
976 | 0 | } |
977 | 0 | r->engine = (OSSL_PARAM *)p; |
978 | 0 | } |
979 | 0 | break; |
980 | 105 | case 'm': |
981 | 105 | if (ossl_likely(strcmp("ac", s + 1) == 0)) { |
982 | | /* OSSL_DRBG_PARAM_MAC */ |
983 | 105 | if (ossl_unlikely(r->mac != NULL)) { |
984 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
985 | 0 | "param %s is repeated", s); |
986 | 0 | return 0; |
987 | 0 | } |
988 | 105 | r->mac = (OSSL_PARAM *)p; |
989 | 105 | } |
990 | 105 | break; |
991 | 210 | case 'p': |
992 | 210 | switch(s[1]) { |
993 | 0 | default: |
994 | 0 | break; |
995 | 210 | case 'r': |
996 | 210 | switch(s[2]) { |
997 | 0 | default: |
998 | 0 | break; |
999 | 210 | case 'o': |
1000 | 210 | switch(s[3]) { |
1001 | 0 | default: |
1002 | 0 | break; |
1003 | 105 | case 'p': |
1004 | 105 | if (ossl_likely(strcmp("erties", s + 4) == 0)) { |
1005 | | /* OSSL_DRBG_PARAM_PROPERTIES */ |
1006 | 105 | if (ossl_unlikely(r->propq != NULL)) { |
1007 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
1008 | 0 | "param %s is repeated", s); |
1009 | 0 | return 0; |
1010 | 0 | } |
1011 | 105 | r->propq = (OSSL_PARAM *)p; |
1012 | 105 | } |
1013 | 105 | break; |
1014 | 105 | case 'v': |
1015 | 105 | if (ossl_likely(strcmp("ider-name", s + 4) == 0)) { |
1016 | | /* OSSL_PROV_PARAM_CORE_PROV_NAME */ |
1017 | 105 | if (ossl_unlikely(r->prov != NULL)) { |
1018 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
1019 | 0 | "param %s is repeated", s); |
1020 | 0 | return 0; |
1021 | 0 | } |
1022 | 105 | r->prov = (OSSL_PARAM *)p; |
1023 | 105 | } |
1024 | 210 | } |
1025 | 210 | } |
1026 | 210 | } |
1027 | 210 | break; |
1028 | 210 | case 'r': |
1029 | 210 | switch(s[1]) { |
1030 | 0 | default: |
1031 | 0 | break; |
1032 | 210 | case 'e': |
1033 | 210 | switch(s[2]) { |
1034 | 0 | default: |
1035 | 0 | break; |
1036 | 210 | case 's': |
1037 | 210 | switch(s[3]) { |
1038 | 0 | default: |
1039 | 0 | break; |
1040 | 210 | case 'e': |
1041 | 210 | switch(s[4]) { |
1042 | 0 | default: |
1043 | 0 | break; |
1044 | 210 | case 'e': |
1045 | 210 | switch(s[5]) { |
1046 | 0 | default: |
1047 | 0 | break; |
1048 | 210 | case 'd': |
1049 | 210 | switch(s[6]) { |
1050 | 0 | default: |
1051 | 0 | break; |
1052 | 210 | case '_': |
1053 | 210 | switch(s[7]) { |
1054 | 0 | default: |
1055 | 0 | break; |
1056 | 105 | case 'r': |
1057 | 105 | if (ossl_likely(strcmp("equests", s + 8) == 0)) { |
1058 | | /* OSSL_DRBG_PARAM_RESEED_REQUESTS */ |
1059 | 105 | if (ossl_unlikely(r->reseed_req != NULL)) { |
1060 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
1061 | 0 | "param %s is repeated", s); |
1062 | 0 | return 0; |
1063 | 0 | } |
1064 | 105 | r->reseed_req = (OSSL_PARAM *)p; |
1065 | 105 | } |
1066 | 105 | break; |
1067 | 105 | case 't': |
1068 | 105 | if (ossl_likely(strcmp("ime_interval", s + 8) == 0)) { |
1069 | | /* OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL */ |
1070 | 105 | if (ossl_unlikely(r->reseed_time != NULL)) { |
1071 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
1072 | 0 | "param %s is repeated", s); |
1073 | 0 | return 0; |
1074 | 0 | } |
1075 | 105 | r->reseed_time = (OSSL_PARAM *)p; |
1076 | 105 | } |
1077 | 210 | } |
1078 | 210 | } |
1079 | 210 | } |
1080 | 210 | } |
1081 | 210 | } |
1082 | 210 | } |
1083 | 210 | } |
1084 | 630 | } |
1085 | 105 | return 1; |
1086 | 105 | } |
1087 | | #endif |
1088 | | /* End of machine generated */ |
1089 | | /* clang-format on */ |
1090 | | |
1091 | | static int drbg_hmac_set_ctx_params(void *vctx, const OSSL_PARAM params[]) |
1092 | 204 | { |
1093 | 204 | PROV_DRBG *drbg = (PROV_DRBG *)vctx; |
1094 | 204 | struct drbg_set_ctx_params_st p; |
1095 | 204 | int ret; |
1096 | | |
1097 | 204 | if (drbg == NULL || !drbg_hmac_set_ctx_params_decoder(params, &p)) |
1098 | 0 | return 0; |
1099 | | |
1100 | 204 | if (drbg->lock != NULL && !CRYPTO_THREAD_write_lock(drbg->lock)) |
1101 | 0 | return 0; |
1102 | | |
1103 | 204 | ret = drbg_hmac_set_ctx_params_locked(drbg, &p); |
1104 | | |
1105 | 204 | if (drbg->lock != NULL) |
1106 | 0 | CRYPTO_THREAD_unlock(drbg->lock); |
1107 | | |
1108 | 204 | return ret; |
1109 | 204 | } |
1110 | | |
1111 | | static const OSSL_PARAM *drbg_hmac_settable_ctx_params(ossl_unused void *vctx, |
1112 | | ossl_unused void *p_ctx) |
1113 | 357 | { |
1114 | 357 | return drbg_hmac_set_ctx_params_list; |
1115 | 357 | } |
1116 | | |
1117 | | const OSSL_DISPATCH ossl_drbg_ossl_hmac_functions[] = { |
1118 | | { OSSL_FUNC_RAND_NEWCTX, (void (*)(void))drbg_hmac_new_wrapper }, |
1119 | | { OSSL_FUNC_RAND_FREECTX, (void (*)(void))drbg_hmac_free }, |
1120 | | { OSSL_FUNC_RAND_INSTANTIATE, |
1121 | | (void (*)(void))drbg_hmac_instantiate_wrapper }, |
1122 | | { OSSL_FUNC_RAND_UNINSTANTIATE, |
1123 | | (void (*)(void))drbg_hmac_uninstantiate_wrapper }, |
1124 | | { OSSL_FUNC_RAND_GENERATE, (void (*)(void))drbg_hmac_generate_wrapper }, |
1125 | | { OSSL_FUNC_RAND_RESEED, (void (*)(void))drbg_hmac_reseed_wrapper }, |
1126 | | { OSSL_FUNC_RAND_ENABLE_LOCKING, (void (*)(void))ossl_drbg_enable_locking }, |
1127 | | { OSSL_FUNC_RAND_LOCK, (void (*)(void))ossl_drbg_lock }, |
1128 | | { OSSL_FUNC_RAND_UNLOCK, (void (*)(void))ossl_drbg_unlock }, |
1129 | | { OSSL_FUNC_RAND_SETTABLE_CTX_PARAMS, |
1130 | | (void (*)(void))drbg_hmac_settable_ctx_params }, |
1131 | | { OSSL_FUNC_RAND_SET_CTX_PARAMS, (void (*)(void))drbg_hmac_set_ctx_params }, |
1132 | | { OSSL_FUNC_RAND_GETTABLE_CTX_PARAMS, |
1133 | | (void (*)(void))drbg_hmac_gettable_ctx_params }, |
1134 | | { OSSL_FUNC_RAND_GET_CTX_PARAMS, (void (*)(void))drbg_hmac_get_ctx_params }, |
1135 | | { OSSL_FUNC_RAND_VERIFY_ZEROIZATION, |
1136 | | (void (*)(void))drbg_hmac_verify_zeroization }, |
1137 | | { OSSL_FUNC_RAND_GET_SEED, (void (*)(void))ossl_drbg_get_seed }, |
1138 | | { OSSL_FUNC_RAND_CLEAR_SEED, (void (*)(void))ossl_drbg_clear_seed }, |
1139 | | OSSL_DISPATCH_END |
1140 | | }; |