Commit c5f4b43e3c for openssl.org
commit c5f4b43e3c363d153ded26ebea58105a23d3da1d
Author: Alexandre Laroche <larochealexandre@hotmail.com>
Date: Mon Nov 23 08:11:11 2026 -0500
Argon2: fail the derivation when a BLAKE2b step fails
initial_hash(), fill_first_blocks() and finalize() returned void and
dropped the result of blake2b()/blake2b_long() and of the EVP digest
calls, so kdf_argon2_derive() reported success whatever happened inside.
A failed allocation or digest operation left the initial hash
uninitialised, the first blocks partly unset, or the output not written
at all, and the caller received that buffer as the derived key.
blake2b_long() itself returned success when one of its chained blake2b()
steps failed, as ret still held the result of the first step.
blake2b_md() and blake2b_long() also finalise into buffers sized for the
digest length they request through OSSL_DIGEST_PARAM_SIZE. A BLAKE2B-512
implementation that does not support that parameter ignores it and
writes its full 64 bytes, past the end of the caller's output when fewer
than 64 bytes were requested. BLAKE2B-512 itself did not support it
before 3.2, and the digest can come from another provider through the
KDF's properties or the default properties.
Propagate the errors, check the digest size the context will produce
before finalising, free the memory blocks on every path and clear the
output when the derivation fails.
Assisted-by: Claude Code:claude-opus-5-5
Reviewed-by: Milan Broz <gmazyland@gmail.com>
Reviewed-by: Bob Beck <beck@openssl.org>
Merge-date: Wed Dec 2 07:00:34 2026
Merged-from: https://github.com/openssl/openssl/pull/33925
diff --git a/providers/implementations/kdfs/argon2.c b/providers/implementations/kdfs/argon2.c
index 4435b0004b..00f0f1f8eb 100644
--- a/providers/implementations/kdfs/argon2.c
+++ b/providers/implementations/kdfs/argon2.c
@@ -235,7 +235,7 @@ static void copy_block(BLOCK *dst, const BLOCK *src);
static void xor_block(BLOCK *dst, const BLOCK *src);
static void load_block(BLOCK *dst, const void *input);
static void store_block(void *output, const BLOCK *src);
-static void fill_first_blocks(uint8_t *blockhash, const KDF_ARGON2 *ctx);
+static int fill_first_blocks(uint8_t *blockhash, const KDF_ARGON2 *ctx);
static void fill_block(const BLOCK *prev, const BLOCK *ref, BLOCK *next,
int with_xor);
@@ -258,9 +258,11 @@ static int fill_mem_blocks_mt(KDF_ARGON2 *ctx);
static int fill_mem_blocks_st(KDF_ARGON2 *ctx);
static ossl_inline int fill_memory_blocks(KDF_ARGON2 *ctx);
-static void initial_hash(uint8_t *blockhash, KDF_ARGON2 *ctx);
+static int initial_hash(uint8_t *blockhash, KDF_ARGON2 *ctx);
static int initialize(KDF_ARGON2 *ctx);
-static void finalize(const KDF_ARGON2 *ctx, void *out);
+static int finalize(const KDF_ARGON2 *ctx, void *out);
+static void free_memory(KDF_ARGON2 *ctx);
+static int check_md_size(const EVP_MD_CTX *ctx, size_t size);
static int blake2b(EVP_MD *md, EVP_MAC *mac, void *out, size_t outlen,
const void *in, size_t inlen, const void *key,
@@ -345,10 +347,11 @@ static void store_block(void *output, const BLOCK *src)
store64((uint8_t *)output + i * sizeof(src->v[i]), src->v[i]);
}
-static void fill_first_blocks(uint8_t *blockhash, const KDF_ARGON2 *ctx)
+static int fill_first_blocks(uint8_t *blockhash, const KDF_ARGON2 *ctx)
{
uint32_t l;
uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE];
+ int ret = 0;
/*
* Make the first and second block in each lane as G(H0||0||i)
@@ -357,17 +360,24 @@ static void fill_first_blocks(uint8_t *blockhash, const KDF_ARGON2 *ctx)
for (l = 0; l < ctx->lanes; ++l) {
store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 0);
store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH + 4, l);
- blake2b_long(ctx->md, ctx->mac, blockhash_bytes, ARGON2_BLOCK_SIZE,
- blockhash, ARGON2_PREHASH_SEED_LENGTH);
+ if (blake2b_long(ctx->md, ctx->mac, blockhash_bytes, ARGON2_BLOCK_SIZE,
+ blockhash, ARGON2_PREHASH_SEED_LENGTH)
+ != 1)
+ goto end;
load_block(&ctx->memory[l * ctx->lane_length + 0],
blockhash_bytes);
store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 1);
- blake2b_long(ctx->md, ctx->mac, blockhash_bytes, ARGON2_BLOCK_SIZE,
- blockhash, ARGON2_PREHASH_SEED_LENGTH);
+ if (blake2b_long(ctx->md, ctx->mac, blockhash_bytes, ARGON2_BLOCK_SIZE,
+ blockhash, ARGON2_PREHASH_SEED_LENGTH)
+ != 1)
+ goto end;
load_block(&ctx->memory[l * ctx->lane_length + 1],
blockhash_bytes);
}
+ ret = 1;
+end:
OPENSSL_cleanse(blockhash_bytes, ARGON2_BLOCK_SIZE);
+ return ret;
}
static void fill_block(const BLOCK *prev, const BLOCK *ref,
@@ -649,15 +659,16 @@ static ossl_inline int fill_memory_blocks(KDF_ARGON2 *ctx)
#endif
}
-static void initial_hash(uint8_t *blockhash, KDF_ARGON2 *ctx)
+static int initial_hash(uint8_t *blockhash, KDF_ARGON2 *ctx)
{
EVP_MD_CTX *mdctx;
uint8_t value[sizeof(uint32_t)];
unsigned int tmp;
uint32_t args[7];
+ int ret = 0;
if (ctx == NULL || blockhash == NULL)
- return;
+ return 0;
args[0] = ctx->lanes;
args[1] = ctx->outlen;
@@ -668,7 +679,8 @@ static void initial_hash(uint8_t *blockhash, KDF_ARGON2 *ctx)
args[6] = ctx->pwdlen;
mdctx = EVP_MD_CTX_create();
- if (mdctx == NULL || EVP_DigestInit_ex(mdctx, ctx->md, NULL) != 1)
+ if (mdctx == NULL || EVP_DigestInit_ex(mdctx, ctx->md, NULL) != 1
+ || check_md_size(mdctx, ARGON2_PREHASH_DIGEST_LENGTH) != 1)
goto fail;
for (tmp = 0; tmp < sizeof(args) / sizeof(uint32_t); ++tmp) {
@@ -719,14 +731,17 @@ static void initial_hash(uint8_t *blockhash, KDF_ARGON2 *ctx)
tmp = ARGON2_PREHASH_DIGEST_LENGTH;
if (EVP_DigestFinal_ex(mdctx, blockhash, &tmp) != 1)
goto fail;
+ ret = 1;
fail:
EVP_MD_CTX_destroy(mdctx);
+ return ret;
}
static int initialize(KDF_ARGON2 *ctx)
{
uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH];
+ int ret;
if (ctx == NULL)
return 0;
@@ -745,24 +760,27 @@ static int initialize(KDF_ARGON2 *ctx)
return 0;
}
- initial_hash(blockhash, ctx);
- OPENSSL_cleanse(blockhash + ARGON2_PREHASH_DIGEST_LENGTH,
- ARGON2_PREHASH_SEED_LENGTH - ARGON2_PREHASH_DIGEST_LENGTH);
- fill_first_blocks(blockhash, ctx);
+ ret = initial_hash(blockhash, ctx);
+ if (ret == 1) {
+ OPENSSL_cleanse(blockhash + ARGON2_PREHASH_DIGEST_LENGTH,
+ ARGON2_PREHASH_SEED_LENGTH - ARGON2_PREHASH_DIGEST_LENGTH);
+ ret = fill_first_blocks(blockhash, ctx);
+ }
OPENSSL_cleanse(blockhash, ARGON2_PREHASH_SEED_LENGTH);
- return 1;
+ return ret;
}
-static void finalize(const KDF_ARGON2 *ctx, void *out)
+static int finalize(const KDF_ARGON2 *ctx, void *out)
{
BLOCK blockhash;
uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE];
uint32_t last_block_in_lane;
uint32_t l;
+ int ret;
if (ctx == NULL)
- return;
+ return 0;
copy_block(&blockhash, ctx->memory + ctx->lane_length - 1);
@@ -774,17 +792,40 @@ static void finalize(const KDF_ARGON2 *ctx, void *out)
/* Hash the result */
store_block(blockhash_bytes, &blockhash);
- blake2b_long(ctx->md, ctx->mac, out, ctx->outlen, blockhash_bytes,
+ ret = blake2b_long(ctx->md, ctx->mac, out, ctx->outlen, blockhash_bytes,
ARGON2_BLOCK_SIZE);
OPENSSL_cleanse(blockhash.v, ARGON2_BLOCK_SIZE);
OPENSSL_cleanse(blockhash_bytes, ARGON2_BLOCK_SIZE);
+ return ret;
+}
+
+static void free_memory(KDF_ARGON2 *ctx)
+{
if (ctx->type != ARGON2_D)
OPENSSL_secure_clear_free(ctx->memory,
ctx->memory_blocks * sizeof(BLOCK));
else
OPENSSL_clear_free(ctx->memory,
ctx->memory_blocks * sizeof(BLOCK));
+ ctx->memory = NULL;
+}
+
+/*
+ * The output buffers passed to EVP_DigestFinal_ex() below are sized for the
+ * requested digest length. A BLAKE2b implementation that does not support
+ * OSSL_DIGEST_PARAM_SIZE ignores it and would write its full digest size, so
+ * check the size the context will actually produce.
+ */
+static int check_md_size(const EVP_MD_CTX *ctx, size_t size)
+{
+ int sz = EVP_MD_CTX_get_size_ex(ctx);
+
+ if (sz <= 0 || (size_t)sz != size) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_SIZE);
+ return 0;
+ }
+ return 1;
}
static int blake2b_mac(EVP_MAC *mac, void *out, size_t outlen, const void *in,
@@ -806,7 +847,8 @@ static int blake2b_mac(EVP_MAC *mac, void *out, size_t outlen, const void *in,
ret = EVP_MAC_CTX_set_params(ctx, par) == 1
&& EVP_MAC_init(ctx, NULL, 0, NULL) == 1
&& EVP_MAC_update(ctx, in, inlen) == 1
- && EVP_MAC_final(ctx, out, (size_t *)&out_written, outlen) == 1;
+ && EVP_MAC_final(ctx, out, (size_t *)&out_written, outlen) == 1
+ && out_written == outlen;
fail:
EVP_MAC_CTX_free(ctx);
@@ -827,6 +869,7 @@ static int blake2b_md(EVP_MD *md, void *out, size_t outlen, const void *in,
par[1] = OSSL_PARAM_construct_end();
ret = EVP_DigestInit_ex2(ctx, md, par) == 1
+ && check_md_size(ctx, outlen) == 1
&& EVP_DigestUpdate(ctx, in, inlen) == 1
&& EVP_DigestFinal_ex(ctx, out, NULL) == 1;
@@ -872,6 +915,7 @@ static int blake2b_long(EVP_MD *md, EVP_MAC *mac, unsigned char *out,
par[1] = OSSL_PARAM_construct_end();
ret = EVP_DigestInit_ex2(ctx, md, par) == 1
+ && check_md_size(ctx, outlen_md) == 1
&& EVP_DigestUpdate(ctx, outlen_bytes, sizeof(outlen_bytes)) == 1
&& EVP_DigestUpdate(ctx, in, inlen) == 1
&& EVP_DigestFinal_ex(ctx, (outlen > BLAKE2B_OUTBYTES) ? outbuf : out,
@@ -880,6 +924,7 @@ static int blake2b_long(EVP_MD *md, EVP_MAC *mac, unsigned char *out,
if (ret == 0)
goto fail;
+ ret = 0;
if (outlen > BLAKE2B_OUTBYTES) {
memcpy(out, outbuf, BLAKE2B_OUTBYTES / 2);
@@ -1020,6 +1065,7 @@ static int kdf_argon2_derive(void *vctx, unsigned char *out, size_t outlen,
KDF_ARGON2 *ctx;
uint32_t memory_blocks, segment_length;
OSSL_PARAM *size_param;
+ int ret;
ctx = (KDF_ARGON2 *)vctx;
@@ -1110,22 +1156,16 @@ static int kdf_argon2_derive(void *vctx, unsigned char *out, size_t outlen,
ctx->passes = ctx->t_cost;
ctx->lane_length = segment_length * ARGON2_SYNC_POINTS;
- if (initialize(ctx) != 1)
- return 0;
+ ret = initialize(ctx) == 1
+ && fill_memory_blocks(ctx) == 1
+ && finalize(ctx, out) == 1;
- if (fill_memory_blocks(ctx) != 1) {
- if (ctx->type != ARGON2_D)
- OPENSSL_secure_clear_free(ctx->memory,
- ctx->memory_blocks * sizeof(BLOCK));
- else
- OPENSSL_clear_free(ctx->memory,
- ctx->memory_blocks * sizeof(BLOCK));
- return 0;
- }
-
- finalize(ctx, out);
+ free_memory(ctx);
+ /* Never hand back a partially computed or unwritten output as a key */
+ if (ret == 0)
+ OPENSSL_cleanse(out, outlen);
- return 1;
+ return ret;
}
static void kdf_argon2_reset(void *vctx)
diff --git a/test/build.info b/test/build.info
index 67d688dc4d..8e95510030 100644
--- a/test/build.info
+++ b/test/build.info
@@ -797,7 +797,7 @@ IF[{- !$disabled{tests} -}]
INCLUDE[pkey_meth_kdf_test]=../include ../apps/include
DEPEND[pkey_meth_kdf_test]=../libcrypto libtestutil.a
- SOURCE[evp_kdf_test]=evp_kdf_test.c
+ SOURCE[evp_kdf_test]=evp_kdf_test.c fake_blake2bprov.c
INCLUDE[evp_kdf_test]=../include ../apps/include
DEPEND[evp_kdf_test]=../libcrypto libtestutil.a
diff --git a/test/evp_kdf_test.c b/test/evp_kdf_test.c
index 801489d135..96552cc57e 100644
--- a/test/evp_kdf_test.c
+++ b/test/evp_kdf_test.c
@@ -18,6 +18,7 @@
#include <openssl/core_names.h>
#include "internal/numbers.h"
#include "internal/sizes.h"
+#include "fake_blake2bprov.h"
#include "testutil.h"
static EVP_KDF_CTX *get_kdfbyname_libctx(OSSL_LIB_CTX *libctx, const char *name)
@@ -3840,6 +3841,70 @@ err:
}
#endif /* OPENSSL_NO_SNMPKDF */
+#if !defined(OPENSSL_NO_ARGON2)
+/*
+ * Argon2 asks BLAKE2b for digest sizes other than 64 and finalises into
+ * buffers of exactly that size. A BLAKE2B-512 that does not support
+ * OSSL_DIGEST_PARAM_SIZE must make the derivation fail, not write past the
+ * output or report success with an unwritten key. With a 100-byte output the
+ * unsupported size is only requested by the last step of the long hash.
+ */
+static int test_kdf_argon2_unsized_blake2b(int idx)
+{
+ static const struct {
+ const char *props;
+ size_t outlen;
+ } tests[] = {
+ { FAKE_BLAKE2B_FIXED_PROPS, 32 },
+ { FAKE_BLAKE2B_FAILING_PROPS, 32 },
+ { FAKE_BLAKE2B_FAILING_PROPS, 100 },
+ };
+ const size_t outlen = tests[idx].outlen;
+ unsigned char out[132], zero[100] = { 0 }, guard[32];
+ uint32_t one = 1, memcost = 32;
+ OSSL_LIB_CTX *libctx = NULL;
+ OSSL_PROVIDER *deflt = NULL, *fake = NULL;
+ EVP_KDF *kdf = NULL;
+ EVP_KDF_CTX *kctx = NULL;
+ OSSL_PARAM params[8], *p = params;
+ int ret = 0;
+
+ if (!TEST_ptr(libctx = OSSL_LIB_CTX_new())
+ || !TEST_ptr(deflt = OSSL_PROVIDER_load(libctx, "default"))
+ || !TEST_ptr(fake = fake_blake2b_start(libctx))
+ || !TEST_ptr(kdf = EVP_KDF_fetch(libctx, "ARGON2ID", NULL))
+ || !TEST_ptr(kctx = EVP_KDF_CTX_new(kdf)))
+ goto err;
+
+ *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PASSWORD,
+ "password", 8);
+ *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
+ "saltsaltsaltsalt", 16);
+ *p++ = OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_ITER, &one);
+ *p++ = OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_THREADS, &one);
+ *p++ = OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_ARGON2_LANES, &one);
+ *p++ = OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_ARGON2_MEMCOST, &memcost);
+ *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_PROPERTIES,
+ (char *)tests[idx].props, 0);
+ *p = OSSL_PARAM_construct_end();
+
+ memset(out, 0xa5, sizeof(out));
+ memset(guard, 0xa5, sizeof(guard));
+ if (!TEST_int_le(EVP_KDF_derive(kctx, out, outlen, params), 0)
+ || !TEST_mem_eq(out + outlen, sizeof(guard), guard, sizeof(guard))
+ || !TEST_mem_eq(out, outlen, zero, outlen))
+ goto err;
+ ret = 1;
+err:
+ EVP_KDF_CTX_free(kctx);
+ EVP_KDF_free(kdf);
+ fake_blake2b_finish(fake);
+ OSSL_PROVIDER_unload(deflt);
+ OSSL_LIB_CTX_free(libctx);
+ return ret;
+}
+#endif /* !defined(OPENSSL_NO_ARGON2) */
+
int setup_tests(void)
{
ADD_TEST(test_kdf_pbkdf1);
@@ -3963,5 +4028,8 @@ int setup_tests(void)
#ifndef OPENSSL_NO_KBKDF
ADD_TEST(test_kbkdf_mac_change);
#endif
+#if !defined(OPENSSL_NO_ARGON2)
+ ADD_ALL_TESTS(test_kdf_argon2_unsized_blake2b, 3);
+#endif /* !defined(OPENSSL_NO_ARGON2) */
return 1;
}
diff --git a/test/fake_blake2bprov.c b/test/fake_blake2bprov.c
new file mode 100644
index 0000000000..67c7a8302e
--- /dev/null
+++ b/test/fake_blake2bprov.c
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2026 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <string.h>
+#include <openssl/core_dispatch.h>
+#include <openssl/core_names.h>
+#include <openssl/crypto.h>
+#include <openssl/evp.h>
+#include <openssl/params.h>
+#include "fake_blake2bprov.h"
+
+#define FAKE_BLAKE2B_SIZE 64
+#define FAKE_BLAKE2B_BLOCK_SIZE 128
+
+typedef struct {
+ EVP_MD_CTX *mdctx;
+ int failing;
+} FAKE_BLAKE2B_CTX;
+
+/* The real digest, from a library context of the provider's own */
+static EVP_MD *fake_blake2b_md(void *provctx)
+{
+ return EVP_MD_fetch((OSSL_LIB_CTX *)provctx, "BLAKE2B-512", NULL);
+}
+
+static void *fake_blake2b_newctx(void *provctx, int failing)
+{
+ FAKE_BLAKE2B_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
+ EVP_MD *md = fake_blake2b_md(provctx);
+
+ if (ctx == NULL || md == NULL
+ || (ctx->mdctx = EVP_MD_CTX_new()) == NULL
+ || !EVP_DigestInit_ex2(ctx->mdctx, md, NULL)) {
+ EVP_MD_free(md);
+ if (ctx != NULL)
+ EVP_MD_CTX_free(ctx->mdctx);
+ OPENSSL_free(ctx);
+ return NULL;
+ }
+ EVP_MD_free(md);
+ ctx->failing = failing;
+ return ctx;
+}
+
+static void *fake_blake2b_fixed_newctx(void *provctx)
+{
+ return fake_blake2b_newctx(provctx, 0);
+}
+
+static void *fake_blake2b_failing_newctx(void *provctx)
+{
+ return fake_blake2b_newctx(provctx, 1);
+}
+
+static void fake_blake2b_freectx(void *vctx)
+{
+ FAKE_BLAKE2B_CTX *ctx = vctx;
+
+ if (ctx != NULL)
+ EVP_MD_CTX_free(ctx->mdctx);
+ OPENSSL_free(ctx);
+}
+
+static int fake_blake2b_init(void *vctx, const OSSL_PARAM params[])
+{
+ FAKE_BLAKE2B_CTX *ctx = vctx;
+ const OSSL_PARAM *p;
+ size_t size;
+
+ p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SIZE);
+ if (ctx->failing && p != NULL
+ && (!OSSL_PARAM_get_size_t(p, &size) || size != FAKE_BLAKE2B_SIZE))
+ return 0;
+ /* Otherwise unknown parameters are ignored, as providers are expected to */
+ return EVP_DigestInit_ex2(ctx->mdctx, NULL, NULL);
+}
+
+static int fake_blake2b_update(void *vctx, const unsigned char *in, size_t inl)
+{
+ return EVP_DigestUpdate(((FAKE_BLAKE2B_CTX *)vctx)->mdctx, in, inl);
+}
+
+static int fake_blake2b_final(void *vctx, unsigned char *out, size_t *outl,
+ size_t outsz)
+{
+ unsigned char md[FAKE_BLAKE2B_SIZE];
+
+ if (outsz < FAKE_BLAKE2B_SIZE
+ || !EVP_DigestFinal_ex(((FAKE_BLAKE2B_CTX *)vctx)->mdctx, md, NULL))
+ return 0;
+ memcpy(out, md, sizeof(md));
+ *outl = sizeof(md);
+ return 1;
+}
+
+static int fake_blake2b_get_params(OSSL_PARAM params[])
+{
+ OSSL_PARAM *p;
+
+ p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE);
+ if (p != NULL && !OSSL_PARAM_set_size_t(p, FAKE_BLAKE2B_SIZE))
+ return 0;
+ p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_BLOCK_SIZE);
+ if (p != NULL && !OSSL_PARAM_set_size_t(p, FAKE_BLAKE2B_BLOCK_SIZE))
+ return 0;
+ return 1;
+}
+
+static const OSSL_PARAM *fake_blake2b_gettable_params(void *provctx)
+{
+ static const OSSL_PARAM gettables[] = {
+ OSSL_PARAM_size_t(OSSL_DIGEST_PARAM_SIZE, NULL),
+ OSSL_PARAM_size_t(OSSL_DIGEST_PARAM_BLOCK_SIZE, NULL),
+ OSSL_PARAM_END
+ };
+
+ return gettables;
+}
+
+static const OSSL_DISPATCH fake_blake2b_fixed_functions[] = {
+ { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))fake_blake2b_fixed_newctx },
+ { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))fake_blake2b_freectx },
+ { OSSL_FUNC_DIGEST_INIT, (void (*)(void))fake_blake2b_init },
+ { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))fake_blake2b_update },
+ { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))fake_blake2b_final },
+ { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))fake_blake2b_get_params },
+ { OSSL_FUNC_DIGEST_GETTABLE_PARAMS,
+ (void (*)(void))fake_blake2b_gettable_params },
+ OSSL_DISPATCH_END
+};
+
+static const OSSL_DISPATCH fake_blake2b_failing_functions[] = {
+ { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))fake_blake2b_failing_newctx },
+ { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))fake_blake2b_freectx },
+ { OSSL_FUNC_DIGEST_INIT, (void (*)(void))fake_blake2b_init },
+ { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))fake_blake2b_update },
+ { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))fake_blake2b_final },
+ { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))fake_blake2b_get_params },
+ { OSSL_FUNC_DIGEST_GETTABLE_PARAMS,
+ (void (*)(void))fake_blake2b_gettable_params },
+ OSSL_DISPATCH_END
+};
+
+static const OSSL_ALGORITHM fake_blake2b_digests[] = {
+ { "BLAKE2B-512:BLAKE2b512", "provider=fake-blake2b,fake.blake2b=fixed",
+ fake_blake2b_fixed_functions, "BLAKE2b-512 without size parameter" },
+ { "BLAKE2B-512:BLAKE2b512", "provider=fake-blake2b,fake.blake2b=failing",
+ fake_blake2b_failing_functions, "BLAKE2b-512 rejecting other sizes" },
+ { NULL, NULL, NULL, NULL }
+};
+
+static const OSSL_ALGORITHM *fake_blake2b_query(void *provctx,
+ int operation_id,
+ int *no_cache)
+{
+ *no_cache = 0;
+ return operation_id == OSSL_OP_DIGEST ? fake_blake2b_digests : NULL;
+}
+
+static void fake_blake2b_teardown(void *provctx)
+{
+ OSSL_LIB_CTX_free((OSSL_LIB_CTX *)provctx);
+}
+
+static const OSSL_DISPATCH fake_blake2b_method[] = {
+ { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))fake_blake2b_teardown },
+ { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fake_blake2b_query },
+ OSSL_DISPATCH_END
+};
+
+static int fake_blake2b_provider_init(const OSSL_CORE_HANDLE *handle,
+ const OSSL_DISPATCH *in,
+ const OSSL_DISPATCH **out, void **provctx)
+{
+ if ((*provctx = OSSL_LIB_CTX_new()) == NULL)
+ return 0;
+ *out = fake_blake2b_method;
+ return 1;
+}
+
+OSSL_PROVIDER *fake_blake2b_start(OSSL_LIB_CTX *libctx)
+{
+ if (!OSSL_PROVIDER_add_builtin(libctx, FAKE_BLAKE2B_PROV_NAME,
+ fake_blake2b_provider_init))
+ return NULL;
+ return OSSL_PROVIDER_try_load(libctx, FAKE_BLAKE2B_PROV_NAME, 1);
+}
+
+void fake_blake2b_finish(OSSL_PROVIDER *p)
+{
+ OSSL_PROVIDER_unload(p);
+}
diff --git a/test/fake_blake2bprov.h b/test/fake_blake2bprov.h
new file mode 100644
index 0000000000..ee4f0f5715
--- /dev/null
+++ b/test/fake_blake2bprov.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2026 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#if !defined(OSSL_TEST_FAKE_BLAKE2BPROV_H)
+#define OSSL_TEST_FAKE_BLAKE2BPROV_H
+
+#include <openssl/provider.h>
+
+/*
+ * Fake BLAKE2B-512 provider: two implementations that do not support the
+ * OSSL_DIGEST_PARAM_SIZE context parameter, selected with the properties below.
+ * fixed: ignores it and always produces 64 bytes (as BLAKE2B-512 did
+ * before OpenSSL 3.2)
+ * failing: rejects any size other than 64
+ */
+/**
+ * @brief Register and load the fake BLAKE2B-512 provider.
+ *
+ * @param libctx library context to load the provider into.
+ * @return the loaded provider, or NULL on failure.
+ */
+OSSL_PROVIDER *fake_blake2b_start(OSSL_LIB_CTX *libctx);
+
+/**
+ * @brief Unload a provider returned by fake_blake2b_start().
+ *
+ * @param p the provider, may be NULL.
+ */
+void fake_blake2b_finish(OSSL_PROVIDER *p);
+
+#define FAKE_BLAKE2B_PROV_NAME "fake-blake2b"
+#define FAKE_BLAKE2B_FIXED_PROPS "?fake.blake2b=fixed"
+#define FAKE_BLAKE2B_FAILING_PROPS "?fake.blake2b=failing"
+
+#endif /* !defined(OSSL_TEST_FAKE_BLAKE2BPROV_H) */