From: tb Date: Thu, 5 May 2022 08:42:27 +0000 (+0000) Subject: Provide versions of EVP_PKEY_CTX_{str,hex}2ctrl() for internal use. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e604f303fe506c5bbc6d856624abfcd126e9ba5e;p=openbsd Provide versions of EVP_PKEY_CTX_{str,hex}2ctrl() for internal use. ok beck jsing --- diff --git a/lib/libcrypto/evp/evp_locl.h b/lib/libcrypto/evp/evp_locl.h index c3d9a6a718e..43e0ac333d8 100644 --- a/lib/libcrypto/evp/evp_locl.h +++ b/lib/libcrypto/evp/evp_locl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: evp_locl.h,v 1.22 2022/01/14 08:38:05 tb Exp $ */ +/* $OpenBSD: evp_locl.h,v 1.23 2022/05/05 08:42:27 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2000. */ @@ -505,6 +505,8 @@ struct evp_aead_ctx_st { void *aead_state; }; +int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str); +int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex); int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name); __END_HIDDEN_DECLS diff --git a/lib/libcrypto/evp/pmeth_lib.c b/lib/libcrypto/evp/pmeth_lib.c index d265e2aced7..ef28ba09d8d 100644 --- a/lib/libcrypto/evp/pmeth_lib.c +++ b/lib/libcrypto/evp/pmeth_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmeth_lib.c,v 1.20 2022/01/10 12:10:26 tb Exp $ */ +/* $OpenBSD: pmeth_lib.c,v 1.21 2022/05/05 08:42:27 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -56,6 +56,7 @@ * */ +#include #include #include #include @@ -65,6 +66,7 @@ #include #include #include +#include #ifndef OPENSSL_NO_ENGINE #include @@ -394,6 +396,38 @@ EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *name, const char *value) return ctx->pmeth->ctrl_str(ctx, name, value); } +int +EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str) +{ + size_t len; + + if ((len = strlen(str)) > INT_MAX) + return -1; + + return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str); +} + +int +EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hexstr) +{ + unsigned char *hex = NULL; + long length; + int ret = 0; + + if ((hex = string_to_hex(hexstr, &length)) == NULL) + goto err; + if (length < 0 || length > INT_MAX) { + ret = -1; + goto err; + } + + ret = ctx->pmeth->ctrl(ctx, cmd, length, hex); + + err: + free(hex); + return ret; +} + int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name) {