From cd7638980a2c2b16bb121bcb2ea8cc3cb03afcc1 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Fri, 7 Apr 2006 17:28:56 +0000 Subject: [PATCH] Include EVP_PKEY argument in EVP_PKEY_CTX_new(). This avoids the need for a separate EVP_PKEY parameter in the other operation initialization routines. --- crypto/evp/evp.h | 2 +- crypto/evp/evp_locl.h | 20 +++++++++----------- crypto/evp/pmeth_fn.c | 20 ++++++++++---------- crypto/evp/pmeth_lib.c | 10 +++++++--- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h index fd5eaadc49..d16e042c78 100644 --- a/crypto/evp/evp.h +++ b/crypto/evp/evp.h @@ -906,7 +906,7 @@ void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type, ENGINE *e); -EVP_PKEY_CTX *EVP_PKEY_CTX_new(int ktype, ENGINE *e); +EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey); void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, int p1, void *p2); diff --git a/crypto/evp/evp_locl.h b/crypto/evp/evp_locl.h index f33803ba4c..26000ac08b 100644 --- a/crypto/evp/evp_locl.h +++ b/crypto/evp/evp_locl.h @@ -266,39 +266,37 @@ struct evp_pkey_method_st int (*init)(EVP_PKEY_CTX *ctx); int (*paramgen_init)(EVP_PKEY_CTX *ctx); - int (*paramgen)(EVP_PKEY *key, EVP_PKEY_CTX *ctx); + int (*paramgen)(EVP_PKEY_CTX *ctx); int (*keygen_init)(EVP_PKEY_CTX *ctx); - int (*keygen)(EVP_PKEY *key, EVP_PKEY_CTX *ctx); + int (*keygen)(EVP_PKEY_CTX *ctx); - int (*sign_init)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey); + int (*sign_init)(EVP_PKEY_CTX *ctx); int (*sign)(EVP_PKEY_CTX *ctx, unsigned char *sig, int *siglen, unsigned char *tbs, int tbslen); - int (*verify_init)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey); + int (*verify_init)(EVP_PKEY_CTX *ctx); int (*verify)(EVP_PKEY_CTX *ctx, unsigned char *sig, int siglen, unsigned char *tbs, int tbslen); - int (*verify_recover_init)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey); + int (*verify_recover_init)(EVP_PKEY_CTX *ctx); int (*verify_recover)(EVP_PKEY_CTX *ctx, unsigned char *rout, int *routlen, unsigned char *sig, int siglen); - int (*signctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx, - EVP_PKEY *pkey); + int (*signctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx); int (*signctx)(EVP_PKEY_CTX *ctx, unsigned char *sig, int *siglen, EVP_MD_CTX *mctx); - int (*verifyctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx, - EVP_PKEY *pkey); + int (*verifyctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx); int (*verifyctx)(EVP_PKEY_CTX *ctx, unsigned char *sig, int siglen, EVP_MD_CTX *mctx); - int (*encrypt_init)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey); + int (*encrypt_init)(EVP_PKEY_CTX *ctx); int (*encrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, int *outlen, unsigned char *in, int inlen); - int (*decrypt_init)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey); + int (*decrypt_init)(EVP_PKEY_CTX *ctx); int (*decrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, int *outlen, unsigned char *in, int inlen); diff --git a/crypto/evp/pmeth_fn.c b/crypto/evp/pmeth_fn.c index 317bf8633c..979588b3a4 100644 --- a/crypto/evp/pmeth_fn.c +++ b/crypto/evp/pmeth_fn.c @@ -63,7 +63,7 @@ #include #include "evp_locl.h" -int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) +int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx) { int ret; if (!ctx || !ctx->pmeth || !ctx->pmeth->sign_init) @@ -73,7 +73,7 @@ int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return -2; } ctx->operation = EVP_PKEY_OP_SIGN; - ret = ctx->pmeth->sign_init(ctx, pkey); + ret = ctx->pmeth->sign_init(ctx); if (ret <= 0) ctx->operation = EVP_PKEY_OP_UNDEFINED; return ret; @@ -97,7 +97,7 @@ int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, return ctx->pmeth->sign(ctx, sig, siglen, tbs, tbslen); } -int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) +int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx) { int ret; if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_init) @@ -107,7 +107,7 @@ int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return -2; } ctx->operation = EVP_PKEY_OP_VERIFY; - ret = ctx->pmeth->verify_init(ctx, pkey); + ret = ctx->pmeth->verify_init(ctx); if (ret <= 0) ctx->operation = EVP_PKEY_OP_UNDEFINED; return ret; @@ -131,7 +131,7 @@ int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen); } -int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) +int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx) { int ret; if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover_init) @@ -141,7 +141,7 @@ int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return -2; } ctx->operation = EVP_PKEY_OP_VERIFYRECOVER; - ret = ctx->pmeth->verify_recover_init(ctx, pkey); + ret = ctx->pmeth->verify_recover_init(ctx); if (ret <= 0) ctx->operation = EVP_PKEY_OP_UNDEFINED; return ret; @@ -165,7 +165,7 @@ int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, return ctx->pmeth->verify_recover(ctx, rout, routlen, sig, siglen); } -int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) +int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx) { int ret; if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt_init) @@ -175,7 +175,7 @@ int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return -2; } ctx->operation = EVP_PKEY_OP_ENCRYPT; - ret = ctx->pmeth->encrypt_init(ctx, pkey); + ret = ctx->pmeth->encrypt_init(ctx); if (ret <= 0) ctx->operation = EVP_PKEY_OP_UNDEFINED; return ret; @@ -199,7 +199,7 @@ int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, return ctx->pmeth->encrypt(ctx, out, outlen, in, inlen); } -int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) +int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx) { int ret; if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt_init) @@ -209,7 +209,7 @@ int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return -2; } ctx->operation = EVP_PKEY_OP_DECRYPT; - ret = ctx->pmeth->decrypt_init(ctx, pkey); + ret = ctx->pmeth->decrypt_init(ctx); if (ret <= 0) ctx->operation = EVP_PKEY_OP_UNDEFINED; return ret; diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index d229b0996d..0c0aa9ba53 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -61,6 +61,7 @@ #include #include "cryptlib.h" #include +#include "asn1_locl.h" #include "evp_locl.h" STACK *app_pkey_methods = NULL; @@ -100,17 +101,20 @@ const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type, ENGINE *e) return *ret; } -EVP_PKEY_CTX *EVP_PKEY_CTX_new(int ktype, ENGINE *e) +EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey) { EVP_PKEY_CTX *ret; const EVP_PKEY_METHOD *pmeth; - pmeth = EVP_PKEY_meth_find(ktype, e); + if (!pkey || !pkey->ameth) + return NULL; + pmeth = EVP_PKEY_meth_find(pkey->ameth->pkey_id, NULL); if (pmeth == NULL) return NULL; ret = OPENSSL_malloc(sizeof(EVP_PKEY_CTX)); ret->pmeth = pmeth; ret->operation = EVP_PKEY_OP_UNDEFINED; - ret->pkey = NULL; + CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); + ret->pkey = pkey; ret->data = NULL; if (pmeth->init) -- 2.34.1