Commit 8579dc59b2 for openssl.org

commit 8579dc59b206e3895f52d086f2a70059d284549c
Author: Dmitry Belyavskiy <beldmit@gmail.com>
Date:   Fri Oct 2 17:34:26 2026 +0200

    Implement TLS 1.3 KDF multi-key derivation provider

    Extend the TLS13-KDF provider to support multi-key derivation via
    EVP_KDF_derive_SKEYs(). A single derive_multi call performs two
    HKDF-Expand-Label operations (one for "key", one for "iv") and stores
    the results for retrieval via get_skey/get_iv with purpose strings
    client_key/server_key and client_iv/server_iv.

    Add unit tests verifying consistency with separate EVP_KDF_derive()
    calls in EXPAND_ONLY mode, and CLI tests for the openssl kdf command.
    Update EVP_KDF-TLS13_KDF.pod and openssl-kdf.pod.in documentation.

    Assisted-By: Claude Opus 4.6 <noreply@anthropic.com>

    Reviewed-by: Mounir Idrassi <mounir.idrassi@idrix.fr>
    Reviewed-by: Simo Sorce <simo@redhat.com>
    MergeDate: Wed Nov 18 12:11:52 2026
    (Merged from https://github.com/openssl/openssl/pull/33082)

diff --git a/doc/man1/openssl-kdf.pod.in b/doc/man1/openssl-kdf.pod.in
index ac15b9858b..a14c7bdc7c 100644
--- a/doc/man1/openssl-kdf.pod.in
+++ b/doc/man1/openssl-kdf.pod.in
@@ -60,7 +60,8 @@ Specifies which key or IV to retrieve from a multi-key derivation.
 Must be used together with B<-multi>.
 The available purpose strings depend on the KDF algorithm; for example,
 TLS1-PRF supports B<client_MAC_key>, B<server_MAC_key>, B<client_cipher_key>,
-B<server_cipher_key>, B<client_IV>, and B<server_IV>.
+B<server_cipher_key>, B<client_iv>, and B<server_iv>.
+TLS13-KDF supports B<client_key>, B<server_key>, B<client_iv>, and B<server_iv>.
 See the documentation of the specific KDF for the supported purpose strings.

 If the purpose identifies a key, it is retrieved via EVP_KDF_CTX_get1_SKEY()
diff --git a/doc/man7/EVP_KDF-TLS13_KDF.pod b/doc/man7/EVP_KDF-TLS13_KDF.pod
index d280500591..4847679557 100644
--- a/doc/man7/EVP_KDF-TLS13_KDF.pod
+++ b/doc/man7/EVP_KDF-TLS13_KDF.pod
@@ -81,6 +81,63 @@ an error will occur.

 =back

+=head2 Multi-key Derivation Parameters
+
+The following additional settable parameters are supported when using
+multi-key derivation via L<EVP_KDF_derive_SKEYs(3)>:
+
+=over 4
+
+=item "cipher_key_len" (B<OSSL_KDF_PARAM_CIPHER_KEY_LEN>) <unsigned integer>
+
+Sets the length of the cipher key to derive. This is used as the output
+length for the HKDF-Expand-Label operation with label "key".
+
+=item "iv_len" (B<OSSL_KDF_PARAM_IV_LEN>) <unsigned integer>
+
+Sets the length of the IV to derive. This is used as the output length for
+the HKDF-Expand-Label operation with label "iv".
+
+=item "cipher" (B<OSSL_KDF_PARAM_CIPHER>) <UTF8 string>
+
+The cipher the derived key is for, for example "AES-128-GCM". This is not
+used by the KDF itself; it tells the provider how large a key to derive and
+which kind of key to produce, making "cipher_key_len" unnecessary. If both are
+given they must agree, and a mismatch is reported by
+L<EVP_KDF_derive_SKEYs(3)>.
+
+The key type settled on is reported by EVP_SKEY_get0_skeymgmt_name() on the
+key that comes back; the default provider produces B<OSSL_SKEY_TYPE_AES> for
+AES ciphers and B<OSSL_SKEY_TYPE_GENERIC> otherwise.
+
+TLS 1.3 is AEAD only and derives no MAC keys, so there is no "mac" parameter.
+
+=back
+
+After calling L<EVP_KDF_derive_SKEYs(3)>, the derived key and IV can be
+retrieved using L<EVP_KDF_CTX_get1_SKEY(3)> and L<EVP_KDF_CTX_get0_IV(3)>
+respectively, with the following purpose strings:
+
+=over 4
+
+=item B<client_key>, B<server_key>
+
+Retrieve the derived cipher key via L<EVP_KDF_CTX_get1_SKEY(3)>.
+In TLS 1.3, the traffic secret already encodes direction, so both purpose
+strings return the same derived key.
+
+=item B<client_iv>, B<server_iv>
+
+Retrieve the derived IV via L<EVP_KDF_CTX_get0_IV(3)>.
+Both purpose strings return the same derived IV for the same reason.
+
+=back
+
+The mode must be set to B<EXPAND_ONLY> when using multi-key derivation.
+The key (traffic secret), prefix, and digest parameters must be set as for
+a normal expand operation. The data parameter, if set, is ignored for key
+and IV derivation, which use an empty context per RFC 8446.
+
 The OpenSSL FIPS provider also supports the following parameters:

 =over 4
@@ -158,7 +215,7 @@ This functionality was added in OpenSSL 3.0.

 =head1 COPYRIGHT

-Copyright 2021-2024 The OpenSSL Project Authors. All Rights Reserved.
+Copyright 2021-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
diff --git a/providers/implementations/kdfs/hkdf.c b/providers/implementations/kdfs/hkdf.c
index c1a68f08ed..bee14aaeaa 100644
--- a/providers/implementations/kdfs/hkdf.c
+++ b/providers/implementations/kdfs/hkdf.c
@@ -51,6 +51,19 @@ static OSSL_FUNC_kdf_get_ctx_params_fn hkdf_common_get_ctx_params;
 static OSSL_FUNC_kdf_derive_fn kdf_tls1_3_derive;
 static OSSL_FUNC_kdf_settable_ctx_params_fn kdf_tls1_3_settable_ctx_params;
 static OSSL_FUNC_kdf_set_ctx_params_fn kdf_tls1_3_set_ctx_params;
+static OSSL_FUNC_kdf_derive_multi_fn kdf_tls1_3_derive_multi;
+static OSSL_FUNC_kdf_get_skey_fn kdf_tls1_3_get_skey;
+static OSSL_FUNC_kdf_get_iv_fn kdf_tls1_3_get_iv;
+
+typedef struct kdf_hkdf_st KDF_HKDF;
+static void kdf_tls1_3_multi_cleanup(KDF_HKDF *ctx);
+
+/*
+ * TLS 1.3 derives one key and one IV from a traffic secret; the secret
+ * already encodes the direction, so the client and server purposes name the
+ * same key and differ only in the type the caller may request.
+ */
+#define TLS13_NUM_KEYS 2
 static OSSL_FUNC_kdf_newctx_fn kdf_hkdf_sha256_new;
 static OSSL_FUNC_kdf_newctx_fn kdf_hkdf_sha384_new;
 static OSSL_FUNC_kdf_newctx_fn kdf_hkdf_sha512_new;
@@ -74,7 +87,7 @@ static int HKDF_Expand(const EVP_MD *evp_md,
     const unsigned char *info, size_t info_len,
     unsigned char *okm, size_t okm_len);

-typedef struct {
+struct kdf_hkdf_st {
     void *provctx;
     int mode;
     PROV_DIGEST digest;
@@ -91,8 +104,40 @@ typedef struct {
     unsigned char *info;
     size_t info_len;
     int fixed_digest;
+
+    /* Multi-key derivation configuration */
+    size_t cipher_key_len;
+    size_t iv_len;
+    /*
+     * The cipher the derived key is for, resolved at set time to just the
+     * two facts needed of it: the name, which decides the key type, and the
+     * key length.  The EVP_CIPHER itself is not kept.
+     *
+     * The length is deliberately *not* merged into cipher_key_len above.
+     * That one is what the caller asked for, this one is what the cipher
+     * requires, and derive_multi() compares them -- naming AES-128-CBC and a
+     * cipher_key_len of 10 is a contradiction worth reporting rather than
+     * silently resolving.  Keeping them apart is also what lets a later
+     * "cipher" replace an earlier one while a caller-supplied length still
+     * conflicts with it, whatever order the two arrive in.
+     */
+    char *multi_cipher_name;
+    size_t multi_cipher_keylen;
+
+    /*
+     * Result of a multi-key derivation, released by kdf_hkdf_reset_ex() and
+     * copied by kdf_hkdf_dup().
+     */
+    struct {
+        unsigned char *key;
+        size_t key_len;
+        unsigned char *iv;
+        size_t iv_len;
+        char *cipher_key_type;
+    } multi;
+
     OSSL_FIPS_IND_DECLARE
-} KDF_HKDF;
+};

 static void *kdf_hkdf_new(void *provctx)
 {
@@ -151,6 +196,8 @@ static void kdf_hkdf_reset_ex(void *vctx, int on_free)
     OPENSSL_clear_free(ctx->data, ctx->data_len);
     OPENSSL_clear_free(ctx->key, ctx->key_len);
     OPENSSL_clear_free(ctx->info, ctx->info_len);
+    OPENSSL_free(ctx->multi_cipher_name);
+    kdf_tls1_3_multi_cleanup(ctx);
     memset(ctx, 0, sizeof(*ctx));
     ctx->provctx = provctx;
     if (preserve_digest) {
@@ -180,6 +227,20 @@ static void *kdf_hkdf_dup(void *vctx)
                 &dest->info, &dest->info_len)
             || !ossl_prov_digest_copy(&dest->digest, &src->digest))
             goto err;
+        if (src->multi_cipher_name != NULL
+            && (dest->multi_cipher_name = OPENSSL_strdup(src->multi_cipher_name)) == NULL)
+            goto err;
+        dest->multi_cipher_keylen = src->multi_cipher_keylen;
+        if (!ossl_prov_memdup(src->multi.key, src->multi.key_len,
+                &dest->multi.key, &dest->multi.key_len)
+            || !ossl_prov_memdup(src->multi.iv, src->multi.iv_len,
+                &dest->multi.iv, &dest->multi.iv_len))
+            goto err;
+        if (src->multi.cipher_key_type != NULL
+            && (dest->multi.cipher_key_type = OPENSSL_strdup(src->multi.cipher_key_type)) == NULL)
+            goto err;
+        dest->cipher_key_len = src->cipher_key_len;
+        dest->iv_len = src->iv_len;
         dest->mode = src->mode;
         dest->fixed_digest = src->fixed_digest;
         OSSL_FIPS_IND_COPY(dest, src)
@@ -283,6 +344,9 @@ struct hkdf_all_set_ctx_params_st {
     OSSL_PARAM *data;
     OSSL_PARAM *info[HKDF_MAX_INFOS];
     int num_info;
+    OSSL_PARAM *cipher_key_len;
+    OSSL_PARAM *iv_len;
+    OSSL_PARAM *cipher;
 };

 #define hkdf_set_ctx_params_st hkdf_all_set_ctx_params_st
@@ -421,6 +485,27 @@ static int hkdf_common_get_ctx_params(void *vctx, OSSL_PARAM params[])
             return 0;
     }

+    /*
+     * Key type settled on by a preceding multi-key derivation (TLS13-KDF only).
+     * Both purposes name the same key, since a TLS 1.3 traffic secret already
+     * encodes the direction.  When no multi-derive has been done, leave the
+     * params unmodified (the caller will see absence via EVP_KDF_CTX_get1_SKEY).
+     */
+    if (p.client_key_type != NULL || p.server_key_type != NULL) {
+        OSSL_PARAM *out = p.client_key_type != NULL ? p.client_key_type
+                                                    : p.server_key_type;
+
+        /* Skip if no multi-derive has been done (e.g., plain HKDF) */
+        if (ctx->multi.key != NULL) {
+            if (!OSSL_PARAM_set_utf8_string(out, ctx->multi.cipher_key_type))
+                return 0;
+            if (p.client_key_type != NULL && p.server_key_type != NULL
+                && !OSSL_PARAM_set_utf8_string(p.server_key_type,
+                    ctx->multi.cipher_key_type))
+                return 0;
+        }
+    }
+
     /* OSSL_KDF_PARAM_MODE has multiple parameter types, so look for all instances */
     if (p.mode != NULL) {
         if (p.mode->data_type == OSSL_PARAM_UTF8_STRING) {
@@ -1024,6 +1109,36 @@ static int kdf_tls1_3_set_ctx_params(void *vctx, const OSSL_PARAM params[])
             return 0;
 #endif

+    if (p.cipher != NULL) {
+        PROV_CIPHER pc = { 0 };
+        const EVP_CIPHER *ciph;
+        int clen;
+
+        if (!ossl_prov_cipher_load(&pc, p.cipher, p.propq,
+                PROV_LIBCTX_OF(ctx->provctx)))
+            return 0;
+        ciph = ossl_prov_cipher_cipher(&pc);
+        clen = ciph != NULL ? EVP_CIPHER_get_key_length(ciph) : -1;
+        if (clen < 0) {
+            ossl_prov_cipher_reset(&pc);
+            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
+            return 0;
+        }
+        OPENSSL_free(ctx->multi_cipher_name);
+        ctx->multi_cipher_name = OPENSSL_strdup(EVP_CIPHER_get0_name(ciph));
+        ctx->multi_cipher_keylen = (size_t)clen;
+        ossl_prov_cipher_reset(&pc);
+        if (ctx->multi_cipher_name == NULL)
+            return 0;
+    }
+
+    if (p.cipher_key_len != NULL
+        && !OSSL_PARAM_get_size_t(p.cipher_key_len, &ctx->cipher_key_len))
+        return 0;
+    if (p.iv_len != NULL
+        && !OSSL_PARAM_get_size_t(p.iv_len, &ctx->iv_len))
+        return 0;
+
     return 1;
 }

@@ -1033,6 +1148,141 @@ static const OSSL_PARAM *kdf_tls1_3_settable_ctx_params(ossl_unused void *ctx,
     return kdf_tls1_3_set_ctx_params_list;
 }

+static void kdf_tls1_3_multi_cleanup(KDF_HKDF *ctx)
+{
+    OPENSSL_clear_free(ctx->multi.key, ctx->multi.key_len);
+    OPENSSL_clear_free(ctx->multi.iv, ctx->multi.iv_len);
+    OPENSSL_free(ctx->multi.cipher_key_type);
+    memset(&ctx->multi, 0, sizeof(ctx->multi));
+}
+
+static int kdf_tls1_3_derive_multi(void *vctx, const OSSL_PARAM params[])
+{
+    KDF_HKDF *ctx = (KDF_HKDF *)vctx;
+    const EVP_MD *md;
+    size_t cipher_key_len;
+
+    /* Discard anything left by a previous derivation on this context */
+    kdf_tls1_3_multi_cleanup(ctx);
+
+    if (!ossl_prov_is_running() || !kdf_tls1_3_set_ctx_params(ctx, params))
+        return 0;
+
+    md = ossl_prov_digest_md(&ctx->digest);
+    if (md == NULL) {
+        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
+        return 0;
+    }
+    if (ctx->key == NULL) {
+        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_KEY);
+        return 0;
+    }
+    if (ctx->mode != EVP_KDF_HKDF_MODE_EXPAND_ONLY) {
+        ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_MODE);
+        return 0;
+    }
+
+    /*
+     * Settle on the cipher key length: the caller's, the named cipher's, or
+     * an error if they disagree.  See the field comments in KDF_HKDF.
+     */
+    cipher_key_len = ctx->cipher_key_len;
+    if (ctx->multi_cipher_keylen != 0) {
+        if (cipher_key_len == 0) {
+            cipher_key_len = ctx->multi_cipher_keylen;
+        } else if (cipher_key_len != ctx->multi_cipher_keylen) {
+            ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH,
+                "%s needs a %zu byte key, not %zu", ctx->multi_cipher_name,
+                ctx->multi_cipher_keylen, cipher_key_len);
+            return 0;
+        }
+    }
+
+    if (cipher_key_len == 0 && ctx->iv_len == 0) {
+        ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
+        return 0;
+    }
+
+    ctx->multi.cipher_key_type = OPENSSL_strdup(ossl_prov_cipher_skey_type(ctx->multi_cipher_name));
+    if (ctx->multi.cipher_key_type == NULL)
+        goto err;
+
+    if (cipher_key_len > 0) {
+        ctx->multi.key = OPENSSL_zalloc(cipher_key_len);
+        if (ctx->multi.key == NULL)
+            goto err;
+        ctx->multi.key_len = cipher_key_len;
+
+        /* ASCII: "key", in hex for EBCDIC compatibility */
+        if (!prov_tls13_hkdf_expand(md, ctx->key, ctx->key_len,
+                ctx->prefix, ctx->prefix_len,
+                (const unsigned char *)"\x6B\x65\x79", 3,
+                NULL, 0,
+                ctx->multi.key, ctx->multi.key_len))
+            goto err;
+    }
+
+    if (ctx->iv_len > 0) {
+        ctx->multi.iv = OPENSSL_zalloc(ctx->iv_len);
+        if (ctx->multi.iv == NULL)
+            goto err;
+        ctx->multi.iv_len = ctx->iv_len;
+
+        /* ASCII: "iv", in hex for EBCDIC compatibility */
+        if (!prov_tls13_hkdf_expand(md, ctx->key, ctx->key_len,
+                ctx->prefix, ctx->prefix_len,
+                (const unsigned char *)"\x69\x76", 2,
+                NULL, 0,
+                ctx->multi.iv, ctx->multi.iv_len))
+            goto err;
+    }
+
+    return 1;
+
+err:
+    kdf_tls1_3_multi_cleanup(ctx);
+    return 0;
+}
+
+static void *kdf_tls1_3_get_skey(void *vctx, const char *purpose,
+    void *provctx, OSSL_FUNC_skeymgmt_import_fn *import)
+{
+    KDF_HKDF *ctx = (KDF_HKDF *)vctx;
+    OSSL_PARAM import_params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
+
+    if (ctx->multi.key == NULL
+        || (strcmp(purpose, OSSL_KDF_PURPOSE_CLIENT_KEY) != 0
+            && strcmp(purpose, OSSL_KDF_PURPOSE_SERVER_KEY) != 0)) {
+        ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DATA);
+        return NULL;
+    }
+
+    import_params[0] = OSSL_PARAM_construct_octet_string(
+        OSSL_SKEY_PARAM_RAW_BYTES, ctx->multi.key, ctx->multi.key_len);
+
+    return import(provctx, OSSL_SKEYMGMT_SELECT_SECRET_KEY, import_params);
+}
+
+static int kdf_tls1_3_get_iv(void *vctx, const char *purpose,
+    const unsigned char **pIV, size_t *pIVlen)
+{
+    KDF_HKDF *ctx = (KDF_HKDF *)vctx;
+
+    if (!ossl_prov_is_running())
+        return 0;
+
+    if (ctx->multi.iv == NULL
+        || (strcmp(purpose, OSSL_KDF_PURPOSE_CLIENT_IV) != 0
+            && strcmp(purpose, OSSL_KDF_PURPOSE_SERVER_IV) != 0)) {
+        ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DATA);
+        return 0;
+    }
+
+    *pIV = ctx->multi.iv;
+    *pIVlen = ctx->multi.iv_len;
+    return 1;
+}
+
 const OSSL_DISPATCH ossl_kdf_tls1_3_kdf_functions[] = {
     { OSSL_FUNC_KDF_NEWCTX, (void (*)(void))kdf_hkdf_new },
     { OSSL_FUNC_KDF_DUPCTX, (void (*)(void))kdf_hkdf_dup },
@@ -1045,5 +1295,11 @@ const OSSL_DISPATCH ossl_kdf_tls1_3_kdf_functions[] = {
     { OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS,
         (void (*)(void))hkdf_gettable_ctx_params },
     { OSSL_FUNC_KDF_GET_CTX_PARAMS, (void (*)(void))hkdf_common_get_ctx_params },
+    { OSSL_FUNC_KDF_DERIVE_MULTI,
+        (void (*)(void))kdf_tls1_3_derive_multi },
+    { OSSL_FUNC_KDF_GET_SKEY,
+        (void (*)(void))kdf_tls1_3_get_skey },
+    { OSSL_FUNC_KDF_GET_IV,
+        (void (*)(void))kdf_tls1_3_get_iv },
     OSSL_DISPATCH_END
 };
diff --git a/providers/implementations/kdfs/hkdf.inc.in b/providers/implementations/kdfs/hkdf.inc.in
index 7fd4f90130..335a025c66 100644
--- a/providers/implementations/kdfs/hkdf.inc.in
+++ b/providers/implementations/kdfs/hkdf.inc.in
@@ -40,6 +40,8 @@ use OpenSSL::paramnames qw(produce_param_decoder);
                           ['OSSL_KDF_PARAM_SALT',                    'salt',   'octet_string'],
                           ['OSSL_KDF_PARAM_INFO',                    'info',   'octet_string'],
                           ['OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR', 'ind',    'int', 'fips'],
+                          ['OSSL_KDF_PURPOSE_CLIENT_KEY', 'client_key_type', 'utf8_string'],
+                          ['OSSL_KDF_PURPOSE_SERVER_KEY', 'server_key_type', 'utf8_string'],
                          )); -}

 {- produce_param_decoder('hkdf_fixed_digest_set_ctx_params',
@@ -52,9 +54,14 @@ use OpenSSL::paramnames qw(produce_param_decoder);
 {- produce_param_decoder('kdf_tls1_3_set_ctx_params',
                          (@HKDF_COMMON_SET_CTX_PARAMS,
                           @HKDF_DIGEST_SET_CTX_PARAMS,
-                          ['OSSL_KDF_PARAM_FIPS_KEY_CHECK',    'ind_k',  'int', 'fips'],
-                          ['OSSL_KDF_PARAM_FIPS_DIGEST_CHECK', 'ind_d',  'int', 'fips'],
-                          ['OSSL_KDF_PARAM_PREFIX',            'prefix', 'octet_string'],
-                          ['OSSL_KDF_PARAM_LABEL',             'label',  'octet_string'],
-                          ['OSSL_KDF_PARAM_DATA',              'data',   'octet_string'],
+                          ['OSSL_KDF_PARAM_FIPS_KEY_CHECK',    'ind_k',          'int', 'fips'],
+                          ['OSSL_KDF_PARAM_FIPS_DIGEST_CHECK', 'ind_d',          'int', 'fips'],
+                          ['OSSL_KDF_PARAM_PREFIX',            'prefix',         'octet_string'],
+                          ['OSSL_KDF_PARAM_LABEL',             'label',          'octet_string'],
+                          ['OSSL_KDF_PARAM_DATA',              'data',           'octet_string'],
+                          ['OSSL_KDF_PARAM_CIPHER_KEY_LEN',    'cipher_key_len', 'size_t'],
+                          ['OSSL_KDF_PARAM_IV_LEN',            'iv_len',         'size_t'],
+                          ['OSSL_KDF_PARAM_CIPHER',            'cipher',         'utf8_string'],
                          )); -}
+
+
diff --git a/test/evp_kdf_test.c b/test/evp_kdf_test.c
index bea17fee42..c9568a8d3a 100644
--- a/test/evp_kdf_test.c
+++ b/test/evp_kdf_test.c
@@ -681,6 +681,808 @@ err:
     return ret;
 }

+/*
+ * Test that a failed EVP_KDF_derive_SKEYs() call properly clears
+ * previous derivation results (TLS1-PRF version)
+ */
+static int test_kdf_tls1_prf_derive_multi_clear_on_fail(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx = NULL;
+    EVP_SKEY *skey = NULL;
+    OSSL_PARAM params_ok[8], params_bad[8], *p;
+    size_t mac_key_len = 20, cipher_key_len = 16, iv_len = 12;
+    const unsigned char *iv = NULL;
+    size_t iv_out_len = 0;
+
+    /* First, do a successful derivation */
+    p = params_ok;
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "sha256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
+        (unsigned char *)"secret", 6);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
+        (unsigned char *)"seed", 4);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_MAC_KEY_LEN,
+        &mac_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN,
+        &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER,
+        "AES-128-CBC", 0);
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_PRF))
+        || !TEST_int_gt(EVP_KDF_derive_SKEYs(kctx, params_ok), 0))
+        goto err;
+
+    /* Verify we can retrieve keys */
+    if (!TEST_ptr(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                      OSSL_KDF_PURPOSE_CLIENT_CIPHER_KEY, NULL)))
+        goto err;
+    EVP_SKEY_free(skey);
+    skey = NULL;
+
+    /* Verify we can retrieve the IV */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_CLIENT_IV,
+                         &iv, &iv_out_len),
+            1))
+        goto err;
+
+    /* Now call derive_SKEYs again with invalid params (invalid digest) */
+    p = params_bad;
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "NONEXISTENT", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
+        (unsigned char *)"secret", 6);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
+        (unsigned char *)"seed", 4);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_MAC_KEY_LEN, &mac_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN, &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *p = OSSL_PARAM_construct_end();
+
+    /* This should fail (invalid digest) */
+    if (!TEST_int_le(EVP_KDF_derive_SKEYs(kctx, params_bad), 0))
+        goto err;
+
+    /* After the failed call, previous keys should be cleared */
+    if (!TEST_ptr_null(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                           OSSL_KDF_PURPOSE_CLIENT_CIPHER_KEY, NULL)))
+        goto err;
+
+    /* IV should also be cleared */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_CLIENT_IV,
+                         &iv, &iv_out_len),
+            0))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_SKEY_free(skey);
+    EVP_KDF_CTX_free(kctx);
+    return ret;
+}
+
+/*
+ * Test that EVP_KDF_CTX_get_params() succeeds even when purpose params
+ * are requested before any multi-derive (backward compatibility)
+ */
+static int test_kdf_tls1_prf_get_params_before_derive(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx = NULL;
+    OSSL_PARAM get_params[6], *p;
+    char client_mac_type[64] = "";
+    char server_cipher_type[64] = "";
+    size_t size = 0;
+
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_PRF)))
+        goto err;
+
+    /* Query gettable params including purpose types before any derive */
+    p = get_params;
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_SIZE, &size);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PURPOSE_CLIENT_MAC_KEY,
+        client_mac_type, sizeof(client_mac_type));
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PURPOSE_SERVER_CIPHER_KEY,
+        server_cipher_type, sizeof(server_cipher_type));
+    *p = OSSL_PARAM_construct_end();
+
+    /*
+     * This should succeed even though no multi-derive has been done.
+     * The purpose params will be left unmodified, size should be SIZE_MAX.
+     */
+    if (!TEST_true(EVP_KDF_CTX_get_params(kctx, get_params)))
+        goto err;
+
+    /* Size should be set */
+    if (!TEST_size_t_eq(size, SIZE_MAX))
+        goto err;
+
+    /* Purpose params should be unmodified (empty strings) */
+    if (!TEST_str_eq(client_mac_type, "")
+        || !TEST_str_eq(server_cipher_type, ""))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_KDF_CTX_free(kctx);
+    return ret;
+}
+
+/*
+ * Test that EVP_KDF_CTX_get_params() succeeds for HKDF before any
+ * multi-derive (HKDF doesn't support multi-derive but lists the params)
+ */
+static int test_kdf_hkdf_get_params_with_purpose(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx = NULL;
+    OSSL_PARAM get_params[4], *p;
+    OSSL_PARAM set_params[3], *sp;
+    char client_key_type[64] = "";
+    size_t size = 0;
+    unsigned char key[32];
+
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_HKDF)))
+        goto err;
+
+    /* Set minimal params for plain HKDF */
+    memset(key, 0x42, sizeof(key));
+    sp = set_params;
+    *sp++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
+    *sp++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, key, sizeof(key));
+    *sp = OSSL_PARAM_construct_end();
+
+    if (!TEST_true(EVP_KDF_CTX_set_params(kctx, set_params)))
+        goto err;
+
+    /* Query including purpose param (which plain HKDF doesn't use) */
+    p = get_params;
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_SIZE, &size);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PURPOSE_CLIENT_KEY,
+        client_key_type, sizeof(client_key_type));
+    *p = OSSL_PARAM_construct_end();
+
+    /*
+     * This should succeed. The purpose param should be left unmodified
+     * since plain HKDF doesn't do multi-derive.
+     */
+    if (!TEST_true(EVP_KDF_CTX_get_params(kctx, get_params)))
+        goto err;
+
+    /* Purpose param should be unmodified (empty string) */
+    if (!TEST_str_eq(client_key_type, ""))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_KDF_CTX_free(kctx);
+    return ret;
+}
+
+/*
+ * Test that TLS1-PRF accepts NULL cipher (zero-length cipher key)
+ * for NULL-encryption TLS 1.2 suites like TLS_RSA_WITH_NULL_SHA256
+ */
+static int test_kdf_tls1_prf_null_cipher(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx = NULL;
+    EVP_SKEY *skey = NULL;
+    OSSL_PARAM params[7], *p;
+    size_t mac_key_len = 20, cipher_key_len = 0;
+
+    p = params;
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "sha256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
+        (unsigned char *)"secret", 6);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
+        (unsigned char *)"seed", 4);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_MAC_KEY_LEN, &mac_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN, &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER, "NULL", 0);
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_PRF)))
+        goto err;
+
+    /* This should succeed with NULL cipher (zero-length cipher key) */
+    if (!TEST_int_gt(EVP_KDF_derive_SKEYs(kctx, params), 0))
+        goto err;
+
+    /* Verify we can get MAC keys but not cipher keys */
+    if (!TEST_ptr(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                      OSSL_KDF_PURPOSE_CLIENT_MAC_KEY, NULL)))
+        goto err;
+    EVP_SKEY_free(skey);
+    skey = NULL;
+
+    /* Cipher key should not be available (length is 0) */
+    if (!TEST_ptr_null(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                           OSSL_KDF_PURPOSE_CLIENT_CIPHER_KEY, NULL)))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_SKEY_free(skey);
+    EVP_KDF_CTX_free(kctx);
+    return ret;
+}
+
+static int test_kdf_tls1_prf_get0_iv(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx = NULL;
+    OSSL_PARAM params[8], *p;
+    size_t mac_key_len = 0, cipher_key_len = 16, iv_len = 4;
+    const unsigned char *client_iv = NULL, *server_iv = NULL;
+    size_t client_iv_len = 0, server_iv_len = 0;
+
+    p = params;
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "sha256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
+        (unsigned char *)"secret", 6);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
+        (unsigned char *)"seed", 4);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_MAC_KEY_LEN, &mac_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN, &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER, "AES-128-GCM", 0);
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_PRF)))
+        goto err;
+
+    if (!TEST_int_gt(EVP_KDF_derive_SKEYs(kctx, params), 0))
+        goto err;
+
+    /* Verify get0_IV works with client_iv purpose */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_CLIENT_IV,
+                         &client_iv, &client_iv_len),
+            1))
+        goto err;
+    if (!TEST_ptr(client_iv) || !TEST_size_t_eq(client_iv_len, iv_len))
+        goto err;
+
+    /* Verify get0_IV works with server_iv purpose */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_SERVER_IV,
+                         &server_iv, &server_iv_len),
+            1))
+        goto err;
+    if (!TEST_ptr(server_iv) || !TEST_size_t_eq(server_iv_len, iv_len))
+        goto err;
+
+    /* Verify the IVs are different */
+    if (!TEST_mem_ne(client_iv, client_iv_len, server_iv, server_iv_len))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_KDF_CTX_free(kctx);
+    return ret;
+}
+
+static int test_kdf_tls1_prf_get0_iv_rejects_keys(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx = NULL;
+    OSSL_PARAM params[8], *p;
+    size_t mac_key_len = 20, cipher_key_len = 16, iv_len = 4;
+    const unsigned char *iv = NULL;
+    size_t iv_len_out = 0;
+
+    p = params;
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "sha256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
+        (unsigned char *)"secret", 6);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
+        (unsigned char *)"seed", 4);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_MAC_KEY_LEN, &mac_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN, &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER, "AES-128-CBC", 0);
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_PRF)))
+        goto err;
+
+    if (!TEST_int_gt(EVP_KDF_derive_SKEYs(kctx, params), 0))
+        goto err;
+
+    /* Verify get0_IV rejects client_MAC_key purpose */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_CLIENT_MAC_KEY,
+                         &iv, &iv_len_out),
+            0))
+        goto err;
+
+    /* Verify get0_IV rejects server_MAC_key purpose */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_SERVER_MAC_KEY,
+                         &iv, &iv_len_out),
+            0))
+        goto err;
+
+    /* Verify get0_IV rejects client_cipher_key purpose */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_CLIENT_CIPHER_KEY,
+                         &iv, &iv_len_out),
+            0))
+        goto err;
+
+    /* Verify get0_IV rejects server_cipher_key purpose */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_SERVER_CIPHER_KEY,
+                         &iv, &iv_len_out),
+            0))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_KDF_CTX_free(kctx);
+    return ret;
+}
+
+static int test_kdf_tls1_prf_get1_skey_rejects_ivs(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx = NULL;
+    OSSL_PARAM params[8], *p;
+    size_t mac_key_len = 0, cipher_key_len = 16, iv_len = 4;
+    EVP_SKEY *skey = NULL;
+
+    p = params;
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "sha256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
+        (unsigned char *)"secret", 6);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
+        (unsigned char *)"seed", 4);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_MAC_KEY_LEN, &mac_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN, &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER, "AES-128-GCM", 0);
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_PRF)))
+        goto err;
+
+    if (!TEST_int_gt(EVP_KDF_derive_SKEYs(kctx, params), 0))
+        goto err;
+
+    /* Verify get1_SKEY rejects client_iv purpose */
+    if (!TEST_ptr_null(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                           OSSL_KDF_PURPOSE_CLIENT_IV, NULL)))
+        goto err;
+
+    /* Verify get1_SKEY rejects server_iv purpose */
+    if (!TEST_ptr_null(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                           OSSL_KDF_PURPOSE_SERVER_IV, NULL)))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_SKEY_free(skey);
+    EVP_KDF_CTX_free(kctx);
+    return ret;
+}
+
+static int test_kdf_tls13_derive_multi_consistency(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx_key = NULL, *kctx_iv = NULL, *kctx_multi = NULL;
+    unsigned char raw_key[16], raw_iv[12];
+    size_t cipher_key_len = 16, iv_len = 12;
+    OSSL_PARAM key_params[7], iv_params[7], multi_params[8];
+    OSSL_PARAM *kp, *ip, *mp;
+    EVP_SKEY *skey = NULL;
+    const unsigned char *export_raw = NULL;
+    size_t export_len = 0;
+    const unsigned char *iv_out = NULL;
+    size_t iv_out_len = 0;
+    static const unsigned char traffic_secret[] = {
+        0xc8, 0x05, 0x83, 0xa9, 0x0e, 0x99, 0x5c, 0x48,
+        0x96, 0x00, 0x49, 0x2a, 0x5d, 0xa6, 0x42, 0xe6,
+        0xb1, 0xf6, 0x79, 0xba, 0x67, 0x48, 0x28, 0x79,
+        0x2d, 0xf0, 0x87, 0xb9, 0x39, 0x63, 0x61, 0x71
+    };
+    static const unsigned char prefix[] = {
+        0x74, 0x6c, 0x73, 0x31, 0x33, 0x20
+    };
+    int mode_expand = EVP_KDF_HKDF_MODE_EXPAND_ONLY;
+
+    /* Derive "key" separately - RFC 8446 uses empty context for key/IV */
+    kp = key_params;
+    *kp++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode_expand);
+    *kp++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
+    *kp++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
+        (void *)traffic_secret, sizeof(traffic_secret));
+    *kp++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PREFIX,
+        (void *)prefix, sizeof(prefix));
+    *kp++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_LABEL,
+        (void *)"key", 3);
+    *kp = OSSL_PARAM_construct_end();
+
+    if (!TEST_ptr(kctx_key = get_kdfbyname(OSSL_KDF_NAME_TLS1_3_KDF))
+        || !TEST_int_gt(EVP_KDF_derive(kctx_key, raw_key, sizeof(raw_key),
+                            key_params),
+            0))
+        goto err;
+
+    /* Derive "iv" separately - RFC 8446 uses empty context for key/IV */
+    ip = iv_params;
+    *ip++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode_expand);
+    *ip++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
+    *ip++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
+        (void *)traffic_secret, sizeof(traffic_secret));
+    *ip++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PREFIX,
+        (void *)prefix, sizeof(prefix));
+    *ip++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_LABEL,
+        (void *)"iv", 2);
+    *ip = OSSL_PARAM_construct_end();
+
+    if (!TEST_ptr(kctx_iv = get_kdfbyname(OSSL_KDF_NAME_TLS1_3_KDF))
+        || !TEST_int_gt(EVP_KDF_derive(kctx_iv, raw_iv, sizeof(raw_iv),
+                            iv_params),
+            0))
+        goto err;
+
+    /* Multi-derive - empty context per RFC 8446 */
+    mp = multi_params;
+    *mp++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode_expand);
+    *mp++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
+    *mp++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
+        (void *)traffic_secret, sizeof(traffic_secret));
+    *mp++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PREFIX,
+        (void *)prefix, sizeof(prefix));
+    *mp++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN,
+        &cipher_key_len);
+    *mp++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *mp = OSSL_PARAM_construct_end();
+
+    if (!TEST_ptr(kctx_multi = get_kdfbyname(OSSL_KDF_NAME_TLS1_3_KDF)))
+        goto err;
+
+    if (!TEST_int_gt(EVP_KDF_derive_SKEYs(kctx_multi, multi_params), 0))
+        goto err;
+
+    /* Both purposes name the same key: the traffic secret encodes direction */
+    if (!TEST_ptr(skey = EVP_KDF_CTX_get1_SKEY(kctx_multi,
+                      OSSL_KDF_PURPOSE_SERVER_KEY, NULL))
+        || !TEST_int_eq(EVP_SKEY_get0_raw_key(skey, &export_raw, &export_len), 1)
+        || !TEST_mem_eq(export_raw, export_len, raw_key, sizeof(raw_key)))
+        goto err;
+    EVP_SKEY_free(skey);
+    skey = NULL;
+
+    /* Verify key matches */
+    if (!TEST_ptr(skey = EVP_KDF_CTX_get1_SKEY(kctx_multi,
+                      OSSL_KDF_PURPOSE_CLIENT_KEY, NULL))
+        || !TEST_int_eq(EVP_SKEY_get0_raw_key(skey, &export_raw, &export_len), 1)
+        || !TEST_size_t_eq(export_len, sizeof(raw_key))
+        || !TEST_mem_eq(export_raw, export_len, raw_key, sizeof(raw_key)))
+        goto err;
+    EVP_SKEY_free(skey);
+    skey = NULL;
+
+    /* Verify IV matches */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx_multi,
+                         OSSL_KDF_PURPOSE_CLIENT_IV,
+                         &iv_out, &iv_out_len),
+            1)
+        || !TEST_size_t_eq(iv_out_len, sizeof(raw_iv))
+        || !TEST_mem_eq(iv_out, iv_out_len, raw_iv, sizeof(raw_iv)))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_SKEY_free(skey);
+    EVP_KDF_CTX_free(kctx_key);
+    EVP_KDF_CTX_free(kctx_iv);
+    EVP_KDF_CTX_free(kctx_multi);
+    return ret;
+}
+
+static int test_kdf_tls13_derive_multi_bad_purpose(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx = NULL;
+    OSSL_PARAM params[6];
+    OSSL_PARAM *p = params;
+    size_t cipher_key_len = 16, iv_len = 12;
+    int mode_expand = EVP_KDF_HKDF_MODE_EXPAND_ONLY;
+    static const unsigned char secret[32] = { 0 };
+    EVP_SKEY *skey = NULL;
+    const unsigned char *iv = NULL;
+    size_t iv_out_len = 0;
+
+    *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode_expand);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
+        (void *)secret, sizeof(secret));
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN,
+        &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_3_KDF))
+        || !TEST_int_gt(EVP_KDF_derive_SKEYs(kctx, params), 0))
+        goto err;
+
+    if (!TEST_ptr_null(skey = EVP_KDF_CTX_get1_SKEY(kctx, "nonexistent", NULL)))
+        goto err;
+
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, "nonexistent", &iv, &iv_out_len), 0))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_SKEY_free(skey);
+    EVP_KDF_CTX_free(kctx);
+    return ret;
+}
+
+/*
+ * Test using published RFC 8448 test vectors to verify correctness
+ * RFC 8448 section 3, pages 10-11: server application traffic secret,
+ * key, and IV from the simple 1-RTT handshake example.
+ * Tests that DATA parameter is properly ignored per RFC 8446 section 7.3.
+ */
+static int test_kdf_tls13_rfc8448_vectors(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx = NULL;
+    EVP_SKEY *skey = NULL;
+    const unsigned char *raw_key = NULL, *raw_iv = NULL;
+    size_t raw_key_len = 0, raw_iv_len = 0;
+    OSSL_PARAM params[8], *p;
+    size_t cipher_key_len = 16, iv_len = 12;
+    int mode_expand = EVP_KDF_HKDF_MODE_EXPAND_ONLY;
+    /* Server application traffic secret from RFC 8448 section 3, page 11 */
+    static const unsigned char traffic_secret[32] = {
+        0xa1, 0x1a, 0xf9, 0xf0, 0x55, 0x31, 0xf8, 0x56,
+        0xad, 0x47, 0x11, 0x6b, 0x45, 0xa9, 0x50, 0x32,
+        0x82, 0x04, 0xb4, 0xf4, 0x4b, 0xfb, 0x6b, 0x3a,
+        0x4b, 0x4f, 0x1f, 0x3f, 0xcb, 0x63, 0x16, 0x43
+    };
+    /* Transcript hash from RFC 8448 section 3, page 10 */
+    static const unsigned char transcript_hash[32] = {
+        0x96, 0x08, 0x10, 0x2a, 0x0f, 0x1c, 0xcc, 0x6d,
+        0xb6, 0x25, 0x0b, 0x7b, 0x7e, 0x41, 0x7b, 0x1a,
+        0x00, 0x0e, 0xaa, 0xda, 0x3d, 0xaa, 0xe4, 0x77,
+        0x7a, 0x76, 0x86, 0xc9, 0xff, 0x83, 0xdf, 0x13
+    };
+    /* "tls13 " prefix in hex for EBCDIC compatibility */
+    static const unsigned char prefix[] = {
+        0x74, 0x6c, 0x73, 0x31, 0x33, 0x20
+    };
+    /* Expected server write key from RFC 8448 section 3, page 11 */
+    static const unsigned char expected_key[16] = {
+        0x9f, 0x02, 0x28, 0x3b, 0x6c, 0x9c, 0x07, 0xef,
+        0xc2, 0x6b, 0xb9, 0xf2, 0xac, 0x92, 0xe3, 0x56
+    };
+    /* Expected server write IV from RFC 8448 section 3, page 11 */
+    static const unsigned char expected_iv[12] = {
+        0xcf, 0x78, 0x2b, 0x88, 0xdd, 0x83,
+        0x54, 0x9a, 0xad, 0xf1, 0xe9, 0x84
+    };
+
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_3_KDF)))
+        goto err;
+
+    /* Case 1: No DATA parameter - empty context per RFC 8446 */
+    p = params;
+    *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode_expand);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
+        (void *)traffic_secret, sizeof(traffic_secret));
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PREFIX,
+        (void *)prefix, sizeof(prefix));
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN,
+        &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_int_gt(EVP_KDF_derive_SKEYs(kctx, params), 0))
+        goto err;
+
+    /* Verify key matches RFC 8448 published value */
+    if (!TEST_ptr(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                      OSSL_KDF_PURPOSE_SERVER_KEY, NULL))
+        || !TEST_int_eq(EVP_SKEY_get0_raw_key(skey, &raw_key, &raw_key_len), 1)
+        || !TEST_size_t_eq(raw_key_len, sizeof(expected_key))
+        || !TEST_mem_eq(raw_key, raw_key_len, expected_key, sizeof(expected_key)))
+        goto err;
+    EVP_SKEY_free(skey);
+    skey = NULL;
+
+    /* Verify IV matches RFC 8448 published value */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_SERVER_IV,
+                         &raw_iv, &raw_iv_len),
+            1)
+        || !TEST_size_t_eq(raw_iv_len, sizeof(expected_iv))
+        || !TEST_mem_eq(raw_iv, raw_iv_len, expected_iv, sizeof(expected_iv)))
+        goto err;
+
+    EVP_KDF_CTX_free(kctx);
+    kctx = NULL;
+
+    /* Case 2: DATA supplied in derive_SKEYs params - should be ignored */
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_3_KDF)))
+        goto err;
+
+    p = params;
+    *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode_expand);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
+        (void *)traffic_secret, sizeof(traffic_secret));
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PREFIX,
+        (void *)prefix, sizeof(prefix));
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_DATA,
+        (void *)transcript_hash, sizeof(transcript_hash));
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN,
+        &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_int_gt(EVP_KDF_derive_SKEYs(kctx, params), 0))
+        goto err;
+
+    /* Verify key still matches RFC 8448 - DATA should be ignored */
+    if (!TEST_ptr(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                      OSSL_KDF_PURPOSE_SERVER_KEY, NULL))
+        || !TEST_int_eq(EVP_SKEY_get0_raw_key(skey, &raw_key, &raw_key_len), 1)
+        || !TEST_size_t_eq(raw_key_len, sizeof(expected_key))
+        || !TEST_mem_eq(raw_key, raw_key_len, expected_key, sizeof(expected_key)))
+        goto err;
+    EVP_SKEY_free(skey);
+    skey = NULL;
+
+    /* Verify IV still matches RFC 8448 - DATA should be ignored */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_SERVER_IV,
+                         &raw_iv, &raw_iv_len),
+            1)
+        || !TEST_size_t_eq(raw_iv_len, sizeof(expected_iv))
+        || !TEST_mem_eq(raw_iv, raw_iv_len, expected_iv, sizeof(expected_iv)))
+        goto err;
+
+    EVP_KDF_CTX_free(kctx);
+    kctx = NULL;
+
+    /* Case 3: DATA set on context via set_params, then derive_SKEYs called */
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_3_KDF)))
+        goto err;
+
+    /*
+     * Set MODE and DATA on context first (simulates reused context after
+     * deriving traffic secret which sets DATA to transcript hash)
+     */
+    p = params;
+    *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode_expand);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_DATA,
+        (void *)transcript_hash, sizeof(transcript_hash));
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_int_gt(EVP_KDF_CTX_set_params(kctx, params), 0))
+        goto err;
+
+    /* Now derive without passing DATA again */
+    p = params;
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
+        (void *)traffic_secret, sizeof(traffic_secret));
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PREFIX,
+        (void *)prefix, sizeof(prefix));
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN,
+        &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_int_gt(EVP_KDF_derive_SKEYs(kctx, params), 0))
+        goto err;
+
+    /* Verify key still matches RFC 8448 - DATA should be ignored */
+    if (!TEST_ptr(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                      OSSL_KDF_PURPOSE_SERVER_KEY, NULL))
+        || !TEST_int_eq(EVP_SKEY_get0_raw_key(skey, &raw_key, &raw_key_len), 1)
+        || !TEST_size_t_eq(raw_key_len, sizeof(expected_key))
+        || !TEST_mem_eq(raw_key, raw_key_len, expected_key, sizeof(expected_key)))
+        goto err;
+    EVP_SKEY_free(skey);
+    skey = NULL;
+
+    /* Verify IV still matches RFC 8448 - DATA should be ignored */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_SERVER_IV,
+                         &raw_iv, &raw_iv_len),
+            1)
+        || !TEST_size_t_eq(raw_iv_len, sizeof(expected_iv))
+        || !TEST_mem_eq(raw_iv, raw_iv_len, expected_iv, sizeof(expected_iv)))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_SKEY_free(skey);
+    EVP_KDF_CTX_free(kctx);
+    return ret;
+}
+
+/*
+ * Test that a failed EVP_KDF_derive_SKEYs() call properly clears
+ * previous derivation results
+ */
+static int test_kdf_tls13_derive_multi_clear_on_fail(void)
+{
+    int ret = 0;
+    EVP_KDF_CTX *kctx = NULL;
+    OSSL_PARAM params_ok[6], params_bad[6];
+    OSSL_PARAM *p;
+    size_t cipher_key_len = 16, iv_len = 12, zero_len = 0;
+    int mode_expand = EVP_KDF_HKDF_MODE_EXPAND_ONLY;
+    static const unsigned char secret[32] = {
+        0xc8, 0x05, 0x83, 0xa9, 0x0e, 0x99, 0x5c, 0x48,
+        0x96, 0x00, 0x49, 0x2a, 0x5d, 0xa6, 0x42, 0xe6,
+        0xb1, 0xf6, 0x79, 0xba, 0x67, 0x48, 0x28, 0x79,
+        0x2d, 0xf0, 0x87, 0xb9, 0x39, 0x63, 0x61, 0x71
+    };
+    EVP_SKEY *skey = NULL;
+    const unsigned char *iv = NULL;
+    size_t iv_out_len = 0;
+
+    /* First, do a successful derivation */
+    p = params_ok;
+    *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode_expand);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
+        (void *)secret, sizeof(secret));
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN,
+        &cipher_key_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &iv_len);
+    *p = OSSL_PARAM_construct_end();
+
+    if (!TEST_ptr(kctx = get_kdfbyname(OSSL_KDF_NAME_TLS1_3_KDF))
+        || !TEST_int_gt(EVP_KDF_derive_SKEYs(kctx, params_ok), 0))
+        goto err;
+
+    /* Verify we can retrieve the key */
+    if (!TEST_ptr(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                      OSSL_KDF_PURPOSE_CLIENT_KEY, NULL)))
+        goto err;
+    EVP_SKEY_free(skey);
+    skey = NULL;
+
+    /* Verify we can retrieve the IV */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_CLIENT_IV,
+                         &iv, &iv_out_len),
+            1))
+        goto err;
+
+    /* Now call derive_SKEYs again with invalid params (zero lengths) */
+    p = params_bad;
+    *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode_expand);
+    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
+        (void *)secret, sizeof(secret));
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_CIPHER_KEY_LEN, &zero_len);
+    *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_IV_LEN, &zero_len);
+    *p = OSSL_PARAM_construct_end();
+
+    /* This should fail (zero lengths) */
+    if (!TEST_int_le(EVP_KDF_derive_SKEYs(kctx, params_bad), 0))
+        goto err;
+
+    /* After the failed call, previous keys should be cleared */
+    if (!TEST_ptr_null(skey = EVP_KDF_CTX_get1_SKEY(kctx,
+                           OSSL_KDF_PURPOSE_CLIENT_KEY, NULL)))
+        goto err;
+
+    /* IV should also be cleared */
+    if (!TEST_int_eq(EVP_KDF_CTX_get0_IV(kctx, OSSL_KDF_PURPOSE_CLIENT_IV,
+                         &iv, &iv_out_len),
+            0))
+        goto err;
+
+    ret = 1;
+err:
+    EVP_SKEY_free(skey);
+    EVP_KDF_CTX_free(kctx);
+    return ret;
+}
+
 static OSSL_PARAM *construct_hkdf_params(char *digest, char *key,
     size_t keylen, char *salt, char *info)
 {
@@ -3020,14 +3822,33 @@ int setup_tests(void)
     ADD_TEST(test_kdf_tls1_prf_1byte_secret);
     ADD_TEST(test_kdf_tls1_prf_empty_seed);
     ADD_TEST(test_kdf_tls1_prf_1byte_seed);
-    ADD_TEST(test_kdf_tls1_prf_derive_multi_consistency);
-    ADD_TEST(test_kdf_tls1_prf_derive_multi_bad_purpose);
-    ADD_TEST(test_kdf_tls1_prf_derive_multi_no_derive);
-    ADD_TEST(test_kdf_tls1_prf_derive_multi_keytypes);
-    ADD_TEST(test_kdf_tls1_prf_derive_multi_dup);
-    ADD_TEST(test_kdf_tls1_prf_derive_multi_bad_keylen);
-    ADD_TEST(test_kdf_tls1_prf_derive_multi_no_mac_keys);
+    ADD_TEST(test_kdf_tls1_prf_get_params_before_derive);
+    /* Multi-derive tests require FIPS provider 4.2.0+ or non-FIPS */
+    if (fips_provider_version_ge(NULL, 4, 2, 0)) {
+        /*
+         * NULL cipher test requires non-FIPS provider (FIPS has no NULL cipher)
+         * Skip if any FIPS provider is loaded
+         */
+        if (!OSSL_PROVIDER_available(NULL, "fips"))
+            ADD_TEST(test_kdf_tls1_prf_null_cipher);
+        ADD_TEST(test_kdf_tls1_prf_derive_multi_consistency);
+        ADD_TEST(test_kdf_tls1_prf_derive_multi_bad_purpose);
+        ADD_TEST(test_kdf_tls1_prf_derive_multi_no_derive);
+        ADD_TEST(test_kdf_tls1_prf_derive_multi_keytypes);
+        ADD_TEST(test_kdf_tls1_prf_derive_multi_dup);
+        ADD_TEST(test_kdf_tls1_prf_derive_multi_bad_keylen);
+        ADD_TEST(test_kdf_tls1_prf_derive_multi_no_mac_keys);
+        ADD_TEST(test_kdf_tls1_prf_derive_multi_clear_on_fail);
+        ADD_TEST(test_kdf_tls1_prf_get0_iv);
+        ADD_TEST(test_kdf_tls1_prf_get0_iv_rejects_keys);
+        ADD_TEST(test_kdf_tls1_prf_get1_skey_rejects_ivs);
+        ADD_TEST(test_kdf_tls13_derive_multi_consistency);
+        ADD_TEST(test_kdf_tls13_derive_multi_bad_purpose);
+        ADD_TEST(test_kdf_tls13_rfc8448_vectors);
+        ADD_TEST(test_kdf_tls13_derive_multi_clear_on_fail);
+    }
     ADD_TEST(test_kdf_hkdf);
+    ADD_TEST(test_kdf_hkdf_get_params_with_purpose);
     ADD_TEST(test_kdf_hkdf_invalid_digest);
     ADD_TEST(test_kdf_hkdf_fixed_digest_change_digest);
     ADD_TEST(test_kdf_hkdf_fixed_digest_preserve_digest);
diff --git a/test/recipes/20-test_kdf.t b/test/recipes/20-test_kdf.t
index 86cdd9d6e8..eafa8c12a4 100755
--- a/test/recipes/20-test_kdf.t
+++ b/test/recipes/20-test_kdf.t
@@ -147,6 +147,26 @@ my @kdf_multi_fail_tests = (
       desc => 'TLS1-PRF multi-derive rejects an unknown purpose' },
 );

+my @tls13_multi_common = (qw{openssl kdf -multi -kdfopt mode:EXPAND_ONLY -kdfopt digest:SHA256},
+    '-kdfopt', 'hexkey:c80583a90e995c489600492a5da642e6b1f679ba674828792df087b939636171',
+    '-kdfopt', 'hexprefix:746c73313320',
+    qw{-kdfopt cipher_key_len:16 -kdfopt iv_len:12});
+
+my @kdf_tls13_multi_tests = (
+    { cmd => [@tls13_multi_common, '-purpose', 'client_key', 'TLS13-KDF'],
+      expected => '2E:4A:AE:5B:39:93:22:B6:DF:D5:6F:40:65:A0:65:83',
+      desc => 'TLS13-KDF multi-derive client_key' },
+    { cmd => [@tls13_multi_common, '-purpose', 'server_key', 'TLS13-KDF'],
+      expected => '2E:4A:AE:5B:39:93:22:B6:DF:D5:6F:40:65:A0:65:83',
+      desc => 'TLS13-KDF multi-derive server_key' },
+    { cmd => [@tls13_multi_common, '-purpose', 'client_iv', 'TLS13-KDF'],
+      expected => 'A1:D0:09:B9:B9:CE:76:D8:33:3C:CD:30',
+      desc => 'TLS13-KDF multi-derive client_iv' },
+    { cmd => [@tls13_multi_common, '-purpose', 'server_iv', 'TLS13-KDF'],
+      expected => 'A1:D0:09:B9:B9:CE:76:D8:33:3C:CD:30',
+      desc => 'TLS13-KDF multi-derive server_iv' },
+);
+
 my @kdf_bin_tests = (
     { cmd => [qw{openssl kdf -keylen 10 -binary -out hkdf-sha256.bin -kdfopt digest:SHA256 -kdfopt key:secret -kdfopt salt:salt -kdfopt info:label HKDF}],
       outfile => 'hkdf-sha256.bin',
@@ -167,7 +187,7 @@ push @kdf_tests, @sskdf_tests unless disabled("sskdf");

 plan tests => scalar @kdf_tests + scalar @kdf_multi_tests
     + scalar @kdf_multi_alg_tests + scalar @kdf_multi_fail_tests
-    + scalar @kdf_bin_tests;
+    + scalar @kdf_tls13_multi_tests + scalar @kdf_bin_tests;

 foreach (@kdf_tests) {
     ok(compareline($_->{cmd}, $_->{expected}), $_->{desc});
@@ -185,6 +205,10 @@ foreach (@kdf_multi_fail_tests) {
     ok(checkfail($_->{cmd}), $_->{desc});
 }

+foreach (@kdf_tls13_multi_tests) {
+    ok(compareline($_->{cmd}, $_->{expected}), $_->{desc});
+}
+
 foreach (@kdf_bin_tests) {
     ok(comparebinary($_->{cmd}, $_->{outfile}, $_->{expected}), $_->{desc});
 }