]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Disallow SHAKE when using PBKDF2 and X9.42 KDF
authorPauli <ppzgs1@gmail.com>
Fri, 12 Jul 2024 02:29:08 +0000 (12:29 +1000)
committerPauli <ppzgs1@gmail.com>
Tue, 30 Jul 2024 08:04:36 +0000 (18:04 +1000)
The operation is non-sensical.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/24862)

providers/implementations/kdfs/pbkdf2.c
providers/implementations/kdfs/x942kdf.c

index bac839ebc623ff4af4e5445385e9663a80b23d7e..eb61b83516f93c1339fd551f018b644c6e137b0d 100644 (file)
@@ -206,12 +206,20 @@ static int kdf_pbkdf2_set_ctx_params(void *vctx, const OSSL_PARAM params[])
     OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(ctx->provctx);
     int pkcs5;
     uint64_t iter, min_iter;
+    const EVP_MD *md;
 
     if (params == NULL)
         return 1;
 
-    if (!ossl_prov_digest_load_from_params(&ctx->digest, params, provctx))
-        return 0;
+    if (OSSL_PARAM_locate_const(params, OSSL_ALG_PARAM_DIGEST) != NULL) {
+        if (!ossl_prov_digest_load_from_params(&ctx->digest, params, provctx))
+            return 0;
+        md = ossl_prov_digest_md(&ctx->digest);
+        if ((EVP_MD_get_flags(md) & EVP_MD_FLAG_XOF) != 0) {
+            ERR_raise(ERR_LIB_PROV, PROV_R_XOF_DIGESTS_NOT_ALLOWED);
+            return 0;
+        }
+    }
 
     if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PKCS5)) != NULL) {
         if (!OSSL_PARAM_get_int(p, &pkcs5))
index 19b54493efca0d3b9fcdf7e443ea64e01dcaac2c..41eaf52404d8d729d95da8e981d6151ba964eb48 100644 (file)
@@ -507,12 +507,21 @@ static int x942kdf_set_ctx_params(void *vctx, const OSSL_PARAM params[])
     KDF_X942 *ctx = vctx;
     OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(ctx->provctx);
     const char *propq = NULL;
+    const EVP_MD *md;
     size_t id;
 
     if (params == NULL)
         return 1;
-    if (!ossl_prov_digest_load_from_params(&ctx->digest, params, provctx))
-        return 0;
+
+    if (OSSL_PARAM_locate_const(params, OSSL_ALG_PARAM_DIGEST) != NULL) {
+        if (!ossl_prov_digest_load_from_params(&ctx->digest, params, provctx))
+            return 0;
+        md = ossl_prov_digest_md(&ctx->digest);
+        if ((EVP_MD_get_flags(md) & EVP_MD_FLAG_XOF) != 0) {
+            ERR_raise(ERR_LIB_PROV, PROV_R_XOF_DIGESTS_NOT_ALLOWED);
+            return 0;
+        }
+    }
 
     p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SECRET);
     if (p == NULL)