Cleanup: fix all sources that used EVP_MD_CTX_(create|init|destroy)
[openssl.git] / crypto / pem / pem_seal.c
index e82ab6fe4224c36220b995bc3564c65f42083057..d0db77783219ed3a9bf25b49707fcccee8183f73 100644 (file)
@@ -59,7 +59,7 @@
 #include <openssl/opensslconf.h> /* for OPENSSL_NO_RSA */
 #ifndef OPENSSL_NO_RSA
 # include <stdio.h>
-# include "cryptlib.h"
+# include "internal/cryptlib.h"
 # include <openssl/evp.h>
 # include <openssl/rand.h>
 # include <openssl/objects.h>
@@ -85,7 +85,7 @@ int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
         if (j > max)
             max = j;
     }
-    s = (char *)OPENSSL_malloc(max * 2);
+    s = OPENSSL_malloc(max * 2);
     if (s == NULL) {
         PEMerr(PEM_F_PEM_SEALINIT, ERR_R_MALLOC_FAILURE);
         goto err;
@@ -93,8 +93,8 @@ int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
 
     EVP_EncodeInit(&ctx->encode);
 
-    EVP_MD_CTX_init(&ctx->md);
-    if (!EVP_SignInit(&ctx->md, md_type))
+    ctx->md = EVP_MD_CTX_new();
+    if (!EVP_SignInit(ctx->md, md_type))
         goto err;
 
     EVP_CIPHER_CTX_init(&ctx->cipher);
@@ -112,8 +112,7 @@ int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
 
     ret = npubk;
  err:
-    if (s != NULL)
-        OPENSSL_free(s);
+    OPENSSL_free(s);
     OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH);
     return (ret);
 }
@@ -125,7 +124,7 @@ int PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
     int i, j;
 
     *outl = 0;
-    if (!EVP_SignUpdate(&ctx->md, in, inl))
+    if (!EVP_SignUpdate(ctx->md, in, inl))
         return 0;
     for (;;) {
         if (inl <= 0)
@@ -159,7 +158,7 @@ int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
     i = RSA_size(priv->pkey.rsa);
     if (i < 100)
         i = 100;
-    s = (unsigned char *)OPENSSL_malloc(i * 2);
+    s = OPENSSL_malloc(i * 2);
     if (s == NULL) {
         PEMerr(PEM_F_PEM_SEALFINAL, ERR_R_MALLOC_FAILURE);
         goto err;
@@ -173,16 +172,15 @@ int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
     EVP_EncodeFinal(&ctx->encode, out, &j);
     *outl += j;
 
-    if (!EVP_SignFinal(&ctx->md, s, &i, priv))
+    if (!EVP_SignFinal(ctx->md, s, &i, priv))
         goto err;
     *sigl = EVP_EncodeBlock(sig, s, i);
 
     ret = 1;
  err:
-    EVP_MD_CTX_cleanup(&ctx->md);
+    EVP_MD_CTX_free(ctx->md);
     EVP_CIPHER_CTX_cleanup(&ctx->cipher);
-    if (s != NULL)
-        OPENSSL_free(s);
+    OPENSSL_free(s);
     return (ret);
 }
 #else                           /* !OPENSSL_NO_RSA */