/src/openssl36/providers/implementations/kdfs/x942kdf.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2019-2025 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
4 | | * |
5 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
6 | | * this file except in compliance with the License. You can obtain a copy |
7 | | * in the file LICENSE in the source distribution or at |
8 | | * https://www.openssl.org/source/license.html |
9 | | */ |
10 | | /* clang-format off */ |
11 | | |
12 | | /* clang-format on */ |
13 | | |
14 | | #include "internal/e_os.h" |
15 | | #include <openssl/core_names.h> |
16 | | #include <openssl/core_dispatch.h> |
17 | | #include <openssl/err.h> |
18 | | #include <openssl/evp.h> |
19 | | #include <openssl/params.h> |
20 | | #include <openssl/proverr.h> |
21 | | #include "internal/common.h" |
22 | | #include "internal/packet.h" |
23 | | #include "internal/der.h" |
24 | | #include "internal/nelem.h" |
25 | | #include "prov/provider_ctx.h" |
26 | | #include "prov/providercommon.h" |
27 | | #include "prov/implementations.h" |
28 | | #include "prov/provider_util.h" |
29 | | #include "prov/securitycheck.h" |
30 | | #include "prov/der_wrap.h" |
31 | | |
32 | 144 | #define X942KDF_MAX_INLEN (1 << 30) |
33 | | |
34 | | static OSSL_FUNC_kdf_newctx_fn x942kdf_new; |
35 | | static OSSL_FUNC_kdf_dupctx_fn x942kdf_dup; |
36 | | static OSSL_FUNC_kdf_freectx_fn x942kdf_free; |
37 | | static OSSL_FUNC_kdf_reset_fn x942kdf_reset; |
38 | | static OSSL_FUNC_kdf_derive_fn x942kdf_derive; |
39 | | static OSSL_FUNC_kdf_settable_ctx_params_fn x942kdf_settable_ctx_params; |
40 | | static OSSL_FUNC_kdf_set_ctx_params_fn x942kdf_set_ctx_params; |
41 | | static OSSL_FUNC_kdf_gettable_ctx_params_fn x942kdf_gettable_ctx_params; |
42 | | static OSSL_FUNC_kdf_get_ctx_params_fn x942kdf_get_ctx_params; |
43 | | |
44 | | typedef struct { |
45 | | void *provctx; |
46 | | PROV_DIGEST digest; |
47 | | unsigned char *secret; |
48 | | size_t secret_len; |
49 | | unsigned char *acvpinfo; |
50 | | size_t acvpinfo_len; |
51 | | unsigned char *partyuinfo, *partyvinfo, *supp_pubinfo, *supp_privinfo; |
52 | | size_t partyuinfo_len, partyvinfo_len, supp_pubinfo_len, supp_privinfo_len; |
53 | | size_t dkm_len; |
54 | | const unsigned char *cek_oid; |
55 | | size_t cek_oid_len; |
56 | | int use_keybits; |
57 | | OSSL_FIPS_IND_DECLARE |
58 | | } KDF_X942; |
59 | | |
60 | | /* |
61 | | * A table of allowed wrapping algorithms, oids and the associated output |
62 | | * lengths. |
63 | | * NOTE: RC2wrap and camellia128_wrap have been removed as there are no |
64 | | * corresponding ciphers for these operations. |
65 | | */ |
66 | | static const struct { |
67 | | const char *name; |
68 | | const unsigned char *oid; |
69 | | size_t oid_len; |
70 | | size_t keklen; /* size in bytes */ |
71 | | } kek_algs[] = { |
72 | | { "AES-128-WRAP", ossl_der_oid_id_aes128_wrap, DER_OID_SZ_id_aes128_wrap, |
73 | | 16 }, |
74 | | { "AES-192-WRAP", ossl_der_oid_id_aes192_wrap, DER_OID_SZ_id_aes192_wrap, |
75 | | 24 }, |
76 | | { "AES-256-WRAP", ossl_der_oid_id_aes256_wrap, DER_OID_SZ_id_aes256_wrap, |
77 | | 32 }, |
78 | | #ifndef FIPS_MODULE |
79 | | { "DES3-WRAP", ossl_der_oid_id_alg_CMS3DESwrap, |
80 | | DER_OID_SZ_id_alg_CMS3DESwrap, 24 }, |
81 | | #endif |
82 | | }; |
83 | | |
84 | | static int find_alg_id(OSSL_LIB_CTX *libctx, const char *algname, |
85 | | const char *propq, size_t *id) |
86 | 66 | { |
87 | 66 | int ret = 1; |
88 | 66 | size_t i; |
89 | 66 | EVP_CIPHER *cipher; |
90 | | |
91 | 66 | cipher = EVP_CIPHER_fetch(libctx, algname, propq); |
92 | 66 | if (cipher != NULL) { |
93 | 83 | for (i = 0; i < OSSL_NELEM(kek_algs); i++) { |
94 | 81 | if (EVP_CIPHER_is_a(cipher, kek_algs[i].name)) { |
95 | 27 | *id = i; |
96 | 27 | goto end; |
97 | 27 | } |
98 | 81 | } |
99 | 29 | } |
100 | 39 | ret = 0; |
101 | 39 | ERR_raise(ERR_LIB_PROV, PROV_R_UNSUPPORTED_CEK_ALG); |
102 | 66 | end: |
103 | 66 | EVP_CIPHER_free(cipher); |
104 | 66 | return ret; |
105 | 39 | } |
106 | | |
107 | | static int DER_w_keyinfo(WPACKET *pkt, |
108 | | const unsigned char *der_oid, size_t der_oidlen, |
109 | | unsigned char **pcounter) |
110 | 48 | { |
111 | 48 | return ossl_DER_w_begin_sequence(pkt, -1) |
112 | | /* Store the initial value of 1 into the counter */ |
113 | 48 | && ossl_DER_w_octet_string_uint32(pkt, -1, 1) |
114 | | /* Remember where we stored the counter in the buffer */ |
115 | 48 | && (pcounter == NULL |
116 | 24 | || (*pcounter = WPACKET_get_curr(pkt)) != NULL) |
117 | 48 | && ossl_DER_w_precompiled(pkt, -1, der_oid, der_oidlen) |
118 | 48 | && ossl_DER_w_end_sequence(pkt, -1); |
119 | 48 | } |
120 | | |
121 | | static int der_encode_sharedinfo(WPACKET *pkt, unsigned char *buf, size_t buflen, |
122 | | const unsigned char *der_oid, size_t der_oidlen, |
123 | | const unsigned char *acvp, size_t acvplen, |
124 | | const unsigned char *partyu, size_t partyulen, |
125 | | const unsigned char *partyv, size_t partyvlen, |
126 | | const unsigned char *supp_pub, size_t supp_publen, |
127 | | const unsigned char *supp_priv, size_t supp_privlen, |
128 | | uint32_t keylen_bits, unsigned char **pcounter) |
129 | 48 | { |
130 | 48 | return (buf != NULL ? WPACKET_init_der(pkt, buf, buflen) : WPACKET_init_null_der(pkt)) |
131 | 48 | && ossl_DER_w_begin_sequence(pkt, -1) |
132 | 48 | && (supp_priv == NULL |
133 | 0 | || ossl_DER_w_octet_string(pkt, 3, supp_priv, supp_privlen)) |
134 | 48 | && (supp_pub == NULL |
135 | 0 | || ossl_DER_w_octet_string(pkt, 2, supp_pub, supp_publen)) |
136 | 48 | && (keylen_bits == 0 |
137 | 0 | || ossl_DER_w_octet_string_uint32(pkt, 2, keylen_bits)) |
138 | 48 | && (partyv == NULL || ossl_DER_w_octet_string(pkt, 1, partyv, partyvlen)) |
139 | 48 | && (partyu == NULL || ossl_DER_w_octet_string(pkt, 0, partyu, partyulen)) |
140 | 48 | && (acvp == NULL || ossl_DER_w_precompiled(pkt, -1, acvp, acvplen)) |
141 | 48 | && DER_w_keyinfo(pkt, der_oid, der_oidlen, pcounter) |
142 | 48 | && ossl_DER_w_end_sequence(pkt, -1) |
143 | 48 | && WPACKET_finish(pkt); |
144 | 48 | } |
145 | | |
146 | | /* |
147 | | * Encode the other info structure. |
148 | | * |
149 | | * The ANS X9.42-2003 standard uses OtherInfo: |
150 | | * |
151 | | * OtherInfo ::= SEQUENCE { |
152 | | * keyInfo KeySpecificInfo, |
153 | | * partyUInfo [0] OCTET STRING OPTIONAL, |
154 | | * partyVInfo [1] OCTET STRING OPTIONAL, |
155 | | * suppPubInfo [2] OCTET STRING OPTIONAL, |
156 | | * suppPrivInfo [3] OCTET STRING OPTIONAL |
157 | | * } |
158 | | * |
159 | | * KeySpecificInfo ::= SEQUENCE { |
160 | | * algorithm OBJECT IDENTIFIER, |
161 | | * counter OCTET STRING SIZE (4..4) |
162 | | * } |
163 | | * |
164 | | * RFC2631 Section 2.1.2 Contains the following definition for OtherInfo |
165 | | * |
166 | | * OtherInfo ::= SEQUENCE { |
167 | | * keyInfo KeySpecificInfo, |
168 | | * partyAInfo [0] OCTET STRING OPTIONAL, |
169 | | * suppPubInfo [2] OCTET STRING |
170 | | * } |
171 | | * Where suppPubInfo is the key length (in bits) (stored into 4 bytes) |
172 | | * |
173 | | * |keylen| is the length (in bytes) of the generated KEK. It is stored into |
174 | | * suppPubInfo (in bits). It is ignored if the value is 0. |
175 | | * |cek_oid| The oid of the key wrapping algorithm. |
176 | | * |cek_oidlen| The length (in bytes) of the key wrapping algorithm oid, |
177 | | * |acvp| is the optional blob of DER data representing one or more of the |
178 | | * OtherInfo fields related to |partyu|, |partyv|, |supp_pub| and |supp_priv|. |
179 | | * This field should normally be NULL. If |acvp| is non NULL then |partyu|, |
180 | | * |partyv|, |supp_pub| and |supp_priv| should all be NULL. |
181 | | * |acvp_len| is the |acvp| length (in bytes). |
182 | | * |partyu| is the optional public info contributed by the initiator. |
183 | | * It can be NULL. (It is also used as the ukm by CMS). |
184 | | * |partyu_len| is the |partyu| length (in bytes). |
185 | | * |partyv| is the optional public info contributed by the responder. |
186 | | * It can be NULL. |
187 | | * |partyv_len| is the |partyv| length (in bytes). |
188 | | * |supp_pub| is the optional additional, mutually-known public information. |
189 | | * It can be NULL. |keylen| should be 0 if this is not NULL. |
190 | | * |supp_pub_len| is the |supp_pub| length (in bytes). |
191 | | * |supp_priv| is the optional additional, mutually-known private information. |
192 | | * It can be NULL. |
193 | | * |supp_priv_len| is the |supp_priv| length (in bytes). |
194 | | * |der| is the returned encoded data. It must be freed by the caller. |
195 | | * |der_len| is the returned size of the encoded data. |
196 | | * |out_ctr| returns a pointer to the counter data which is embedded inside the |
197 | | * encoded data. This allows the counter bytes to be updated without |
198 | | * re-encoding. |
199 | | * |
200 | | * Returns: 1 if successfully encoded, or 0 otherwise. |
201 | | * Assumptions: |der|, |der_len| & |out_ctr| are not NULL. |
202 | | */ |
203 | | static int |
204 | | x942_encode_otherinfo(size_t keylen, |
205 | | const unsigned char *cek_oid, size_t cek_oid_len, |
206 | | const unsigned char *acvp, size_t acvp_len, |
207 | | const unsigned char *partyu, size_t partyu_len, |
208 | | const unsigned char *partyv, size_t partyv_len, |
209 | | const unsigned char *supp_pub, size_t supp_pub_len, |
210 | | const unsigned char *supp_priv, size_t supp_priv_len, |
211 | | unsigned char **der, size_t *der_len, |
212 | | unsigned char **out_ctr) |
213 | 24 | { |
214 | 24 | int ret = 0; |
215 | 24 | unsigned char *pcounter = NULL, *der_buf = NULL; |
216 | 24 | size_t der_buflen = 0; |
217 | 24 | WPACKET pkt; |
218 | 24 | uint32_t keylen_bits; |
219 | | |
220 | | /* keylenbits must fit into 4 bytes */ |
221 | 24 | if (keylen > 0xFFFFFF) |
222 | 0 | return 0; |
223 | 24 | keylen_bits = (uint32_t)(8 * keylen); |
224 | | |
225 | | /* Calculate the size of the buffer */ |
226 | 24 | if (!der_encode_sharedinfo(&pkt, NULL, 0, cek_oid, cek_oid_len, |
227 | 24 | acvp, acvp_len, |
228 | 24 | partyu, partyu_len, partyv, partyv_len, |
229 | 24 | supp_pub, supp_pub_len, supp_priv, supp_priv_len, |
230 | 24 | keylen_bits, NULL) |
231 | 24 | || !WPACKET_get_total_written(&pkt, &der_buflen)) |
232 | 0 | goto err; |
233 | 24 | WPACKET_cleanup(&pkt); |
234 | | /* Alloc the buffer */ |
235 | 24 | der_buf = OPENSSL_zalloc(der_buflen); |
236 | 24 | if (der_buf == NULL) |
237 | 0 | goto err; |
238 | | /* Encode into the buffer */ |
239 | 24 | if (!der_encode_sharedinfo(&pkt, der_buf, der_buflen, cek_oid, cek_oid_len, |
240 | 24 | acvp, acvp_len, |
241 | 24 | partyu, partyu_len, partyv, partyv_len, |
242 | 24 | supp_pub, supp_pub_len, supp_priv, supp_priv_len, |
243 | 24 | keylen_bits, &pcounter)) |
244 | 0 | goto err; |
245 | | /* |
246 | | * Since we allocated the exact size required, the buffer should point to the |
247 | | * start of the allocated buffer at this point. |
248 | | */ |
249 | 24 | if (WPACKET_get_curr(&pkt) != der_buf) |
250 | 0 | goto err; |
251 | | |
252 | | /* |
253 | | * The data for the DER encoded octet string of a 32 bit counter = 1 |
254 | | * should be 04 04 00 00 00 01 |
255 | | * So just check the header is correct and skip over it. |
256 | | * This counter will be incremented in the kdf update loop. |
257 | | */ |
258 | 24 | if (pcounter == NULL |
259 | 24 | || pcounter[0] != 0x04 |
260 | 24 | || pcounter[1] != 0x04) |
261 | 0 | goto err; |
262 | 24 | *out_ctr = (pcounter + 2); |
263 | 24 | *der = der_buf; |
264 | 24 | *der_len = der_buflen; |
265 | 24 | ret = 1; |
266 | 24 | err: |
267 | 24 | WPACKET_cleanup(&pkt); |
268 | 24 | return ret; |
269 | 24 | } |
270 | | |
271 | | static int x942kdf_hash_kdm(const EVP_MD *kdf_md, |
272 | | const unsigned char *z, size_t z_len, |
273 | | const unsigned char *other, size_t other_len, |
274 | | unsigned char *ctr, |
275 | | unsigned char *derived_key, size_t derived_key_len) |
276 | 24 | { |
277 | 24 | int ret = 0, hlen; |
278 | 24 | size_t counter, out_len, len = derived_key_len; |
279 | 24 | unsigned char mac[EVP_MAX_MD_SIZE]; |
280 | 24 | unsigned char *out = derived_key; |
281 | 24 | EVP_MD_CTX *ctx = NULL, *ctx_init = NULL; |
282 | | |
283 | 24 | if (z_len > X942KDF_MAX_INLEN |
284 | 24 | || other_len > X942KDF_MAX_INLEN |
285 | 24 | || derived_key_len > X942KDF_MAX_INLEN |
286 | 24 | || derived_key_len == 0) { |
287 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_BAD_LENGTH); |
288 | 0 | return 0; |
289 | 0 | } |
290 | | |
291 | 24 | hlen = EVP_MD_get_size(kdf_md); |
292 | 24 | if (hlen <= 0) |
293 | 1 | return 0; |
294 | 23 | out_len = (size_t)hlen; |
295 | | |
296 | 23 | ctx = EVP_MD_CTX_create(); |
297 | 23 | ctx_init = EVP_MD_CTX_create(); |
298 | 23 | if (ctx == NULL || ctx_init == NULL) |
299 | 0 | goto end; |
300 | | |
301 | 23 | if (!EVP_DigestInit(ctx_init, kdf_md)) |
302 | 0 | goto end; |
303 | | |
304 | 30 | for (counter = 1;; counter++) { |
305 | | /* updating the ctr modifies 4 bytes in the 'other' buffer */ |
306 | 30 | ctr[0] = (unsigned char)((counter >> 24) & 0xff); |
307 | 30 | ctr[1] = (unsigned char)((counter >> 16) & 0xff); |
308 | 30 | ctr[2] = (unsigned char)((counter >> 8) & 0xff); |
309 | 30 | ctr[3] = (unsigned char)(counter & 0xff); |
310 | | |
311 | 30 | if (!EVP_MD_CTX_copy_ex(ctx, ctx_init) |
312 | 30 | || !EVP_DigestUpdate(ctx, z, z_len) |
313 | 30 | || !EVP_DigestUpdate(ctx, other, other_len)) |
314 | 0 | goto end; |
315 | 30 | if (len >= out_len) { |
316 | 17 | if (!EVP_DigestFinal_ex(ctx, out, NULL)) |
317 | 0 | goto end; |
318 | 17 | out += out_len; |
319 | 17 | len -= out_len; |
320 | 17 | if (len == 0) |
321 | 10 | break; |
322 | 17 | } else { |
323 | 13 | if (!EVP_DigestFinal_ex(ctx, mac, NULL)) |
324 | 0 | goto end; |
325 | 13 | memcpy(out, mac, len); |
326 | 13 | break; |
327 | 13 | } |
328 | 30 | } |
329 | 23 | ret = 1; |
330 | 23 | end: |
331 | 23 | EVP_MD_CTX_free(ctx); |
332 | 23 | EVP_MD_CTX_free(ctx_init); |
333 | 23 | OPENSSL_cleanse(mac, sizeof(mac)); |
334 | 23 | return ret; |
335 | 23 | } |
336 | | |
337 | | static void *x942kdf_new(void *provctx) |
338 | 92 | { |
339 | 92 | KDF_X942 *ctx; |
340 | | |
341 | 92 | if (!ossl_prov_is_running()) |
342 | 0 | return NULL; |
343 | | |
344 | 92 | ctx = OPENSSL_zalloc(sizeof(*ctx)); |
345 | 92 | if (ctx == NULL) |
346 | 0 | return NULL; |
347 | | |
348 | 92 | ctx->provctx = provctx; |
349 | 92 | OSSL_FIPS_IND_INIT(ctx) |
350 | 92 | ctx->use_keybits = 1; |
351 | 92 | return ctx; |
352 | 92 | } |
353 | | |
354 | | static void x942kdf_reset(void *vctx) |
355 | 92 | { |
356 | 92 | KDF_X942 *ctx = (KDF_X942 *)vctx; |
357 | 92 | void *provctx = ctx->provctx; |
358 | | |
359 | 92 | ossl_prov_digest_reset(&ctx->digest); |
360 | 92 | OPENSSL_clear_free(ctx->secret, ctx->secret_len); |
361 | 92 | OPENSSL_clear_free(ctx->acvpinfo, ctx->acvpinfo_len); |
362 | 92 | OPENSSL_clear_free(ctx->partyuinfo, ctx->partyuinfo_len); |
363 | 92 | OPENSSL_clear_free(ctx->partyvinfo, ctx->partyvinfo_len); |
364 | 92 | OPENSSL_clear_free(ctx->supp_pubinfo, ctx->supp_pubinfo_len); |
365 | 92 | OPENSSL_clear_free(ctx->supp_privinfo, ctx->supp_privinfo_len); |
366 | 92 | memset(ctx, 0, sizeof(*ctx)); |
367 | 92 | ctx->provctx = provctx; |
368 | 92 | ctx->use_keybits = 1; |
369 | 92 | } |
370 | | |
371 | | static void x942kdf_free(void *vctx) |
372 | 92 | { |
373 | 92 | KDF_X942 *ctx = (KDF_X942 *)vctx; |
374 | | |
375 | 92 | if (ctx != NULL) { |
376 | 92 | x942kdf_reset(ctx); |
377 | 92 | OPENSSL_free(ctx); |
378 | 92 | } |
379 | 92 | } |
380 | | |
381 | | static void *x942kdf_dup(void *vctx) |
382 | 0 | { |
383 | 0 | const KDF_X942 *src = (const KDF_X942 *)vctx; |
384 | 0 | KDF_X942 *dest; |
385 | |
|
386 | 0 | dest = x942kdf_new(src->provctx); |
387 | 0 | if (dest != NULL) { |
388 | 0 | if (!ossl_prov_memdup(src->secret, src->secret_len, |
389 | 0 | &dest->secret, &dest->secret_len) |
390 | 0 | || !ossl_prov_memdup(src->acvpinfo, src->acvpinfo_len, |
391 | 0 | &dest->acvpinfo, &dest->acvpinfo_len) |
392 | 0 | || !ossl_prov_memdup(src->partyuinfo, src->partyuinfo_len, |
393 | 0 | &dest->partyuinfo, &dest->partyuinfo_len) |
394 | 0 | || !ossl_prov_memdup(src->partyvinfo, src->partyvinfo_len, |
395 | 0 | &dest->partyvinfo, &dest->partyvinfo_len) |
396 | 0 | || !ossl_prov_memdup(src->supp_pubinfo, src->supp_pubinfo_len, |
397 | 0 | &dest->supp_pubinfo, |
398 | 0 | &dest->supp_pubinfo_len) |
399 | 0 | || !ossl_prov_memdup(src->supp_privinfo, src->supp_privinfo_len, |
400 | 0 | &dest->supp_privinfo, |
401 | 0 | &dest->supp_privinfo_len) |
402 | 0 | || !ossl_prov_digest_copy(&dest->digest, &src->digest)) |
403 | 0 | goto err; |
404 | 0 | dest->cek_oid = src->cek_oid; |
405 | 0 | dest->cek_oid_len = src->cek_oid_len; |
406 | 0 | dest->dkm_len = src->dkm_len; |
407 | 0 | dest->use_keybits = src->use_keybits; |
408 | 0 | OSSL_FIPS_IND_COPY(dest, src) |
409 | 0 | } |
410 | 0 | return dest; |
411 | | |
412 | 0 | err: |
413 | 0 | x942kdf_free(dest); |
414 | 0 | return NULL; |
415 | 0 | } |
416 | | |
417 | | static int x942kdf_set_buffer(unsigned char **out, size_t *out_len, |
418 | | const OSSL_PARAM *p) |
419 | 396 | { |
420 | 396 | if (p->data_size == 0 || p->data == NULL) |
421 | 282 | return 1; |
422 | | |
423 | 114 | OPENSSL_free(*out); |
424 | 114 | *out = NULL; |
425 | 114 | return OSSL_PARAM_get_octet_string(p, (void **)out, 0, out_len); |
426 | 396 | } |
427 | | |
428 | | static size_t x942kdf_size(KDF_X942 *ctx) |
429 | 0 | { |
430 | 0 | int len; |
431 | 0 | const EVP_MD *md = ossl_prov_digest_md(&ctx->digest); |
432 | |
|
433 | 0 | if (md == NULL) { |
434 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST); |
435 | 0 | return 0; |
436 | 0 | } |
437 | 0 | len = EVP_MD_get_size(md); |
438 | 0 | return (len <= 0) ? 0 : (size_t)len; |
439 | 0 | } |
440 | | |
441 | | #ifdef FIPS_MODULE |
442 | | static int fips_x942kdf_key_check_passed(KDF_X942 *ctx) |
443 | | { |
444 | | OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx); |
445 | | int key_approved = ossl_kdf_check_key_size(ctx->secret_len); |
446 | | |
447 | | if (!key_approved) { |
448 | | if (!OSSL_FIPS_IND_ON_UNAPPROVED(ctx, OSSL_FIPS_IND_SETTABLE0, |
449 | | libctx, "X942KDF", "Key size", |
450 | | ossl_fips_config_x942kdf_key_check)) { |
451 | | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); |
452 | | return 0; |
453 | | } |
454 | | } |
455 | | return 1; |
456 | | } |
457 | | #endif |
458 | | |
459 | | static int x942kdf_derive(void *vctx, unsigned char *key, size_t keylen, |
460 | | const OSSL_PARAM params[]) |
461 | 27 | { |
462 | 27 | KDF_X942 *ctx = (KDF_X942 *)vctx; |
463 | 27 | const EVP_MD *md; |
464 | 27 | int ret = 0; |
465 | 27 | unsigned char *ctr; |
466 | 27 | unsigned char *der = NULL; |
467 | 27 | size_t der_len = 0; |
468 | | |
469 | 27 | if (!ossl_prov_is_running() || !x942kdf_set_ctx_params(ctx, params)) |
470 | 0 | return 0; |
471 | | |
472 | | /* |
473 | | * These 2 options encode to the same field so only one of them should be |
474 | | * active at once. |
475 | | */ |
476 | 27 | if (ctx->use_keybits && ctx->supp_pubinfo != NULL) { |
477 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_PUBINFO); |
478 | 0 | return 0; |
479 | 0 | } |
480 | | /* |
481 | | * If the blob of acvp data is used then the individual info fields that it |
482 | | * replaces should not also be defined. |
483 | | */ |
484 | 27 | if (ctx->acvpinfo != NULL |
485 | 23 | && (ctx->partyuinfo != NULL |
486 | 21 | || ctx->partyvinfo != NULL |
487 | 21 | || ctx->supp_pubinfo != NULL |
488 | 21 | || ctx->supp_privinfo != NULL)) { |
489 | 2 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DATA); |
490 | 2 | return 0; |
491 | 2 | } |
492 | 25 | if (ctx->secret == NULL) { |
493 | 1 | ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_SECRET); |
494 | 1 | return 0; |
495 | 1 | } |
496 | 24 | md = ossl_prov_digest_md(&ctx->digest); |
497 | 24 | if (md == NULL) { |
498 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST); |
499 | 0 | return 0; |
500 | 0 | } |
501 | 24 | if (ctx->cek_oid == NULL || ctx->cek_oid_len == 0) { |
502 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_CEK_ALG); |
503 | 0 | return 0; |
504 | 0 | } |
505 | 24 | if (ctx->partyuinfo != NULL && ctx->partyuinfo_len >= X942KDF_MAX_INLEN) { |
506 | | /* |
507 | | * Note the ukm length MUST be 512 bits if it is used. |
508 | | * For backwards compatibility the old check is being done. |
509 | | */ |
510 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_UKM_LENGTH); |
511 | 0 | return 0; |
512 | 0 | } |
513 | | /* generate the otherinfo der */ |
514 | 24 | if (!x942_encode_otherinfo(ctx->use_keybits ? ctx->dkm_len : 0, |
515 | 24 | ctx->cek_oid, ctx->cek_oid_len, |
516 | 24 | ctx->acvpinfo, ctx->acvpinfo_len, |
517 | 24 | ctx->partyuinfo, ctx->partyuinfo_len, |
518 | 24 | ctx->partyvinfo, ctx->partyvinfo_len, |
519 | 24 | ctx->supp_pubinfo, ctx->supp_pubinfo_len, |
520 | 24 | ctx->supp_privinfo, ctx->supp_privinfo_len, |
521 | 24 | &der, &der_len, &ctr)) { |
522 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_BAD_ENCODING); |
523 | 0 | return 0; |
524 | 0 | } |
525 | 24 | ret = x942kdf_hash_kdm(md, ctx->secret, ctx->secret_len, |
526 | 24 | der, der_len, ctr, key, keylen); |
527 | 24 | OPENSSL_free(der); |
528 | 24 | return ret; |
529 | 24 | } |
530 | | |
531 | | /* clang-format off */ |
532 | | /* Machine generated by util/perl/OpenSSL/paramnames.pm */ |
533 | | #ifndef sshkdf_set_ctx_params_list |
534 | | static const OSSL_PARAM sshkdf_set_ctx_params_list[] = { |
535 | | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0), |
536 | | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_DIGEST, NULL, 0), |
537 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SECRET, NULL, 0), |
538 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_KEY, NULL, 0), |
539 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_UKM, NULL, 0), |
540 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_X942_ACVPINFO, NULL, 0), |
541 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_X942_PARTYUINFO, NULL, 0), |
542 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_X942_PARTYVINFO, NULL, 0), |
543 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_X942_SUPP_PUBINFO, NULL, 0), |
544 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_X942_SUPP_PRIVINFO, NULL, 0), |
545 | | OSSL_PARAM_int(OSSL_KDF_PARAM_X942_USE_KEYBITS, NULL), |
546 | | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_CEK_ALG, NULL, 0), |
547 | | # if defined(FIPS_MODULE) |
548 | | OSSL_PARAM_int(OSSL_KDF_PARAM_FIPS_KEY_CHECK, NULL), |
549 | | # endif |
550 | | OSSL_PARAM_END |
551 | | }; |
552 | | #endif |
553 | | |
554 | | #ifndef sshkdf_set_ctx_params_st |
555 | | struct sshkdf_set_ctx_params_st { |
556 | | OSSL_PARAM *acvp; |
557 | | OSSL_PARAM *cekalg; |
558 | | OSSL_PARAM *digest; |
559 | | OSSL_PARAM *engine; |
560 | | # if defined(FIPS_MODULE) |
561 | | OSSL_PARAM *ind_k; |
562 | | # endif |
563 | | OSSL_PARAM *kbits; |
564 | | OSSL_PARAM *priv; |
565 | | OSSL_PARAM *propq; |
566 | | OSSL_PARAM *pub; |
567 | | OSSL_PARAM *secret; |
568 | | OSSL_PARAM *uinfo; |
569 | | OSSL_PARAM *vinfo; |
570 | | }; |
571 | | #endif |
572 | | |
573 | | #ifndef sshkdf_set_ctx_params_decoder |
574 | | static int sshkdf_set_ctx_params_decoder |
575 | | (const OSSL_PARAM *p, struct sshkdf_set_ctx_params_st *r) |
576 | 6 | { |
577 | 6 | const char *s; |
578 | | |
579 | 6 | memset(r, 0, sizeof(*r)); |
580 | 6 | if (p != NULL) |
581 | 24 | for (; (s = p->key) != NULL; p++) |
582 | 24 | switch(s[0]) { |
583 | 0 | default: |
584 | 0 | break; |
585 | 0 | case 'a': |
586 | 0 | if (ossl_likely(strcmp("cvp-info", s + 1) == 0)) { |
587 | | /* OSSL_KDF_PARAM_X942_ACVPINFO */ |
588 | 0 | if (ossl_unlikely(r->acvp != NULL)) { |
589 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
590 | 0 | "param %s is repeated", s); |
591 | 0 | return 0; |
592 | 0 | } |
593 | 0 | r->acvp = (OSSL_PARAM *)p; |
594 | 0 | } |
595 | 0 | break; |
596 | 0 | case 'c': |
597 | 0 | if (ossl_likely(strcmp("ekalg", s + 1) == 0)) { |
598 | | /* OSSL_KDF_PARAM_CEK_ALG */ |
599 | 0 | if (ossl_unlikely(r->cekalg != NULL)) { |
600 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
601 | 0 | "param %s is repeated", s); |
602 | 0 | return 0; |
603 | 0 | } |
604 | 0 | r->cekalg = (OSSL_PARAM *)p; |
605 | 0 | } |
606 | 0 | break; |
607 | 6 | case 'd': |
608 | 6 | if (ossl_likely(strcmp("igest", s + 1) == 0)) { |
609 | | /* OSSL_KDF_PARAM_DIGEST */ |
610 | 6 | if (ossl_unlikely(r->digest != 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 | 6 | r->digest = (OSSL_PARAM *)p; |
616 | 6 | } |
617 | 6 | break; |
618 | 6 | case 'e': |
619 | 0 | if (ossl_likely(strcmp("ngine", s + 1) == 0)) { |
620 | | /* OSSL_ALG_PARAM_ENGINE */ |
621 | 0 | if (ossl_unlikely(r->engine != 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->engine = (OSSL_PARAM *)p; |
627 | 0 | } |
628 | 0 | break; |
629 | 6 | case 'k': |
630 | 6 | switch(s[1]) { |
631 | 0 | default: |
632 | 0 | break; |
633 | 6 | case 'e': |
634 | 6 | switch(s[2]) { |
635 | 0 | default: |
636 | 0 | break; |
637 | 6 | case 'y': |
638 | 6 | switch(s[3]) { |
639 | 0 | default: |
640 | 0 | break; |
641 | 0 | case '-': |
642 | | # if defined(FIPS_MODULE) |
643 | | if (ossl_likely(strcmp("check", s + 4) == 0)) { |
644 | | /* OSSL_KDF_PARAM_FIPS_KEY_CHECK */ |
645 | | if (ossl_unlikely(r->ind_k != NULL)) { |
646 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
647 | | "param %s is repeated", s); |
648 | | return 0; |
649 | | } |
650 | | r->ind_k = (OSSL_PARAM *)p; |
651 | | } |
652 | | # endif |
653 | 0 | break; |
654 | 6 | case '\0': |
655 | 6 | if (ossl_unlikely(r->secret != NULL)) { |
656 | 6 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
657 | 6 | "param %s is repeated", s); |
658 | 6 | return 0; |
659 | 6 | } |
660 | 0 | r->secret = (OSSL_PARAM *)p; |
661 | 6 | } |
662 | 6 | } |
663 | 6 | } |
664 | 0 | break; |
665 | 6 | case 'p': |
666 | 6 | switch(s[1]) { |
667 | 0 | default: |
668 | 0 | break; |
669 | 0 | case 'a': |
670 | 0 | switch(s[2]) { |
671 | 0 | default: |
672 | 0 | break; |
673 | 0 | case 'r': |
674 | 0 | switch(s[3]) { |
675 | 0 | default: |
676 | 0 | break; |
677 | 0 | case 't': |
678 | 0 | switch(s[4]) { |
679 | 0 | default: |
680 | 0 | break; |
681 | 0 | case 'y': |
682 | 0 | switch(s[5]) { |
683 | 0 | default: |
684 | 0 | break; |
685 | 0 | case 'u': |
686 | 0 | if (ossl_likely(strcmp("-info", s + 6) == 0)) { |
687 | | /* OSSL_KDF_PARAM_X942_PARTYUINFO */ |
688 | 0 | if (ossl_unlikely(r->uinfo != NULL)) { |
689 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
690 | 0 | "param %s is repeated", s); |
691 | 0 | return 0; |
692 | 0 | } |
693 | 0 | r->uinfo = (OSSL_PARAM *)p; |
694 | 0 | } |
695 | 0 | break; |
696 | 0 | case 'v': |
697 | 0 | if (ossl_likely(strcmp("-info", s + 6) == 0)) { |
698 | | /* OSSL_KDF_PARAM_X942_PARTYVINFO */ |
699 | 0 | if (ossl_unlikely(r->vinfo != NULL)) { |
700 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
701 | 0 | "param %s is repeated", s); |
702 | 0 | return 0; |
703 | 0 | } |
704 | 0 | r->vinfo = (OSSL_PARAM *)p; |
705 | 0 | } |
706 | 0 | } |
707 | 0 | } |
708 | 0 | } |
709 | 0 | } |
710 | 0 | break; |
711 | 6 | case 'r': |
712 | 6 | if (ossl_likely(strcmp("operties", s + 2) == 0)) { |
713 | | /* OSSL_KDF_PARAM_PROPERTIES */ |
714 | 6 | if (ossl_unlikely(r->propq != NULL)) { |
715 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
716 | 0 | "param %s is repeated", s); |
717 | 0 | return 0; |
718 | 0 | } |
719 | 6 | r->propq = (OSSL_PARAM *)p; |
720 | 6 | } |
721 | 6 | } |
722 | 6 | break; |
723 | 6 | case 's': |
724 | 6 | switch(s[1]) { |
725 | 0 | default: |
726 | 0 | break; |
727 | 6 | case 'e': |
728 | 6 | if (ossl_likely(strcmp("cret", s + 2) == 0)) { |
729 | | /* OSSL_KDF_PARAM_SECRET */ |
730 | 6 | if (ossl_unlikely(r->secret != NULL)) { |
731 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
732 | 0 | "param %s is repeated", s); |
733 | 0 | return 0; |
734 | 0 | } |
735 | 6 | r->secret = (OSSL_PARAM *)p; |
736 | 6 | } |
737 | 6 | break; |
738 | 6 | case 'u': |
739 | 0 | switch(s[2]) { |
740 | 0 | default: |
741 | 0 | break; |
742 | 0 | case 'p': |
743 | 0 | switch(s[3]) { |
744 | 0 | default: |
745 | 0 | break; |
746 | 0 | case 'p': |
747 | 0 | switch(s[4]) { |
748 | 0 | default: |
749 | 0 | break; |
750 | 0 | case '-': |
751 | 0 | switch(s[5]) { |
752 | 0 | default: |
753 | 0 | break; |
754 | 0 | case 'p': |
755 | 0 | switch(s[6]) { |
756 | 0 | default: |
757 | 0 | break; |
758 | 0 | case 'r': |
759 | 0 | if (ossl_likely(strcmp("ivinfo", s + 7) == 0)) { |
760 | | /* OSSL_KDF_PARAM_X942_SUPP_PRIVINFO */ |
761 | 0 | if (ossl_unlikely(r->priv != NULL)) { |
762 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
763 | 0 | "param %s is repeated", s); |
764 | 0 | return 0; |
765 | 0 | } |
766 | 0 | r->priv = (OSSL_PARAM *)p; |
767 | 0 | } |
768 | 0 | break; |
769 | 0 | case 'u': |
770 | 0 | if (ossl_likely(strcmp("binfo", s + 7) == 0)) { |
771 | | /* OSSL_KDF_PARAM_X942_SUPP_PUBINFO */ |
772 | 0 | if (ossl_unlikely(r->pub != NULL)) { |
773 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
774 | 0 | "param %s is repeated", s); |
775 | 0 | return 0; |
776 | 0 | } |
777 | 0 | r->pub = (OSSL_PARAM *)p; |
778 | 0 | } |
779 | 0 | } |
780 | 0 | } |
781 | 0 | } |
782 | 0 | } |
783 | 0 | } |
784 | 6 | } |
785 | 6 | break; |
786 | 6 | case 'u': |
787 | 0 | switch(s[1]) { |
788 | 0 | default: |
789 | 0 | break; |
790 | 0 | case 'k': |
791 | 0 | if (ossl_likely(strcmp("m", s + 2) == 0)) { |
792 | | /* OSSL_KDF_PARAM_UKM */ |
793 | 0 | if (ossl_unlikely(r->uinfo != NULL)) { |
794 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
795 | 0 | "param %s is repeated", s); |
796 | 0 | return 0; |
797 | 0 | } |
798 | 0 | r->uinfo = (OSSL_PARAM *)p; |
799 | 0 | } |
800 | 0 | break; |
801 | 0 | case 's': |
802 | 0 | if (ossl_likely(strcmp("e-keybits", s + 2) == 0)) { |
803 | | /* OSSL_KDF_PARAM_X942_USE_KEYBITS */ |
804 | 0 | if (ossl_unlikely(r->kbits != NULL)) { |
805 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
806 | 0 | "param %s is repeated", s); |
807 | 0 | return 0; |
808 | 0 | } |
809 | 0 | r->kbits = (OSSL_PARAM *)p; |
810 | 0 | } |
811 | 0 | } |
812 | 24 | } |
813 | 0 | return 1; |
814 | 6 | } |
815 | | #endif |
816 | | /* End of machine generated */ |
817 | | /* clang-format on */ |
818 | | |
819 | | static int x942kdf_set_ctx_params(void *vctx, const OSSL_PARAM params[]) |
820 | 9 | { |
821 | 9 | struct sshkdf_set_ctx_params_st p; |
822 | 9 | KDF_X942 *ctx = vctx; |
823 | 9 | OSSL_LIB_CTX *provctx; |
824 | 9 | const char *cekalg, *propq = NULL; |
825 | 9 | const EVP_MD *md; |
826 | 9 | size_t id; |
827 | | |
828 | 9 | if (ctx == NULL || !sshkdf_set_ctx_params_decoder(params, &p)) |
829 | 9 | return 0; |
830 | | |
831 | 0 | provctx = PROV_LIBCTX_OF(ctx->provctx); |
832 | |
|
833 | 0 | if (!OSSL_FIPS_IND_SET_CTX_FROM_PARAM(ctx, OSSL_FIPS_IND_SETTABLE0, p.ind_k)) |
834 | 0 | return 0; |
835 | | |
836 | 0 | if (p.digest != NULL) { |
837 | 0 | if (!ossl_prov_digest_load(&ctx->digest, p.digest, |
838 | 0 | p.propq, p.engine, provctx)) |
839 | 0 | return 0; |
840 | 0 | md = ossl_prov_digest_md(&ctx->digest); |
841 | 0 | if (EVP_MD_xof(md)) { |
842 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_XOF_DIGESTS_NOT_ALLOWED); |
843 | 0 | return 0; |
844 | 0 | } |
845 | 0 | } |
846 | | |
847 | 0 | if (p.secret != NULL) { |
848 | 0 | if (!x942kdf_set_buffer(&ctx->secret, &ctx->secret_len, p.secret)) |
849 | 0 | return 0; |
850 | | #ifdef FIPS_MODULE |
851 | | if (!fips_x942kdf_key_check_passed(ctx)) |
852 | | return 0; |
853 | | #endif |
854 | 0 | } |
855 | | |
856 | 0 | if (p.acvp != NULL |
857 | 0 | && !x942kdf_set_buffer(&ctx->acvpinfo, &ctx->acvpinfo_len, p.acvp)) |
858 | 0 | return 0; |
859 | | |
860 | 0 | if (p.uinfo != NULL |
861 | 0 | && !x942kdf_set_buffer(&ctx->partyuinfo, &ctx->partyuinfo_len, p.uinfo)) |
862 | 0 | return 0; |
863 | | |
864 | 0 | if (p.vinfo != NULL |
865 | 0 | && !x942kdf_set_buffer(&ctx->partyvinfo, &ctx->partyvinfo_len, p.vinfo)) |
866 | 0 | return 0; |
867 | | |
868 | 0 | if (p.kbits != NULL && !OSSL_PARAM_get_int(p.kbits, &ctx->use_keybits)) |
869 | 0 | return 0; |
870 | | |
871 | 0 | if (p.pub != NULL) { |
872 | 0 | if (!x942kdf_set_buffer(&ctx->supp_pubinfo, &ctx->supp_pubinfo_len, p.pub)) |
873 | 0 | return 0; |
874 | 0 | ctx->use_keybits = 0; |
875 | 0 | } |
876 | | |
877 | 0 | if (p.priv != NULL |
878 | 0 | && !x942kdf_set_buffer(&ctx->supp_privinfo, &ctx->supp_privinfo_len, p.priv)) |
879 | 0 | return 0; |
880 | | |
881 | 0 | if (p.cekalg != NULL) { |
882 | 0 | if (!OSSL_PARAM_get_utf8_string_ptr(p.cekalg, &cekalg)) |
883 | 0 | return 0; |
884 | 0 | if (p.propq != NULL && !OSSL_PARAM_get_utf8_string_ptr(p.propq, &propq)) |
885 | 0 | return 0; |
886 | 0 | if (find_alg_id(provctx, cekalg, propq, &id) == 0) |
887 | 0 | return 0; |
888 | 0 | ctx->cek_oid = kek_algs[id].oid; |
889 | 0 | ctx->cek_oid_len = kek_algs[id].oid_len; |
890 | 0 | ctx->dkm_len = kek_algs[id].keklen; |
891 | 0 | } |
892 | 0 | return 1; |
893 | 0 | } |
894 | | |
895 | | static const OSSL_PARAM *x942kdf_settable_ctx_params(ossl_unused void *ctx, |
896 | | ossl_unused void *provctx) |
897 | 92 | { |
898 | 92 | return sshkdf_set_ctx_params_list; |
899 | 92 | } |
900 | | |
901 | | /* clang-format off */ |
902 | | /* Machine generated by util/perl/OpenSSL/paramnames.pm */ |
903 | | #ifndef sshkdf_get_ctx_params_list |
904 | | static const OSSL_PARAM sshkdf_get_ctx_params_list[] = { |
905 | | OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL), |
906 | | # if defined(FIPS_MODULE) |
907 | | OSSL_PARAM_int(OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR, NULL), |
908 | | # endif |
909 | | OSSL_PARAM_END |
910 | | }; |
911 | | #endif |
912 | | |
913 | | #ifndef sshkdf_get_ctx_params_st |
914 | | struct sshkdf_get_ctx_params_st { |
915 | | # if defined(FIPS_MODULE) |
916 | | OSSL_PARAM *ind; |
917 | | # endif |
918 | | OSSL_PARAM *size; |
919 | | }; |
920 | | #endif |
921 | | |
922 | | #ifndef sshkdf_get_ctx_params_decoder |
923 | | static int sshkdf_get_ctx_params_decoder |
924 | | (const OSSL_PARAM *p, struct sshkdf_get_ctx_params_st *r) |
925 | 0 | { |
926 | 0 | const char *s; |
927 | |
|
928 | 0 | memset(r, 0, sizeof(*r)); |
929 | 0 | if (p != NULL) |
930 | 0 | for (; (s = p->key) != NULL; p++) |
931 | 0 | switch(s[0]) { |
932 | 0 | default: |
933 | 0 | break; |
934 | 0 | case 'f': |
935 | | # if defined(FIPS_MODULE) |
936 | | if (ossl_likely(strcmp("ips-indicator", s + 1) == 0)) { |
937 | | /* OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR */ |
938 | | if (ossl_unlikely(r->ind != NULL)) { |
939 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
940 | | "param %s is repeated", s); |
941 | | return 0; |
942 | | } |
943 | | r->ind = (OSSL_PARAM *)p; |
944 | | } |
945 | | # endif |
946 | 0 | break; |
947 | 0 | case 's': |
948 | 0 | if (ossl_likely(strcmp("ize", s + 1) == 0)) { |
949 | | /* OSSL_KDF_PARAM_SIZE */ |
950 | 0 | if (ossl_unlikely(r->size != NULL)) { |
951 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
952 | 0 | "param %s is repeated", s); |
953 | 0 | return 0; |
954 | 0 | } |
955 | 0 | r->size = (OSSL_PARAM *)p; |
956 | 0 | } |
957 | 0 | } |
958 | 0 | return 1; |
959 | 0 | } |
960 | | #endif |
961 | | /* End of machine generated */ |
962 | | /* clang-format on */ |
963 | | |
964 | | static int x942kdf_get_ctx_params(void *vctx, OSSL_PARAM params[]) |
965 | 0 | { |
966 | 0 | KDF_X942 *ctx = (KDF_X942 *)vctx; |
967 | 0 | struct sshkdf_get_ctx_params_st p; |
968 | |
|
969 | 0 | if (ctx == NULL || !sshkdf_get_ctx_params_decoder(params, &p)) |
970 | 0 | return 0; |
971 | | |
972 | 0 | if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, x942kdf_size(ctx))) |
973 | 0 | return 0; |
974 | | |
975 | 0 | if (!OSSL_FIPS_IND_GET_CTX_FROM_PARAM(ctx, p.ind)) |
976 | 0 | return 0; |
977 | 0 | return 1; |
978 | 0 | } |
979 | | |
980 | | static const OSSL_PARAM *x942kdf_gettable_ctx_params(ossl_unused void *ctx, |
981 | | ossl_unused void *provctx) |
982 | 0 | { |
983 | 0 | return sshkdf_get_ctx_params_list; |
984 | 0 | } |
985 | | |
986 | | const OSSL_DISPATCH ossl_kdf_x942_kdf_functions[] = { |
987 | | { OSSL_FUNC_KDF_NEWCTX, (void (*)(void))x942kdf_new }, |
988 | | { OSSL_FUNC_KDF_DUPCTX, (void (*)(void))x942kdf_dup }, |
989 | | { OSSL_FUNC_KDF_FREECTX, (void (*)(void))x942kdf_free }, |
990 | | { OSSL_FUNC_KDF_RESET, (void (*)(void))x942kdf_reset }, |
991 | | { OSSL_FUNC_KDF_DERIVE, (void (*)(void))x942kdf_derive }, |
992 | | { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS, |
993 | | (void (*)(void))x942kdf_settable_ctx_params }, |
994 | | { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void (*)(void))x942kdf_set_ctx_params }, |
995 | | { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS, |
996 | | (void (*)(void))x942kdf_gettable_ctx_params }, |
997 | | { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void (*)(void))x942kdf_get_ctx_params }, |
998 | | OSSL_DISPATCH_END |
999 | | }; |