Flag to disable automatic copying of contexts.
[openssl.git] / crypto / evp / p_verify.c
index c66d63c..a3df5df 100644 (file)
@@ -68,15 +68,25 @@ int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
        unsigned char m[EVP_MAX_MD_SIZE];
        unsigned int m_len;
        int i = 0,ok = 0,v;
-       EVP_MD_CTX tmp_ctx;
        EVP_PKEY_CTX *pkctx = NULL;
 
-       EVP_MD_CTX_init(&tmp_ctx);
-       if (!EVP_MD_CTX_copy_ex(&tmp_ctx,ctx))
-               goto err;    
-       if (!EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len))
-               goto err;
-       EVP_MD_CTX_cleanup(&tmp_ctx);
+       if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE)
+               {
+               if (!EVP_DigestFinal_ex(ctx, m, &m_len))
+                       goto err;
+               }
+       else
+               {
+               int rv;
+               EVP_MD_CTX tmp_ctx;
+               EVP_MD_CTX_init(&tmp_ctx);
+               rv = EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
+               if (rv)
+                       rv = EVP_DigestFinal_ex(&tmp_ctx, m, &m_len);
+               EVP_MD_CTX_cleanup(&tmp_ctx);
+               if (!rv)
+                       return 0;
+               }
 
        if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE)
                {