Retain compatibility of EVP_DigestInit() and EVP_DigestFinal()
[openssl.git] / crypto / asn1 / a_sign.c
index 67f130840d178cfe0414c6bad06a30d905206ae4..fc65b4ea5684f0e0da12668f6e4d062bf6da40e8 100644 (file)
@@ -82,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)
@@ -122,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))
@@ -141,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)
@@ -160,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)
@@ -197,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))
@@ -216,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)