diff options
author | Mark J. Cox <mark@openssl.org> | 1999-01-31 13:14:39 +0100 |
---|---|---|
committer | Mark J. Cox <mark@openssl.org> | 1999-01-31 13:14:39 +0100 |
commit | 351d899878c567448b9b9b6d715ec828c888f3c2 (patch) | |
tree | 4afa6a04d378d8107b454ba1dba0c8b4beb92999 /crypto/evp | |
parent | Reflect correct filename (diff) | |
download | openssl-351d899878c567448b9b9b6d715ec828c888f3c2.tar.xz openssl-351d899878c567448b9b9b6d715ec828c888f3c2.zip |
Add new function, EVP_MD_CTX_copy() to replace frequent use of memcpy.
Submitted by: Eric A Young - from changes to C2Net SSLeay
Reviewed by: Mark Cox
PR:
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/digest.c | 10 | ||||
-rw-r--r-- | crypto/evp/evp.err | 2 | ||||
-rw-r--r-- | crypto/evp/evp.h | 4 | ||||
-rw-r--r-- | crypto/evp/evp_err.c | 2 | ||||
-rw-r--r-- | crypto/evp/p_sign.c | 2 | ||||
-rw-r--r-- | crypto/evp/p_verify.c | 2 |
6 files changed, 20 insertions, 2 deletions
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index d65f0036f7..7ef0e73b5a 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -87,3 +87,13 @@ unsigned int *size; *size=ctx->digest->md_size; memset(&(ctx->md),0,sizeof(ctx->md)); } + +int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in) +{ + if ((in == NULL) || (in->digest == NULL)) { + EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITALISED); + return 0; + } + memcpy((char *)out,(char *)in,in->digest->ctx_size); + return 1; +} diff --git a/crypto/evp/evp.err b/crypto/evp/evp.err index b6ed829482..c2470f678c 100644 --- a/crypto/evp/evp.err +++ b/crypto/evp/evp.err @@ -11,6 +11,7 @@ #define EVP_F_EVP_SIGNFINAL 107 #define EVP_F_EVP_VERIFYFINAL 108 #define EVP_F_RC2_MAGIC_TO_METH 109 +#define EVP_F_EVP_MD_CTX_COPY 110 /* Reason codes. */ #define EVP_R_BAD_DECRYPT 100 @@ -24,3 +25,4 @@ #define EVP_R_UNSUPPORTED_KEY_SIZE 108 #define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109 #define EVP_R_WRONG_PUBLIC_KEY_TYPE 110 +#define EVP_R_INPUT_NOT_INITALISED 111 diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h index e6296ce834..c780543a32 100644 --- a/crypto/evp/evp.h +++ b/crypto/evp/evp.h @@ -460,6 +460,7 @@ typedef struct evp_Encode_Ctx_st #ifndef NOPROTO +int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in); void EVP_DigestInit(EVP_MD_CTX *ctx, EVP_MD *type); void EVP_DigestUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); @@ -626,6 +627,7 @@ int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); #else +int EVP_MD_CTX_copy(); void EVP_DigestInit(); void EVP_DigestUpdate(); void EVP_DigestFinal(); @@ -782,6 +784,7 @@ int EVP_CIPHER_get_asn1_iv(); #define EVP_F_EVP_SIGNFINAL 107 #define EVP_F_EVP_VERIFYFINAL 108 #define EVP_F_RC2_MAGIC_TO_METH 109 +#define EVP_F_EVP_MD_CTX_COPY 110 /* Reason codes. */ #define EVP_R_BAD_DECRYPT 100 @@ -795,6 +798,7 @@ int EVP_CIPHER_get_asn1_iv(); #define EVP_R_UNSUPPORTED_KEY_SIZE 108 #define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109 #define EVP_R_WRONG_PUBLIC_KEY_TYPE 110 +#define EVP_R_INPUT_NOT_INITALISED 111 #ifdef __cplusplus } diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c index c7caa3b13b..19b3a1896e 100644 --- a/crypto/evp/evp_err.c +++ b/crypto/evp/evp_err.c @@ -73,6 +73,7 @@ static ERR_STRING_DATA EVP_str_functs[]= {ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"}, {ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"}, {ERR_PACK(0,EVP_F_RC2_MAGIC_TO_METH,0), "RC2_MAGIC_TO_METH"}, +{ERR_PACK(0,EVP_F_EVP_MD_CTX_COPY,0), "EVP_MD_CTX_copy"}, {0,NULL}, }; @@ -89,6 +90,7 @@ static ERR_STRING_DATA EVP_str_reasons[]= {EVP_R_UNSUPPORTED_KEY_SIZE ,"unsupported key size"}, {EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"}, {EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"}, +{EVP_R_INPUT_NOT_INITALISED ,"input not initalised"}, {0,NULL}, }; diff --git a/crypto/evp/p_sign.c b/crypto/evp/p_sign.c index 073270ce31..4b34206083 100644 --- a/crypto/evp/p_sign.c +++ b/crypto/evp/p_sign.c @@ -91,7 +91,7 @@ EVP_PKEY *pkey; MS_STATIC EVP_MD_CTX tmp_ctx; *siglen=0; - memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX)); + EVP_MD_CTX_copy(&tmp_ctx,ctx); EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); for (i=0; i<4; i++) { diff --git a/crypto/evp/p_verify.c b/crypto/evp/p_verify.c index 8d727d8f02..0a9bb05a74 100644 --- a/crypto/evp/p_verify.c +++ b/crypto/evp/p_verify.c @@ -88,7 +88,7 @@ EVP_PKEY *pkey; EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); return(-1); } - memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX)); + EVP_MD_CTX_copy(&tmp_ctx,ctx); EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); if (ctx->digest->verify == NULL) { |