Coverage Report

Created: 2023-04-12 06:22

/src/openssl/providers/implementations/kdfs/sskdf.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2019-2022 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
 * Refer to https://csrc.nist.gov/publications/detail/sp/800-56c/rev-1/final
13
 * Section 4.1.
14
 *
15
 * The Single Step KDF algorithm is given by:
16
 *
17
 * Result(0) = empty bit string (i.e., the null string).
18
 * For i = 1 to reps, do the following:
19
 *   Increment counter by 1.
20
 *   Result(i) = Result(i - 1) || H(counter || Z || FixedInfo).
21
 * DKM = LeftmostBits(Result(reps), L))
22
 *
23
 * NOTES:
24
 *   Z is a shared secret required to produce the derived key material.
25
 *   counter is a 4 byte buffer.
26
 *   FixedInfo is a bit string containing context specific data.
27
 *   DKM is the output derived key material.
28
 *   L is the required size of the DKM.
29
 *   reps = [L / H_outputBits]
30
 *   H(x) is the auxiliary function that can be either a hash, HMAC or KMAC.
31
 *   H_outputBits is the length of the output of the auxiliary function H(x).
32
 *
33
 * Currently there is not a comprehensive list of test vectors for this
34
 * algorithm, especially for H(x) = HMAC and H(x) = KMAC.
35
 * Test vectors for H(x) = Hash are indirectly used by CAVS KAS tests.
36
 */
37
#include <stdlib.h>
38
#include <stdarg.h>
39
#include <string.h>
40
#include <openssl/hmac.h>
41
#include <openssl/evp.h>
42
#include <openssl/kdf.h>
43
#include <openssl/core_names.h>
44
#include <openssl/params.h>
45
#include <openssl/proverr.h>
46
#include "internal/cryptlib.h"
47
#include "internal/numbers.h"
48
#include "crypto/evp.h"
49
#include "prov/provider_ctx.h"
50
#include "prov/providercommon.h"
51
#include "prov/implementations.h"
52
#include "prov/provider_util.h"
53
54
typedef struct {
55
    void *provctx;
56
    EVP_MAC_CTX *macctx;         /* H(x) = HMAC_hash OR H(x) = KMAC */
57
    PROV_DIGEST digest;          /* H(x) = hash(x) */
58
    unsigned char *secret;
59
    size_t secret_len;
60
    unsigned char *info;
61
    size_t info_len;
62
    unsigned char *salt;
63
    size_t salt_len;
64
    size_t out_len; /* optional KMAC parameter */
65
    int is_kmac;
66
} KDF_SSKDF;
67
68
0
#define SSKDF_MAX_INLEN (1<<30)
69
0
#define SSKDF_KMAC128_DEFAULT_SALT_SIZE (168 - 4)
70
0
#define SSKDF_KMAC256_DEFAULT_SALT_SIZE (136 - 4)
71
72
/* KMAC uses a Customisation string of 'KDF' */
73
static const unsigned char kmac_custom_str[] = { 0x4B, 0x44, 0x46 };
74
75
static OSSL_FUNC_kdf_newctx_fn sskdf_new;
76
static OSSL_FUNC_kdf_dupctx_fn sskdf_dup;
77
static OSSL_FUNC_kdf_freectx_fn sskdf_free;
78
static OSSL_FUNC_kdf_reset_fn sskdf_reset;
79
static OSSL_FUNC_kdf_derive_fn sskdf_derive;
80
static OSSL_FUNC_kdf_derive_fn x963kdf_derive;
81
static OSSL_FUNC_kdf_settable_ctx_params_fn sskdf_settable_ctx_params;
82
static OSSL_FUNC_kdf_set_ctx_params_fn sskdf_set_ctx_params;
83
static OSSL_FUNC_kdf_gettable_ctx_params_fn sskdf_gettable_ctx_params;
84
static OSSL_FUNC_kdf_get_ctx_params_fn sskdf_get_ctx_params;
85
86
/*
87
 * Refer to https://csrc.nist.gov/publications/detail/sp/800-56c/rev-1/final
88
 * Section 4. One-Step Key Derivation using H(x) = hash(x)
89
 * Note: X9.63 also uses this code with the only difference being that the
90
 * counter is appended to the secret 'z'.
91
 * i.e.
92
 *   result[i] = Hash(counter || z || info) for One Step OR
93
 *   result[i] = Hash(z || counter || info) for X9.63.
94
 */
95
static int SSKDF_hash_kdm(const EVP_MD *kdf_md,
96
                          const unsigned char *z, size_t z_len,
97
                          const unsigned char *info, size_t info_len,
98
                          unsigned int append_ctr,
99
                          unsigned char *derived_key, size_t derived_key_len)
100
0
{
101
0
    int ret = 0, hlen;
102
0
    size_t counter, out_len, len = derived_key_len;
103
0
    unsigned char c[4];
104
0
    unsigned char mac[EVP_MAX_MD_SIZE];
105
0
    unsigned char *out = derived_key;
106
0
    EVP_MD_CTX *ctx = NULL, *ctx_init = NULL;
107
108
0
    if (z_len > SSKDF_MAX_INLEN || info_len > SSKDF_MAX_INLEN
109
0
            || derived_key_len > SSKDF_MAX_INLEN
110
0
            || derived_key_len == 0)
111
0
        return 0;
112
113
0
    hlen = EVP_MD_get_size(kdf_md);
114
0
    if (hlen <= 0)
115
0
        return 0;
116
0
    out_len = (size_t)hlen;
117
118
0
    ctx = EVP_MD_CTX_create();
119
0
    ctx_init = EVP_MD_CTX_create();
120
0
    if (ctx == NULL || ctx_init == NULL)
121
0
        goto end;
122
123
0
    if (!EVP_DigestInit(ctx_init, kdf_md))
124
0
        goto end;
125
126
0
    for (counter = 1;; counter++) {
127
0
        c[0] = (unsigned char)((counter >> 24) & 0xff);
128
0
        c[1] = (unsigned char)((counter >> 16) & 0xff);
129
0
        c[2] = (unsigned char)((counter >> 8) & 0xff);
130
0
        c[3] = (unsigned char)(counter & 0xff);
131
132
0
        if (!(EVP_MD_CTX_copy_ex(ctx, ctx_init)
133
0
                && (append_ctr || EVP_DigestUpdate(ctx, c, sizeof(c)))
134
0
                && EVP_DigestUpdate(ctx, z, z_len)
135
0
                && (!append_ctr || EVP_DigestUpdate(ctx, c, sizeof(c)))
136
0
                && EVP_DigestUpdate(ctx, info, info_len)))
137
0
            goto end;
138
0
        if (len >= out_len) {
139
0
            if (!EVP_DigestFinal_ex(ctx, out, NULL))
140
0
                goto end;
141
0
            out += out_len;
142
0
            len -= out_len;
143
0
            if (len == 0)
144
0
                break;
145
0
        } else {
146
0
            if (!EVP_DigestFinal_ex(ctx, mac, NULL))
147
0
                goto end;
148
0
            memcpy(out, mac, len);
149
0
            break;
150
0
        }
151
0
    }
152
0
    ret = 1;
153
0
end:
154
0
    EVP_MD_CTX_destroy(ctx);
155
0
    EVP_MD_CTX_destroy(ctx_init);
156
0
    OPENSSL_cleanse(mac, sizeof(mac));
157
0
    return ret;
158
0
}
159
160
static int kmac_init(EVP_MAC_CTX *ctx, const unsigned char *custom,
161
                     size_t custom_len, size_t kmac_out_len,
162
                     size_t derived_key_len, unsigned char **out)
163
0
{
164
0
    OSSL_PARAM params[2];
165
166
    /* Only KMAC has custom data - so return if not KMAC */
167
0
    if (custom == NULL)
168
0
        return 1;
169
170
0
    params[0] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_CUSTOM,
171
0
                                                  (void *)custom, custom_len);
172
0
    params[1] = OSSL_PARAM_construct_end();
173
174
0
    if (!EVP_MAC_CTX_set_params(ctx, params))
175
0
        return 0;
176
177
    /* By default only do one iteration if kmac_out_len is not specified */
178
0
    if (kmac_out_len == 0)
179
0
        kmac_out_len = derived_key_len;
180
    /* otherwise check the size is valid */
181
0
    else if (!(kmac_out_len == derived_key_len
182
0
            || kmac_out_len == 20
183
0
            || kmac_out_len == 28
184
0
            || kmac_out_len == 32
185
0
            || kmac_out_len == 48
186
0
            || kmac_out_len == 64))
187
0
        return 0;
188
189
0
    params[0] = OSSL_PARAM_construct_size_t(OSSL_MAC_PARAM_SIZE,
190
0
                                            &kmac_out_len);
191
192
0
    if (EVP_MAC_CTX_set_params(ctx, params) <= 0)
193
0
        return 0;
194
195
    /*
196
     * For kmac the output buffer can be larger than EVP_MAX_MD_SIZE: so
197
     * alloc a buffer for this case.
198
     */
199
0
    if (kmac_out_len > EVP_MAX_MD_SIZE) {
200
0
        *out = OPENSSL_zalloc(kmac_out_len);
201
0
        if (*out == NULL)
202
0
            return 0;
203
0
    }
204
0
    return 1;
205
0
}
206
207
/*
208
 * Refer to https://csrc.nist.gov/publications/detail/sp/800-56c/rev-1/final
209
 * Section 4. One-Step Key Derivation using MAC: i.e either
210
 *     H(x) = HMAC-hash(salt, x) OR
211
 *     H(x) = KMAC#(salt, x, outbits, CustomString='KDF')
212
 */
213
static int SSKDF_mac_kdm(EVP_MAC_CTX *ctx_init,
214
                         const unsigned char *kmac_custom,
215
                         size_t kmac_custom_len, size_t kmac_out_len,
216
                         const unsigned char *salt, size_t salt_len,
217
                         const unsigned char *z, size_t z_len,
218
                         const unsigned char *info, size_t info_len,
219
                         unsigned char *derived_key, size_t derived_key_len)
220
0
{
221
0
    int ret = 0;
222
0
    size_t counter, out_len, len;
223
0
    unsigned char c[4];
224
0
    unsigned char mac_buf[EVP_MAX_MD_SIZE];
225
0
    unsigned char *out = derived_key;
226
0
    EVP_MAC_CTX *ctx = NULL;
227
0
    unsigned char *mac = mac_buf, *kmac_buffer = NULL;
228
229
0
    if (z_len > SSKDF_MAX_INLEN || info_len > SSKDF_MAX_INLEN
230
0
            || derived_key_len > SSKDF_MAX_INLEN
231
0
            || derived_key_len == 0)
232
0
        return 0;
233
234
0
    if (!kmac_init(ctx_init, kmac_custom, kmac_custom_len, kmac_out_len,
235
0
                   derived_key_len, &kmac_buffer))
236
0
        goto end;
237
0
    if (kmac_buffer != NULL)
238
0
        mac = kmac_buffer;
239
240
0
    if (!EVP_MAC_init(ctx_init, salt, salt_len, NULL))
241
0
        goto end;
242
243
0
    out_len = EVP_MAC_CTX_get_mac_size(ctx_init); /* output size */
244
0
    if (out_len <= 0 || (mac == mac_buf && out_len > sizeof(mac_buf)))
245
0
        goto end;
246
0
    len = derived_key_len;
247
248
0
    for (counter = 1;; counter++) {
249
0
        c[0] = (unsigned char)((counter >> 24) & 0xff);
250
0
        c[1] = (unsigned char)((counter >> 16) & 0xff);
251
0
        c[2] = (unsigned char)((counter >> 8) & 0xff);
252
0
        c[3] = (unsigned char)(counter & 0xff);
253
254
0
        ctx = EVP_MAC_CTX_dup(ctx_init);
255
0
        if (!(ctx != NULL
256
0
                && EVP_MAC_update(ctx, c, sizeof(c))
257
0
                && EVP_MAC_update(ctx, z, z_len)
258
0
                && EVP_MAC_update(ctx, info, info_len)))
259
0
            goto end;
260
0
        if (len >= out_len) {
261
0
            if (!EVP_MAC_final(ctx, out, NULL, len))
262
0
                goto end;
263
0
            out += out_len;
264
0
            len -= out_len;
265
0
            if (len == 0)
266
0
                break;
267
0
        } else {
268
0
            if (!EVP_MAC_final(ctx, mac, NULL, out_len))
269
0
                goto end;
270
0
            memcpy(out, mac, len);
271
0
            break;
272
0
        }
273
0
        EVP_MAC_CTX_free(ctx);
274
0
        ctx = NULL;
275
0
    }
276
0
    ret = 1;
277
0
end:
278
0
    if (kmac_buffer != NULL)
279
0
        OPENSSL_clear_free(kmac_buffer, kmac_out_len);
280
0
    else
281
0
        OPENSSL_cleanse(mac_buf, sizeof(mac_buf));
282
283
0
    EVP_MAC_CTX_free(ctx);
284
0
    return ret;
285
0
}
286
287
static void *sskdf_new(void *provctx)
288
0
{
289
0
    KDF_SSKDF *ctx;
290
291
0
    if (!ossl_prov_is_running())
292
0
        return NULL;
293
294
0
    if ((ctx = OPENSSL_zalloc(sizeof(*ctx))) != NULL)
295
0
        ctx->provctx = provctx;
296
0
    return ctx;
297
0
}
298
299
static void sskdf_reset(void *vctx)
300
0
{
301
0
    KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
302
0
    void *provctx = ctx->provctx;
303
304
0
    EVP_MAC_CTX_free(ctx->macctx);
305
0
    ossl_prov_digest_reset(&ctx->digest);
306
0
    OPENSSL_clear_free(ctx->secret, ctx->secret_len);
307
0
    OPENSSL_clear_free(ctx->info, ctx->info_len);
308
0
    OPENSSL_clear_free(ctx->salt, ctx->salt_len);
309
0
    memset(ctx, 0, sizeof(*ctx));
310
0
    ctx->provctx = provctx;
311
0
}
312
313
static void sskdf_free(void *vctx)
314
0
{
315
0
    KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
316
317
0
    if (ctx != NULL) {
318
0
        sskdf_reset(ctx);
319
0
        OPENSSL_free(ctx);
320
0
    }
321
0
}
322
323
static void *sskdf_dup(void *vctx)
324
0
{
325
0
    const KDF_SSKDF *src = (const KDF_SSKDF *)vctx;
326
0
    KDF_SSKDF *dest;
327
328
0
    dest = sskdf_new(src->provctx);
329
0
    if (dest != NULL) {
330
0
        if (src->macctx != NULL) {
331
0
            dest->macctx = EVP_MAC_CTX_dup(src->macctx);
332
0
            if (dest->macctx == NULL)
333
0
                goto err;
334
0
        }
335
0
        if (!ossl_prov_memdup(src->info, src->info_len,
336
0
                              &dest->info, &dest->info_len)
337
0
                || !ossl_prov_memdup(src->salt, src->salt_len,
338
0
                                     &dest->salt , &dest->salt_len)
339
0
                || !ossl_prov_memdup(src->secret, src->secret_len,
340
0
                                     &dest->secret, &dest->secret_len)
341
0
                || !ossl_prov_digest_copy(&dest->digest, &src->digest))
342
0
            goto err;
343
0
        dest->out_len = src->out_len;
344
0
        dest->is_kmac = src->is_kmac;
345
0
    }
346
0
    return dest;
347
348
0
 err:
349
0
    sskdf_free(dest);
350
0
    return NULL;
351
0
}
352
353
static int sskdf_set_buffer(unsigned char **out, size_t *out_len,
354
                            const OSSL_PARAM *p)
355
0
{
356
0
    if (p->data == NULL || p->data_size == 0)
357
0
        return 1;
358
0
    OPENSSL_free(*out);
359
0
    *out = NULL;
360
0
    return OSSL_PARAM_get_octet_string(p, (void **)out, 0, out_len);
361
0
}
362
363
static size_t sskdf_size(KDF_SSKDF *ctx)
364
0
{
365
0
    int len;
366
0
    const EVP_MD *md = NULL;
367
368
0
    if (ctx->is_kmac)
369
0
        return SIZE_MAX;
370
371
0
    md = ossl_prov_digest_md(&ctx->digest);
372
0
    if (md == NULL) {
373
0
        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
374
0
        return 0;
375
0
    }
376
0
    len = EVP_MD_get_size(md);
377
0
    return (len <= 0) ? 0 : (size_t)len;
378
0
}
379
380
static int sskdf_derive(void *vctx, unsigned char *key, size_t keylen,
381
                        const OSSL_PARAM params[])
382
0
{
383
0
    KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
384
0
    const EVP_MD *md;
385
386
0
    if (!ossl_prov_is_running() || !sskdf_set_ctx_params(ctx, params))
387
0
        return 0;
388
0
    if (ctx->secret == NULL) {
389
0
        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_SECRET);
390
0
        return 0;
391
0
    }
392
0
    md = ossl_prov_digest_md(&ctx->digest);
393
394
0
    if (ctx->macctx != NULL) {
395
        /* H(x) = KMAC or H(x) = HMAC */
396
0
        int ret;
397
0
        const unsigned char *custom = NULL;
398
0
        size_t custom_len = 0;
399
0
        int default_salt_len;
400
0
        EVP_MAC *mac = EVP_MAC_CTX_get0_mac(ctx->macctx);
401
402
0
        if (EVP_MAC_is_a(mac, OSSL_MAC_NAME_HMAC)) {
403
            /* H(x) = HMAC(x, salt, hash) */
404
0
            if (md == NULL) {
405
0
                ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
406
0
                return 0;
407
0
            }
408
0
            default_salt_len = EVP_MD_get_size(md);
409
0
            if (default_salt_len <= 0)
410
0
                return 0;
411
0
        } else if (ctx->is_kmac) {
412
            /* H(x) = KMACzzz(x, salt, custom) */
413
0
            custom = kmac_custom_str;
414
0
            custom_len = sizeof(kmac_custom_str);
415
0
            if (EVP_MAC_is_a(mac, OSSL_MAC_NAME_KMAC128))
416
0
                default_salt_len = SSKDF_KMAC128_DEFAULT_SALT_SIZE;
417
0
            else
418
0
                default_salt_len = SSKDF_KMAC256_DEFAULT_SALT_SIZE;
419
0
        } else {
420
0
            ERR_raise(ERR_LIB_PROV, PROV_R_UNSUPPORTED_MAC_TYPE);
421
0
            return 0;
422
0
        }
423
        /* If no salt is set then use a default_salt of zeros */
424
0
        if (ctx->salt == NULL || ctx->salt_len <= 0) {
425
0
            ctx->salt = OPENSSL_zalloc(default_salt_len);
426
0
            if (ctx->salt == NULL)
427
0
                return 0;
428
0
            ctx->salt_len = default_salt_len;
429
0
        }
430
0
        ret = SSKDF_mac_kdm(ctx->macctx,
431
0
                            custom, custom_len, ctx->out_len,
432
0
                            ctx->salt, ctx->salt_len,
433
0
                            ctx->secret, ctx->secret_len,
434
0
                            ctx->info, ctx->info_len, key, keylen);
435
0
        return ret;
436
0
    } else {
437
        /* H(x) = hash */
438
0
        if (md == NULL) {
439
0
            ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
440
0
            return 0;
441
0
        }
442
0
        return SSKDF_hash_kdm(md, ctx->secret, ctx->secret_len,
443
0
                              ctx->info, ctx->info_len, 0, key, keylen);
444
0
    }
445
0
}
446
447
static int x963kdf_derive(void *vctx, unsigned char *key, size_t keylen,
448
                          const OSSL_PARAM params[])
449
0
{
450
0
    KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
451
0
    const EVP_MD *md;
452
453
0
    if (!ossl_prov_is_running() || !sskdf_set_ctx_params(ctx, params))
454
0
        return 0;
455
456
0
    if (ctx->secret == NULL) {
457
0
        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_SECRET);
458
0
        return 0;
459
0
    }
460
461
0
    if (ctx->macctx != NULL) {
462
0
        ERR_raise(ERR_LIB_PROV, PROV_R_NOT_SUPPORTED);
463
0
        return 0;
464
0
    }
465
466
    /* H(x) = hash */
467
0
    md = ossl_prov_digest_md(&ctx->digest);
468
0
    if (md == NULL) {
469
0
        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
470
0
        return 0;
471
0
    }
472
473
0
    return SSKDF_hash_kdm(md, ctx->secret, ctx->secret_len,
474
0
                          ctx->info, ctx->info_len, 1, key, keylen);
475
0
}
476
477
static int sskdf_set_ctx_params(void *vctx, const OSSL_PARAM params[])
478
0
{
479
0
    const OSSL_PARAM *p;
480
0
    KDF_SSKDF *ctx = vctx;
481
0
    OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx);
482
0
    size_t sz;
483
484
0
    if (params == NULL)
485
0
        return 1;
486
487
0
    if (!ossl_prov_macctx_load_from_params(&ctx->macctx, params,
488
0
                                           NULL, NULL, NULL, libctx))
489
0
        return 0;
490
0
   if (ctx->macctx != NULL) {
491
0
        if (EVP_MAC_is_a(EVP_MAC_CTX_get0_mac(ctx->macctx),
492
0
                         OSSL_MAC_NAME_KMAC128)
493
0
            || EVP_MAC_is_a(EVP_MAC_CTX_get0_mac(ctx->macctx),
494
0
                            OSSL_MAC_NAME_KMAC256)) {
495
0
            ctx->is_kmac = 1;
496
0
        }
497
0
   }
498
499
0
   if (!ossl_prov_digest_load_from_params(&ctx->digest, params, libctx))
500
0
       return 0;
501
502
0
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SECRET)) != NULL
503
0
        || (p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_KEY)) != NULL)
504
0
        if (!sskdf_set_buffer(&ctx->secret, &ctx->secret_len, p))
505
0
            return 0;
506
507
0
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_INFO)) != NULL)
508
0
        if (!sskdf_set_buffer(&ctx->info, &ctx->info_len, p))
509
0
            return 0;
510
511
0
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SALT)) != NULL)
512
0
        if (!sskdf_set_buffer(&ctx->salt, &ctx->salt_len, p))
513
0
            return 0;
514
515
0
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_MAC_SIZE))
516
0
        != NULL) {
517
0
        if (!OSSL_PARAM_get_size_t(p, &sz) || sz == 0)
518
0
            return 0;
519
0
        ctx->out_len = sz;
520
0
    }
521
0
    return 1;
522
0
}
523
524
static const OSSL_PARAM *sskdf_settable_ctx_params(ossl_unused void *ctx,
525
                                                   ossl_unused void *provctx)
526
0
{
527
0
    static const OSSL_PARAM known_settable_ctx_params[] = {
528
0
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SECRET, NULL, 0),
529
0
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_KEY, NULL, 0),
530
0
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_INFO, NULL, 0),
531
0
        OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0),
532
0
        OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_DIGEST, NULL, 0),
533
0
        OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_MAC, NULL, 0),
534
0
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SALT, NULL, 0),
535
0
        OSSL_PARAM_size_t(OSSL_KDF_PARAM_MAC_SIZE, NULL),
536
0
        OSSL_PARAM_END
537
0
    };
538
0
    return known_settable_ctx_params;
539
0
}
540
541
static int sskdf_get_ctx_params(void *vctx, OSSL_PARAM params[])
542
0
{
543
0
    KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
544
0
    OSSL_PARAM *p;
545
546
0
    if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL)
547
0
        return OSSL_PARAM_set_size_t(p, sskdf_size(ctx));
548
0
    return -2;
549
0
}
550
551
static const OSSL_PARAM *sskdf_gettable_ctx_params(ossl_unused void *ctx,
552
                                                   ossl_unused void *provctx)
553
0
{
554
0
    static const OSSL_PARAM known_gettable_ctx_params[] = {
555
0
        OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL),
556
0
        OSSL_PARAM_END
557
0
    };
558
0
    return known_gettable_ctx_params;
559
0
}
560
561
const OSSL_DISPATCH ossl_kdf_sskdf_functions[] = {
562
    { OSSL_FUNC_KDF_NEWCTX, (void(*)(void))sskdf_new },
563
    { OSSL_FUNC_KDF_DUPCTX, (void(*)(void))sskdf_dup },
564
    { OSSL_FUNC_KDF_FREECTX, (void(*)(void))sskdf_free },
565
    { OSSL_FUNC_KDF_RESET, (void(*)(void))sskdf_reset },
566
    { OSSL_FUNC_KDF_DERIVE, (void(*)(void))sskdf_derive },
567
    { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS,
568
      (void(*)(void))sskdf_settable_ctx_params },
569
    { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void(*)(void))sskdf_set_ctx_params },
570
    { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
571
      (void(*)(void))sskdf_gettable_ctx_params },
572
    { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void(*)(void))sskdf_get_ctx_params },
573
    { 0, NULL }
574
};
575
576
const OSSL_DISPATCH ossl_kdf_x963_kdf_functions[] = {
577
    { OSSL_FUNC_KDF_NEWCTX, (void(*)(void))sskdf_new },
578
    { OSSL_FUNC_KDF_DUPCTX, (void(*)(void))sskdf_dup },
579
    { OSSL_FUNC_KDF_FREECTX, (void(*)(void))sskdf_free },
580
    { OSSL_FUNC_KDF_RESET, (void(*)(void))sskdf_reset },
581
    { OSSL_FUNC_KDF_DERIVE, (void(*)(void))x963kdf_derive },
582
    { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS,
583
      (void(*)(void))sskdf_settable_ctx_params },
584
    { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void(*)(void))sskdf_set_ctx_params },
585
    { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
586
      (void(*)(void))sskdf_gettable_ctx_params },
587
    { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void(*)(void))sskdf_get_ctx_params },
588
    { 0, NULL }
589
};