From a33f242ca5415644acbc08c2651ca4079240ee25 Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Tue, 29 Oct 2019 07:52:18 +0000 Subject: Provide EVP_PKEY_CTX_md(). This handles controls with a message digest by name, looks up the message digest and then proxies the control through with the EVP_MD *. This is internal only for now and will be used in upcoming RSA related changes. Based on OpenSSL 1.1.1d. ok inoguchi@ tb@ --- lib/libcrypto/evp/evp_locl.h | 4 +++- lib/libcrypto/evp/pmeth_lib.c | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/libcrypto/evp/evp_locl.h b/lib/libcrypto/evp/evp_locl.h index 0b1bea9583c..8df61354930 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.15 2018/11/24 11:16:44 tb Exp $ */ +/* $OpenBSD: evp_locl.h,v 1.16 2019/10/29 07:52:17 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2000. */ @@ -367,4 +367,6 @@ struct evp_aead_st { const unsigned char *ad, size_t ad_len); }; +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 6b86a0ecfb0..ea9b8fed0cd 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.14 2018/04/14 07:09:21 tb Exp $ */ +/* $OpenBSD: pmeth_lib.c,v 1.15 2019/10/29 07:52:17 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -438,16 +438,24 @@ EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *name, const char *value) return -2; } if (!strcmp(name, "digest")) { - const EVP_MD *md; - if (!value || !(md = EVP_get_digestbyname(value))) { - EVPerror(EVP_R_INVALID_DIGEST); - return 0; - } - return EVP_PKEY_CTX_set_signature_md(ctx, md); + return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG, + EVP_PKEY_CTRL_MD, value); } return ctx->pmeth->ctrl_str(ctx, name, value); } +int +EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name) +{ + const EVP_MD *md; + + if ((md = EVP_get_digestbyname(md_name)) == NULL) { + EVPerror(EVP_R_INVALID_DIGEST); + return 0; + } + return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)md); +} + int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx) { -- cgit v1.2.3