]>
Commit | Line | Data |
---|---|---|
a39bc440 | 1 | /* |
fecb3aae | 2 | * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved. |
a39bc440 RH |
3 | * Copyright 2019 Red Hat, Inc. |
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 | * This implements https://csrc.nist.gov/publications/detail/sp/800-108/final | |
f6dead1b RH |
13 | * section 5.1 ("counter mode") and section 5.2 ("feedback mode") in both HMAC |
14 | * and CMAC. That document does not name the KDFs it defines; the name is | |
15 | * derived from | |
a39bc440 RH |
16 | * https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/Key-Derivation |
17 | * | |
f6dead1b RH |
18 | * Note that section 5.3 ("double-pipeline mode") is not implemented, though |
19 | * it would be possible to do so in the future. | |
a39bc440 RH |
20 | * |
21 | * These versions all assume the counter is used. It would be relatively | |
22 | * straightforward to expose a configuration handle should the need arise. | |
23 | * | |
24 | * Variable names attempt to match those of SP800-108. | |
25 | */ | |
26 | ||
27 | #include <stdarg.h> | |
28 | #include <stdlib.h> | |
29 | #include <string.h> | |
30 | ||
31 | #include <openssl/core_names.h> | |
32 | #include <openssl/evp.h> | |
33 | #include <openssl/hmac.h> | |
34 | #include <openssl/kdf.h> | |
35 | #include <openssl/params.h> | |
2741128e | 36 | #include <openssl/proverr.h> |
a39bc440 RH |
37 | |
38 | #include "internal/cryptlib.h" | |
25f2138b | 39 | #include "crypto/evp.h" |
a39bc440 | 40 | #include "internal/numbers.h" |
e23d850f | 41 | #include "internal/endian.h" |
af3e7e1b | 42 | #include "prov/implementations.h" |
ddd21319 RL |
43 | #include "prov/provider_ctx.h" |
44 | #include "prov/provider_util.h" | |
2b9e4e95 | 45 | #include "prov/providercommon.h" |
a39bc440 | 46 | |
d5f9166b | 47 | #include "internal/e_os.h" |
345b42be | 48 | #include "internal/params.h" |
a39bc440 | 49 | |
f4f77c2d | 50 | #define ossl_min(a, b) ((a) < (b)) ? (a) : (b) |
a39bc440 | 51 | |
f6dead1b RH |
52 | typedef enum { |
53 | COUNTER = 0, | |
54 | FEEDBACK | |
55 | } kbkdf_mode; | |
56 | ||
a39bc440 RH |
57 | /* Our context structure. */ |
58 | typedef struct { | |
59 | void *provctx; | |
f6dead1b | 60 | kbkdf_mode mode; |
a39bc440 RH |
61 | EVP_MAC_CTX *ctx_init; |
62 | ||
63 | /* Names are lowercased versions of those found in SP800-108. */ | |
0e9a265e | 64 | int r; |
a39bc440 RH |
65 | unsigned char *ki; |
66 | size_t ki_len; | |
67 | unsigned char *label; | |
68 | size_t label_len; | |
69 | unsigned char *context; | |
70 | size_t context_len; | |
f6dead1b RH |
71 | unsigned char *iv; |
72 | size_t iv_len; | |
4757a347 | 73 | int use_l; |
211c47ca | 74 | int is_kmac; |
4757a347 | 75 | int use_separator; |
a39bc440 RH |
76 | } KBKDF; |
77 | ||
78 | /* Definitions needed for typechecking. */ | |
363b1e5d | 79 | static OSSL_FUNC_kdf_newctx_fn kbkdf_new; |
344d3b32 | 80 | static OSSL_FUNC_kdf_dupctx_fn kbkdf_dup; |
363b1e5d DMSP |
81 | static OSSL_FUNC_kdf_freectx_fn kbkdf_free; |
82 | static OSSL_FUNC_kdf_reset_fn kbkdf_reset; | |
83 | static OSSL_FUNC_kdf_derive_fn kbkdf_derive; | |
84 | static OSSL_FUNC_kdf_settable_ctx_params_fn kbkdf_settable_ctx_params; | |
85 | static OSSL_FUNC_kdf_set_ctx_params_fn kbkdf_set_ctx_params; | |
af5e1e85 P |
86 | static OSSL_FUNC_kdf_gettable_ctx_params_fn kbkdf_gettable_ctx_params; |
87 | static OSSL_FUNC_kdf_get_ctx_params_fn kbkdf_get_ctx_params; | |
a39bc440 RH |
88 | |
89 | /* Not all platforms have htobe32(). */ | |
90 | static uint32_t be32(uint32_t host) | |
91 | { | |
92 | uint32_t big = 0; | |
e23d850f | 93 | DECLARE_IS_ENDIAN; |
a39bc440 | 94 | |
e23d850f | 95 | if (!IS_LITTLE_ENDIAN) |
a39bc440 RH |
96 | return host; |
97 | ||
98 | big |= (host & 0xff000000) >> 24; | |
99 | big |= (host & 0x00ff0000) >> 8; | |
100 | big |= (host & 0x0000ff00) << 8; | |
101 | big |= (host & 0x000000ff) << 24; | |
102 | return big; | |
103 | } | |
104 | ||
4757a347 SL |
105 | static void init(KBKDF *ctx) |
106 | { | |
0e9a265e | 107 | ctx->r = 32; |
4757a347 SL |
108 | ctx->use_l = 1; |
109 | ctx->use_separator = 1; | |
211c47ca | 110 | ctx->is_kmac = 0; |
4757a347 SL |
111 | } |
112 | ||
a39bc440 RH |
113 | static void *kbkdf_new(void *provctx) |
114 | { | |
115 | KBKDF *ctx; | |
116 | ||
2b9e4e95 P |
117 | if (!ossl_prov_is_running()) |
118 | return NULL; | |
119 | ||
a39bc440 | 120 | ctx = OPENSSL_zalloc(sizeof(*ctx)); |
e077455e | 121 | if (ctx == NULL) |
a39bc440 | 122 | return NULL; |
a39bc440 RH |
123 | |
124 | ctx->provctx = provctx; | |
4757a347 | 125 | init(ctx); |
a39bc440 RH |
126 | return ctx; |
127 | } | |
128 | ||
129 | static void kbkdf_free(void *vctx) | |
130 | { | |
131 | KBKDF *ctx = (KBKDF *)vctx; | |
132 | ||
3c659415 P |
133 | if (ctx != NULL) { |
134 | kbkdf_reset(ctx); | |
135 | OPENSSL_free(ctx); | |
136 | } | |
a39bc440 RH |
137 | } |
138 | ||
139 | static void kbkdf_reset(void *vctx) | |
140 | { | |
141 | KBKDF *ctx = (KBKDF *)vctx; | |
0577959c | 142 | void *provctx = ctx->provctx; |
a39bc440 | 143 | |
865adf97 | 144 | EVP_MAC_CTX_free(ctx->ctx_init); |
a39bc440 RH |
145 | OPENSSL_clear_free(ctx->context, ctx->context_len); |
146 | OPENSSL_clear_free(ctx->label, ctx->label_len); | |
147 | OPENSSL_clear_free(ctx->ki, ctx->ki_len); | |
f6dead1b | 148 | OPENSSL_clear_free(ctx->iv, ctx->iv_len); |
a39bc440 | 149 | memset(ctx, 0, sizeof(*ctx)); |
0577959c | 150 | ctx->provctx = provctx; |
4757a347 | 151 | init(ctx); |
a39bc440 RH |
152 | } |
153 | ||
d54c52c2 P |
154 | static void *kbkdf_dup(void *vctx) |
155 | { | |
156 | const KBKDF *src = (const KBKDF *)vctx; | |
157 | KBKDF *dest; | |
158 | ||
159 | dest = kbkdf_new(src->provctx); | |
160 | if (dest != NULL) { | |
161 | dest->ctx_init = EVP_MAC_CTX_dup(src->ctx_init); | |
162 | if (dest->ctx_init == NULL | |
163 | || !ossl_prov_memdup(src->ki, src->ki_len, | |
164 | &dest->ki, &dest->ki_len) | |
165 | || !ossl_prov_memdup(src->label, src->label_len, | |
166 | &dest->label, &dest->label_len) | |
167 | || !ossl_prov_memdup(src->context, src->context_len, | |
168 | &dest->context, &dest->context_len) | |
169 | || !ossl_prov_memdup(src->iv, src->iv_len, | |
170 | &dest->iv, &dest->iv_len)) | |
171 | goto err; | |
172 | dest->mode = src->mode; | |
173 | dest->r = src->r; | |
174 | dest->use_l = src->use_l; | |
175 | dest->use_separator = src->use_separator; | |
211c47ca | 176 | dest->is_kmac = src->is_kmac; |
d54c52c2 P |
177 | } |
178 | return dest; | |
179 | ||
180 | err: | |
181 | kbkdf_free(dest); | |
182 | return NULL; | |
183 | } | |
184 | ||
f6dead1b RH |
185 | /* SP800-108 section 5.1 or section 5.2 depending on mode. */ |
186 | static int derive(EVP_MAC_CTX *ctx_init, kbkdf_mode mode, unsigned char *iv, | |
187 | size_t iv_len, unsigned char *label, size_t label_len, | |
188 | unsigned char *context, size_t context_len, | |
4757a347 | 189 | unsigned char *k_i, size_t h, uint32_t l, int has_separator, |
0e9a265e | 190 | unsigned char *ko, size_t ko_len, int r) |
a39bc440 RH |
191 | { |
192 | int ret = 0; | |
193 | EVP_MAC_CTX *ctx = NULL; | |
f6dead1b | 194 | size_t written = 0, to_write, k_i_len = iv_len; |
a39bc440 RH |
195 | const unsigned char zero = 0; |
196 | uint32_t counter, i; | |
4757a347 SL |
197 | /* |
198 | * From SP800-108: | |
199 | * The fixed input data is a concatenation of a Label, | |
200 | * a separation indicator 0x00, the Context, and L. | |
201 | * One or more of these fixed input data fields may be omitted. | |
202 | * | |
203 | * has_separator == 0 means that the separator is omitted. | |
204 | * Passing a value of l == 0 means that L is omitted. | |
205 | * The Context and L are omitted automatically if a NULL buffer is passed. | |
206 | */ | |
207 | int has_l = (l != 0); | |
a39bc440 | 208 | |
f6dead1b RH |
209 | /* Setup K(0) for feedback mode. */ |
210 | if (iv_len > 0) | |
211 | memcpy(k_i, iv, iv_len); | |
212 | ||
a39bc440 RH |
213 | for (counter = 1; written < ko_len; counter++) { |
214 | i = be32(counter); | |
215 | ||
865adf97 | 216 | ctx = EVP_MAC_CTX_dup(ctx_init); |
a39bc440 RH |
217 | if (ctx == NULL) |
218 | goto done; | |
219 | ||
f6dead1b RH |
220 | /* Perform feedback, if appropriate. */ |
221 | if (mode == FEEDBACK && !EVP_MAC_update(ctx, k_i, k_i_len)) | |
222 | goto done; | |
223 | ||
0e9a265e | 224 | if (!EVP_MAC_update(ctx, 4 - (r / 8) + (unsigned char *)&i, r / 8) |
a39bc440 | 225 | || !EVP_MAC_update(ctx, label, label_len) |
4757a347 | 226 | || (has_separator && !EVP_MAC_update(ctx, &zero, 1)) |
a39bc440 | 227 | || !EVP_MAC_update(ctx, context, context_len) |
4757a347 | 228 | || (has_l && !EVP_MAC_update(ctx, (unsigned char *)&l, 4)) |
a39bc440 RH |
229 | || !EVP_MAC_final(ctx, k_i, NULL, h)) |
230 | goto done; | |
231 | ||
232 | to_write = ko_len - written; | |
f4f77c2d | 233 | memcpy(ko + written, k_i, ossl_min(to_write, h)); |
a39bc440 RH |
234 | written += h; |
235 | ||
f6dead1b | 236 | k_i_len = h; |
865adf97 | 237 | EVP_MAC_CTX_free(ctx); |
a39bc440 RH |
238 | ctx = NULL; |
239 | } | |
240 | ||
241 | ret = 1; | |
242 | done: | |
865adf97 | 243 | EVP_MAC_CTX_free(ctx); |
a39bc440 RH |
244 | return ret; |
245 | } | |
246 | ||
211c47ca | 247 | /* This must be run before the key is set */ |
248 | static int kmac_init(EVP_MAC_CTX *ctx, const unsigned char *custom, size_t customlen) | |
249 | { | |
250 | OSSL_PARAM params[2]; | |
251 | ||
252 | if (custom == NULL || customlen == 0) | |
253 | return 1; | |
254 | params[0] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_CUSTOM, | |
255 | (void *)custom, customlen); | |
256 | params[1] = OSSL_PARAM_construct_end(); | |
257 | return EVP_MAC_CTX_set_params(ctx, params) > 0; | |
258 | } | |
259 | ||
260 | static int kmac_derive(EVP_MAC_CTX *ctx, unsigned char *out, size_t outlen, | |
261 | const unsigned char *context, size_t contextlen) | |
262 | { | |
263 | OSSL_PARAM params[2]; | |
264 | ||
265 | params[0] = OSSL_PARAM_construct_size_t(OSSL_MAC_PARAM_SIZE, &outlen); | |
266 | params[1] = OSSL_PARAM_construct_end(); | |
267 | return EVP_MAC_CTX_set_params(ctx, params) > 0 | |
268 | && EVP_MAC_update(ctx, context, contextlen) | |
269 | && EVP_MAC_final(ctx, out, NULL, outlen); | |
270 | } | |
271 | ||
3469b388 P |
272 | static int kbkdf_derive(void *vctx, unsigned char *key, size_t keylen, |
273 | const OSSL_PARAM params[]) | |
a39bc440 RH |
274 | { |
275 | KBKDF *ctx = (KBKDF *)vctx; | |
276 | int ret = 0; | |
277 | unsigned char *k_i = NULL; | |
4757a347 | 278 | uint32_t l = 0; |
a39bc440 | 279 | size_t h = 0; |
0e9a265e | 280 | uint64_t counter_max; |
a39bc440 | 281 | |
3469b388 | 282 | if (!ossl_prov_is_running() || !kbkdf_set_ctx_params(ctx, params)) |
2b9e4e95 P |
283 | return 0; |
284 | ||
f6dead1b RH |
285 | /* label, context, and iv are permitted to be empty. Check everything |
286 | * else. */ | |
a39bc440 RH |
287 | if (ctx->ctx_init == NULL) { |
288 | if (ctx->ki_len == 0 || ctx->ki == NULL) { | |
289 | ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET); | |
290 | return 0; | |
291 | } | |
f6dead1b RH |
292 | /* Could either be missing MAC or missing message digest or missing |
293 | * cipher - arbitrarily, I pick this one. */ | |
a39bc440 RH |
294 | ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MAC); |
295 | return 0; | |
296 | } | |
297 | ||
1cae59d1 JS |
298 | /* Fail if the output length is zero */ |
299 | if (keylen == 0) { | |
300 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); | |
301 | return 0; | |
302 | } | |
303 | ||
211c47ca | 304 | if (ctx->is_kmac) { |
305 | ret = kmac_derive(ctx->ctx_init, key, keylen, | |
306 | ctx->context, ctx->context_len); | |
307 | goto done; | |
308 | } | |
309 | ||
90a2576b | 310 | h = EVP_MAC_CTX_get_mac_size(ctx->ctx_init); |
a39bc440 RH |
311 | if (h == 0) |
312 | goto done; | |
211c47ca | 313 | |
f6dead1b RH |
314 | if (ctx->iv_len != 0 && ctx->iv_len != h) { |
315 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_SEED_LENGTH); | |
316 | goto done; | |
317 | } | |
a39bc440 | 318 | |
0e9a265e PU |
319 | if (ctx->mode == COUNTER) { |
320 | /* Fail if keylen is too large for r */ | |
321 | counter_max = (uint64_t)1 << (uint64_t)ctx->r; | |
322 | if ((uint64_t)(keylen / h) >= counter_max) { | |
323 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); | |
324 | goto done; | |
325 | } | |
326 | } | |
327 | ||
4757a347 SL |
328 | if (ctx->use_l != 0) |
329 | l = be32(keylen * 8); | |
330 | ||
a39bc440 RH |
331 | k_i = OPENSSL_zalloc(h); |
332 | if (k_i == NULL) | |
333 | goto done; | |
334 | ||
f6dead1b RH |
335 | ret = derive(ctx->ctx_init, ctx->mode, ctx->iv, ctx->iv_len, ctx->label, |
336 | ctx->label_len, ctx->context, ctx->context_len, k_i, h, l, | |
0e9a265e | 337 | ctx->use_separator, key, keylen, ctx->r); |
a39bc440 RH |
338 | done: |
339 | if (ret != 1) | |
340 | OPENSSL_cleanse(key, keylen); | |
341 | OPENSSL_clear_free(k_i, h); | |
342 | return ret; | |
343 | } | |
344 | ||
a39bc440 RH |
345 | static int kbkdf_set_ctx_params(void *vctx, const OSSL_PARAM params[]) |
346 | { | |
347 | KBKDF *ctx = (KBKDF *)vctx; | |
a829b735 | 348 | OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx); |
a39bc440 | 349 | const OSSL_PARAM *p; |
a39bc440 | 350 | |
c983a0e5 P |
351 | if (params == NULL) |
352 | return 1; | |
353 | ||
a39bc440 RH |
354 | if (!ossl_prov_macctx_load_from_params(&ctx->ctx_init, params, NULL, |
355 | NULL, NULL, libctx)) | |
356 | return 0; | |
211c47ca | 357 | else if (ctx->ctx_init != NULL) { |
358 | if (EVP_MAC_is_a(EVP_MAC_CTX_get0_mac(ctx->ctx_init), | |
359 | OSSL_MAC_NAME_KMAC128) | |
360 | || EVP_MAC_is_a(EVP_MAC_CTX_get0_mac(ctx->ctx_init), | |
361 | OSSL_MAC_NAME_KMAC256)) { | |
362 | ctx->is_kmac = 1; | |
363 | } else if (!EVP_MAC_is_a(EVP_MAC_CTX_get0_mac(ctx->ctx_init), | |
364 | OSSL_MAC_NAME_HMAC) | |
365 | && !EVP_MAC_is_a(EVP_MAC_CTX_get0_mac(ctx->ctx_init), | |
366 | OSSL_MAC_NAME_CMAC)) { | |
367 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_MAC); | |
368 | return 0; | |
369 | } | |
a39bc440 RH |
370 | } |
371 | ||
f6dead1b | 372 | p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_MODE); |
fba140c7 DB |
373 | if (p != NULL |
374 | && OPENSSL_strncasecmp("counter", p->data, p->data_size) == 0) { | |
f6dead1b RH |
375 | ctx->mode = COUNTER; |
376 | } else if (p != NULL | |
fba140c7 | 377 | && OPENSSL_strncasecmp("feedback", p->data, p->data_size) == 0) { |
f6dead1b RH |
378 | ctx->mode = FEEDBACK; |
379 | } else if (p != NULL) { | |
380 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_MODE); | |
381 | return 0; | |
382 | } | |
383 | ||
345b42be P |
384 | if (ossl_param_get1_octet_string(params, OSSL_KDF_PARAM_KEY, |
385 | &ctx->ki, &ctx->ki_len) == 0) | |
386 | return 0; | |
a39bc440 | 387 | |
345b42be P |
388 | if (ossl_param_get1_octet_string(params, OSSL_KDF_PARAM_SALT, |
389 | &ctx->label, &ctx->label_len) == 0) | |
390 | return 0; | |
a39bc440 | 391 | |
345b42be P |
392 | if (ossl_param_get1_concat_octet_string(params, OSSL_KDF_PARAM_INFO, |
393 | &ctx->context, &ctx->context_len, | |
394 | 0) == 0) | |
a39bc440 RH |
395 | return 0; |
396 | ||
345b42be P |
397 | if (ossl_param_get1_octet_string(params, OSSL_KDF_PARAM_SEED, |
398 | &ctx->iv, &ctx->iv_len) == 0) | |
399 | return 0; | |
f6dead1b | 400 | |
4757a347 SL |
401 | p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_KBKDF_USE_L); |
402 | if (p != NULL && !OSSL_PARAM_get_int(p, &ctx->use_l)) | |
403 | return 0; | |
404 | ||
0e9a265e PU |
405 | p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_KBKDF_R); |
406 | if (p != NULL) { | |
407 | int new_r = 0; | |
408 | ||
409 | if (!OSSL_PARAM_get_int(p, &new_r)) | |
410 | return 0; | |
411 | if (new_r != 8 && new_r != 16 && new_r != 24 && new_r != 32) | |
412 | return 0; | |
413 | ctx->r = new_r; | |
414 | } | |
415 | ||
4757a347 SL |
416 | p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_KBKDF_USE_SEPARATOR); |
417 | if (p != NULL && !OSSL_PARAM_get_int(p, &ctx->use_separator)) | |
418 | return 0; | |
419 | ||
a39bc440 | 420 | /* Set up digest context, if we can. */ |
211c47ca | 421 | if (ctx->ctx_init != NULL && ctx->ki_len != 0) { |
422 | if ((ctx->is_kmac && !kmac_init(ctx->ctx_init, ctx->label, ctx->label_len)) | |
423 | || !EVP_MAC_init(ctx->ctx_init, ctx->ki, ctx->ki_len, NULL)) | |
a39bc440 | 424 | return 0; |
211c47ca | 425 | } |
a39bc440 RH |
426 | return 1; |
427 | } | |
428 | ||
1e8e5c60 P |
429 | static const OSSL_PARAM *kbkdf_settable_ctx_params(ossl_unused void *ctx, |
430 | ossl_unused void *provctx) | |
a39bc440 RH |
431 | { |
432 | static const OSSL_PARAM known_settable_ctx_params[] = { | |
433 | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_INFO, NULL, 0), | |
434 | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SALT, NULL, 0), | |
435 | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_KEY, NULL, 0), | |
f6dead1b | 436 | OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SEED, NULL, 0), |
a39bc440 | 437 | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_DIGEST, NULL, 0), |
f6dead1b | 438 | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_CIPHER, NULL, 0), |
a39bc440 | 439 | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_MAC, NULL, 0), |
f6dead1b | 440 | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_MODE, NULL, 0), |
a39bc440 | 441 | OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0), |
4757a347 SL |
442 | OSSL_PARAM_int(OSSL_KDF_PARAM_KBKDF_USE_L, NULL), |
443 | OSSL_PARAM_int(OSSL_KDF_PARAM_KBKDF_USE_SEPARATOR, NULL), | |
0e9a265e | 444 | OSSL_PARAM_int(OSSL_KDF_PARAM_KBKDF_R, NULL), |
a39bc440 RH |
445 | OSSL_PARAM_END, |
446 | }; | |
447 | return known_settable_ctx_params; | |
448 | } | |
449 | ||
450 | static int kbkdf_get_ctx_params(void *vctx, OSSL_PARAM params[]) | |
451 | { | |
452 | OSSL_PARAM *p; | |
453 | ||
454 | p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE); | |
455 | if (p == NULL) | |
456 | return -2; | |
457 | ||
458 | /* KBKDF can produce results as large as you like. */ | |
459 | return OSSL_PARAM_set_size_t(p, SIZE_MAX); | |
460 | } | |
461 | ||
1e8e5c60 P |
462 | static const OSSL_PARAM *kbkdf_gettable_ctx_params(ossl_unused void *ctx, |
463 | ossl_unused void *provctx) | |
a39bc440 RH |
464 | { |
465 | static const OSSL_PARAM known_gettable_ctx_params[] = | |
466 | { OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL), OSSL_PARAM_END }; | |
467 | return known_gettable_ctx_params; | |
468 | } | |
469 | ||
1be63951 | 470 | const OSSL_DISPATCH ossl_kdf_kbkdf_functions[] = { |
a39bc440 | 471 | { OSSL_FUNC_KDF_NEWCTX, (void(*)(void))kbkdf_new }, |
d54c52c2 | 472 | { OSSL_FUNC_KDF_DUPCTX, (void(*)(void))kbkdf_dup }, |
a39bc440 RH |
473 | { OSSL_FUNC_KDF_FREECTX, (void(*)(void))kbkdf_free }, |
474 | { OSSL_FUNC_KDF_RESET, (void(*)(void))kbkdf_reset }, | |
475 | { OSSL_FUNC_KDF_DERIVE, (void(*)(void))kbkdf_derive }, | |
476 | { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS, | |
477 | (void(*)(void))kbkdf_settable_ctx_params }, | |
478 | { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void(*)(void))kbkdf_set_ctx_params }, | |
479 | { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS, | |
480 | (void(*)(void))kbkdf_gettable_ctx_params }, | |
481 | { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void(*)(void))kbkdf_get_ctx_params }, | |
1e6bd31e | 482 | OSSL_DISPATCH_END, |
a39bc440 | 483 | }; |