]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
krb5kdf: convert to generated OSSL_PARAM parser
authorPauli <ppzgs1@gmail.com>
Wed, 2 Jul 2025 06:53:40 +0000 (16:53 +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/krb5kdf.c.in

index 9022da6d770c82ff56a51668da2eba65d64175f6..25883cd68e6e9c5bcd9a4e0e3b218da6bb07e709 100644 (file)
@@ -6,6 +6,9 @@
  * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
  */
+{-
+use OpenSSL::paramnames qw(produce_param_decoder);
+-}
 
 /*
  * DES low level APIs are deprecated for public use, but still ok for internal
@@ -151,26 +154,32 @@ static int krb5kdf_derive(void *vctx, unsigned char *key, size_t keylen,
                    key, keylen);
 }
 
+{- produce_param_decoder('krb5kdf_set_ctx_params',
+                         (['KDF_PARAM_PROPERTIES',  'propq',    'utf8_string'],
+                          ['ALG_PARAM_ENGINE',      'engine',   'utf8_string'],
+                          ['KDF_PARAM_CIPHER',      'cipher',   'utf8_string'],
+                          ['KDF_PARAM_KEY',         'key',      'octet_string'],
+                          ['KDF_PARAM_CONSTANT',    'cnst',     'octet_string'],
+                         )); -}
+
 static int krb5kdf_set_ctx_params(void *vctx, const OSSL_PARAM params[])
 {
-    const OSSL_PARAM *p;
+    struct krb5kdf_set_ctx_params_st p;
     KRB5KDF_CTX *ctx = vctx;
     OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(ctx->provctx);
 
-    if (ossl_param_is_empty(params))
-        return 1;
+    if (ctx == NULL || !krb5kdf_set_ctx_params_decoder(params, &p))
+        return 0;
 
-    if (!ossl_prov_cipher_load_from_params(&ctx->cipher, params, provctx))
+    if (!ossl_prov_cipher_load(&ctx->cipher, p.cipher, p.propq, p.engine, provctx))
         return 0;
 
-    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_KEY)) != NULL)
-        if (!krb5kdf_set_membuf(&ctx->key, &ctx->key_len, p))
-            return 0;
+    if (p.key != NULL && !krb5kdf_set_membuf(&ctx->key, &ctx->key_len, p.key))
+        return 0;
 
-    if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_CONSTANT))
-        != NULL)
-        if (!krb5kdf_set_membuf(&ctx->constant, &ctx->constant_len, p))
-            return 0;
+    if (p.cnst != NULL
+            && !krb5kdf_set_membuf(&ctx->constant, &ctx->constant_len, p.cnst))
+        return 0;
 
     return 1;
 }
@@ -178,42 +187,40 @@ static int krb5kdf_set_ctx_params(void *vctx, const OSSL_PARAM params[])
 static const OSSL_PARAM *krb5kdf_settable_ctx_params(ossl_unused void *ctx,
                                                      ossl_unused void *provctx)
 {
-    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_CIPHER, NULL, 0),
-        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_KEY, NULL, 0),
-        OSSL_PARAM_octet_string(OSSL_KDF_PARAM_CONSTANT, NULL, 0),
-        OSSL_PARAM_END
-    };
-    return known_settable_ctx_params;
+     return krb5kdf_set_ctx_params_list;
 }
 
+{- produce_param_decoder('krb5kdf_get_ctx_params',
+                         (['KDF_PARAM_SIZE',                    'size', 'size_t'],
+                         )); -}
+
 static int krb5kdf_get_ctx_params(void *vctx, OSSL_PARAM params[])
 {
+    struct krb5kdf_get_ctx_params_st p;
     KRB5KDF_CTX *ctx = (KRB5KDF_CTX *)vctx;
-    const EVP_CIPHER *cipher;
-    size_t len;
-    OSSL_PARAM *p;
 
-    cipher = ossl_prov_cipher_cipher(&ctx->cipher);
-    if (cipher)
-        len = EVP_CIPHER_get_key_length(cipher);
-    else
-        len = EVP_MAX_KEY_LENGTH;
-
-    if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL)
-        return OSSL_PARAM_set_size_t(p, len);
-    return -2;
+    if (ctx == NULL || !krb5kdf_get_ctx_params_decoder(params, &p))
+        return 0;
+
+    if (p.size != NULL) {
+        const EVP_CIPHER *cipher = ossl_prov_cipher_cipher(&ctx->cipher);
+        size_t len;
+
+        if (cipher != NULL)
+            len = EVP_CIPHER_get_key_length(cipher);
+        else
+            len = EVP_MAX_KEY_LENGTH;
+
+        if (!OSSL_PARAM_set_size_t(p.size, len))
+            return 0;
+    }
+    return 1;
 }
 
 static const OSSL_PARAM *krb5kdf_gettable_ctx_params(ossl_unused void *ctx,
                                                      ossl_unused void *provctx)
 {
-    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 krb5kdf_get_ctx_params_list;
 }
 
 const OSSL_DISPATCH ossl_kdf_krb5kdf_functions[] = {