Add new function, EVP_MD_CTX_copy() to replace frequent use of memcpy.
authorMark J. Cox <mark@openssl.org>
Sun, 31 Jan 1999 12:14:39 +0000 (12:14 +0000)
committerMark J. Cox <mark@openssl.org>
Sun, 31 Jan 1999 12:14:39 +0000 (12:14 +0000)
Submitted by: Eric A Young - from changes to C2Net SSLeay
Reviewed by: Mark Cox
PR:

CHANGES
crypto/evp/digest.c
crypto/evp/evp.err
crypto/evp/evp.h
crypto/evp/evp_err.c
crypto/evp/p_sign.c
crypto/evp/p_verify.c

diff --git a/CHANGES b/CHANGES
index 4cd84ccc8e75cf639a381bef89b61918e453df80..9c33fbe2c743e633649a737663eceabc0aaf20da 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,9 @@
 
  Changes between 0.9.1c and 0.9.2
 
+  *) Add new function, EVP_MD_CTX_copy() to replace frequent use of memcpy.
+     [Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)]
+
   *) Make sure `make rehash' target really finds the `openssl' program.
      [Ralf S. Engelschall, Matthias Loepfe <Matthias.Loepfe@adnovum.ch>]
 
index d65f0036f7b51dda6f0f6017e23771b4e9d12299..7ef0e73b5a5aa37f57142a754171f09e8a8a38e4 100644 (file)
@@ -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;
+}    
index b6ed829482e6e98e23be458a6d1f32d3437acbf6..c2470f678c20f91124fe2501af54094088e081c8 100644 (file)
@@ -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
index e6296ce8340c7d74f76c80d162f455464e5f17dc..c780543a3232d34ad1de4d3f9d17186578453050 100644 (file)
@@ -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
 }
index c7caa3b13bdef37dd294c8484eb3372aa8ffdf92..19b3a1896e8f08d08b8532c0ae18a75adcef1d9a 100644 (file)
@@ -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},
        };
 
index 073270ce31535d646f39975b867afc0b6bf4439f..4b3420608360331b914fc1c0c25db3eb08ce9813 100644 (file)
@@ -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++)
                {
index 8d727d8f02d9b9474eb599801ef89f53764b6161..0a9bb05a746ef30b9d6c5bc227e7ba0496c2369a 100644 (file)
@@ -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)
                 {