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