Coverage Report

Created: 2026-02-14 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl33/providers/implementations/kdfs/argon2.c
Line
Count
Source
1
/*
2
 * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 *
9
 * RFC 9106 Argon2 (see https://www.rfc-editor.org/rfc/rfc9106.txt)
10
 *
11
 */
12
13
#include <stdlib.h>
14
#include <stddef.h>
15
#include <stdarg.h>
16
#include <string.h>
17
#include <openssl/e_os2.h>
18
#include <openssl/evp.h>
19
#include <openssl/objects.h>
20
#include <openssl/crypto.h>
21
#include <openssl/kdf.h>
22
#include <openssl/err.h>
23
#include <openssl/core_names.h>
24
#include <openssl/params.h>
25
#include <openssl/thread.h>
26
#include <openssl/proverr.h>
27
#include "internal/thread.h"
28
#include "internal/numbers.h"
29
#include "internal/endian.h"
30
#include "crypto/evp.h"
31
#include "prov/implementations.h"
32
#include "prov/provider_ctx.h"
33
#include "prov/providercommon.h"
34
#include "prov/blake2.h"
35
36
#if defined(OPENSSL_NO_DEFAULT_THREAD_POOL) && defined(OPENSSL_NO_THREAD_POOL)
37
#define ARGON2_NO_THREADS
38
#endif
39
40
#if !defined(OPENSSL_THREADS)
41
#define ARGON2_NO_THREADS
42
#endif
43
44
#ifndef OPENSSL_NO_ARGON2
45
46
579
#define ARGON2_MIN_LANES 1u
47
547
#define ARGON2_MAX_LANES 0xFFFFFFu
48
633
#define ARGON2_MIN_THREADS 1u
49
547
#define ARGON2_MAX_THREADS 0xFFFFFFu
50
14.2k
#define ARGON2_SYNC_POINTS 4u
51
1.09k
#define ARGON2_MIN_OUT_LENGTH 4u
52
#define ARGON2_MAX_OUT_LENGTH 0xFFFFFFFFu
53
1.38k
#define ARGON2_MIN_MEMORY (2 * ARGON2_SYNC_POINTS)
54
#define ARGON2_MIN(a, b) ((a) < (b) ? (a) : (b))
55
#define ARGON2_MAX_MEMORY 0xFFFFFFFFu
56
590
#define ARGON2_MIN_TIME 1u
57
#define ARGON2_MAX_TIME 0xFFFFFFFFu
58
#define ARGON2_MIN_PWD_LENGTH 0u
59
826
#define ARGON2_MAX_PWD_LENGTH 0xFFFFFFFFu
60
#define ARGON2_MIN_AD_LENGTH 0u
61
681
#define ARGON2_MAX_AD_LENGTH 0xFFFFFFFFu
62
971
#define ARGON2_MIN_SALT_LENGTH 8u
63
681
#define ARGON2_MAX_SALT_LENGTH 0xFFFFFFFFu
64
#define ARGON2_MIN_SECRET 0u
65
681
#define ARGON2_MAX_SECRET 0xFFFFFFFFu
66
13.3M
#define ARGON2_BLOCK_SIZE 1024
67
13.3M
#define ARGON2_QWORDS_IN_BLOCK ((ARGON2_BLOCK_SIZE) / 8)
68
#define ARGON2_OWORDS_IN_BLOCK ((ARGON2_BLOCK_SIZE) / 16)
69
#define ARGON2_HWORDS_IN_BLOCK ((ARGON2_BLOCK_SIZE) / 32)
70
#define ARGON2_512BIT_WORDS_IN_BLOCK ((ARGON2_BLOCK_SIZE) / 64)
71
35.5k
#define ARGON2_ADDRESSES_IN_BLOCK 128
72
14.5k
#define ARGON2_PREHASH_DIGEST_LENGTH 64
73
#define ARGON2_PREHASH_SEED_LENGTH \
74
5.80k
    (ARGON2_PREHASH_DIGEST_LENGTH + (2 * sizeof(uint32_t)))
75
76
826
#define ARGON2_DEFAULT_OUTLEN 64u
77
826
#define ARGON2_DEFAULT_T_COST 3u
78
826
#define ARGON2_DEFAULT_M_COST ARGON2_MIN_MEMORY
79
826
#define ARGON2_DEFAULT_LANES 1u
80
826
#define ARGON2_DEFAULT_THREADS 1u
81
826
#define ARGON2_DEFAULT_VERSION ARGON2_VERSION_NUMBER
82
83
#undef G
84
#define G(a, b, c, d)                    \
85
6.08M
    do {                                 \
86
6.08M
        a = a + b + 2 * mul_lower(a, b); \
87
6.08M
        d = rotr64(d ^ a, 32);           \
88
6.08M
        c = c + d + 2 * mul_lower(c, d); \
89
6.08M
        b = rotr64(b ^ c, 24);           \
90
6.08M
        a = a + b + 2 * mul_lower(a, b); \
91
6.08M
        d = rotr64(d ^ a, 16);           \
92
6.08M
        c = c + d + 2 * mul_lower(c, d); \
93
6.08M
        b = rotr64(b ^ c, 63);           \
94
6.08M
    } while ((void)0, 0)
95
96
#undef PERMUTATION_P
97
#define PERMUTATION_P(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, \
98
    v12, v13, v14, v15)                                                 \
99
760k
    do {                                                                \
100
760k
        G(v0, v4, v8, v12);                                             \
101
760k
        G(v1, v5, v9, v13);                                             \
102
760k
        G(v2, v6, v10, v14);                                            \
103
760k
        G(v3, v7, v11, v15);                                            \
104
760k
        G(v0, v5, v10, v15);                                            \
105
760k
        G(v1, v6, v11, v12);                                            \
106
760k
        G(v2, v7, v8, v13);                                             \
107
760k
        G(v3, v4, v9, v14);                                             \
108
760k
    } while ((void)0, 0)
109
110
#undef PERMUTATION_P_COLUMN
111
#define PERMUTATION_P_COLUMN(x, i)                                   \
112
380k
    do {                                                             \
113
380k
        uint64_t *base = &x[16 * i];                                 \
114
380k
        PERMUTATION_P(                                               \
115
380k
            *base, *(base + 1), *(base + 2), *(base + 3),            \
116
380k
            *(base + 4), *(base + 5), *(base + 6), *(base + 7),      \
117
380k
            *(base + 8), *(base + 9), *(base + 10), *(base + 11),    \
118
380k
            *(base + 12), *(base + 13), *(base + 14), *(base + 15)); \
119
380k
    } while ((void)0, 0)
120
121
#undef PERMUTATION_P_ROW
122
#define PERMUTATION_P_ROW(x, i)                                        \
123
380k
    do {                                                               \
124
380k
        uint64_t *base = &x[2 * i];                                    \
125
380k
        PERMUTATION_P(                                                 \
126
380k
            *base, *(base + 1), *(base + 16), *(base + 17),            \
127
380k
            *(base + 32), *(base + 33), *(base + 48), *(base + 49),    \
128
380k
            *(base + 64), *(base + 65), *(base + 80), *(base + 81),    \
129
380k
            *(base + 96), *(base + 97), *(base + 112), *(base + 113)); \
130
380k
    } while ((void)0, 0)
131
132
typedef struct {
133
    uint64_t v[ARGON2_QWORDS_IN_BLOCK];
134
} BLOCK;
135
136
typedef enum {
137
    ARGON2_VERSION_10 = 0x10,
138
    ARGON2_VERSION_13 = 0x13,
139
    ARGON2_VERSION_NUMBER = ARGON2_VERSION_13
140
} ARGON2_VERSION;
141
142
typedef enum {
143
    ARGON2_D = 0,
144
    ARGON2_I = 1,
145
    ARGON2_ID = 2
146
} ARGON2_TYPE;
147
148
typedef struct {
149
    uint32_t pass;
150
    uint32_t lane;
151
    uint8_t slice;
152
    uint32_t index;
153
} ARGON2_POS;
154
155
typedef struct {
156
    void *provctx;
157
    uint32_t outlen;
158
    uint8_t *pwd;
159
    uint32_t pwdlen;
160
    uint8_t *salt;
161
    uint32_t saltlen;
162
    uint8_t *secret;
163
    uint32_t secretlen;
164
    uint8_t *ad;
165
    uint32_t adlen;
166
    uint32_t t_cost;
167
    uint32_t m_cost;
168
    uint32_t lanes;
169
    uint32_t threads;
170
    uint32_t version;
171
    uint32_t early_clean;
172
    ARGON2_TYPE type;
173
    BLOCK *memory;
174
    uint32_t passes;
175
    uint32_t memory_blocks;
176
    uint32_t segment_length;
177
    uint32_t lane_length;
178
    OSSL_LIB_CTX *libctx;
179
    EVP_MD *md;
180
    EVP_MAC *mac;
181
    char *propq;
182
} KDF_ARGON2;
183
184
typedef struct {
185
    ARGON2_POS pos;
186
    KDF_ARGON2 *ctx;
187
} ARGON2_THREAD_DATA;
188
189
static OSSL_FUNC_kdf_newctx_fn kdf_argon2i_new;
190
static OSSL_FUNC_kdf_newctx_fn kdf_argon2d_new;
191
static OSSL_FUNC_kdf_newctx_fn kdf_argon2id_new;
192
static OSSL_FUNC_kdf_freectx_fn kdf_argon2_free;
193
static OSSL_FUNC_kdf_reset_fn kdf_argon2_reset;
194
static OSSL_FUNC_kdf_derive_fn kdf_argon2_derive;
195
static OSSL_FUNC_kdf_settable_ctx_params_fn kdf_argon2_settable_ctx_params;
196
static OSSL_FUNC_kdf_set_ctx_params_fn kdf_argon2_set_ctx_params;
197
198
static void kdf_argon2_init(KDF_ARGON2 *ctx, ARGON2_TYPE t);
199
static void *kdf_argon2d_new(void *provctx);
200
static void *kdf_argon2i_new(void *provctx);
201
static void *kdf_argon2id_new(void *provctx);
202
static void kdf_argon2_free(void *vctx);
203
static int kdf_argon2_derive(void *vctx, unsigned char *out, size_t outlen,
204
    const OSSL_PARAM params[]);
205
static void kdf_argon2_reset(void *vctx);
206
static int kdf_argon2_ctx_set_threads(KDF_ARGON2 *ctx, uint32_t threads);
207
static int kdf_argon2_ctx_set_lanes(KDF_ARGON2 *ctx, uint32_t lanes);
208
static int kdf_argon2_ctx_set_t_cost(KDF_ARGON2 *ctx, uint32_t t_cost);
209
static int kdf_argon2_ctx_set_m_cost(KDF_ARGON2 *ctx, uint32_t m_cost);
210
static int kdf_argon2_ctx_set_out_length(KDF_ARGON2 *ctx, uint32_t outlen);
211
static int kdf_argon2_ctx_set_secret(KDF_ARGON2 *ctx, const OSSL_PARAM *p);
212
static int kdf_argon2_ctx_set_pwd(KDF_ARGON2 *ctx, const OSSL_PARAM *p);
213
static int kdf_argon2_ctx_set_salt(KDF_ARGON2 *ctx, const OSSL_PARAM *p);
214
static int kdf_argon2_ctx_set_ad(KDF_ARGON2 *ctx, const OSSL_PARAM *p);
215
static int kdf_argon2_set_ctx_params(void *vctx, const OSSL_PARAM params[]);
216
static int kdf_argon2_get_ctx_params(void *vctx, OSSL_PARAM params[]);
217
static int kdf_argon2_ctx_set_version(KDF_ARGON2 *ctx, uint32_t version);
218
static const OSSL_PARAM *kdf_argon2_settable_ctx_params(ossl_unused void *ctx,
219
    ossl_unused void *p_ctx);
220
static const OSSL_PARAM *kdf_argon2_gettable_ctx_params(ossl_unused void *ctx,
221
    ossl_unused void *p_ctx);
222
223
static ossl_inline uint64_t load64(const uint8_t *src);
224
static ossl_inline void store32(uint8_t *dst, uint32_t w);
225
static ossl_inline void store64(uint8_t *dst, uint64_t w);
226
static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned int c);
227
static ossl_inline uint64_t mul_lower(uint64_t x, uint64_t y);
228
229
static void init_block_value(BLOCK *b, uint8_t in);
230
static void copy_block(BLOCK *dst, const BLOCK *src);
231
static void xor_block(BLOCK *dst, const BLOCK *src);
232
static void load_block(BLOCK *dst, const void *input);
233
static void store_block(void *output, const BLOCK *src);
234
static void fill_first_blocks(uint8_t *blockhash, const KDF_ARGON2 *ctx);
235
static void fill_block(const BLOCK *prev, const BLOCK *ref, BLOCK *next,
236
    int with_xor);
237
238
static void next_addresses(BLOCK *address_block, BLOCK *input_block,
239
    const BLOCK *zero_block);
240
static int data_indep_addressing(const KDF_ARGON2 *ctx, uint32_t pass,
241
    uint8_t slice);
242
static uint32_t index_alpha(const KDF_ARGON2 *ctx, uint32_t pass,
243
    uint8_t slice, uint32_t index,
244
    uint32_t pseudo_rand, int same_lane);
245
246
static void fill_segment(const KDF_ARGON2 *ctx, uint32_t pass, uint32_t lane,
247
    uint8_t slice);
248
249
#if !defined(ARGON2_NO_THREADS)
250
static uint32_t fill_segment_thr(void *thread_data);
251
static int fill_mem_blocks_mt(KDF_ARGON2 *ctx);
252
#endif
253
254
static int fill_mem_blocks_st(KDF_ARGON2 *ctx);
255
static ossl_inline int fill_memory_blocks(KDF_ARGON2 *ctx);
256
257
static void initial_hash(uint8_t *blockhash, KDF_ARGON2 *ctx);
258
static int initialize(KDF_ARGON2 *ctx);
259
static void finalize(const KDF_ARGON2 *ctx, void *out);
260
261
static int blake2b(EVP_MD *md, EVP_MAC *mac, void *out, size_t outlen,
262
    const void *in, size_t inlen, const void *key,
263
    size_t keylen);
264
static int blake2b_long(EVP_MD *md, EVP_MAC *mac, unsigned char *out,
265
    size_t outlen, const void *in, size_t inlen);
266
267
static ossl_inline uint64_t load64(const uint8_t *src)
268
651k
{
269
651k
    return (((uint64_t)src[0]) << 0)
270
651k
        | (((uint64_t)src[1]) << 8)
271
651k
        | (((uint64_t)src[2]) << 16)
272
651k
        | (((uint64_t)src[3]) << 24)
273
651k
        | (((uint64_t)src[4]) << 32)
274
651k
        | (((uint64_t)src[5]) << 40)
275
651k
        | (((uint64_t)src[6]) << 48)
276
651k
        | (((uint64_t)src[7]) << 56);
277
651k
}
278
279
static ossl_inline void store32(uint8_t *dst, uint32_t w)
280
16.6k
{
281
16.6k
    dst[0] = (uint8_t)(w >> 0);
282
16.6k
    dst[1] = (uint8_t)(w >> 8);
283
16.6k
    dst[2] = (uint8_t)(w >> 16);
284
16.6k
    dst[3] = (uint8_t)(w >> 24);
285
16.6k
}
286
287
static ossl_inline void store64(uint8_t *dst, uint64_t w)
288
45.9k
{
289
45.9k
    dst[0] = (uint8_t)(w >> 0);
290
45.9k
    dst[1] = (uint8_t)(w >> 8);
291
45.9k
    dst[2] = (uint8_t)(w >> 16);
292
45.9k
    dst[3] = (uint8_t)(w >> 24);
293
45.9k
    dst[4] = (uint8_t)(w >> 32);
294
45.9k
    dst[5] = (uint8_t)(w >> 40);
295
45.9k
    dst[6] = (uint8_t)(w >> 48);
296
45.9k
    dst[7] = (uint8_t)(w >> 56);
297
45.9k
}
298
299
static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned int c)
300
24.3M
{
301
24.3M
    return (w >> c) | (w << (64 - c));
302
24.3M
}
303
304
static ossl_inline uint64_t mul_lower(uint64_t x, uint64_t y)
305
24.3M
{
306
24.3M
    const uint64_t m = 0xFFFFFFFFUL;
307
24.3M
    return (x & m) * (y & m);
308
24.3M
}
309
310
static void init_block_value(BLOCK *b, uint8_t in)
311
10.9k
{
312
10.9k
    memset(b->v, in, sizeof(b->v));
313
10.9k
}
314
315
static void copy_block(BLOCK *dst, const BLOCK *src)
316
142k
{
317
142k
    memcpy(dst->v, src->v, sizeof(uint64_t) * ARGON2_QWORDS_IN_BLOCK);
318
142k
}
319
320
static void xor_block(BLOCK *dst, const BLOCK *src)
321
97.2k
{
322
97.2k
    int i;
323
324
12.5M
    for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i)
325
12.4M
        dst->v[i] ^= src->v[i];
326
97.2k
}
327
328
static void load_block(BLOCK *dst, const void *input)
329
5.08k
{
330
5.08k
    unsigned i;
331
332
656k
    for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i)
333
651k
        dst->v[i] = load64((const uint8_t *)input + i * sizeof(dst->v[i]));
334
5.08k
}
335
336
static void store_block(void *output, const BLOCK *src)
337
359
{
338
359
    unsigned i;
339
340
46.3k
    for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i)
341
45.9k
        store64((uint8_t *)output + i * sizeof(src->v[i]), src->v[i]);
342
359
}
343
344
static void fill_first_blocks(uint8_t *blockhash, const KDF_ARGON2 *ctx)
345
359
{
346
359
    uint32_t l;
347
359
    uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE];
348
349
    /*
350
     * Make the first and second block in each lane as G(H0||0||i)
351
     * or G(H0||1||i).
352
     */
353
2.90k
    for (l = 0; l < ctx->lanes; ++l) {
354
2.54k
        store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 0);
355
2.54k
        store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH + 4, l);
356
2.54k
        blake2b_long(ctx->md, ctx->mac, blockhash_bytes, ARGON2_BLOCK_SIZE,
357
2.54k
            blockhash, ARGON2_PREHASH_SEED_LENGTH);
358
2.54k
        load_block(&ctx->memory[l * ctx->lane_length + 0],
359
2.54k
            blockhash_bytes);
360
2.54k
        store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 1);
361
2.54k
        blake2b_long(ctx->md, ctx->mac, blockhash_bytes, ARGON2_BLOCK_SIZE,
362
2.54k
            blockhash, ARGON2_PREHASH_SEED_LENGTH);
363
2.54k
        load_block(&ctx->memory[l * ctx->lane_length + 1],
364
2.54k
            blockhash_bytes);
365
2.54k
    }
366
359
    OPENSSL_cleanse(blockhash_bytes, ARGON2_BLOCK_SIZE);
367
359
}
368
369
static void fill_block(const BLOCK *prev, const BLOCK *ref,
370
    BLOCK *next, int with_xor)
371
47.5k
{
372
47.5k
    BLOCK blockR, tmp;
373
47.5k
    unsigned i;
374
375
47.5k
    copy_block(&blockR, ref);
376
47.5k
    xor_block(&blockR, prev);
377
47.5k
    copy_block(&tmp, &blockR);
378
379
47.5k
    if (with_xor)
380
0
        xor_block(&tmp, next);
381
382
427k
    for (i = 0; i < 8; ++i)
383
380k
        PERMUTATION_P_COLUMN(blockR.v, i);
384
385
427k
    for (i = 0; i < 8; ++i)
386
380k
        PERMUTATION_P_ROW(blockR.v, i);
387
388
47.5k
    copy_block(next, &tmp);
389
47.5k
    xor_block(next, &blockR);
390
47.5k
}
391
392
static void next_addresses(BLOCK *address_block, BLOCK *input_block,
393
    const BLOCK *zero_block)
394
5.46k
{
395
5.46k
    input_block->v[6]++;
396
5.46k
    fill_block(zero_block, input_block, address_block, 0);
397
5.46k
    fill_block(zero_block, address_block, address_block, 0);
398
5.46k
}
399
400
static int data_indep_addressing(const KDF_ARGON2 *ctx, uint32_t pass,
401
    uint8_t slice)
402
49.3k
{
403
49.3k
    switch (ctx->type) {
404
20.3k
    case ARGON2_I:
405
20.3k
        return 1;
406
9.61k
    case ARGON2_ID:
407
9.61k
        return (pass == 0) && (slice < ARGON2_SYNC_POINTS / 2);
408
19.3k
    case ARGON2_D:
409
19.3k
    default:
410
19.3k
        return 0;
411
49.3k
    }
412
49.3k
}
413
414
/*
415
 * Pass 0 (pass = 0):
416
 * This lane: all already finished segments plus already constructed blocks
417
 *            in this segment
418
 * Other lanes: all already finished segments
419
 *
420
 * Pass 1+:
421
 * This lane: (SYNC_POINTS - 1) last segments plus already constructed
422
 *            blocks in this segment
423
 * Other lanes: (SYNC_POINTS - 1) last segments
424
 */
425
static uint32_t index_alpha(const KDF_ARGON2 *ctx, uint32_t pass,
426
    uint8_t slice, uint32_t index,
427
    uint32_t pseudo_rand, int same_lane)
428
36.6k
{
429
36.6k
    uint32_t ref_area_sz;
430
36.6k
    uint64_t rel_pos;
431
36.6k
    uint32_t start_pos, abs_pos;
432
433
36.6k
    start_pos = 0;
434
36.6k
    switch (pass) {
435
36.6k
    case 0:
436
36.6k
        if (slice == 0)
437
5.33k
            ref_area_sz = index - 1;
438
31.2k
        else if (same_lane)
439
10.5k
            ref_area_sz = slice * ctx->segment_length + index - 1;
440
20.7k
        else
441
20.7k
            ref_area_sz = slice * ctx->segment_length + ((index == 0) ? (-1) : 0);
442
36.6k
        break;
443
0
    default:
444
0
        if (same_lane)
445
0
            ref_area_sz = ctx->lane_length - ctx->segment_length + index - 1;
446
0
        else
447
0
            ref_area_sz = ctx->lane_length - ctx->segment_length + ((index == 0) ? (-1) : 0);
448
0
        if (slice != ARGON2_SYNC_POINTS - 1)
449
0
            start_pos = (slice + 1) * ctx->segment_length;
450
0
        break;
451
36.6k
    }
452
453
36.6k
    rel_pos = pseudo_rand;
454
36.6k
    rel_pos = rel_pos * rel_pos >> 32;
455
36.6k
    rel_pos = ref_area_sz - 1 - (ref_area_sz * rel_pos >> 32);
456
36.6k
    abs_pos = (start_pos + rel_pos) % ctx->lane_length;
457
458
36.6k
    return abs_pos;
459
36.6k
}
460
461
static void fill_segment(const KDF_ARGON2 *ctx, uint32_t pass, uint32_t lane,
462
    uint8_t slice)
463
10.1k
{
464
10.1k
    BLOCK *ref_block = NULL, *curr_block = NULL;
465
10.1k
    BLOCK address_block, input_block, zero_block;
466
10.1k
    uint64_t rnd, ref_index, ref_lane;
467
10.1k
    uint32_t prev_offset;
468
10.1k
    uint32_t start_idx;
469
10.1k
    uint32_t j;
470
10.1k
    uint32_t curr_offset; /* Offset of the current block */
471
472
10.1k
    memset(&input_block, 0, sizeof(BLOCK));
473
474
10.1k
    if (ctx == NULL)
475
0
        return;
476
477
10.1k
    if (data_indep_addressing(ctx, pass, slice)) {
478
5.46k
        init_block_value(&zero_block, 0);
479
5.46k
        init_block_value(&input_block, 0);
480
481
5.46k
        input_block.v[0] = pass;
482
5.46k
        input_block.v[1] = lane;
483
5.46k
        input_block.v[2] = slice;
484
5.46k
        input_block.v[3] = ctx->memory_blocks;
485
5.46k
        input_block.v[4] = ctx->passes;
486
5.46k
        input_block.v[5] = ctx->type;
487
5.46k
    }
488
489
10.1k
    start_idx = 0;
490
491
    /* We've generated the first two blocks. Generate the 1st block of addrs. */
492
10.1k
    if ((pass == 0) && (slice == 0)) {
493
2.54k
        start_idx = 2;
494
2.54k
        if (data_indep_addressing(ctx, pass, slice))
495
1.63k
            next_addresses(&address_block, &input_block, &zero_block);
496
2.54k
    }
497
498
10.1k
    curr_offset = lane * ctx->lane_length + slice * ctx->segment_length
499
10.1k
        + start_idx;
500
501
10.1k
    if ((curr_offset % ctx->lane_length) == 0)
502
0
        prev_offset = curr_offset + ctx->lane_length - 1;
503
10.1k
    else
504
10.1k
        prev_offset = curr_offset - 1;
505
506
46.7k
    for (j = start_idx; j < ctx->segment_length; ++j, ++curr_offset, ++prev_offset) {
507
36.6k
        if (curr_offset % ctx->lane_length == 1)
508
0
            prev_offset = curr_offset - 1;
509
510
        /* Taking pseudo-random value from the previous block. */
511
36.6k
        if (data_indep_addressing(ctx, pass, slice)) {
512
17.7k
            if (j % ARGON2_ADDRESSES_IN_BLOCK == 0)
513
3.83k
                next_addresses(&address_block, &input_block, &zero_block);
514
17.7k
            rnd = address_block.v[j % ARGON2_ADDRESSES_IN_BLOCK];
515
18.8k
        } else {
516
18.8k
            rnd = ctx->memory[prev_offset].v[0];
517
18.8k
        }
518
519
        /* Computing the lane of the reference block */
520
36.6k
        ref_lane = ((rnd >> 32)) % ctx->lanes;
521
        /* Can not reference other lanes yet */
522
36.6k
        if ((pass == 0) && (slice == 0))
523
5.33k
            ref_lane = lane;
524
525
        /* Computing the number of possible reference block within the lane. */
526
36.6k
        ref_index = index_alpha(ctx, pass, slice, j, rnd & 0xFFFFFFFF,
527
36.6k
            ref_lane == lane);
528
529
        /* Creating a new block */
530
36.6k
        ref_block = ctx->memory + ctx->lane_length * ref_lane + ref_index;
531
36.6k
        curr_block = ctx->memory + curr_offset;
532
36.6k
        if (ARGON2_VERSION_10 == ctx->version) {
533
            /* Version 1.2.1 and earlier: overwrite, not XOR */
534
15.4k
            fill_block(ctx->memory + prev_offset, ref_block, curr_block, 0);
535
15.4k
            continue;
536
15.4k
        }
537
538
21.1k
        fill_block(ctx->memory + prev_offset, ref_block, curr_block,
539
21.1k
            pass == 0 ? 0 : 1);
540
21.1k
    }
541
10.1k
}
542
543
#if !defined(ARGON2_NO_THREADS)
544
545
static uint32_t fill_segment_thr(void *thread_data)
546
0
{
547
0
    ARGON2_THREAD_DATA *my_data;
548
549
0
    my_data = (ARGON2_THREAD_DATA *)thread_data;
550
0
    fill_segment(my_data->ctx, my_data->pos.pass, my_data->pos.lane,
551
0
        my_data->pos.slice);
552
553
0
    return 0;
554
0
}
555
556
static int fill_mem_blocks_mt(KDF_ARGON2 *ctx)
557
0
{
558
0
    uint32_t r, s, l, ll;
559
0
    void **t;
560
0
    ARGON2_THREAD_DATA *t_data;
561
562
0
    t = OPENSSL_zalloc(sizeof(void *) * ctx->lanes);
563
0
    t_data = OPENSSL_zalloc(ctx->lanes * sizeof(ARGON2_THREAD_DATA));
564
565
0
    if (t == NULL || t_data == NULL)
566
0
        goto fail;
567
568
0
    for (r = 0; r < ctx->passes; ++r) {
569
0
        for (s = 0; s < ARGON2_SYNC_POINTS; ++s) {
570
0
            for (l = 0; l < ctx->lanes; ++l) {
571
0
                ARGON2_POS p;
572
0
                if (l >= ctx->threads) {
573
0
                    if (ossl_crypto_thread_join(t[l - ctx->threads], NULL) == 0)
574
0
                        goto fail;
575
0
                    if (ossl_crypto_thread_clean(t[l - ctx->threads]) == 0)
576
0
                        goto fail;
577
0
                    t[l] = NULL;
578
0
                }
579
580
0
                p.pass = r;
581
0
                p.lane = l;
582
0
                p.slice = (uint8_t)s;
583
0
                p.index = 0;
584
585
0
                t_data[l].ctx = ctx;
586
0
                memcpy(&(t_data[l].pos), &p, sizeof(ARGON2_POS));
587
0
                t[l] = ossl_crypto_thread_start(ctx->libctx, &fill_segment_thr,
588
0
                    (void *)&t_data[l]);
589
0
                if (t[l] == NULL) {
590
0
                    for (ll = 0; ll < l; ++ll) {
591
0
                        if (ossl_crypto_thread_join(t[ll], NULL) == 0)
592
0
                            goto fail;
593
0
                        if (ossl_crypto_thread_clean(t[ll]) == 0)
594
0
                            goto fail;
595
0
                        t[ll] = NULL;
596
0
                    }
597
0
                    goto fail;
598
0
                }
599
0
            }
600
0
            for (l = ctx->lanes - ctx->threads; l < ctx->lanes; ++l) {
601
0
                if (ossl_crypto_thread_join(t[l], NULL) == 0)
602
0
                    goto fail;
603
0
                if (ossl_crypto_thread_clean(t[l]) == 0)
604
0
                    goto fail;
605
0
                t[l] = NULL;
606
0
            }
607
0
        }
608
0
    }
609
610
0
    OPENSSL_free(t_data);
611
0
    OPENSSL_free(t);
612
613
0
    return 1;
614
615
0
fail:
616
0
    if (t_data != NULL)
617
0
        OPENSSL_free(t_data);
618
0
    if (t != NULL)
619
0
        OPENSSL_free(t);
620
0
    return 0;
621
0
}
622
623
#endif /* !defined(ARGON2_NO_THREADS) */
624
625
static int fill_mem_blocks_st(KDF_ARGON2 *ctx)
626
359
{
627
359
    uint32_t r, s, l;
628
629
718
    for (r = 0; r < ctx->passes; ++r)
630
1.79k
        for (s = 0; s < ARGON2_SYNC_POINTS; ++s)
631
11.6k
            for (l = 0; l < ctx->lanes; ++l)
632
10.1k
                fill_segment(ctx, r, l, s);
633
359
    return 1;
634
359
}
635
636
static ossl_inline int fill_memory_blocks(KDF_ARGON2 *ctx)
637
359
{
638
359
#if !defined(ARGON2_NO_THREADS)
639
359
    return ctx->threads == 1 ? fill_mem_blocks_st(ctx) : fill_mem_blocks_mt(ctx);
640
#else
641
    return ctx->threads == 1 ? fill_mem_blocks_st(ctx) : 0;
642
#endif
643
359
}
644
645
static void initial_hash(uint8_t *blockhash, KDF_ARGON2 *ctx)
646
359
{
647
359
    EVP_MD_CTX *mdctx;
648
359
    uint8_t value[sizeof(uint32_t)];
649
359
    unsigned int tmp;
650
359
    uint32_t args[7];
651
652
359
    if (ctx == NULL || blockhash == NULL)
653
0
        return;
654
655
359
    args[0] = ctx->lanes;
656
359
    args[1] = ctx->outlen;
657
359
    args[2] = ctx->m_cost;
658
359
    args[3] = ctx->t_cost;
659
359
    args[4] = ctx->version;
660
359
    args[5] = (uint32_t)ctx->type;
661
359
    args[6] = ctx->pwdlen;
662
663
359
    mdctx = EVP_MD_CTX_create();
664
359
    if (mdctx == NULL || EVP_DigestInit_ex(mdctx, ctx->md, NULL) != 1)
665
0
        goto fail;
666
667
2.87k
    for (tmp = 0; tmp < sizeof(args) / sizeof(uint32_t); ++tmp) {
668
2.51k
        store32((uint8_t *)&value, args[tmp]);
669
2.51k
        if (EVP_DigestUpdate(mdctx, &value, sizeof(value)) != 1)
670
0
            goto fail;
671
2.51k
    }
672
673
359
    if (ctx->pwd != NULL) {
674
359
        if (EVP_DigestUpdate(mdctx, ctx->pwd, ctx->pwdlen) != 1)
675
0
            goto fail;
676
359
        if (ctx->early_clean) {
677
305
            OPENSSL_cleanse(ctx->pwd, ctx->pwdlen);
678
305
            ctx->pwdlen = 0;
679
305
        }
680
359
    }
681
682
359
    store32((uint8_t *)&value, ctx->saltlen);
683
684
359
    if (EVP_DigestUpdate(mdctx, &value, sizeof(value)) != 1)
685
0
        goto fail;
686
687
359
    if (ctx->salt != NULL)
688
359
        if (EVP_DigestUpdate(mdctx, ctx->salt, ctx->saltlen) != 1)
689
0
            goto fail;
690
691
359
    store32((uint8_t *)&value, ctx->secretlen);
692
359
    if (EVP_DigestUpdate(mdctx, &value, sizeof(value)) != 1)
693
0
        goto fail;
694
695
359
    if (ctx->secret != NULL) {
696
359
        if (EVP_DigestUpdate(mdctx, ctx->secret, ctx->secretlen) != 1)
697
0
            goto fail;
698
359
        if (ctx->early_clean) {
699
305
            OPENSSL_cleanse(ctx->secret, ctx->secretlen);
700
305
            ctx->secretlen = 0;
701
305
        }
702
359
    }
703
704
359
    store32((uint8_t *)&value, ctx->adlen);
705
359
    if (EVP_DigestUpdate(mdctx, &value, sizeof(value)) != 1)
706
0
        goto fail;
707
708
359
    if (ctx->ad != NULL)
709
359
        if (EVP_DigestUpdate(mdctx, ctx->ad, ctx->adlen) != 1)
710
0
            goto fail;
711
712
359
    tmp = ARGON2_PREHASH_DIGEST_LENGTH;
713
359
    if (EVP_DigestFinal_ex(mdctx, blockhash, &tmp) != 1)
714
0
        goto fail;
715
716
359
fail:
717
359
    EVP_MD_CTX_destroy(mdctx);
718
359
}
719
720
static int initialize(KDF_ARGON2 *ctx)
721
359
{
722
359
    uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH];
723
724
359
    if (ctx == NULL)
725
0
        return 0;
726
727
359
    if (ctx->memory_blocks * sizeof(BLOCK) / sizeof(BLOCK) != ctx->memory_blocks)
728
0
        return 0;
729
730
359
    if (ctx->type != ARGON2_D)
731
206
        ctx->memory = OPENSSL_secure_zalloc(ctx->memory_blocks * sizeof(BLOCK));
732
153
    else
733
153
        ctx->memory = OPENSSL_zalloc(ctx->memory_blocks * sizeof(BLOCK));
734
735
359
    if (ctx->memory == NULL) {
736
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MEMORY_SIZE,
737
0
            "cannot allocate required memory");
738
0
        return 0;
739
0
    }
740
741
359
    initial_hash(blockhash, ctx);
742
359
    OPENSSL_cleanse(blockhash + ARGON2_PREHASH_DIGEST_LENGTH,
743
359
        ARGON2_PREHASH_SEED_LENGTH - ARGON2_PREHASH_DIGEST_LENGTH);
744
359
    fill_first_blocks(blockhash, ctx);
745
359
    OPENSSL_cleanse(blockhash, ARGON2_PREHASH_SEED_LENGTH);
746
747
359
    return 1;
748
359
}
749
750
static void finalize(const KDF_ARGON2 *ctx, void *out)
751
359
{
752
359
    BLOCK blockhash;
753
359
    uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE];
754
359
    uint32_t last_block_in_lane;
755
359
    uint32_t l;
756
757
359
    if (ctx == NULL)
758
0
        return;
759
760
359
    copy_block(&blockhash, ctx->memory + ctx->lane_length - 1);
761
762
    /* XOR the last blocks */
763
2.54k
    for (l = 1; l < ctx->lanes; ++l) {
764
2.18k
        last_block_in_lane = l * ctx->lane_length + (ctx->lane_length - 1);
765
2.18k
        xor_block(&blockhash, ctx->memory + last_block_in_lane);
766
2.18k
    }
767
768
    /* Hash the result */
769
359
    store_block(blockhash_bytes, &blockhash);
770
359
    blake2b_long(ctx->md, ctx->mac, out, ctx->outlen, blockhash_bytes,
771
359
        ARGON2_BLOCK_SIZE);
772
359
    OPENSSL_cleanse(blockhash.v, ARGON2_BLOCK_SIZE);
773
359
    OPENSSL_cleanse(blockhash_bytes, ARGON2_BLOCK_SIZE);
774
775
359
    if (ctx->type != ARGON2_D)
776
206
        OPENSSL_secure_clear_free(ctx->memory,
777
359
            ctx->memory_blocks * sizeof(BLOCK));
778
153
    else
779
153
        OPENSSL_clear_free(ctx->memory,
780
359
            ctx->memory_blocks * sizeof(BLOCK));
781
359
}
782
783
static int blake2b_mac(EVP_MAC *mac, void *out, size_t outlen, const void *in,
784
    size_t inlen, const void *key, size_t keylen)
785
0
{
786
0
    int ret = 0;
787
0
    size_t par_n = 0, out_written;
788
0
    EVP_MAC_CTX *ctx = NULL;
789
0
    OSSL_PARAM par[3];
790
791
0
    if ((ctx = EVP_MAC_CTX_new(mac)) == NULL)
792
0
        goto fail;
793
794
0
    par[par_n++] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,
795
0
        (void *)key, keylen);
796
0
    par[par_n++] = OSSL_PARAM_construct_size_t(OSSL_MAC_PARAM_SIZE, &outlen);
797
0
    par[par_n++] = OSSL_PARAM_construct_end();
798
799
0
    ret = EVP_MAC_CTX_set_params(ctx, par) == 1
800
0
        && EVP_MAC_init(ctx, NULL, 0, NULL) == 1
801
0
        && EVP_MAC_update(ctx, in, inlen) == 1
802
0
        && EVP_MAC_final(ctx, out, (size_t *)&out_written, outlen) == 1;
803
804
0
fail:
805
0
    EVP_MAC_CTX_free(ctx);
806
0
    return ret;
807
0
}
808
809
static int blake2b_md(EVP_MD *md, void *out, size_t outlen, const void *in,
810
    size_t inlen)
811
152k
{
812
152k
    int ret = 0;
813
152k
    EVP_MD_CTX *ctx = NULL;
814
152k
    OSSL_PARAM par[2];
815
816
152k
    if ((ctx = EVP_MD_CTX_create()) == NULL)
817
0
        return 0;
818
819
152k
    par[0] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_SIZE, &outlen);
820
152k
    par[1] = OSSL_PARAM_construct_end();
821
822
152k
    ret = EVP_DigestInit_ex2(ctx, md, par) == 1
823
152k
        && EVP_DigestUpdate(ctx, in, inlen) == 1
824
152k
        && EVP_DigestFinal_ex(ctx, out, NULL) == 1;
825
826
152k
    EVP_MD_CTX_free(ctx);
827
152k
    return ret;
828
152k
}
829
830
static int blake2b(EVP_MD *md, EVP_MAC *mac, void *out, size_t outlen,
831
    const void *in, size_t inlen, const void *key, size_t keylen)
832
152k
{
833
152k
    if (out == NULL || outlen == 0)
834
0
        return 0;
835
836
152k
    if (key == NULL || keylen == 0)
837
152k
        return blake2b_md(md, out, outlen, in, inlen);
838
839
0
    return blake2b_mac(mac, out, outlen, in, inlen, key, keylen);
840
152k
}
841
842
static int blake2b_long(EVP_MD *md, EVP_MAC *mac, unsigned char *out,
843
    size_t outlen, const void *in, size_t inlen)
844
5.44k
{
845
5.44k
    int ret = 0;
846
5.44k
    EVP_MD_CTX *ctx = NULL;
847
5.44k
    uint32_t outlen_curr;
848
5.44k
    uint8_t outbuf[BLAKE2B_OUTBYTES];
849
5.44k
    uint8_t inbuf[BLAKE2B_OUTBYTES];
850
5.44k
    uint8_t outlen_bytes[sizeof(uint32_t)] = { 0 };
851
5.44k
    OSSL_PARAM par[2];
852
5.44k
    size_t outlen_md;
853
854
5.44k
    if (out == NULL || outlen == 0)
855
0
        return 0;
856
857
    /* Ensure little-endian byte order */
858
5.44k
    store32(outlen_bytes, (uint32_t)outlen);
859
860
5.44k
    if ((ctx = EVP_MD_CTX_create()) == NULL)
861
0
        return 0;
862
863
5.44k
    outlen_md = (outlen <= BLAKE2B_OUTBYTES) ? outlen : BLAKE2B_OUTBYTES;
864
5.44k
    par[0] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_SIZE, &outlen_md);
865
5.44k
    par[1] = OSSL_PARAM_construct_end();
866
867
5.44k
    ret = EVP_DigestInit_ex2(ctx, md, par) == 1
868
5.44k
        && EVP_DigestUpdate(ctx, outlen_bytes, sizeof(outlen_bytes)) == 1
869
5.44k
        && EVP_DigestUpdate(ctx, in, inlen) == 1
870
5.44k
        && EVP_DigestFinal_ex(ctx, (outlen > BLAKE2B_OUTBYTES) ? outbuf : out,
871
5.44k
               NULL)
872
5.44k
            == 1;
873
874
5.44k
    if (ret == 0)
875
0
        goto fail;
876
877
5.44k
    if (outlen > BLAKE2B_OUTBYTES) {
878
5.08k
        memcpy(out, outbuf, BLAKE2B_OUTBYTES / 2);
879
5.08k
        out += BLAKE2B_OUTBYTES / 2;
880
5.08k
        outlen_curr = (uint32_t)outlen - BLAKE2B_OUTBYTES / 2;
881
882
152k
        while (outlen_curr > BLAKE2B_OUTBYTES) {
883
147k
            memcpy(inbuf, outbuf, BLAKE2B_OUTBYTES);
884
147k
            if (blake2b(md, mac, outbuf, BLAKE2B_OUTBYTES, inbuf,
885
147k
                    BLAKE2B_OUTBYTES, NULL, 0)
886
147k
                != 1)
887
0
                goto fail;
888
147k
            memcpy(out, outbuf, BLAKE2B_OUTBYTES / 2);
889
147k
            out += BLAKE2B_OUTBYTES / 2;
890
147k
            outlen_curr -= BLAKE2B_OUTBYTES / 2;
891
147k
        }
892
893
5.08k
        memcpy(inbuf, outbuf, BLAKE2B_OUTBYTES);
894
5.08k
        if (blake2b(md, mac, outbuf, outlen_curr, inbuf, BLAKE2B_OUTBYTES,
895
5.08k
                NULL, 0)
896
5.08k
            != 1)
897
0
            goto fail;
898
5.08k
        memcpy(out, outbuf, outlen_curr);
899
5.08k
    }
900
5.44k
    ret = 1;
901
902
5.44k
fail:
903
5.44k
    EVP_MD_CTX_free(ctx);
904
5.44k
    return ret;
905
5.44k
}
906
907
static void kdf_argon2_init(KDF_ARGON2 *c, ARGON2_TYPE type)
908
826
{
909
826
    OSSL_LIB_CTX *libctx;
910
911
826
    libctx = c->libctx;
912
826
    memset(c, 0, sizeof(*c));
913
914
826
    c->libctx = libctx;
915
826
    c->outlen = ARGON2_DEFAULT_OUTLEN;
916
826
    c->t_cost = ARGON2_DEFAULT_T_COST;
917
826
    c->m_cost = ARGON2_DEFAULT_M_COST;
918
826
    c->lanes = ARGON2_DEFAULT_LANES;
919
826
    c->threads = ARGON2_DEFAULT_THREADS;
920
826
    c->version = ARGON2_DEFAULT_VERSION;
921
826
    c->type = type;
922
826
}
923
924
static void *kdf_argon2d_new(void *provctx)
925
330
{
926
330
    KDF_ARGON2 *ctx;
927
928
330
    if (!ossl_prov_is_running())
929
0
        return NULL;
930
931
330
    ctx = OPENSSL_zalloc(sizeof(*ctx));
932
330
    if (ctx == NULL) {
933
0
        ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
934
0
        return NULL;
935
0
    }
936
937
330
    ctx->libctx = PROV_LIBCTX_OF(provctx);
938
939
330
    kdf_argon2_init(ctx, ARGON2_D);
940
330
    return ctx;
941
330
}
942
943
static void *kdf_argon2i_new(void *provctx)
944
283
{
945
283
    KDF_ARGON2 *ctx;
946
947
283
    if (!ossl_prov_is_running())
948
0
        return NULL;
949
950
283
    ctx = OPENSSL_zalloc(sizeof(*ctx));
951
283
    if (ctx == NULL) {
952
0
        ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
953
0
        return NULL;
954
0
    }
955
956
283
    ctx->libctx = PROV_LIBCTX_OF(provctx);
957
958
283
    kdf_argon2_init(ctx, ARGON2_I);
959
283
    return ctx;
960
283
}
961
962
static void *kdf_argon2id_new(void *provctx)
963
213
{
964
213
    KDF_ARGON2 *ctx;
965
966
213
    if (!ossl_prov_is_running())
967
0
        return NULL;
968
969
213
    ctx = OPENSSL_zalloc(sizeof(*ctx));
970
213
    if (ctx == NULL) {
971
0
        ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
972
0
        return NULL;
973
0
    }
974
975
213
    ctx->libctx = PROV_LIBCTX_OF(provctx);
976
977
213
    kdf_argon2_init(ctx, ARGON2_ID);
978
213
    return ctx;
979
213
}
980
981
static void kdf_argon2_free(void *vctx)
982
826
{
983
826
    KDF_ARGON2 *ctx = (KDF_ARGON2 *)vctx;
984
985
826
    if (ctx == NULL)
986
0
        return;
987
988
826
    if (ctx->pwd != NULL)
989
826
        OPENSSL_clear_free(ctx->pwd, ctx->pwdlen);
990
991
826
    if (ctx->salt != NULL)
992
681
        OPENSSL_clear_free(ctx->salt, ctx->saltlen);
993
994
826
    if (ctx->secret != NULL)
995
681
        OPENSSL_clear_free(ctx->secret, ctx->secretlen);
996
997
826
    if (ctx->ad != NULL)
998
681
        OPENSSL_clear_free(ctx->ad, ctx->adlen);
999
1000
826
    EVP_MD_free(ctx->md);
1001
826
    EVP_MAC_free(ctx->mac);
1002
1003
826
    OPENSSL_free(ctx->propq);
1004
1005
826
    memset(ctx, 0, sizeof(*ctx));
1006
1007
826
    OPENSSL_free(ctx);
1008
826
}
1009
1010
static int kdf_argon2_derive(void *vctx, unsigned char *out, size_t outlen,
1011
    const OSSL_PARAM params[])
1012
406
{
1013
406
    KDF_ARGON2 *ctx;
1014
406
    uint32_t memory_blocks, segment_length;
1015
1016
406
    ctx = (KDF_ARGON2 *)vctx;
1017
1018
406
    if (!ossl_prov_is_running() || !kdf_argon2_set_ctx_params(vctx, params))
1019
0
        return 0;
1020
1021
406
    if (ctx->mac == NULL)
1022
406
        ctx->mac = EVP_MAC_fetch(ctx->libctx, "blake2bmac", ctx->propq);
1023
406
    if (ctx->mac == NULL) {
1024
5
        ERR_raise_data(ERR_LIB_PROV, PROV_R_MISSING_MAC,
1025
5
            "cannot fetch blake2bmac");
1026
5
        return 0;
1027
5
    }
1028
1029
401
    if (ctx->md == NULL)
1030
401
        ctx->md = EVP_MD_fetch(ctx->libctx, "blake2b512", ctx->propq);
1031
401
    if (ctx->md == NULL) {
1032
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST,
1033
0
            "cannot fetch blake2b512");
1034
0
        return 0;
1035
0
    }
1036
1037
401
    if (ctx->salt == NULL || ctx->saltlen == 0) {
1038
0
        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_SALT);
1039
0
        return 0;
1040
0
    }
1041
1042
401
    if (outlen != ctx->outlen) {
1043
327
        if (OSSL_PARAM_locate((OSSL_PARAM *)params, "size") != NULL) {
1044
0
            ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
1045
0
            return 0;
1046
0
        }
1047
327
        if (!kdf_argon2_ctx_set_out_length(ctx, (uint32_t)outlen))
1048
0
            return 0;
1049
327
    }
1050
1051
401
    switch (ctx->type) {
1052
161
    case ARGON2_D:
1053
309
    case ARGON2_I:
1054
401
    case ARGON2_ID:
1055
401
        break;
1056
0
    default:
1057
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MODE, "invalid Argon2 type");
1058
0
        return 0;
1059
401
    }
1060
1061
401
    if (ctx->threads > 1) {
1062
#ifdef ARGON2_NO_THREADS
1063
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_THREAD_POOL_SIZE,
1064
            "requested %u threads, single-threaded mode supported only",
1065
            ctx->threads);
1066
        return 0;
1067
#else
1068
28
        if (ctx->threads > ossl_get_avail_threads(ctx->libctx)) {
1069
28
            ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_THREAD_POOL_SIZE,
1070
28
                "requested %u threads, available: %u",
1071
28
                ctx->threads, ossl_get_avail_threads(ctx->libctx));
1072
28
            return 0;
1073
28
        }
1074
0
#endif
1075
0
        if (ctx->threads > ctx->lanes) {
1076
0
            ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_THREAD_POOL_SIZE,
1077
0
                "requested more threads (%u) than lanes (%u)",
1078
0
                ctx->threads, ctx->lanes);
1079
0
            return 0;
1080
0
        }
1081
0
    }
1082
1083
373
    if (ctx->m_cost < 8 * ctx->lanes) {
1084
14
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MEMORY_SIZE,
1085
14
            "m_cost must be greater or equal than 8 times the number of lanes");
1086
14
        return 0;
1087
14
    }
1088
1089
359
    memory_blocks = ctx->m_cost;
1090
359
    if (memory_blocks < 2 * ARGON2_SYNC_POINTS * ctx->lanes)
1091
0
        memory_blocks = 2 * ARGON2_SYNC_POINTS * ctx->lanes;
1092
1093
    /* Ensure that all segments have equal length */
1094
359
    segment_length = memory_blocks / (ctx->lanes * ARGON2_SYNC_POINTS);
1095
359
    memory_blocks = segment_length * (ctx->lanes * ARGON2_SYNC_POINTS);
1096
1097
359
    ctx->memory = NULL;
1098
359
    ctx->memory_blocks = memory_blocks;
1099
359
    ctx->segment_length = segment_length;
1100
359
    ctx->passes = ctx->t_cost;
1101
359
    ctx->lane_length = segment_length * ARGON2_SYNC_POINTS;
1102
1103
359
    if (initialize(ctx) != 1)
1104
0
        return 0;
1105
1106
359
    if (fill_memory_blocks(ctx) != 1)
1107
0
        return 0;
1108
1109
359
    finalize(ctx, out);
1110
1111
359
    return 1;
1112
359
}
1113
1114
static void kdf_argon2_reset(void *vctx)
1115
0
{
1116
0
    OSSL_LIB_CTX *libctx;
1117
0
    KDF_ARGON2 *ctx;
1118
0
    ARGON2_TYPE type;
1119
1120
0
    ctx = (KDF_ARGON2 *)vctx;
1121
0
    type = ctx->type;
1122
0
    libctx = ctx->libctx;
1123
1124
0
    EVP_MD_free(ctx->md);
1125
0
    EVP_MAC_free(ctx->mac);
1126
1127
0
    OPENSSL_free(ctx->propq);
1128
1129
0
    if (ctx->pwd != NULL)
1130
0
        OPENSSL_clear_free(ctx->pwd, ctx->pwdlen);
1131
1132
0
    if (ctx->salt != NULL)
1133
0
        OPENSSL_clear_free(ctx->salt, ctx->saltlen);
1134
1135
0
    if (ctx->secret != NULL)
1136
0
        OPENSSL_clear_free(ctx->secret, ctx->secretlen);
1137
1138
0
    if (ctx->ad != NULL)
1139
0
        OPENSSL_clear_free(ctx->ad, ctx->adlen);
1140
1141
0
    memset(ctx, 0, sizeof(*ctx));
1142
0
    ctx->libctx = libctx;
1143
0
    kdf_argon2_init(ctx, type);
1144
0
}
1145
1146
static int kdf_argon2_ctx_set_threads(KDF_ARGON2 *ctx, uint32_t threads)
1147
590
{
1148
590
    if (threads < ARGON2_MIN_THREADS) {
1149
43
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_THREAD_POOL_SIZE,
1150
43
            "min threads: %u", ARGON2_MIN_THREADS);
1151
43
        return 0;
1152
43
    }
1153
1154
547
    if (threads > ARGON2_MAX_THREADS) {
1155
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_THREAD_POOL_SIZE,
1156
0
            "max threads: %u", ARGON2_MAX_THREADS);
1157
0
        return 0;
1158
0
    }
1159
1160
547
    ctx->threads = threads;
1161
547
    return 1;
1162
547
}
1163
1164
static int kdf_argon2_ctx_set_lanes(KDF_ARGON2 *ctx, uint32_t lanes)
1165
547
{
1166
547
    if (lanes > ARGON2_MAX_LANES) {
1167
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER,
1168
0
            "max lanes: %u", ARGON2_MAX_LANES);
1169
0
        return 0;
1170
0
    }
1171
1172
547
    if (lanes < ARGON2_MIN_LANES) {
1173
32
        ERR_raise_data(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER,
1174
32
            "min lanes: %u", ARGON2_MIN_LANES);
1175
32
        return 0;
1176
32
    }
1177
1178
515
    ctx->lanes = lanes;
1179
515
    return 1;
1180
547
}
1181
1182
static int kdf_argon2_ctx_set_t_cost(KDF_ARGON2 *ctx, uint32_t t_cost)
1183
590
{
1184
    /* ARGON2_MAX_MEMORY == max m_cost value, so skip check  */
1185
1186
590
    if (t_cost < ARGON2_MIN_TIME) {
1187
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_ITERATION_COUNT,
1188
0
            "min: %u", ARGON2_MIN_TIME);
1189
0
        return 0;
1190
0
    }
1191
1192
590
    ctx->t_cost = t_cost;
1193
590
    return 1;
1194
590
}
1195
1196
static int kdf_argon2_ctx_set_m_cost(KDF_ARGON2 *ctx, uint32_t m_cost)
1197
515
{
1198
    /* ARGON2_MAX_MEMORY == max m_cost value, so skip check */
1199
1200
515
    if (m_cost < ARGON2_MIN_MEMORY) {
1201
39
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MEMORY_SIZE, "min: %u",
1202
39
            ARGON2_MIN_MEMORY);
1203
39
        return 0;
1204
39
    }
1205
1206
476
    ctx->m_cost = m_cost;
1207
476
    return 1;
1208
515
}
1209
1210
static int kdf_argon2_ctx_set_out_length(KDF_ARGON2 *ctx, uint32_t outlen)
1211
1.00k
{
1212
    /*
1213
     * ARGON2_MAX_OUT_LENGTH == max outlen value, so upper bounds checks
1214
     * are always satisfied; to suppress compiler if statement tautology
1215
     * warnings, these checks are skipped.
1216
     */
1217
1218
1.00k
    if (outlen < ARGON2_MIN_OUT_LENGTH) {
1219
91
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_OUTPUT_LENGTH, "min: %u",
1220
91
            ARGON2_MIN_OUT_LENGTH);
1221
91
        return 0;
1222
91
    }
1223
1224
917
    ctx->outlen = outlen;
1225
917
    return 1;
1226
1.00k
}
1227
1228
static int kdf_argon2_ctx_set_secret(KDF_ARGON2 *ctx, const OSSL_PARAM *p)
1229
681
{
1230
681
    size_t buflen;
1231
1232
681
    if (p->data == NULL)
1233
0
        return 0;
1234
1235
681
    if (ctx->secret != NULL) {
1236
0
        OPENSSL_clear_free(ctx->secret, ctx->secretlen);
1237
0
        ctx->secret = NULL;
1238
0
        ctx->secretlen = 0U;
1239
0
    }
1240
1241
681
    if (!OSSL_PARAM_get_octet_string(p, (void **)&ctx->secret, 0, &buflen))
1242
0
        return 0;
1243
1244
681
    if (buflen > ARGON2_MAX_SECRET) {
1245
0
        OPENSSL_free(ctx->secret);
1246
0
        ctx->secret = NULL;
1247
0
        ctx->secretlen = 0U;
1248
0
        return 0;
1249
0
    }
1250
1251
681
    ctx->secretlen = (uint32_t)buflen;
1252
681
    return 1;
1253
681
}
1254
1255
static int kdf_argon2_ctx_set_pwd(KDF_ARGON2 *ctx, const OSSL_PARAM *p)
1256
826
{
1257
826
    size_t buflen;
1258
1259
826
    if (p->data == NULL)
1260
0
        return 0;
1261
1262
826
    if (ctx->pwd != NULL) {
1263
0
        OPENSSL_clear_free(ctx->pwd, ctx->pwdlen);
1264
0
        ctx->pwd = NULL;
1265
0
        ctx->pwdlen = 0U;
1266
0
    }
1267
1268
826
    if (!OSSL_PARAM_get_octet_string(p, (void **)&ctx->pwd, 0, &buflen))
1269
0
        return 0;
1270
1271
826
    if (buflen > ARGON2_MAX_PWD_LENGTH) {
1272
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_SALT_LENGTH, "max: %u",
1273
0
            ARGON2_MAX_PWD_LENGTH);
1274
0
        goto fail;
1275
0
    }
1276
1277
826
    ctx->pwdlen = (uint32_t)buflen;
1278
826
    return 1;
1279
1280
0
fail:
1281
0
    OPENSSL_free(ctx->pwd);
1282
0
    ctx->pwd = NULL;
1283
0
    ctx->pwdlen = 0U;
1284
0
    return 0;
1285
826
}
1286
1287
static int kdf_argon2_ctx_set_salt(KDF_ARGON2 *ctx, const OSSL_PARAM *p)
1288
826
{
1289
826
    size_t buflen;
1290
1291
826
    if (p->data == NULL)
1292
0
        return 0;
1293
1294
826
    if (ctx->salt != NULL) {
1295
0
        OPENSSL_clear_free(ctx->salt, ctx->saltlen);
1296
0
        ctx->salt = NULL;
1297
0
        ctx->saltlen = 0U;
1298
0
    }
1299
1300
826
    if (!OSSL_PARAM_get_octet_string(p, (void **)&ctx->salt, 0, &buflen))
1301
0
        return 0;
1302
1303
826
    if (buflen < ARGON2_MIN_SALT_LENGTH) {
1304
145
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_SALT_LENGTH, "min: %u",
1305
145
            ARGON2_MIN_SALT_LENGTH);
1306
145
        goto fail;
1307
145
    }
1308
1309
681
    if (buflen > ARGON2_MAX_SALT_LENGTH) {
1310
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_SALT_LENGTH, "max: %u",
1311
0
            ARGON2_MAX_SALT_LENGTH);
1312
0
        goto fail;
1313
0
    }
1314
1315
681
    ctx->saltlen = (uint32_t)buflen;
1316
681
    return 1;
1317
1318
145
fail:
1319
145
    OPENSSL_free(ctx->salt);
1320
145
    ctx->salt = NULL;
1321
145
    ctx->saltlen = 0U;
1322
145
    return 0;
1323
681
}
1324
1325
static int kdf_argon2_ctx_set_ad(KDF_ARGON2 *ctx, const OSSL_PARAM *p)
1326
681
{
1327
681
    size_t buflen;
1328
1329
681
    if (p->data == NULL)
1330
0
        return 0;
1331
1332
681
    if (ctx->ad != NULL) {
1333
0
        OPENSSL_clear_free(ctx->ad, ctx->adlen);
1334
0
        ctx->ad = NULL;
1335
0
        ctx->adlen = 0U;
1336
0
    }
1337
1338
681
    if (!OSSL_PARAM_get_octet_string(p, (void **)&ctx->ad, 0, &buflen))
1339
0
        return 0;
1340
1341
681
    if (buflen > ARGON2_MAX_AD_LENGTH) {
1342
0
        OPENSSL_free(ctx->ad);
1343
0
        ctx->ad = NULL;
1344
0
        ctx->adlen = 0U;
1345
0
        return 0;
1346
0
    }
1347
1348
681
    ctx->adlen = (uint32_t)buflen;
1349
681
    return 1;
1350
681
}
1351
1352
static void kdf_argon2_ctx_set_flag_early_clean(KDF_ARGON2 *ctx, uint32_t f)
1353
476
{
1354
476
    ctx->early_clean = !!(f);
1355
476
}
1356
1357
static int kdf_argon2_ctx_set_version(KDF_ARGON2 *ctx, uint32_t version)
1358
476
{
1359
476
    switch (version) {
1360
192
    case ARGON2_VERSION_10:
1361
406
    case ARGON2_VERSION_13:
1362
406
        ctx->version = version;
1363
406
        return 1;
1364
70
    default:
1365
70
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MODE,
1366
70
            "invalid Argon2 version");
1367
70
        return 0;
1368
476
    }
1369
476
}
1370
1371
static int set_property_query(KDF_ARGON2 *ctx, const char *propq)
1372
406
{
1373
406
    OPENSSL_free(ctx->propq);
1374
406
    ctx->propq = NULL;
1375
406
    if (propq != NULL) {
1376
406
        ctx->propq = OPENSSL_strdup(propq);
1377
406
        if (ctx->propq == NULL)
1378
0
            return 0;
1379
406
    }
1380
406
    EVP_MD_free(ctx->md);
1381
406
    ctx->md = NULL;
1382
406
    EVP_MAC_free(ctx->mac);
1383
406
    ctx->mac = NULL;
1384
406
    return 1;
1385
406
}
1386
1387
static int kdf_argon2_set_ctx_params(void *vctx, const OSSL_PARAM params[])
1388
331
{
1389
331
    const OSSL_PARAM *p;
1390
331
    KDF_ARGON2 *ctx;
1391
331
    uint32_t u32_value;
1392
1393
331
    if (params == NULL)
1394
100
        return 1;
1395
1396
231
    ctx = (KDF_ARGON2 *)vctx;
1397
231
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PASSWORD)) != NULL)
1398
231
        if (!kdf_argon2_ctx_set_pwd(ctx, p))
1399
0
            return 0;
1400
1401
231
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SALT)) != NULL)
1402
231
        if (!kdf_argon2_ctx_set_salt(ctx, p))
1403
44
            return 0;
1404
1405
187
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SECRET)) != NULL)
1406
187
        if (!kdf_argon2_ctx_set_secret(ctx, p))
1407
0
            return 0;
1408
1409
187
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ARGON2_AD)) != NULL)
1410
187
        if (!kdf_argon2_ctx_set_ad(ctx, p))
1411
0
            return 0;
1412
1413
187
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SIZE)) != NULL) {
1414
187
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1415
0
            return 0;
1416
187
        if (!kdf_argon2_ctx_set_out_length(ctx, u32_value))
1417
32
            return 0;
1418
187
    }
1419
1420
155
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ITER)) != NULL) {
1421
155
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1422
0
            return 0;
1423
155
        if (!kdf_argon2_ctx_set_t_cost(ctx, u32_value))
1424
0
            return 0;
1425
155
    }
1426
1427
155
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_THREADS)) != NULL) {
1428
155
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1429
0
            return 0;
1430
155
        if (!kdf_argon2_ctx_set_threads(ctx, u32_value))
1431
20
            return 0;
1432
155
    }
1433
1434
135
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ARGON2_LANES)) != NULL) {
1435
135
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1436
0
            return 0;
1437
135
        if (!kdf_argon2_ctx_set_lanes(ctx, u32_value))
1438
9
            return 0;
1439
135
    }
1440
1441
126
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ARGON2_MEMCOST)) != NULL) {
1442
126
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1443
0
            return 0;
1444
126
        if (!kdf_argon2_ctx_set_m_cost(ctx, u32_value))
1445
8
            return 0;
1446
126
    }
1447
1448
118
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_EARLY_CLEAN)) != NULL) {
1449
118
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1450
0
            return 0;
1451
118
        kdf_argon2_ctx_set_flag_early_clean(ctx, u32_value);
1452
118
    }
1453
1454
118
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ARGON2_VERSION)) != NULL) {
1455
118
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1456
0
            return 0;
1457
118
        if (!kdf_argon2_ctx_set_version(ctx, u32_value))
1458
18
            return 0;
1459
118
    }
1460
1461
100
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PROPERTIES)) != NULL) {
1462
100
        if (p->data_type != OSSL_PARAM_UTF8_STRING
1463
100
            || !set_property_query(ctx, p->data))
1464
0
            return 0;
1465
100
    }
1466
1467
100
    return 1;
1468
100
}
1469
1470
static const OSSL_PARAM *kdf_argon2_settable_ctx_params(ossl_unused void *ctx,
1471
    ossl_unused void *p_ctx)
1472
826
{
1473
826
    static const OSSL_PARAM known_settable_ctx_params[] = {
1474
826
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_PASSWORD, NULL, 0),
1475
826
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SALT, NULL, 0),
1476
826
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SECRET, NULL, 0),
1477
826
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_ARGON2_AD, NULL, 0),
1478
826
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_SIZE, NULL),
1479
826
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_ITER, NULL),
1480
826
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_THREADS, NULL),
1481
826
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_ARGON2_LANES, NULL),
1482
826
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_ARGON2_MEMCOST, NULL),
1483
826
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_EARLY_CLEAN, NULL),
1484
826
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_ARGON2_VERSION, NULL),
1485
826
        OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0),
1486
826
        OSSL_PARAM_END
1487
826
    };
1488
1489
826
    return known_settable_ctx_params;
1490
826
}
1491
1492
static int kdf_argon2_get_ctx_params(void *vctx, OSSL_PARAM params[])
1493
0
{
1494
0
    OSSL_PARAM *p;
1495
1496
0
    (void)vctx;
1497
0
    if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL)
1498
0
        return OSSL_PARAM_set_size_t(p, SIZE_MAX);
1499
1500
0
    return -2;
1501
0
}
1502
1503
static const OSSL_PARAM *kdf_argon2_gettable_ctx_params(ossl_unused void *ctx,
1504
    ossl_unused void *p_ctx)
1505
0
{
1506
0
    static const OSSL_PARAM known_gettable_ctx_params[] = {
1507
0
        OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL),
1508
0
        OSSL_PARAM_END
1509
0
    };
1510
1511
0
    return known_gettable_ctx_params;
1512
0
}
1513
1514
const OSSL_DISPATCH ossl_kdf_argon2i_functions[] = {
1515
    { OSSL_FUNC_KDF_NEWCTX, (void (*)(void))kdf_argon2i_new },
1516
    { OSSL_FUNC_KDF_FREECTX, (void (*)(void))kdf_argon2_free },
1517
    { OSSL_FUNC_KDF_RESET, (void (*)(void))kdf_argon2_reset },
1518
    { OSSL_FUNC_KDF_DERIVE, (void (*)(void))kdf_argon2_derive },
1519
    { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS,
1520
        (void (*)(void))kdf_argon2_settable_ctx_params },
1521
    { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void (*)(void))kdf_argon2_set_ctx_params },
1522
    { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
1523
        (void (*)(void))kdf_argon2_gettable_ctx_params },
1524
    { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void (*)(void))kdf_argon2_get_ctx_params },
1525
    OSSL_DISPATCH_END
1526
};
1527
1528
const OSSL_DISPATCH ossl_kdf_argon2d_functions[] = {
1529
    { OSSL_FUNC_KDF_NEWCTX, (void (*)(void))kdf_argon2d_new },
1530
    { OSSL_FUNC_KDF_FREECTX, (void (*)(void))kdf_argon2_free },
1531
    { OSSL_FUNC_KDF_RESET, (void (*)(void))kdf_argon2_reset },
1532
    { OSSL_FUNC_KDF_DERIVE, (void (*)(void))kdf_argon2_derive },
1533
    { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS,
1534
        (void (*)(void))kdf_argon2_settable_ctx_params },
1535
    { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void (*)(void))kdf_argon2_set_ctx_params },
1536
    { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
1537
        (void (*)(void))kdf_argon2_gettable_ctx_params },
1538
    { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void (*)(void))kdf_argon2_get_ctx_params },
1539
    OSSL_DISPATCH_END
1540
};
1541
1542
const OSSL_DISPATCH ossl_kdf_argon2id_functions[] = {
1543
    { OSSL_FUNC_KDF_NEWCTX, (void (*)(void))kdf_argon2id_new },
1544
    { OSSL_FUNC_KDF_FREECTX, (void (*)(void))kdf_argon2_free },
1545
    { OSSL_FUNC_KDF_RESET, (void (*)(void))kdf_argon2_reset },
1546
    { OSSL_FUNC_KDF_DERIVE, (void (*)(void))kdf_argon2_derive },
1547
    { OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS,
1548
        (void (*)(void))kdf_argon2_settable_ctx_params },
1549
    { OSSL_FUNC_KDF_SET_CTX_PARAMS, (void (*)(void))kdf_argon2_set_ctx_params },
1550
    { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
1551
        (void (*)(void))kdf_argon2_gettable_ctx_params },
1552
    { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void (*)(void))kdf_argon2_get_ctx_params },
1553
    OSSL_DISPATCH_END
1554
};
1555
1556
#endif