]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
pvkkdf: convert to generated OSSL_PARAM parser
authorPauli <ppzgs1@gmail.com>
Wed, 2 Jul 2025 00:07:19 +0000 (10:07 +1000)
committerTomas Mraz <tomas@openssl.org>
Thu, 31 Jul 2025 18:20:48 +0000 (20:20 +0200)
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27923)

providers/implementations/kdfs/pvkkdf.c.in

index f60092d7717362cb33987769434c15c395084ae1..2ce8d2ebc7822a07c97e4d61f230289105e7378f 100644 (file)
@@ -6,11 +6,16 @@
  * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
  */
+{-
+use OpenSSL::paramnames qw(produce_param_decoder);
+-}
 
+#include <string.h>
 #include <openssl/evp.h>
 #include <openssl/core_names.h>
 #include <openssl/proverr.h>
 #include <openssl/err.h>
+#include "internal/common.h"
 #include "internal/numbers.h"    /* SIZE_MAX */
 #include "prov/provider_ctx.h"
 #include "prov/providercommon.h"
@@ -176,26 +181,32 @@ static int kdf_pvk_derive(void *vctx, unsigned char *key, size_t keylen,
     return res;
 }
 
+{- produce_param_decoder('pvk_set_ctx_params',
+                         (['KDF_PARAM_PROPERTIES',  'propq',    'utf8_string'],
+                          ['ALG_PARAM_ENGINE',      'engine',   'utf8_string'],
+                          ['KDF_PARAM_DIGEST',      'digest',   'utf8_string'],
+                          ['KDF_PARAM_PASSWORD',    'pass',     'octet_string'],
+                          ['KDF_PARAM_SALT',        'salt',     'octet_string'],
+                         )); -}
+
 static int kdf_pvk_set_ctx_params(void *vctx, const OSSL_PARAM params[])
 {
-    const OSSL_PARAM *p;
+    struct pvk_set_ctx_params_st p;
     KDF_PVK *ctx = vctx;
     OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(ctx->provctx);
 
-    if (ossl_param_is_empty(params))
-        return 1;
+    if (ctx == NULL || !pvk_set_ctx_params_decoder(params, &p))
+        return 0;
 
-    if (!ossl_prov_digest_load_from_params(&ctx->digest, params, provctx))
+    if (!ossl_prov_digest_load(&ctx->digest, p.digest, p.propq, p.engine,
+                               provctx))
         return 0;
 
-    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PASSWORD)) != NULL)
-        if (!pvk_set_membuf(&ctx->pass, &ctx->pass_len, p))
-            return 0;
+    if (p.pass != NULL && !pvk_set_membuf(&ctx->pass, &ctx->pass_len, p.pass))
+        return 0;
 
-    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SALT)) != NULL) {
-        if (!pvk_set_membuf(&ctx->salt, &ctx->salt_len, p))
-            return 0;
-    }
+    if (p.salt != NULL && !pvk_set_membuf(&ctx->salt, &ctx->salt_len, p.salt))
+        return 0;
 
     return 1;
 }
@@ -203,33 +214,30 @@ static int kdf_pvk_set_ctx_params(void *vctx, const OSSL_PARAM params[])
 static const OSSL_PARAM *kdf_pvk_settable_ctx_params(ossl_unused void *ctx,
                                                         ossl_unused void *p_ctx)
 {
-    static const OSSL_PARAM known_settable_ctx_params[] = {
-        OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0),
-        OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_DIGEST, NULL, 0),
-        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_PASSWORD, NULL, 0),
-        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SALT, NULL, 0),
-        OSSL_PARAM_END
-    };
-    return known_settable_ctx_params;
+    return pvk_set_ctx_params_list;
 }
 
+{- produce_param_decoder('pvk_get_ctx_params',
+                         (['KDF_PARAM_SIZE',    'size', 'size_t'],
+                         )); -}
+
 static int kdf_pvk_get_ctx_params(void *vctx, OSSL_PARAM params[])
 {
-    OSSL_PARAM *p;
+    struct pvk_get_ctx_params_st p;
+    KDF_PVK *ctx = vctx;
 
-    if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL)
-        return OSSL_PARAM_set_size_t(p, SIZE_MAX);
-    return -2;
+    if (ctx == NULL || !pvk_get_ctx_params_decoder(params, &p))
+        return 0;
+
+    if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, SIZE_MAX))
+        return 0;
+    return 1;
 }
 
 static const OSSL_PARAM *kdf_pvk_gettable_ctx_params(ossl_unused void *ctx,
                                                         ossl_unused void *p_ctx)
 {
-    static const OSSL_PARAM known_gettable_ctx_params[] = {
-        OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL),
-        OSSL_PARAM_END
-    };
-    return known_gettable_ctx_params;
+    return pvk_get_ctx_params_list;
 }
 
 const OSSL_DISPATCH ossl_kdf_pvk_functions[] = {