diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2006-04-19 17:05:59 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2006-04-19 17:05:59 +0000 |
commit | ee1d9ec019a7584482bd95891404f1cad66a4a0a (patch) | |
tree | 54973962e56f5e576096c999be3b2bc3ca19c0fa /crypto/evp | |
parent | 614b448a67839c2af96aa6aee8856dfffb025293 (diff) |
Remove link between digests and signature algorithms.
Use cross reference table in ASN1_item_sign(), ASN1_item_verify() to eliminate
the need for algorithm specific code.
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/evp.h | 10 | ||||
-rw-r--r-- | crypto/evp/m_dss.c | 2 | ||||
-rw-r--r-- | crypto/evp/m_dss1.c | 2 | ||||
-rw-r--r-- | crypto/evp/m_ecdsa.c | 2 | ||||
-rw-r--r-- | crypto/evp/m_sha1.c | 2 | ||||
-rw-r--r-- | crypto/evp/p_sign.c | 23 | ||||
-rw-r--r-- | crypto/evp/p_verify.c | 26 |
7 files changed, 59 insertions, 8 deletions
diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h index e054d211f6..6ec2fa798a 100644 --- a/crypto/evp/evp.h +++ b/crypto/evp/evp.h @@ -188,6 +188,15 @@ typedef int evp_verify_method(int type,const unsigned char *m, #define EVP_MD_FLAG_ONESHOT 0x0001 /* digest can only handle a single * block */ +#define EVP_MD_FLAG_PKEY_DIGEST 0x0002 /* digest is a "clone" digest used + * which is a copy of an existing + * one for a specific public key type. + * EVP_dss1() etc */ + +/* Digest uses EVP_PKEY_METHOD for signing instead of MD specific signing */ + +#define EVP_MD_FLAG_PKEY_METHOD_SIGNATURE 0x0004 + #define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0} #ifndef OPENSSL_NO_DSA @@ -792,6 +801,7 @@ void EVP_PBE_cleanup(void); #define ASN1_PKEY_ALIAS 0x1 #define ASN1_PKEY_DYNAMIC 0x2 +#define ASN1_PKEY_SIGPARAM_NULL 0x4 #define ASN1_PKEY_CTRL_PKCS7_SIGN 0x1 diff --git a/crypto/evp/m_dss.c b/crypto/evp/m_dss.c index a948c77fa4..48c2689504 100644 --- a/crypto/evp/m_dss.c +++ b/crypto/evp/m_dss.c @@ -81,7 +81,7 @@ static const EVP_MD dsa_md= NID_dsaWithSHA, NID_dsaWithSHA, SHA_DIGEST_LENGTH, - 0, + EVP_MD_FLAG_PKEY_DIGEST, init, update, final, diff --git a/crypto/evp/m_dss1.c b/crypto/evp/m_dss1.c index c12e13972b..4f03fb70e0 100644 --- a/crypto/evp/m_dss1.c +++ b/crypto/evp/m_dss1.c @@ -82,7 +82,7 @@ static const EVP_MD dss1_md= NID_dsa, NID_dsaWithSHA1, SHA_DIGEST_LENGTH, - 0, + EVP_MD_FLAG_PKEY_DIGEST, init, update, final, diff --git a/crypto/evp/m_ecdsa.c b/crypto/evp/m_ecdsa.c index fad270faca..8d87a49ebe 100644 --- a/crypto/evp/m_ecdsa.c +++ b/crypto/evp/m_ecdsa.c @@ -130,7 +130,7 @@ static const EVP_MD ecdsa_md= NID_ecdsa_with_SHA1, NID_ecdsa_with_SHA1, SHA_DIGEST_LENGTH, - 0, + EVP_MD_FLAG_PKEY_DIGEST, init, update, final, diff --git a/crypto/evp/m_sha1.c b/crypto/evp/m_sha1.c index 4679b1c463..41c8d3dfe2 100644 --- a/crypto/evp/m_sha1.c +++ b/crypto/evp/m_sha1.c @@ -82,7 +82,7 @@ static const EVP_MD sha1_md= NID_sha1, NID_sha1WithRSAEncryption, SHA_DIGEST_LENGTH, - 0, + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, init, update, final, diff --git a/crypto/evp/p_sign.c b/crypto/evp/p_sign.c index e4ae5906f5..54ad0fc7f7 100644 --- a/crypto/evp/p_sign.c +++ b/crypto/evp/p_sign.c @@ -88,6 +88,28 @@ int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, EVP_MD_CTX_copy_ex(&tmp_ctx,ctx); EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len); EVP_MD_CTX_cleanup(&tmp_ctx); + + if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) + { + EVP_PKEY_CTX *pkctx = NULL; + int sltmp = EVP_PKEY_size(pkey); + i = 0; + pkctx = EVP_PKEY_CTX_new(pkey, NULL); + if (!pkctx) + goto err; + if (EVP_PKEY_sign_init(pkctx) <= 0) + goto err; + if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0) + goto err; + if (EVP_PKEY_sign(pkctx, sigret, &sltmp, m, m_len) <= 0) + goto err; + *siglen = sltmp; + i = 1; + err: + EVP_PKEY_CTX_free(pkctx); + return i; + } + for (i=0; i<4; i++) { v=ctx->digest->required_pkey_type[i]; @@ -103,6 +125,7 @@ int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); return(0); } + if (ctx->digest->sign == NULL) { EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED); diff --git a/crypto/evp/p_verify.c b/crypto/evp/p_verify.c index 21a40a375e..8db46412f3 100644 --- a/crypto/evp/p_verify.c +++ b/crypto/evp/p_verify.c @@ -70,6 +70,28 @@ int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf, int i,ok=0,v; MS_STATIC EVP_MD_CTX tmp_ctx; + EVP_MD_CTX_init(&tmp_ctx); + EVP_MD_CTX_copy_ex(&tmp_ctx,ctx); + EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len); + EVP_MD_CTX_cleanup(&tmp_ctx); + + if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) + { + EVP_PKEY_CTX *pkctx = NULL; + i = -1; + pkctx = EVP_PKEY_CTX_new(pkey, NULL); + if (!pkctx) + goto err; + if (EVP_PKEY_verify_init(pkctx) <= 0) + goto err; + if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0) + goto err; + i = EVP_PKEY_verify(pkctx, sigbuf, siglen, m, m_len); + err: + EVP_PKEY_CTX_free(pkctx); + return i; + } + for (i=0; i<4; i++) { v=ctx->digest->required_pkey_type[i]; @@ -85,10 +107,6 @@ int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf, EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); return(-1); } - EVP_MD_CTX_init(&tmp_ctx); - EVP_MD_CTX_copy_ex(&tmp_ctx,ctx); - EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len); - EVP_MD_CTX_cleanup(&tmp_ctx); if (ctx->digest->verify == NULL) { EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED); |