Retain compatibility of EVP_DigestInit() and EVP_DigestFinal()
[openssl.git] / crypto / asn1 / a_sign.c
index 5be077ddfc5a38519e7bf33c957c4a254c489518..fc65b4ea5684f0e0da12668f6e4d062bf6da40e8 100644 (file)
@@ -71,6 +71,8 @@
 #include <openssl/objects.h>
 #include <openssl/buffer.h>
 
+#ifndef NO_ASN1_OLD
+
 int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
             ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
             const EVP_MD *type)
@@ -80,6 +82,7 @@ int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
        int i,inl=0,outl=0,outll=0;
        X509_ALGOR *a;
 
+       EVP_MD_CTX_init(&ctx);
        for (i=0; i<2; i++)
                {
                if (i == 0)
@@ -120,7 +123,7 @@ int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
        p=buf_in;
 
        i2d(data,&p);
-       EVP_SignInit(&ctx,type);
+       EVP_SignInit_ex(&ctx,type, NULL);
        EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
        if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
                        (unsigned int *)&outl,pkey))
@@ -139,7 +142,7 @@ int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
        signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
        signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
 err:
-       memset(&ctx,0,sizeof(ctx));
+       EVP_MD_CTX_cleanup(&ctx);
        if (buf_in != NULL)
                { memset((char *)buf_in,0,(unsigned int)inl); OPENSSL_free(buf_in); }
        if (buf_out != NULL)
@@ -147,6 +150,8 @@ err:
        return(outl);
        }
 
+#endif
+
 int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
             ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey,
             const EVP_MD *type)
@@ -156,6 +161,7 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
        int i,inl=0,outl=0,outll=0;
        X509_ALGOR *a;
 
+       EVP_MD_CTX_init(&ctx);
        for (i=0; i<2; i++)
                {
                if (i == 0)
@@ -193,7 +199,7 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
                goto err;
                }
 
-       EVP_SignInit(&ctx,type);
+       EVP_SignInit_ex(&ctx,type, NULL);
        EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
        if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
                        (unsigned int *)&outl,pkey))
@@ -212,7 +218,7 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
        signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
        signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
 err:
-       memset(&ctx,0,sizeof(ctx));
+       EVP_MD_CTX_cleanup(&ctx);
        if (buf_in != NULL)
                { memset((char *)buf_in,0,(unsigned int)inl); OPENSSL_free(buf_in); }
        if (buf_out != NULL)