summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2019-10-29 07:52:17 +0000
committerjsing <>2019-10-29 07:52:17 +0000
commitc20b0b4d3d1da89ee904502f4241815376c15133 (patch)
tree20651aef6d8c3bc2f88401c4929ba130cbfccf7e
parent807a786996712e07f0fe283c5bbf5400b5f2ac2c (diff)
downloadopenbsd-c20b0b4d3d1da89ee904502f4241815376c15133.tar.gz
openbsd-c20b0b4d3d1da89ee904502f4241815376c15133.tar.bz2
openbsd-c20b0b4d3d1da89ee904502f4241815376c15133.zip
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@
-rw-r--r--src/lib/libcrypto/evp/evp_locl.h4
-rw-r--r--src/lib/libcrypto/evp/pmeth_lib.c22
2 files changed, 18 insertions, 8 deletions
diff --git a/src/lib/libcrypto/evp/evp_locl.h b/src/lib/libcrypto/evp/evp_locl.h
index 0b1bea9583..8df6135493 100644
--- a/src/lib/libcrypto/evp/evp_locl.h
+++ b/src/lib/libcrypto/evp/evp_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_locl.h,v 1.15 2018/11/24 11:16:44 tb Exp $ */ 1/* $OpenBSD: evp_locl.h,v 1.16 2019/10/29 07:52:17 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -367,4 +367,6 @@ struct evp_aead_st {
367 const unsigned char *ad, size_t ad_len); 367 const unsigned char *ad, size_t ad_len);
368}; 368};
369 369
370int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name);
371
370__END_HIDDEN_DECLS 372__END_HIDDEN_DECLS
diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c
index 6b86a0ecfb..ea9b8fed0c 100644
--- a/src/lib/libcrypto/evp/pmeth_lib.c
+++ b/src/lib/libcrypto/evp/pmeth_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_lib.c,v 1.14 2018/04/14 07:09:21 tb Exp $ */ 1/* $OpenBSD: pmeth_lib.c,v 1.15 2019/10/29 07:52:17 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -438,17 +438,25 @@ EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *name, const char *value)
438 return -2; 438 return -2;
439 } 439 }
440 if (!strcmp(name, "digest")) { 440 if (!strcmp(name, "digest")) {
441 const EVP_MD *md; 441 return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG,
442 if (!value || !(md = EVP_get_digestbyname(value))) { 442 EVP_PKEY_CTRL_MD, value);
443 EVPerror(EVP_R_INVALID_DIGEST);
444 return 0;
445 }
446 return EVP_PKEY_CTX_set_signature_md(ctx, md);
447 } 443 }
448 return ctx->pmeth->ctrl_str(ctx, name, value); 444 return ctx->pmeth->ctrl_str(ctx, name, value);
449} 445}
450 446
451int 447int
448EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name)
449{
450 const EVP_MD *md;
451
452 if ((md = EVP_get_digestbyname(md_name)) == NULL) {
453 EVPerror(EVP_R_INVALID_DIGEST);
454 return 0;
455 }
456 return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)md);
457}
458
459int
452EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx) 460EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
453{ 461{
454 return ctx->operation; 462 return ctx->operation;