/src/openssl36/providers/implementations/kdfs/x942kdf.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2019-2026 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 | 300 | #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 | 113 | { |
87 | 113 | int ret = 1; |
88 | 113 | size_t i; |
89 | 113 | EVP_CIPHER *cipher; |
90 | | |
91 | 113 | cipher = EVP_CIPHER_fetch(libctx, algname, propq); |
92 | 113 | if (cipher != NULL) { |
93 | 151 | for (i = 0; i < OSSL_NELEM(kek_algs); i++) { |
94 | 148 | if (EVP_CIPHER_is_a(cipher, kek_algs[i].name)) { |
95 | 54 | *id = i; |
96 | 54 | goto end; |
97 | 54 | } |
98 | 148 | } |
99 | 57 | } |
100 | 59 | ret = 0; |
101 | 59 | ERR_raise(ERR_LIB_PROV, PROV_R_UNSUPPORTED_CEK_ALG); |
102 | 113 | end: |
103 | 113 | EVP_CIPHER_free(cipher); |
104 | 113 | return ret; |
105 | 59 | } |
106 | | |
107 | | static int DER_w_keyinfo(WPACKET *pkt, |
108 | | const unsigned char *der_oid, size_t der_oidlen, |
109 | | unsigned char **pcounter) |
110 | 100 | { |
111 | 100 | return ossl_DER_w_begin_sequence(pkt, -1) |
112 | | /* Store the initial value of 1 into the counter */ |
113 | 100 | && ossl_DER_w_octet_string_uint32(pkt, -1, 1) |
114 | | /* Remember where we stored the counter in the buffer */ |
115 | 100 | && (pcounter == NULL |
116 | 50 | || (*pcounter = WPACKET_get_curr(pkt)) != NULL) |
117 | 100 | && ossl_DER_w_precompiled(pkt, -1, der_oid, der_oidlen) |
118 | 100 | && ossl_DER_w_end_sequence(pkt, -1); |
119 | 100 | } |
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 | 100 | { |
130 | 100 | return (buf != NULL ? WPACKET_init_der(pkt, buf, buflen) : WPACKET_init_null_der(pkt)) |
131 | 100 | && ossl_DER_w_begin_sequence(pkt, -1) |
132 | 100 | && (supp_priv == NULL |
133 | 0 | || ossl_DER_w_octet_string(pkt, 3, supp_priv, supp_privlen)) |
134 | 100 | && (supp_pub == NULL |
135 | 0 | || ossl_DER_w_octet_string(pkt, 2, supp_pub, supp_publen)) |
136 | 100 | && (keylen_bits == 0 |
137 | 0 | || ossl_DER_w_octet_string_uint32(pkt, 2, keylen_bits)) |
138 | 100 | && (partyv == NULL || ossl_DER_w_octet_string(pkt, 1, partyv, partyvlen)) |
139 | 100 | && (partyu == NULL || ossl_DER_w_octet_string(pkt, 0, partyu, partyulen)) |
140 | 100 | && (acvp == NULL || ossl_DER_w_precompiled(pkt, -1, acvp, acvplen)) |
141 | 100 | && DER_w_keyinfo(pkt, der_oid, der_oidlen, pcounter) |
142 | 100 | && ossl_DER_w_end_sequence(pkt, -1) |
143 | 100 | && WPACKET_finish(pkt); |
144 | 100 | } |
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 | 50 | { |
214 | 50 | int ret = 0; |
215 | 50 | unsigned char *pcounter = NULL, *der_buf = NULL; |
216 | 50 | size_t der_buflen = 0; |
217 | 50 | WPACKET pkt; |
218 | 50 | uint32_t keylen_bits; |
219 | | |
220 | | /* keylenbits must fit into 4 bytes */ |
221 | 50 | if (keylen > 0xFFFFFF) |
222 | 0 | return 0; |
223 | 50 | keylen_bits = (uint32_t)(8 * keylen); |
224 | | |
225 | | /* Calculate the size of the buffer */ |
226 | 50 | if (!der_encode_sharedinfo(&pkt, NULL, 0, cek_oid, cek_oid_len, |
227 | 50 | acvp, acvp_len, |
228 | 50 | partyu, partyu_len, partyv, partyv_len, |
229 | 50 | supp_pub, supp_pub_len, supp_priv, supp_priv_len, |
230 | 50 | keylen_bits, NULL) |
231 | 50 | || !WPACKET_get_total_written(&pkt, &der_buflen)) |
232 | 0 | goto err; |
233 | 50 | WPACKET_cleanup(&pkt); |
234 | | /* Alloc the buffer */ |
235 | 50 | der_buf = OPENSSL_zalloc(der_buflen); |
236 | 50 | if (der_buf == NULL) |
237 | 0 | goto err; |
238 | | /* Encode into the buffer */ |
239 | 50 | if (!der_encode_sharedinfo(&pkt, der_buf, der_buflen, cek_oid, cek_oid_len, |
240 | 50 | acvp, acvp_len, |
241 | 50 | partyu, partyu_len, partyv, partyv_len, |
242 | 50 | supp_pub, supp_pub_len, supp_priv, supp_priv_len, |
243 | 50 | 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 | 50 | 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 | 50 | if (pcounter == NULL |
259 | 50 | || pcounter[0] != 0x04 |
260 | 50 | || pcounter[1] != 0x04) |
261 | 0 | goto err; |
262 | 50 | *out_ctr = (pcounter + 2); |
263 | 50 | *der = der_buf; |
264 | 50 | der_buf = NULL; |
265 | 50 | *der_len = der_buflen; |
266 | 50 | ret = 1; |
267 | 50 | err: |
268 | 50 | OPENSSL_free(der_buf); |
269 | 50 | WPACKET_cleanup(&pkt); |
270 | 50 | return ret; |
271 | 50 | } |
272 | | |
273 | | static int x942kdf_hash_kdm(const EVP_MD *kdf_md, |
274 | | const unsigned char *z, size_t z_len, |
275 | | const unsigned char *other, size_t other_len, |
276 | | unsigned char *ctr, |
277 | | unsigned char *derived_key, size_t derived_key_len) |
278 | 50 | { |
279 | 50 | int ret = 0, hlen; |
280 | 50 | size_t counter, out_len, len = derived_key_len; |
281 | 50 | unsigned char mac[EVP_MAX_MD_SIZE]; |
282 | 50 | unsigned char *out = derived_key; |
283 | 50 | EVP_MD_CTX *ctx = NULL, *ctx_init = NULL; |
284 | | |
285 | 50 | if (z_len > X942KDF_MAX_INLEN |
286 | 50 | || other_len > X942KDF_MAX_INLEN |
287 | 50 | || derived_key_len > X942KDF_MAX_INLEN |
288 | 50 | || derived_key_len == 0) { |
289 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_BAD_LENGTH); |
290 | 0 | return 0; |
291 | 0 | } |
292 | | |
293 | 50 | hlen = EVP_MD_get_size(kdf_md); |
294 | 50 | if (hlen <= 0) |
295 | 3 | return 0; |
296 | 47 | out_len = (size_t)hlen; |
297 | | |
298 | 47 | ctx = EVP_MD_CTX_create(); |
299 | 47 | ctx_init = EVP_MD_CTX_create(); |
300 | 47 | if (ctx == NULL || ctx_init == NULL) |
301 | 0 | goto end; |
302 | | |
303 | 47 | if (!EVP_DigestInit(ctx_init, kdf_md)) |
304 | 0 | goto end; |
305 | | |
306 | 65 | for (counter = 1;; counter++) { |
307 | | /* updating the ctr modifies 4 bytes in the 'other' buffer */ |
308 | 65 | ctr[0] = (unsigned char)((counter >> 24) & 0xff); |
309 | 65 | ctr[1] = (unsigned char)((counter >> 16) & 0xff); |
310 | 65 | ctr[2] = (unsigned char)((counter >> 8) & 0xff); |
311 | 65 | ctr[3] = (unsigned char)(counter & 0xff); |
312 | | |
313 | 65 | if (!EVP_MD_CTX_copy_ex(ctx, ctx_init) |
314 | 65 | || !EVP_DigestUpdate(ctx, z, z_len) |
315 | 65 | || !EVP_DigestUpdate(ctx, other, other_len)) |
316 | 0 | goto end; |
317 | 65 | if (len >= out_len) { |
318 | 46 | if (!EVP_DigestFinal_ex(ctx, out, NULL)) |
319 | 0 | goto end; |
320 | 46 | out += out_len; |
321 | 46 | len -= out_len; |
322 | 46 | if (len == 0) |
323 | 28 | break; |
324 | 46 | } else { |
325 | 19 | if (!EVP_DigestFinal_ex(ctx, mac, NULL)) |
326 | 0 | goto end; |
327 | 19 | memcpy(out, mac, len); |
328 | 19 | break; |
329 | 19 | } |
330 | 65 | } |
331 | 47 | ret = 1; |
332 | 47 | end: |
333 | 47 | EVP_MD_CTX_free(ctx); |
334 | 47 | EVP_MD_CTX_free(ctx_init); |
335 | 47 | OPENSSL_cleanse(mac, sizeof(mac)); |
336 | 47 | return ret; |
337 | 47 | } |
338 | | |
339 | | static void *x942kdf_new(void *provctx) |
340 | 149 | { |
341 | 149 | KDF_X942 *ctx; |
342 | | |
343 | 149 | if (!ossl_prov_is_running()) |
344 | 0 | return NULL; |
345 | | |
346 | 149 | ctx = OPENSSL_zalloc(sizeof(*ctx)); |
347 | 149 | if (ctx == NULL) |
348 | 0 | return NULL; |
349 | | |
350 | 149 | ctx->provctx = provctx; |
351 | 149 | OSSL_FIPS_IND_INIT(ctx) |
352 | 149 | ctx->use_keybits = 1; |
353 | 149 | return ctx; |
354 | 149 | } |
355 | | |
356 | | static void x942kdf_reset(void *vctx) |
357 | 149 | { |
358 | 149 | KDF_X942 *ctx = (KDF_X942 *)vctx; |
359 | 149 | void *provctx = ctx->provctx; |
360 | | |
361 | 149 | ossl_prov_digest_reset(&ctx->digest); |
362 | 149 | OPENSSL_clear_free(ctx->secret, ctx->secret_len); |
363 | 149 | OPENSSL_clear_free(ctx->acvpinfo, ctx->acvpinfo_len); |
364 | 149 | OPENSSL_clear_free(ctx->partyuinfo, ctx->partyuinfo_len); |
365 | 149 | OPENSSL_clear_free(ctx->partyvinfo, ctx->partyvinfo_len); |
366 | 149 | OPENSSL_clear_free(ctx->supp_pubinfo, ctx->supp_pubinfo_len); |
367 | 149 | OPENSSL_clear_free(ctx->supp_privinfo, ctx->supp_privinfo_len); |
368 | 149 | memset(ctx, 0, sizeof(*ctx)); |
369 | 149 | ctx->provctx = provctx; |
370 | 149 | ctx->use_keybits = 1; |
371 | 149 | } |
372 | | |
373 | | static void x942kdf_free(void *vctx) |
374 | 149 | { |
375 | 149 | KDF_X942 *ctx = (KDF_X942 *)vctx; |
376 | | |
377 | 149 | if (ctx != NULL) { |
378 | 149 | x942kdf_reset(ctx); |
379 | 149 | OPENSSL_free(ctx); |
380 | 149 | } |
381 | 149 | } |
382 | | |
383 | | static void *x942kdf_dup(void *vctx) |
384 | 0 | { |
385 | 0 | const KDF_X942 *src = (const KDF_X942 *)vctx; |
386 | 0 | KDF_X942 *dest; |
387 | |
|
388 | 0 | dest = x942kdf_new(src->provctx); |
389 | 0 | if (dest != NULL) { |
390 | 0 | if (!ossl_prov_memdup(src->secret, src->secret_len, |
391 | 0 | &dest->secret, &dest->secret_len) |
392 | 0 | || !ossl_prov_memdup(src->acvpinfo, src->acvpinfo_len, |
393 | 0 | &dest->acvpinfo, &dest->acvpinfo_len) |
394 | 0 | || !ossl_prov_memdup(src->partyuinfo, src->partyuinfo_len, |
395 | 0 | &dest->partyuinfo, &dest->partyuinfo_len) |
396 | 0 | || !ossl_prov_memdup(src->partyvinfo, src->partyvinfo_len, |
397 | 0 | &dest->partyvinfo, &dest->partyvinfo_len) |
398 | 0 | || !ossl_prov_memdup(src->supp_pubinfo, src->supp_pubinfo_len, |
399 | 0 | &dest->supp_pubinfo, |
400 | 0 | &dest->supp_pubinfo_len) |
401 | 0 | || !ossl_prov_memdup(src->supp_privinfo, src->supp_privinfo_len, |
402 | 0 | &dest->supp_privinfo, |
403 | 0 | &dest->supp_privinfo_len) |
404 | 0 | || !ossl_prov_digest_copy(&dest->digest, &src->digest)) |
405 | 0 | goto err; |
406 | 0 | dest->cek_oid = src->cek_oid; |
407 | 0 | dest->cek_oid_len = src->cek_oid_len; |
408 | 0 | dest->dkm_len = src->dkm_len; |
409 | 0 | dest->use_keybits = src->use_keybits; |
410 | 0 | OSSL_FIPS_IND_COPY(dest, src) |
411 | 0 | } |
412 | 0 | return dest; |
413 | | |
414 | 0 | err: |
415 | 0 | x942kdf_free(dest); |
416 | 0 | return NULL; |
417 | 0 | } |
418 | | |
419 | | static int x942kdf_set_buffer(unsigned char **out, size_t *out_len, |
420 | | const OSSL_PARAM *p) |
421 | 678 | { |
422 | 678 | if (p->data_size == 0 || p->data == NULL) |
423 | 421 | return 1; |
424 | | |
425 | 257 | OPENSSL_free(*out); |
426 | 257 | *out = NULL; |
427 | 257 | return OSSL_PARAM_get_octet_string(p, (void **)out, 0, out_len); |
428 | 678 | } |
429 | | |
430 | | static size_t x942kdf_size(KDF_X942 *ctx) |
431 | 0 | { |
432 | 0 | int len; |
433 | 0 | const EVP_MD *md = ossl_prov_digest_md(&ctx->digest); |
434 | |
|
435 | 0 | if (md == NULL) { |
436 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST); |
437 | 0 | return 0; |
438 | 0 | } |
439 | 0 | len = EVP_MD_get_size(md); |
440 | 0 | return (len <= 0) ? 0 : (size_t)len; |
441 | 0 | } |
442 | | |
443 | | #ifdef FIPS_MODULE |
444 | | static int fips_x942kdf_key_check_passed(KDF_X942 *ctx) |
445 | | { |
446 | | OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx); |
447 | | int key_approved = ossl_kdf_check_key_size(ctx->secret_len); |
448 | | |
449 | | if (!key_approved) { |
450 | | if (!OSSL_FIPS_IND_ON_UNAPPROVED(ctx, OSSL_FIPS_IND_SETTABLE0, |
451 | | libctx, "X942KDF", "Key size", |
452 | | ossl_fips_config_x942kdf_key_check)) { |
453 | | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); |
454 | | return 0; |
455 | | } |
456 | | } |
457 | | return 1; |
458 | | } |
459 | | #endif |
460 | | |
461 | | static int x942kdf_derive(void *vctx, unsigned char *key, size_t keylen, |
462 | | const OSSL_PARAM params[]) |
463 | 54 | { |
464 | 54 | KDF_X942 *ctx = (KDF_X942 *)vctx; |
465 | 54 | const EVP_MD *md; |
466 | 54 | int ret = 0; |
467 | 54 | unsigned char *ctr; |
468 | 54 | unsigned char *der = NULL; |
469 | 54 | size_t der_len = 0; |
470 | | |
471 | 54 | if (!ossl_prov_is_running() || !x942kdf_set_ctx_params(ctx, params)) |
472 | 0 | return 0; |
473 | | |
474 | | /* |
475 | | * These 2 options encode to the same field so only one of them should be |
476 | | * active at once. |
477 | | */ |
478 | 54 | if (ctx->use_keybits && ctx->supp_pubinfo != NULL) { |
479 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_PUBINFO); |
480 | 0 | return 0; |
481 | 0 | } |
482 | | /* |
483 | | * If the blob of acvp data is used then the individual info fields that it |
484 | | * replaces should not also be defined. |
485 | | */ |
486 | 54 | if (ctx->acvpinfo != NULL |
487 | 47 | && (ctx->partyuinfo != NULL |
488 | 45 | || ctx->partyvinfo != NULL |
489 | 45 | || ctx->supp_pubinfo != NULL |
490 | 45 | || ctx->supp_privinfo != NULL)) { |
491 | 2 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DATA); |
492 | 2 | return 0; |
493 | 2 | } |
494 | 52 | if (ctx->secret == NULL) { |
495 | 2 | ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_SECRET); |
496 | 2 | return 0; |
497 | 2 | } |
498 | 50 | md = ossl_prov_digest_md(&ctx->digest); |
499 | 50 | if (md == NULL) { |
500 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST); |
501 | 0 | return 0; |
502 | 0 | } |
503 | 50 | if (ctx->cek_oid == NULL || ctx->cek_oid_len == 0) { |
504 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_CEK_ALG); |
505 | 0 | return 0; |
506 | 0 | } |
507 | 50 | if (ctx->partyuinfo != NULL && ctx->partyuinfo_len >= X942KDF_MAX_INLEN) { |
508 | | /* |
509 | | * Note the ukm length MUST be 512 bits if it is used. |
510 | | * For backwards compatibility the old check is being done. |
511 | | */ |
512 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_UKM_LENGTH); |
513 | 0 | return 0; |
514 | 0 | } |
515 | | /* generate the otherinfo der */ |
516 | 50 | if (!x942_encode_otherinfo(ctx->use_keybits ? ctx->dkm_len : 0, |
517 | 50 | ctx->cek_oid, ctx->cek_oid_len, |
518 | 50 | ctx->acvpinfo, ctx->acvpinfo_len, |
519 | 50 | ctx->partyuinfo, ctx->partyuinfo_len, |
520 | 50 | ctx->partyvinfo, ctx->partyvinfo_len, |
521 | 50 | ctx->supp_pubinfo, ctx->supp_pubinfo_len, |
522 | 50 | ctx->supp_privinfo, ctx->supp_privinfo_len, |
523 | 50 | &der, &der_len, &ctr)) { |
524 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_BAD_ENCODING); |
525 | 0 | return 0; |
526 | 0 | } |
527 | 50 | ret = x942kdf_hash_kdm(md, ctx->secret, ctx->secret_len, |
528 | 50 | der, der_len, ctr, key, keylen); |
529 | 50 | OPENSSL_free(der); |
530 | 50 | return ret; |
531 | 50 | } |
532 | | |
533 | | /* clang-format off */ |
534 | | /* Machine generated by util/perl/OpenSSL/paramnames.pm */ |
535 | | #ifndef sshkdf_set_ctx_params_list |
536 | | static ossl_unused const OSSL_PARAM sshkdf_set_ctx_params_list[] = { |
537 | | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0), |
538 | | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_DIGEST, NULL, 0), |
539 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SECRET, NULL, 0), |
540 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_KEY, NULL, 0), |
541 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_UKM, NULL, 0), |
542 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_X942_ACVPINFO, NULL, 0), |
543 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_X942_PARTYUINFO, NULL, 0), |
544 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_X942_PARTYVINFO, NULL, 0), |
545 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_X942_SUPP_PUBINFO, NULL, 0), |
546 | | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_X942_SUPP_PRIVINFO, NULL, 0), |
547 | | OSSL_PARAM_int(OSSL_KDF_PARAM_X942_USE_KEYBITS, NULL), |
548 | | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_CEK_ALG, NULL, 0), |
549 | | # if defined(FIPS_MODULE) |
550 | | OSSL_PARAM_int(OSSL_KDF_PARAM_FIPS_KEY_CHECK, NULL), |
551 | | # endif |
552 | | OSSL_PARAM_END |
553 | | }; |
554 | | #endif |
555 | | |
556 | | #ifndef sshkdf_set_ctx_params_st |
557 | | struct sshkdf_set_ctx_params_st { |
558 | | OSSL_PARAM *acvp; |
559 | | OSSL_PARAM *cekalg; |
560 | | OSSL_PARAM *digest; |
561 | | OSSL_PARAM *engine; |
562 | | # if defined(FIPS_MODULE) |
563 | | OSSL_PARAM *ind_k; |
564 | | # endif |
565 | | OSSL_PARAM *kbits; |
566 | | OSSL_PARAM *priv; |
567 | | OSSL_PARAM *propq; |
568 | | OSSL_PARAM *pub; |
569 | | OSSL_PARAM *secret; |
570 | | OSSL_PARAM *uinfo; |
571 | | OSSL_PARAM *vinfo; |
572 | | }; |
573 | | #endif |
574 | | |
575 | | #ifndef sshkdf_set_ctx_params_decoder |
576 | | static ossl_unused int sshkdf_set_ctx_params_decoder |
577 | | (const OSSL_PARAM *p, struct sshkdf_set_ctx_params_st *r) |
578 | 5 | { |
579 | 5 | const char *s; |
580 | | |
581 | 5 | memset(r, 0, sizeof(*r)); |
582 | 5 | if (p != NULL) |
583 | 20 | for (; (s = p->key) != NULL; p++) |
584 | 20 | switch(s[0]) { |
585 | 0 | default: |
586 | 0 | break; |
587 | 0 | case 'a': |
588 | 0 | if (ossl_likely(strcmp("cvp-info", s + 1) == 0)) { |
589 | | /* OSSL_KDF_PARAM_X942_ACVPINFO */ |
590 | 0 | if (ossl_unlikely(r->acvp != NULL)) { |
591 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
592 | 0 | "param %s is repeated", s); |
593 | 0 | return 0; |
594 | 0 | } |
595 | 0 | r->acvp = (OSSL_PARAM *)p; |
596 | 0 | } |
597 | 0 | break; |
598 | 0 | case 'c': |
599 | 0 | if (ossl_likely(strcmp("ekalg", s + 1) == 0)) { |
600 | | /* OSSL_KDF_PARAM_CEK_ALG */ |
601 | 0 | if (ossl_unlikely(r->cekalg != NULL)) { |
602 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
603 | 0 | "param %s is repeated", s); |
604 | 0 | return 0; |
605 | 0 | } |
606 | 0 | r->cekalg = (OSSL_PARAM *)p; |
607 | 0 | } |
608 | 0 | break; |
609 | 5 | case 'd': |
610 | 5 | if (ossl_likely(strcmp("igest", s + 1) == 0)) { |
611 | | /* OSSL_KDF_PARAM_DIGEST */ |
612 | 5 | if (ossl_unlikely(r->digest != NULL)) { |
613 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
614 | 0 | "param %s is repeated", s); |
615 | 0 | return 0; |
616 | 0 | } |
617 | 5 | r->digest = (OSSL_PARAM *)p; |
618 | 5 | } |
619 | 5 | break; |
620 | 5 | case 'e': |
621 | 0 | if (ossl_likely(strcmp("ngine", s + 1) == 0)) { |
622 | | /* OSSL_ALG_PARAM_ENGINE */ |
623 | 0 | if (ossl_unlikely(r->engine != NULL)) { |
624 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
625 | 0 | "param %s is repeated", s); |
626 | 0 | return 0; |
627 | 0 | } |
628 | 0 | r->engine = (OSSL_PARAM *)p; |
629 | 0 | } |
630 | 0 | break; |
631 | 5 | case 'k': |
632 | 5 | switch(s[1]) { |
633 | 0 | default: |
634 | 0 | break; |
635 | 5 | case 'e': |
636 | 5 | switch(s[2]) { |
637 | 0 | default: |
638 | 0 | break; |
639 | 5 | case 'y': |
640 | 5 | switch(s[3]) { |
641 | 0 | default: |
642 | 0 | break; |
643 | 0 | case '-': |
644 | | # if defined(FIPS_MODULE) |
645 | | if (ossl_likely(strcmp("check", s + 4) == 0)) { |
646 | | /* OSSL_KDF_PARAM_FIPS_KEY_CHECK */ |
647 | | if (ossl_unlikely(r->ind_k != NULL)) { |
648 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
649 | | "param %s is repeated", s); |
650 | | return 0; |
651 | | } |
652 | | r->ind_k = (OSSL_PARAM *)p; |
653 | | } |
654 | | # endif |
655 | 0 | break; |
656 | 5 | case '\0': |
657 | 5 | if (ossl_unlikely(r->secret != NULL)) { |
658 | 5 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
659 | 5 | "param %s is repeated", s); |
660 | 5 | return 0; |
661 | 5 | } |
662 | 0 | r->secret = (OSSL_PARAM *)p; |
663 | 5 | } |
664 | 5 | } |
665 | 5 | } |
666 | 0 | break; |
667 | 5 | case 'p': |
668 | 5 | switch(s[1]) { |
669 | 0 | default: |
670 | 0 | break; |
671 | 0 | case 'a': |
672 | 0 | switch(s[2]) { |
673 | 0 | default: |
674 | 0 | break; |
675 | 0 | case 'r': |
676 | 0 | switch(s[3]) { |
677 | 0 | default: |
678 | 0 | break; |
679 | 0 | case 't': |
680 | 0 | switch(s[4]) { |
681 | 0 | default: |
682 | 0 | break; |
683 | 0 | case 'y': |
684 | 0 | switch(s[5]) { |
685 | 0 | default: |
686 | 0 | break; |
687 | 0 | case 'u': |
688 | 0 | if (ossl_likely(strcmp("-info", s + 6) == 0)) { |
689 | | /* OSSL_KDF_PARAM_X942_PARTYUINFO */ |
690 | 0 | if (ossl_unlikely(r->uinfo != NULL)) { |
691 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
692 | 0 | "param %s is repeated", s); |
693 | 0 | return 0; |
694 | 0 | } |
695 | 0 | r->uinfo = (OSSL_PARAM *)p; |
696 | 0 | } |
697 | 0 | break; |
698 | 0 | case 'v': |
699 | 0 | if (ossl_likely(strcmp("-info", s + 6) == 0)) { |
700 | | /* OSSL_KDF_PARAM_X942_PARTYVINFO */ |
701 | 0 | if (ossl_unlikely(r->vinfo != NULL)) { |
702 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
703 | 0 | "param %s is repeated", s); |
704 | 0 | return 0; |
705 | 0 | } |
706 | 0 | r->vinfo = (OSSL_PARAM *)p; |
707 | 0 | } |
708 | 0 | } |
709 | 0 | } |
710 | 0 | } |
711 | 0 | } |
712 | 0 | break; |
713 | 5 | case 'r': |
714 | 5 | if (ossl_likely(strcmp("operties", s + 2) == 0)) { |
715 | | /* OSSL_KDF_PARAM_PROPERTIES */ |
716 | 5 | if (ossl_unlikely(r->propq != NULL)) { |
717 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
718 | 0 | "param %s is repeated", s); |
719 | 0 | return 0; |
720 | 0 | } |
721 | 5 | r->propq = (OSSL_PARAM *)p; |
722 | 5 | } |
723 | 5 | } |
724 | 5 | break; |
725 | 5 | case 's': |
726 | 5 | switch(s[1]) { |
727 | 0 | default: |
728 | 0 | break; |
729 | 5 | case 'e': |
730 | 5 | if (ossl_likely(strcmp("cret", s + 2) == 0)) { |
731 | | /* OSSL_KDF_PARAM_SECRET */ |
732 | 5 | if (ossl_unlikely(r->secret != NULL)) { |
733 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
734 | 0 | "param %s is repeated", s); |
735 | 0 | return 0; |
736 | 0 | } |
737 | 5 | r->secret = (OSSL_PARAM *)p; |
738 | 5 | } |
739 | 5 | break; |
740 | 5 | case 'u': |
741 | 0 | switch(s[2]) { |
742 | 0 | default: |
743 | 0 | break; |
744 | 0 | case 'p': |
745 | 0 | switch(s[3]) { |
746 | 0 | default: |
747 | 0 | break; |
748 | 0 | case 'p': |
749 | 0 | switch(s[4]) { |
750 | 0 | default: |
751 | 0 | break; |
752 | 0 | case '-': |
753 | 0 | switch(s[5]) { |
754 | 0 | default: |
755 | 0 | break; |
756 | 0 | case 'p': |
757 | 0 | switch(s[6]) { |
758 | 0 | default: |
759 | 0 | break; |
760 | 0 | case 'r': |
761 | 0 | if (ossl_likely(strcmp("ivinfo", s + 7) == 0)) { |
762 | | /* OSSL_KDF_PARAM_X942_SUPP_PRIVINFO */ |
763 | 0 | if (ossl_unlikely(r->priv != NULL)) { |
764 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
765 | 0 | "param %s is repeated", s); |
766 | 0 | return 0; |
767 | 0 | } |
768 | 0 | r->priv = (OSSL_PARAM *)p; |
769 | 0 | } |
770 | 0 | break; |
771 | 0 | case 'u': |
772 | 0 | if (ossl_likely(strcmp("binfo", s + 7) == 0)) { |
773 | | /* OSSL_KDF_PARAM_X942_SUPP_PUBINFO */ |
774 | 0 | if (ossl_unlikely(r->pub != NULL)) { |
775 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
776 | 0 | "param %s is repeated", s); |
777 | 0 | return 0; |
778 | 0 | } |
779 | 0 | r->pub = (OSSL_PARAM *)p; |
780 | 0 | } |
781 | 0 | } |
782 | 0 | } |
783 | 0 | } |
784 | 0 | } |
785 | 0 | } |
786 | 5 | } |
787 | 5 | break; |
788 | 5 | case 'u': |
789 | 0 | switch(s[1]) { |
790 | 0 | default: |
791 | 0 | break; |
792 | 0 | case 'k': |
793 | 0 | if (ossl_likely(strcmp("m", s + 2) == 0)) { |
794 | | /* OSSL_KDF_PARAM_UKM */ |
795 | 0 | if (ossl_unlikely(r->uinfo != NULL)) { |
796 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
797 | 0 | "param %s is repeated", s); |
798 | 0 | return 0; |
799 | 0 | } |
800 | 0 | r->uinfo = (OSSL_PARAM *)p; |
801 | 0 | } |
802 | 0 | break; |
803 | 0 | case 's': |
804 | 0 | if (ossl_likely(strcmp("e-keybits", s + 2) == 0)) { |
805 | | /* OSSL_KDF_PARAM_X942_USE_KEYBITS */ |
806 | 0 | if (ossl_unlikely(r->kbits != NULL)) { |
807 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
808 | 0 | "param %s is repeated", s); |
809 | 0 | return 0; |
810 | 0 | } |
811 | 0 | r->kbits = (OSSL_PARAM *)p; |
812 | 0 | } |
813 | 0 | } |
814 | 20 | } |
815 | 0 | return 1; |
816 | 5 | } |
817 | | #endif |
818 | | /* End of machine generated */ |
819 | | /* clang-format on */ |
820 | | |
821 | | static int x942kdf_set_ctx_params(void *vctx, const OSSL_PARAM params[]) |
822 | 19 | { |
823 | 19 | struct sshkdf_set_ctx_params_st p; |
824 | 19 | KDF_X942 *ctx = vctx; |
825 | 19 | OSSL_LIB_CTX *provctx; |
826 | 19 | const char *cekalg, *propq = NULL; |
827 | 19 | const EVP_MD *md; |
828 | 19 | size_t id; |
829 | | |
830 | 19 | if (ctx == NULL || !sshkdf_set_ctx_params_decoder(params, &p)) |
831 | 19 | return 0; |
832 | | |
833 | 0 | provctx = PROV_LIBCTX_OF(ctx->provctx); |
834 | |
|
835 | 0 | if (!OSSL_FIPS_IND_SET_CTX_FROM_PARAM(ctx, OSSL_FIPS_IND_SETTABLE0, p.ind_k)) |
836 | 0 | return 0; |
837 | | |
838 | 0 | if (p.digest != NULL) { |
839 | 0 | if (!ossl_prov_digest_load(&ctx->digest, p.digest, |
840 | 0 | p.propq, p.engine, provctx)) |
841 | 0 | return 0; |
842 | 0 | md = ossl_prov_digest_md(&ctx->digest); |
843 | 0 | if (EVP_MD_xof(md)) { |
844 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_XOF_DIGESTS_NOT_ALLOWED); |
845 | 0 | return 0; |
846 | 0 | } |
847 | 0 | } |
848 | | |
849 | 0 | if (p.secret != NULL) { |
850 | 0 | if (!x942kdf_set_buffer(&ctx->secret, &ctx->secret_len, p.secret)) |
851 | 0 | return 0; |
852 | | #ifdef FIPS_MODULE |
853 | | if (!fips_x942kdf_key_check_passed(ctx)) |
854 | | return 0; |
855 | | #endif |
856 | 0 | } |
857 | | |
858 | 0 | if (p.acvp != NULL |
859 | 0 | && !x942kdf_set_buffer(&ctx->acvpinfo, &ctx->acvpinfo_len, p.acvp)) |
860 | 0 | return 0; |
861 | | |
862 | 0 | if (p.uinfo != NULL |
863 | 0 | && !x942kdf_set_buffer(&ctx->partyuinfo, &ctx->partyuinfo_len, p.uinfo)) |
864 | 0 | return 0; |
865 | | |
866 | 0 | if (p.vinfo != NULL |
867 | 0 | && !x942kdf_set_buffer(&ctx->partyvinfo, &ctx->partyvinfo_len, p.vinfo)) |
868 | 0 | return 0; |
869 | | |
870 | 0 | if (p.kbits != NULL && !OSSL_PARAM_get_int(p.kbits, &ctx->use_keybits)) |
871 | 0 | return 0; |
872 | | |
873 | 0 | if (p.pub != NULL) { |
874 | 0 | if (!x942kdf_set_buffer(&ctx->supp_pubinfo, &ctx->supp_pubinfo_len, p.pub)) |
875 | 0 | return 0; |
876 | 0 | ctx->use_keybits = 0; |
877 | 0 | } |
878 | | |
879 | 0 | if (p.priv != NULL |
880 | 0 | && !x942kdf_set_buffer(&ctx->supp_privinfo, &ctx->supp_privinfo_len, p.priv)) |
881 | 0 | return 0; |
882 | | |
883 | 0 | if (p.cekalg != NULL) { |
884 | 0 | if (!OSSL_PARAM_get_utf8_string_ptr(p.cekalg, &cekalg)) |
885 | 0 | return 0; |
886 | 0 | if (p.propq != NULL && !OSSL_PARAM_get_utf8_string_ptr(p.propq, &propq)) |
887 | 0 | return 0; |
888 | 0 | if (find_alg_id(provctx, cekalg, propq, &id) == 0) |
889 | 0 | return 0; |
890 | 0 | ctx->cek_oid = kek_algs[id].oid; |
891 | 0 | ctx->cek_oid_len = kek_algs[id].oid_len; |
892 | 0 | ctx->dkm_len = kek_algs[id].keklen; |
893 | 0 | } |
894 | 0 | return 1; |
895 | 0 | } |
896 | | |
897 | | static const OSSL_PARAM *x942kdf_settable_ctx_params(ossl_unused void *ctx, |
898 | | ossl_unused void *provctx) |
899 | 149 | { |
900 | 149 | return sshkdf_set_ctx_params_list; |
901 | 149 | } |
902 | | |
903 | | /* clang-format off */ |
904 | | /* Machine generated by util/perl/OpenSSL/paramnames.pm */ |
905 | | #ifndef sshkdf_get_ctx_params_list |
906 | | static ossl_unused const OSSL_PARAM sshkdf_get_ctx_params_list[] = { |
907 | | OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL), |
908 | | # if defined(FIPS_MODULE) |
909 | | OSSL_PARAM_int(OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR, NULL), |
910 | | # endif |
911 | | OSSL_PARAM_END |
912 | | }; |
913 | | #endif |
914 | | |
915 | | #ifndef sshkdf_get_ctx_params_st |
916 | | struct sshkdf_get_ctx_params_st { |
917 | | # if defined(FIPS_MODULE) |
918 | | OSSL_PARAM *ind; |
919 | | # endif |
920 | | OSSL_PARAM *size; |
921 | | }; |
922 | | #endif |
923 | | |
924 | | #ifndef sshkdf_get_ctx_params_decoder |
925 | | static ossl_unused int sshkdf_get_ctx_params_decoder |
926 | | (const OSSL_PARAM *p, struct sshkdf_get_ctx_params_st *r) |
927 | 0 | { |
928 | 0 | const char *s; |
929 | |
|
930 | 0 | memset(r, 0, sizeof(*r)); |
931 | 0 | if (p != NULL) |
932 | 0 | for (; (s = p->key) != NULL; p++) |
933 | 0 | switch(s[0]) { |
934 | 0 | default: |
935 | 0 | break; |
936 | 0 | case 'f': |
937 | | # if defined(FIPS_MODULE) |
938 | | if (ossl_likely(strcmp("ips-indicator", s + 1) == 0)) { |
939 | | /* OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR */ |
940 | | if (ossl_unlikely(r->ind != NULL)) { |
941 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
942 | | "param %s is repeated", s); |
943 | | return 0; |
944 | | } |
945 | | r->ind = (OSSL_PARAM *)p; |
946 | | } |
947 | | # endif |
948 | 0 | break; |
949 | 0 | case 's': |
950 | 0 | if (ossl_likely(strcmp("ize", s + 1) == 0)) { |
951 | | /* OSSL_KDF_PARAM_SIZE */ |
952 | 0 | if (ossl_unlikely(r->size != NULL)) { |
953 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
954 | 0 | "param %s is repeated", s); |
955 | 0 | return 0; |
956 | 0 | } |
957 | 0 | r->size = (OSSL_PARAM *)p; |
958 | 0 | } |
959 | 0 | } |
960 | 0 | return 1; |
961 | 0 | } |
962 | | #endif |
963 | | /* End of machine generated */ |
964 | | /* clang-format on */ |
965 | | |
966 | | static int x942kdf_get_ctx_params(void *vctx, OSSL_PARAM params[]) |
967 | 0 | { |
968 | 0 | KDF_X942 *ctx = (KDF_X942 *)vctx; |
969 | 0 | struct sshkdf_get_ctx_params_st p; |
970 | |
|
971 | 0 | if (ctx == NULL || !sshkdf_get_ctx_params_decoder(params, &p)) |
972 | 0 | return 0; |
973 | | |
974 | 0 | if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, x942kdf_size(ctx))) |
975 | 0 | return 0; |
976 | | |
977 | 0 | if (!OSSL_FIPS_IND_GET_CTX_FROM_PARAM(ctx, p.ind)) |
978 | 0 | return 0; |
979 | 0 | return 1; |
980 | 0 | } |
981 | | |
982 | | static const OSSL_PARAM *x942kdf_gettable_ctx_params(ossl_unused void *ctx, |
983 | | ossl_unused void *provctx) |
984 | 0 | { |
985 | 0 | return sshkdf_get_ctx_params_list; |
986 | 0 | } |
987 | | |
988 | | const OSSL_DISPATCH ossl_kdf_x942_kdf_functions[] = { |
989 | | { OSSL_FUNC_KDF_NEWCTX, (void (*)(void))x942kdf_new }, |
990 | | { OSSL_FUNC_KDF_DUPCTX, (void (*)(void))x942kdf_dup }, |
991 | | { OSSL_FUNC_KDF_FREECTX, (void (*)(void))x942kdf_free }, |
992 | | { OSSL_FUNC_KDF_RESET, (void (*)(void))x942kdf_reset }, |
993 | | { OSSL_FUNC_KDF_DERIVE, (void (*)(void))x942kdf_derive }, |
994 | | { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS, |
995 | | (void (*)(void))x942kdf_settable_ctx_params }, |
996 | | { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void (*)(void))x942kdf_set_ctx_params }, |
997 | | { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS, |
998 | | (void (*)(void))x942kdf_gettable_ctx_params }, |
999 | | { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void (*)(void))x942kdf_get_ctx_params }, |
1000 | | OSSL_DISPATCH_END |
1001 | | }; |