Coverage Report

Created: 2026-04-01 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl34/providers/implementations/kdfs/argon2.c
Line
Count
Source
1
/*
2
 * Copyright 2022-2024 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
555
#define ARGON2_MIN_LANES 1u
47
524
#define ARGON2_MAX_LANES 0xFFFFFFu
48
604
#define ARGON2_MIN_THREADS 1u
49
524
#define ARGON2_MAX_THREADS 0xFFFFFFu
50
14.6k
#define ARGON2_SYNC_POINTS 4u
51
1.08k
#define ARGON2_MIN_OUT_LENGTH 4u
52
#define ARGON2_MAX_OUT_LENGTH 0xFFFFFFFFu
53
1.31k
#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
564
#define ARGON2_MIN_TIME 1u
57
#define ARGON2_MAX_TIME 0xFFFFFFFFu
58
#define ARGON2_MIN_PWD_LENGTH 0u
59
790
#define ARGON2_MAX_PWD_LENGTH 0xFFFFFFFFu
60
#define ARGON2_MIN_AD_LENGTH 0u
61
658
#define ARGON2_MAX_AD_LENGTH 0xFFFFFFFFu
62
922
#define ARGON2_MIN_SALT_LENGTH 8u
63
658
#define ARGON2_MAX_SALT_LENGTH 0xFFFFFFFFu
64
#define ARGON2_MIN_SECRET 0u
65
658
#define ARGON2_MAX_SECRET 0xFFFFFFFFu
66
12.1M
#define ARGON2_BLOCK_SIZE 1024
67
12.1M
#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
27.3k
#define ARGON2_ADDRESSES_IN_BLOCK 128
72
14.0k
#define ARGON2_PREHASH_DIGEST_LENGTH 64
73
#define ARGON2_PREHASH_SEED_LENGTH \
74
5.61k
    (ARGON2_PREHASH_DIGEST_LENGTH + (2 * sizeof(uint32_t)))
75
76
790
#define ARGON2_DEFAULT_OUTLEN 64u
77
790
#define ARGON2_DEFAULT_T_COST 3u
78
790
#define ARGON2_DEFAULT_M_COST ARGON2_MIN_MEMORY
79
790
#define ARGON2_DEFAULT_LANES 1u
80
790
#define ARGON2_DEFAULT_THREADS 1u
81
790
#define ARGON2_DEFAULT_VERSION ARGON2_VERSION_NUMBER
82
83
#undef G
84
#define G(a, b, c, d)                    \
85
5.49M
    do {                                 \
86
5.49M
        a = a + b + 2 * mul_lower(a, b); \
87
5.49M
        d = rotr64(d ^ a, 32);           \
88
5.49M
        c = c + d + 2 * mul_lower(c, d); \
89
5.49M
        b = rotr64(b ^ c, 24);           \
90
5.49M
        a = a + b + 2 * mul_lower(a, b); \
91
5.49M
        d = rotr64(d ^ a, 16);           \
92
5.49M
        c = c + d + 2 * mul_lower(c, d); \
93
5.49M
        b = rotr64(b ^ c, 63);           \
94
5.49M
    } 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
686k
    do {                                                                \
100
686k
        G(v0, v4, v8, v12);                                             \
101
686k
        G(v1, v5, v9, v13);                                             \
102
686k
        G(v2, v6, v10, v14);                                            \
103
686k
        G(v3, v7, v11, v15);                                            \
104
686k
        G(v0, v5, v10, v15);                                            \
105
686k
        G(v1, v6, v11, v12);                                            \
106
686k
        G(v2, v7, v8, v13);                                             \
107
686k
        G(v3, v4, v9, v14);                                             \
108
686k
    } while ((void)0, 0)
109
110
#undef PERMUTATION_P_COLUMN
111
#define PERMUTATION_P_COLUMN(x, i)                                   \
112
343k
    do {                                                             \
113
343k
        uint64_t *base = &x[16 * i];                                 \
114
343k
        PERMUTATION_P(                                               \
115
343k
            *base, *(base + 1), *(base + 2), *(base + 3),            \
116
343k
            *(base + 4), *(base + 5), *(base + 6), *(base + 7),      \
117
343k
            *(base + 8), *(base + 9), *(base + 10), *(base + 11),    \
118
343k
            *(base + 12), *(base + 13), *(base + 14), *(base + 15)); \
119
343k
    } while ((void)0, 0)
120
121
#undef PERMUTATION_P_ROW
122
#define PERMUTATION_P_ROW(x, i)                                        \
123
343k
    do {                                                               \
124
343k
        uint64_t *base = &x[2 * i];                                    \
125
343k
        PERMUTATION_P(                                                 \
126
343k
            *base, *(base + 1), *(base + 16), *(base + 17),            \
127
343k
            *(base + 32), *(base + 33), *(base + 48), *(base + 49),    \
128
343k
            *(base + 64), *(base + 65), *(base + 80), *(base + 81),    \
129
343k
            *(base + 96), *(base + 97), *(base + 112), *(base + 113)); \
130
343k
    } 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
631k
{
269
631k
    return (((uint64_t)src[0]) << 0)
270
631k
        | (((uint64_t)src[1]) << 8)
271
631k
        | (((uint64_t)src[2]) << 16)
272
631k
        | (((uint64_t)src[3]) << 24)
273
631k
        | (((uint64_t)src[4]) << 32)
274
631k
        | (((uint64_t)src[5]) << 40)
275
631k
        | (((uint64_t)src[6]) << 48)
276
631k
        | (((uint64_t)src[7]) << 56);
277
631k
}
278
279
static ossl_inline void store32(uint8_t *dst, uint32_t w)
280
16.0k
{
281
16.0k
    dst[0] = (uint8_t)(w >> 0);
282
16.0k
    dst[1] = (uint8_t)(w >> 8);
283
16.0k
    dst[2] = (uint8_t)(w >> 16);
284
16.0k
    dst[3] = (uint8_t)(w >> 24);
285
16.0k
}
286
287
static ossl_inline void store64(uint8_t *dst, uint64_t w)
288
43.7k
{
289
43.7k
    dst[0] = (uint8_t)(w >> 0);
290
43.7k
    dst[1] = (uint8_t)(w >> 8);
291
43.7k
    dst[2] = (uint8_t)(w >> 16);
292
43.7k
    dst[3] = (uint8_t)(w >> 24);
293
43.7k
    dst[4] = (uint8_t)(w >> 32);
294
43.7k
    dst[5] = (uint8_t)(w >> 40);
295
43.7k
    dst[6] = (uint8_t)(w >> 48);
296
43.7k
    dst[7] = (uint8_t)(w >> 56);
297
43.7k
}
298
299
static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned int c)
300
21.9M
{
301
21.9M
    return (w >> c) | (w << (64 - c));
302
21.9M
}
303
304
static ossl_inline uint64_t mul_lower(uint64_t x, uint64_t y)
305
21.9M
{
306
21.9M
    const uint64_t m = 0xFFFFFFFFUL;
307
21.9M
    return (x & m) * (y & m);
308
21.9M
}
309
310
static void init_block_value(BLOCK *b, uint8_t in)
311
8.67k
{
312
8.67k
    memset(b->v, in, sizeof(b->v));
313
8.67k
}
314
315
static void copy_block(BLOCK *dst, const BLOCK *src)
316
129k
{
317
129k
    memcpy(dst->v, src->v, sizeof(uint64_t) * ARGON2_QWORDS_IN_BLOCK);
318
129k
}
319
320
static void xor_block(BLOCK *dst, const BLOCK *src)
321
87.9k
{
322
87.9k
    int i;
323
324
11.3M
    for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i)
325
11.2M
        dst->v[i] ^= src->v[i];
326
87.9k
}
327
328
static void load_block(BLOCK *dst, const void *input)
329
4.93k
{
330
4.93k
    unsigned i;
331
332
636k
    for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i)
333
631k
        dst->v[i] = load64((const uint8_t *)input + i * sizeof(dst->v[i]));
334
4.93k
}
335
336
static void store_block(void *output, const BLOCK *src)
337
342
{
338
342
    unsigned i;
339
340
44.1k
    for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i)
341
43.7k
        store64((uint8_t *)output + i * sizeof(src->v[i]), src->v[i]);
342
342
}
343
344
static void fill_first_blocks(uint8_t *blockhash, const KDF_ARGON2 *ctx)
345
342
{
346
342
    uint32_t l;
347
342
    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.80k
    for (l = 0; l < ctx->lanes; ++l) {
354
2.46k
        store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 0);
355
2.46k
        store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH + 4, l);
356
2.46k
        blake2b_long(ctx->md, ctx->mac, blockhash_bytes, ARGON2_BLOCK_SIZE,
357
2.46k
            blockhash, ARGON2_PREHASH_SEED_LENGTH);
358
2.46k
        load_block(&ctx->memory[l * ctx->lane_length + 0],
359
2.46k
            blockhash_bytes);
360
2.46k
        store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 1);
361
2.46k
        blake2b_long(ctx->md, ctx->mac, blockhash_bytes, ARGON2_BLOCK_SIZE,
362
2.46k
            blockhash, ARGON2_PREHASH_SEED_LENGTH);
363
2.46k
        load_block(&ctx->memory[l * ctx->lane_length + 1],
364
2.46k
            blockhash_bytes);
365
2.46k
    }
366
342
    OPENSSL_cleanse(blockhash_bytes, ARGON2_BLOCK_SIZE);
367
342
}
368
369
static void fill_block(const BLOCK *prev, const BLOCK *ref,
370
    BLOCK *next, int with_xor)
371
42.9k
{
372
42.9k
    BLOCK blockR, tmp;
373
42.9k
    unsigned i;
374
375
42.9k
    copy_block(&blockR, ref);
376
42.9k
    xor_block(&blockR, prev);
377
42.9k
    copy_block(&tmp, &blockR);
378
379
42.9k
    if (with_xor)
380
0
        xor_block(&tmp, next);
381
382
386k
    for (i = 0; i < 8; ++i)
383
343k
        PERMUTATION_P_COLUMN(blockR.v, i);
384
385
386k
    for (i = 0; i < 8; ++i)
386
343k
        PERMUTATION_P_ROW(blockR.v, i);
387
388
42.9k
    copy_block(next, &tmp);
389
42.9k
    xor_block(next, &blockR);
390
42.9k
}
391
392
static void next_addresses(BLOCK *address_block, BLOCK *input_block,
393
    const BLOCK *zero_block)
394
4.33k
{
395
4.33k
    input_block->v[6]++;
396
4.33k
    fill_block(zero_block, input_block, address_block, 0);
397
4.33k
    fill_block(zero_block, address_block, address_block, 0);
398
4.33k
}
399
400
static int data_indep_addressing(const KDF_ARGON2 *ctx, uint32_t pass,
401
    uint8_t slice)
402
46.5k
{
403
46.5k
    switch (ctx->type) {
404
14.5k
    case ARGON2_I:
405
14.5k
        return 1;
406
10.2k
    case ARGON2_ID:
407
10.2k
        return (pass == 0) && (slice < ARGON2_SYNC_POINTS / 2);
408
21.7k
    case ARGON2_D:
409
21.7k
    default:
410
21.7k
        return 0;
411
46.5k
    }
412
46.5k
}
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
34.2k
{
429
34.2k
    uint32_t ref_area_sz;
430
34.2k
    uint64_t rel_pos;
431
34.2k
    uint32_t start_pos, abs_pos;
432
433
34.2k
    start_pos = 0;
434
34.2k
    switch (pass) {
435
34.2k
    case 0:
436
34.2k
        if (slice == 0)
437
4.85k
            ref_area_sz = index - 1;
438
29.3k
        else if (same_lane)
439
10.1k
            ref_area_sz = slice * ctx->segment_length + index - 1;
440
19.2k
        else
441
19.2k
            ref_area_sz = slice * ctx->segment_length + ((index == 0) ? (-1) : 0);
442
34.2k
        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
34.2k
    }
452
453
34.2k
    rel_pos = pseudo_rand;
454
34.2k
    rel_pos = rel_pos * rel_pos >> 32;
455
34.2k
    rel_pos = ref_area_sz - 1 - (ref_area_sz * rel_pos >> 32);
456
34.2k
    abs_pos = (start_pos + rel_pos) % ctx->lane_length;
457
458
34.2k
    return abs_pos;
459
34.2k
}
460
461
static void fill_segment(const KDF_ARGON2 *ctx, uint32_t pass, uint32_t lane,
462
    uint8_t slice)
463
9.86k
{
464
9.86k
    BLOCK *ref_block = NULL, *curr_block = NULL;
465
9.86k
    BLOCK address_block, input_block, zero_block;
466
9.86k
    uint64_t rnd, ref_index, ref_lane;
467
9.86k
    uint32_t prev_offset;
468
9.86k
    uint32_t start_idx;
469
9.86k
    uint32_t j;
470
9.86k
    uint32_t curr_offset; /* Offset of the current block */
471
472
9.86k
    memset(&input_block, 0, sizeof(BLOCK));
473
474
9.86k
    if (ctx == NULL)
475
0
        return;
476
477
9.86k
    if (data_indep_addressing(ctx, pass, slice)) {
478
4.33k
        init_block_value(&zero_block, 0);
479
4.33k
        init_block_value(&input_block, 0);
480
481
4.33k
        input_block.v[0] = pass;
482
4.33k
        input_block.v[1] = lane;
483
4.33k
        input_block.v[2] = slice;
484
4.33k
        input_block.v[3] = ctx->memory_blocks;
485
4.33k
        input_block.v[4] = ctx->passes;
486
4.33k
        input_block.v[5] = ctx->type;
487
4.33k
    }
488
489
9.86k
    start_idx = 0;
490
491
    /* We've generated the first two blocks. Generate the 1st block of addrs. */
492
9.86k
    if ((pass == 0) && (slice == 0)) {
493
2.46k
        start_idx = 2;
494
2.46k
        if (data_indep_addressing(ctx, pass, slice))
495
1.36k
            next_addresses(&address_block, &input_block, &zero_block);
496
2.46k
    }
497
498
9.86k
    curr_offset = lane * ctx->lane_length + slice * ctx->segment_length
499
9.86k
        + start_idx;
500
501
9.86k
    if ((curr_offset % ctx->lane_length) == 0)
502
0
        prev_offset = curr_offset + ctx->lane_length - 1;
503
9.86k
    else
504
9.86k
        prev_offset = curr_offset - 1;
505
506
44.0k
    for (j = start_idx; j < ctx->segment_length; ++j, ++curr_offset, ++prev_offset) {
507
34.2k
        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
34.2k
        if (data_indep_addressing(ctx, pass, slice)) {
512
13.6k
            if (j % ARGON2_ADDRESSES_IN_BLOCK == 0)
513
2.97k
                next_addresses(&address_block, &input_block, &zero_block);
514
13.6k
            rnd = address_block.v[j % ARGON2_ADDRESSES_IN_BLOCK];
515
20.5k
        } else {
516
20.5k
            rnd = ctx->memory[prev_offset].v[0];
517
20.5k
        }
518
519
        /* Computing the lane of the reference block */
520
34.2k
        ref_lane = ((rnd >> 32)) % ctx->lanes;
521
        /* Can not reference other lanes yet */
522
34.2k
        if ((pass == 0) && (slice == 0))
523
4.85k
            ref_lane = lane;
524
525
        /* Computing the number of possible reference block within the lane. */
526
34.2k
        ref_index = index_alpha(ctx, pass, slice, j, rnd & 0xFFFFFFFF,
527
34.2k
            ref_lane == lane);
528
529
        /* Creating a new block */
530
34.2k
        ref_block = ctx->memory + ctx->lane_length * ref_lane + ref_index;
531
34.2k
        curr_block = ctx->memory + curr_offset;
532
34.2k
        if (ARGON2_VERSION_10 == ctx->version) {
533
            /* Version 1.2.1 and earlier: overwrite, not XOR */
534
15.7k
            fill_block(ctx->memory + prev_offset, ref_block, curr_block, 0);
535
15.7k
            continue;
536
15.7k
        }
537
538
18.5k
        fill_block(ctx->memory + prev_offset, ref_block, curr_block,
539
18.5k
            pass == 0 ? 0 : 1);
540
18.5k
    }
541
9.86k
}
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
342
{
627
342
    uint32_t r, s, l;
628
629
684
    for (r = 0; r < ctx->passes; ++r)
630
1.71k
        for (s = 0; s < ARGON2_SYNC_POINTS; ++s)
631
11.2k
            for (l = 0; l < ctx->lanes; ++l)
632
9.86k
                fill_segment(ctx, r, l, s);
633
342
    return 1;
634
342
}
635
636
static ossl_inline int fill_memory_blocks(KDF_ARGON2 *ctx)
637
342
{
638
342
#if !defined(ARGON2_NO_THREADS)
639
342
    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
342
}
644
645
static void initial_hash(uint8_t *blockhash, KDF_ARGON2 *ctx)
646
342
{
647
342
    EVP_MD_CTX *mdctx;
648
342
    uint8_t value[sizeof(uint32_t)];
649
342
    unsigned int tmp;
650
342
    uint32_t args[7];
651
652
342
    if (ctx == NULL || blockhash == NULL)
653
0
        return;
654
655
342
    args[0] = ctx->lanes;
656
342
    args[1] = ctx->outlen;
657
342
    args[2] = ctx->m_cost;
658
342
    args[3] = ctx->t_cost;
659
342
    args[4] = ctx->version;
660
342
    args[5] = (uint32_t)ctx->type;
661
342
    args[6] = ctx->pwdlen;
662
663
342
    mdctx = EVP_MD_CTX_create();
664
342
    if (mdctx == NULL || EVP_DigestInit_ex(mdctx, ctx->md, NULL) != 1)
665
0
        goto fail;
666
667
2.73k
    for (tmp = 0; tmp < sizeof(args) / sizeof(uint32_t); ++tmp) {
668
2.39k
        store32((uint8_t *)&value, args[tmp]);
669
2.39k
        if (EVP_DigestUpdate(mdctx, &value, sizeof(value)) != 1)
670
0
            goto fail;
671
2.39k
    }
672
673
342
    if (ctx->pwd != NULL) {
674
342
        if (EVP_DigestUpdate(mdctx, ctx->pwd, ctx->pwdlen) != 1)
675
0
            goto fail;
676
342
        if (ctx->early_clean) {
677
308
            OPENSSL_cleanse(ctx->pwd, ctx->pwdlen);
678
308
            ctx->pwdlen = 0;
679
308
        }
680
342
    }
681
682
342
    store32((uint8_t *)&value, ctx->saltlen);
683
684
342
    if (EVP_DigestUpdate(mdctx, &value, sizeof(value)) != 1)
685
0
        goto fail;
686
687
342
    if (ctx->salt != NULL)
688
342
        if (EVP_DigestUpdate(mdctx, ctx->salt, ctx->saltlen) != 1)
689
0
            goto fail;
690
691
342
    store32((uint8_t *)&value, ctx->secretlen);
692
342
    if (EVP_DigestUpdate(mdctx, &value, sizeof(value)) != 1)
693
0
        goto fail;
694
695
342
    if (ctx->secret != NULL) {
696
342
        if (EVP_DigestUpdate(mdctx, ctx->secret, ctx->secretlen) != 1)
697
0
            goto fail;
698
342
        if (ctx->early_clean) {
699
308
            OPENSSL_cleanse(ctx->secret, ctx->secretlen);
700
308
            ctx->secretlen = 0;
701
308
        }
702
342
    }
703
704
342
    store32((uint8_t *)&value, ctx->adlen);
705
342
    if (EVP_DigestUpdate(mdctx, &value, sizeof(value)) != 1)
706
0
        goto fail;
707
708
342
    if (ctx->ad != NULL)
709
342
        if (EVP_DigestUpdate(mdctx, ctx->ad, ctx->adlen) != 1)
710
0
            goto fail;
711
712
342
    tmp = ARGON2_PREHASH_DIGEST_LENGTH;
713
342
    if (EVP_DigestFinal_ex(mdctx, blockhash, &tmp) != 1)
714
0
        goto fail;
715
716
342
fail:
717
342
    EVP_MD_CTX_destroy(mdctx);
718
342
}
719
720
static int initialize(KDF_ARGON2 *ctx)
721
342
{
722
342
    uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH];
723
724
342
    if (ctx == NULL)
725
0
        return 0;
726
727
342
    if (ctx->memory_blocks * sizeof(BLOCK) / sizeof(BLOCK) != ctx->memory_blocks)
728
0
        return 0;
729
730
342
    if (ctx->type != ARGON2_D)
731
174
        ctx->memory = OPENSSL_secure_zalloc(ctx->memory_blocks * sizeof(BLOCK));
732
168
    else
733
168
        ctx->memory = OPENSSL_zalloc(ctx->memory_blocks * sizeof(BLOCK));
734
735
342
    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
342
    initial_hash(blockhash, ctx);
742
342
    OPENSSL_cleanse(blockhash + ARGON2_PREHASH_DIGEST_LENGTH,
743
342
        ARGON2_PREHASH_SEED_LENGTH - ARGON2_PREHASH_DIGEST_LENGTH);
744
342
    fill_first_blocks(blockhash, ctx);
745
342
    OPENSSL_cleanse(blockhash, ARGON2_PREHASH_SEED_LENGTH);
746
747
342
    return 1;
748
342
}
749
750
static void finalize(const KDF_ARGON2 *ctx, void *out)
751
342
{
752
342
    BLOCK blockhash;
753
342
    uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE];
754
342
    uint32_t last_block_in_lane;
755
342
    uint32_t l;
756
757
342
    if (ctx == NULL)
758
0
        return;
759
760
342
    copy_block(&blockhash, ctx->memory + ctx->lane_length - 1);
761
762
    /* XOR the last blocks */
763
2.46k
    for (l = 1; l < ctx->lanes; ++l) {
764
2.12k
        last_block_in_lane = l * ctx->lane_length + (ctx->lane_length - 1);
765
2.12k
        xor_block(&blockhash, ctx->memory + last_block_in_lane);
766
2.12k
    }
767
768
    /* Hash the result */
769
342
    store_block(blockhash_bytes, &blockhash);
770
342
    blake2b_long(ctx->md, ctx->mac, out, ctx->outlen, blockhash_bytes,
771
342
        ARGON2_BLOCK_SIZE);
772
342
    OPENSSL_cleanse(blockhash.v, ARGON2_BLOCK_SIZE);
773
342
    OPENSSL_cleanse(blockhash_bytes, ARGON2_BLOCK_SIZE);
774
775
342
    if (ctx->type != ARGON2_D)
776
174
        OPENSSL_secure_clear_free(ctx->memory,
777
342
            ctx->memory_blocks * sizeof(BLOCK));
778
168
    else
779
168
        OPENSSL_clear_free(ctx->memory,
780
342
            ctx->memory_blocks * sizeof(BLOCK));
781
342
}
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
148k
{
812
148k
    int ret = 0;
813
148k
    EVP_MD_CTX *ctx = NULL;
814
148k
    OSSL_PARAM par[2];
815
816
148k
    if ((ctx = EVP_MD_CTX_create()) == NULL)
817
0
        return 0;
818
819
148k
    par[0] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_SIZE, &outlen);
820
148k
    par[1] = OSSL_PARAM_construct_end();
821
822
148k
    ret = EVP_DigestInit_ex2(ctx, md, par) == 1
823
148k
        && EVP_DigestUpdate(ctx, in, inlen) == 1
824
148k
        && EVP_DigestFinal_ex(ctx, out, NULL) == 1;
825
826
148k
    EVP_MD_CTX_free(ctx);
827
148k
    return ret;
828
148k
}
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
148k
{
833
148k
    if (out == NULL || outlen == 0)
834
0
        return 0;
835
836
148k
    if (key == NULL || keylen == 0)
837
148k
        return blake2b_md(md, out, outlen, in, inlen);
838
839
0
    return blake2b_mac(mac, out, outlen, in, inlen, key, keylen);
840
148k
}
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.27k
{
845
5.27k
    int ret = 0;
846
5.27k
    EVP_MD_CTX *ctx = NULL;
847
5.27k
    uint32_t outlen_curr;
848
5.27k
    uint8_t outbuf[BLAKE2B_OUTBYTES];
849
5.27k
    uint8_t inbuf[BLAKE2B_OUTBYTES];
850
5.27k
    uint8_t outlen_bytes[sizeof(uint32_t)] = { 0 };
851
5.27k
    OSSL_PARAM par[2];
852
5.27k
    size_t outlen_md;
853
854
5.27k
    if (out == NULL || outlen == 0)
855
0
        return 0;
856
857
    /* Ensure little-endian byte order */
858
5.27k
    store32(outlen_bytes, (uint32_t)outlen);
859
860
5.27k
    if ((ctx = EVP_MD_CTX_create()) == NULL)
861
0
        return 0;
862
863
5.27k
    outlen_md = (outlen <= BLAKE2B_OUTBYTES) ? outlen : BLAKE2B_OUTBYTES;
864
5.27k
    par[0] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_SIZE, &outlen_md);
865
5.27k
    par[1] = OSSL_PARAM_construct_end();
866
867
5.27k
    ret = EVP_DigestInit_ex2(ctx, md, par) == 1
868
5.27k
        && EVP_DigestUpdate(ctx, outlen_bytes, sizeof(outlen_bytes)) == 1
869
5.27k
        && EVP_DigestUpdate(ctx, in, inlen) == 1
870
5.27k
        && EVP_DigestFinal_ex(ctx, (outlen > BLAKE2B_OUTBYTES) ? outbuf : out,
871
5.27k
               NULL)
872
5.27k
            == 1;
873
874
5.27k
    if (ret == 0)
875
0
        goto fail;
876
877
5.27k
    if (outlen > BLAKE2B_OUTBYTES) {
878
4.93k
        memcpy(out, outbuf, BLAKE2B_OUTBYTES / 2);
879
4.93k
        out += BLAKE2B_OUTBYTES / 2;
880
4.93k
        outlen_curr = (uint32_t)outlen - BLAKE2B_OUTBYTES / 2;
881
882
148k
        while (outlen_curr > BLAKE2B_OUTBYTES) {
883
143k
            memcpy(inbuf, outbuf, BLAKE2B_OUTBYTES);
884
143k
            if (blake2b(md, mac, outbuf, BLAKE2B_OUTBYTES, inbuf,
885
143k
                    BLAKE2B_OUTBYTES, NULL, 0)
886
143k
                != 1)
887
0
                goto fail;
888
143k
            memcpy(out, outbuf, BLAKE2B_OUTBYTES / 2);
889
143k
            out += BLAKE2B_OUTBYTES / 2;
890
143k
            outlen_curr -= BLAKE2B_OUTBYTES / 2;
891
143k
        }
892
893
4.93k
        memcpy(inbuf, outbuf, BLAKE2B_OUTBYTES);
894
4.93k
        if (blake2b(md, mac, outbuf, outlen_curr, inbuf, BLAKE2B_OUTBYTES,
895
4.93k
                NULL, 0)
896
4.93k
            != 1)
897
0
            goto fail;
898
4.93k
        memcpy(out, outbuf, outlen_curr);
899
4.93k
    }
900
5.27k
    ret = 1;
901
902
5.27k
fail:
903
5.27k
    EVP_MD_CTX_free(ctx);
904
5.27k
    return ret;
905
5.27k
}
906
907
static void kdf_argon2_init(KDF_ARGON2 *c, ARGON2_TYPE type)
908
790
{
909
790
    OSSL_LIB_CTX *libctx;
910
911
790
    libctx = c->libctx;
912
790
    memset(c, 0, sizeof(*c));
913
914
790
    c->libctx = libctx;
915
790
    c->outlen = ARGON2_DEFAULT_OUTLEN;
916
790
    c->t_cost = ARGON2_DEFAULT_T_COST;
917
790
    c->m_cost = ARGON2_DEFAULT_M_COST;
918
790
    c->lanes = ARGON2_DEFAULT_LANES;
919
790
    c->threads = ARGON2_DEFAULT_THREADS;
920
790
    c->version = ARGON2_DEFAULT_VERSION;
921
790
    c->type = type;
922
790
}
923
924
static void *kdf_argon2d_new(void *provctx)
925
354
{
926
354
    KDF_ARGON2 *ctx;
927
928
354
    if (!ossl_prov_is_running())
929
0
        return NULL;
930
931
354
    ctx = OPENSSL_zalloc(sizeof(*ctx));
932
354
    if (ctx == NULL) {
933
0
        ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
934
0
        return NULL;
935
0
    }
936
937
354
    ctx->libctx = PROV_LIBCTX_OF(provctx);
938
939
354
    kdf_argon2_init(ctx, ARGON2_D);
940
354
    return ctx;
941
354
}
942
943
static void *kdf_argon2i_new(void *provctx)
944
220
{
945
220
    KDF_ARGON2 *ctx;
946
947
220
    if (!ossl_prov_is_running())
948
0
        return NULL;
949
950
220
    ctx = OPENSSL_zalloc(sizeof(*ctx));
951
220
    if (ctx == NULL) {
952
0
        ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
953
0
        return NULL;
954
0
    }
955
956
220
    ctx->libctx = PROV_LIBCTX_OF(provctx);
957
958
220
    kdf_argon2_init(ctx, ARGON2_I);
959
220
    return ctx;
960
220
}
961
962
static void *kdf_argon2id_new(void *provctx)
963
216
{
964
216
    KDF_ARGON2 *ctx;
965
966
216
    if (!ossl_prov_is_running())
967
0
        return NULL;
968
969
216
    ctx = OPENSSL_zalloc(sizeof(*ctx));
970
216
    if (ctx == NULL) {
971
0
        ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
972
0
        return NULL;
973
0
    }
974
975
216
    ctx->libctx = PROV_LIBCTX_OF(provctx);
976
977
216
    kdf_argon2_init(ctx, ARGON2_ID);
978
216
    return ctx;
979
216
}
980
981
static void kdf_argon2_free(void *vctx)
982
790
{
983
790
    KDF_ARGON2 *ctx = (KDF_ARGON2 *)vctx;
984
985
790
    if (ctx == NULL)
986
0
        return;
987
988
790
    if (ctx->pwd != NULL)
989
790
        OPENSSL_clear_free(ctx->pwd, ctx->pwdlen);
990
991
790
    if (ctx->salt != NULL)
992
658
        OPENSSL_clear_free(ctx->salt, ctx->saltlen);
993
994
790
    if (ctx->secret != NULL)
995
658
        OPENSSL_clear_free(ctx->secret, ctx->secretlen);
996
997
790
    if (ctx->ad != NULL)
998
658
        OPENSSL_clear_free(ctx->ad, ctx->adlen);
999
1000
790
    EVP_MD_free(ctx->md);
1001
790
    EVP_MAC_free(ctx->mac);
1002
1003
790
    OPENSSL_free(ctx->propq);
1004
1005
790
    memset(ctx, 0, sizeof(*ctx));
1006
1007
790
    OPENSSL_free(ctx);
1008
790
}
1009
1010
static int kdf_argon2_derive(void *vctx, unsigned char *out, size_t outlen,
1011
    const OSSL_PARAM params[])
1012
391
{
1013
391
    KDF_ARGON2 *ctx;
1014
391
    uint32_t memory_blocks, segment_length;
1015
1016
391
    ctx = (KDF_ARGON2 *)vctx;
1017
1018
391
    if (!ossl_prov_is_running() || !kdf_argon2_set_ctx_params(vctx, params))
1019
0
        return 0;
1020
1021
391
    if (ctx->mac == NULL)
1022
391
        ctx->mac = EVP_MAC_fetch(ctx->libctx, "blake2bmac", ctx->propq);
1023
391
    if (ctx->mac == NULL) {
1024
6
        ERR_raise_data(ERR_LIB_PROV, PROV_R_MISSING_MAC,
1025
6
            "cannot fetch blake2bmac");
1026
6
        return 0;
1027
6
    }
1028
1029
385
    if (ctx->md == NULL)
1030
385
        ctx->md = EVP_MD_fetch(ctx->libctx, "blake2b512", ctx->propq);
1031
385
    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
385
    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
385
    if (outlen != ctx->outlen) {
1043
334
        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
334
        if (!kdf_argon2_ctx_set_out_length(ctx, (uint32_t)outlen))
1048
0
            return 0;
1049
334
    }
1050
1051
385
    switch (ctx->type) {
1052
184
    case ARGON2_D:
1053
286
    case ARGON2_I:
1054
385
    case ARGON2_ID:
1055
385
        break;
1056
0
    default:
1057
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MODE, "invalid Argon2 type");
1058
0
        return 0;
1059
385
    }
1060
1061
385
    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
34
        if (ctx->threads > ossl_get_avail_threads(ctx->libctx)) {
1069
34
            ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_THREAD_POOL_SIZE,
1070
34
                "requested %u threads, available: %u",
1071
34
                ctx->threads, ossl_get_avail_threads(ctx->libctx));
1072
34
            return 0;
1073
34
        }
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
351
    if (ctx->m_cost < 8 * ctx->lanes) {
1084
9
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MEMORY_SIZE,
1085
9
            "m_cost must be greater or equal than 8 times the number of lanes");
1086
9
        return 0;
1087
9
    }
1088
1089
342
    memory_blocks = ctx->m_cost;
1090
342
    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
342
    segment_length = memory_blocks / (ctx->lanes * ARGON2_SYNC_POINTS);
1095
342
    memory_blocks = segment_length * (ctx->lanes * ARGON2_SYNC_POINTS);
1096
1097
342
    ctx->memory = NULL;
1098
342
    ctx->memory_blocks = memory_blocks;
1099
342
    ctx->segment_length = segment_length;
1100
342
    ctx->passes = ctx->t_cost;
1101
342
    ctx->lane_length = segment_length * ARGON2_SYNC_POINTS;
1102
1103
342
    if (initialize(ctx) != 1)
1104
0
        return 0;
1105
1106
342
    if (fill_memory_blocks(ctx) != 1)
1107
0
        return 0;
1108
1109
342
    finalize(ctx, out);
1110
1111
342
    return 1;
1112
342
}
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
564
{
1148
564
    if (threads < ARGON2_MIN_THREADS) {
1149
40
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_THREAD_POOL_SIZE,
1150
40
            "min threads: %u", ARGON2_MIN_THREADS);
1151
40
        return 0;
1152
40
    }
1153
1154
524
    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
524
    ctx->threads = threads;
1161
524
    return 1;
1162
524
}
1163
1164
static int kdf_argon2_ctx_set_lanes(KDF_ARGON2 *ctx, uint32_t lanes)
1165
524
{
1166
524
    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
524
    if (lanes < ARGON2_MIN_LANES) {
1173
31
        ERR_raise_data(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER,
1174
31
            "min lanes: %u", ARGON2_MIN_LANES);
1175
31
        return 0;
1176
31
    }
1177
1178
493
    ctx->lanes = lanes;
1179
493
    return 1;
1180
524
}
1181
1182
static int kdf_argon2_ctx_set_t_cost(KDF_ARGON2 *ctx, uint32_t t_cost)
1183
564
{
1184
    /* ARGON2_MAX_MEMORY == max m_cost value, so skip check  */
1185
1186
564
    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
564
    ctx->t_cost = t_cost;
1193
564
    return 1;
1194
564
}
1195
1196
static int kdf_argon2_ctx_set_m_cost(KDF_ARGON2 *ctx, uint32_t m_cost)
1197
493
{
1198
    /* ARGON2_MAX_MEMORY == max m_cost value, so skip check */
1199
1200
493
    if (m_cost < ARGON2_MIN_MEMORY) {
1201
34
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MEMORY_SIZE, "min: %u",
1202
34
            ARGON2_MIN_MEMORY);
1203
34
        return 0;
1204
34
    }
1205
1206
459
    ctx->m_cost = m_cost;
1207
459
    return 1;
1208
493
}
1209
1210
static int kdf_argon2_ctx_set_out_length(KDF_ARGON2 *ctx, uint32_t outlen)
1211
992
{
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
992
    if (outlen < ARGON2_MIN_OUT_LENGTH) {
1219
94
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_OUTPUT_LENGTH, "min: %u",
1220
94
            ARGON2_MIN_OUT_LENGTH);
1221
94
        return 0;
1222
94
    }
1223
1224
898
    ctx->outlen = outlen;
1225
898
    return 1;
1226
992
}
1227
1228
static int kdf_argon2_ctx_set_secret(KDF_ARGON2 *ctx, const OSSL_PARAM *p)
1229
658
{
1230
658
    size_t buflen;
1231
1232
658
    if (p->data == NULL)
1233
0
        return 0;
1234
1235
658
    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
658
    if (!OSSL_PARAM_get_octet_string(p, (void **)&ctx->secret, 0, &buflen))
1242
0
        return 0;
1243
1244
658
    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
658
    ctx->secretlen = (uint32_t)buflen;
1252
658
    return 1;
1253
658
}
1254
1255
static int kdf_argon2_ctx_set_pwd(KDF_ARGON2 *ctx, const OSSL_PARAM *p)
1256
790
{
1257
790
    size_t buflen;
1258
1259
790
    if (p->data == NULL)
1260
0
        return 0;
1261
1262
790
    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
790
    if (!OSSL_PARAM_get_octet_string(p, (void **)&ctx->pwd, 0, &buflen))
1269
0
        return 0;
1270
1271
790
    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
790
    ctx->pwdlen = (uint32_t)buflen;
1278
790
    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
790
}
1286
1287
static int kdf_argon2_ctx_set_salt(KDF_ARGON2 *ctx, const OSSL_PARAM *p)
1288
790
{
1289
790
    size_t buflen;
1290
1291
790
    if (p->data == NULL)
1292
0
        return 0;
1293
1294
790
    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
790
    if (!OSSL_PARAM_get_octet_string(p, (void **)&ctx->salt, 0, &buflen))
1301
0
        return 0;
1302
1303
790
    if (buflen < ARGON2_MIN_SALT_LENGTH) {
1304
132
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_SALT_LENGTH, "min: %u",
1305
132
            ARGON2_MIN_SALT_LENGTH);
1306
132
        goto fail;
1307
132
    }
1308
1309
658
    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
658
    ctx->saltlen = (uint32_t)buflen;
1316
658
    return 1;
1317
1318
132
fail:
1319
132
    OPENSSL_free(ctx->salt);
1320
132
    ctx->salt = NULL;
1321
132
    ctx->saltlen = 0U;
1322
132
    return 0;
1323
658
}
1324
1325
static int kdf_argon2_ctx_set_ad(KDF_ARGON2 *ctx, const OSSL_PARAM *p)
1326
658
{
1327
658
    size_t buflen;
1328
1329
658
    if (p->data == NULL)
1330
0
        return 0;
1331
1332
658
    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
658
    if (!OSSL_PARAM_get_octet_string(p, (void **)&ctx->ad, 0, &buflen))
1339
0
        return 0;
1340
1341
658
    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
658
    ctx->adlen = (uint32_t)buflen;
1349
658
    return 1;
1350
658
}
1351
1352
static void kdf_argon2_ctx_set_flag_early_clean(KDF_ARGON2 *ctx, uint32_t f)
1353
459
{
1354
459
    ctx->early_clean = !!(f);
1355
459
}
1356
1357
static int kdf_argon2_ctx_set_version(KDF_ARGON2 *ctx, uint32_t version)
1358
459
{
1359
459
    switch (version) {
1360
194
    case ARGON2_VERSION_10:
1361
391
    case ARGON2_VERSION_13:
1362
391
        ctx->version = version;
1363
391
        return 1;
1364
68
    default:
1365
68
        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MODE,
1366
68
            "invalid Argon2 version");
1367
68
        return 0;
1368
459
    }
1369
459
}
1370
1371
static int set_property_query(KDF_ARGON2 *ctx, const char *propq)
1372
391
{
1373
391
    OPENSSL_free(ctx->propq);
1374
391
    ctx->propq = NULL;
1375
391
    if (propq != NULL) {
1376
391
        ctx->propq = OPENSSL_strdup(propq);
1377
391
        if (ctx->propq == NULL)
1378
0
            return 0;
1379
391
    }
1380
391
    EVP_MD_free(ctx->md);
1381
391
    ctx->md = NULL;
1382
391
    EVP_MAC_free(ctx->mac);
1383
391
    ctx->mac = NULL;
1384
391
    return 1;
1385
391
}
1386
1387
static int kdf_argon2_set_ctx_params(void *vctx, const OSSL_PARAM params[])
1388
307
{
1389
307
    const OSSL_PARAM *p;
1390
307
    KDF_ARGON2 *ctx;
1391
307
    uint32_t u32_value;
1392
1393
307
    if (params == NULL)
1394
96
        return 1;
1395
1396
211
    ctx = (KDF_ARGON2 *)vctx;
1397
211
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PASSWORD)) != NULL)
1398
211
        if (!kdf_argon2_ctx_set_pwd(ctx, p))
1399
0
            return 0;
1400
1401
211
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SALT)) != NULL)
1402
211
        if (!kdf_argon2_ctx_set_salt(ctx, p))
1403
39
            return 0;
1404
1405
172
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SECRET)) != NULL)
1406
172
        if (!kdf_argon2_ctx_set_secret(ctx, p))
1407
0
            return 0;
1408
1409
172
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ARGON2_AD)) != NULL)
1410
172
        if (!kdf_argon2_ctx_set_ad(ctx, p))
1411
0
            return 0;
1412
1413
172
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SIZE)) != NULL) {
1414
172
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1415
0
            return 0;
1416
172
        if (!kdf_argon2_ctx_set_out_length(ctx, u32_value))
1417
30
            return 0;
1418
172
    }
1419
1420
142
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ITER)) != NULL) {
1421
142
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1422
0
            return 0;
1423
142
        if (!kdf_argon2_ctx_set_t_cost(ctx, u32_value))
1424
0
            return 0;
1425
142
    }
1426
1427
142
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_THREADS)) != NULL) {
1428
142
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1429
0
            return 0;
1430
142
        if (!kdf_argon2_ctx_set_threads(ctx, u32_value))
1431
20
            return 0;
1432
142
    }
1433
1434
122
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ARGON2_LANES)) != NULL) {
1435
122
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1436
0
            return 0;
1437
122
        if (!kdf_argon2_ctx_set_lanes(ctx, u32_value))
1438
8
            return 0;
1439
122
    }
1440
1441
114
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ARGON2_MEMCOST)) != NULL) {
1442
114
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1443
0
            return 0;
1444
114
        if (!kdf_argon2_ctx_set_m_cost(ctx, u32_value))
1445
8
            return 0;
1446
114
    }
1447
1448
106
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_EARLY_CLEAN)) != NULL) {
1449
106
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1450
0
            return 0;
1451
106
        kdf_argon2_ctx_set_flag_early_clean(ctx, u32_value);
1452
106
    }
1453
1454
106
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ARGON2_VERSION)) != NULL) {
1455
106
        if (!OSSL_PARAM_get_uint32(p, &u32_value))
1456
0
            return 0;
1457
106
        if (!kdf_argon2_ctx_set_version(ctx, u32_value))
1458
10
            return 0;
1459
106
    }
1460
1461
96
    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PROPERTIES)) != NULL) {
1462
96
        if (p->data_type != OSSL_PARAM_UTF8_STRING
1463
96
            || !set_property_query(ctx, p->data))
1464
0
            return 0;
1465
96
    }
1466
1467
96
    return 1;
1468
96
}
1469
1470
static const OSSL_PARAM *kdf_argon2_settable_ctx_params(ossl_unused void *ctx,
1471
    ossl_unused void *p_ctx)
1472
790
{
1473
790
    static const OSSL_PARAM known_settable_ctx_params[] = {
1474
790
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_PASSWORD, NULL, 0),
1475
790
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SALT, NULL, 0),
1476
790
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SECRET, NULL, 0),
1477
790
        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_ARGON2_AD, NULL, 0),
1478
790
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_SIZE, NULL),
1479
790
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_ITER, NULL),
1480
790
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_THREADS, NULL),
1481
790
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_ARGON2_LANES, NULL),
1482
790
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_ARGON2_MEMCOST, NULL),
1483
790
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_EARLY_CLEAN, NULL),
1484
790
        OSSL_PARAM_uint32(OSSL_KDF_PARAM_ARGON2_VERSION, NULL),
1485
790
        OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0),
1486
790
        OSSL_PARAM_END
1487
790
    };
1488
1489
790
    return known_settable_ctx_params;
1490
790
}
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