Clean up use of EVP_MD_CTX_{legacy_clear,cleanup} in PKCS1_MGF1
authorjoshua <joshua@openbsd.org>
Tue, 26 Mar 2024 05:37:28 +0000 (05:37 +0000)
committerjoshua <joshua@openbsd.org>
Tue, 26 Mar 2024 05:37:28 +0000 (05:37 +0000)
ok tb@

lib/libcrypto/rsa/rsa_oaep.c

index 4927673..d1e138c 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: rsa_oaep.c,v 1.38 2024/02/18 15:45:42 tb Exp $ */
+/* $OpenBSD: rsa_oaep.c,v 1.39 2024/03/26 05:37:28 joshua Exp $ */
 /*
  * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved.
  *
@@ -326,12 +326,14 @@ PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed,
 {
        long i, outlen = 0;
        unsigned char cnt[4];
-       EVP_MD_CTX c;
+       EVP_MD_CTX *md_ctx;
        unsigned char md[EVP_MAX_MD_SIZE];
        int mdlen;
        int rv = -1;
 
-       EVP_MD_CTX_legacy_clear(&c);
+       if ((md_ctx = EVP_MD_CTX_new()) == NULL)
+               goto err;
+
        mdlen = EVP_MD_size(dgst);
        if (mdlen < 0)
                goto err;
@@ -340,24 +342,27 @@ PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed,
                cnt[1] = (unsigned char)((i >> 16) & 255);
                cnt[2] = (unsigned char)((i >> 8)) & 255;
                cnt[3] = (unsigned char)(i & 255);
-               if (!EVP_DigestInit_ex(&c, dgst, NULL) ||
-                   !EVP_DigestUpdate(&c, seed, seedlen) ||
-                   !EVP_DigestUpdate(&c, cnt, 4))
+               if (!EVP_DigestInit_ex(md_ctx, dgst, NULL) ||
+                   !EVP_DigestUpdate(md_ctx, seed, seedlen) ||
+                   !EVP_DigestUpdate(md_ctx, cnt, 4))
                        goto err;
                if (outlen + mdlen <= len) {
-                       if (!EVP_DigestFinal_ex(&c, mask + outlen, NULL))
+                       if (!EVP_DigestFinal_ex(md_ctx, mask + outlen, NULL))
                                goto err;
                        outlen += mdlen;
                } else {
-                       if (!EVP_DigestFinal_ex(&c, md, NULL))
+                       if (!EVP_DigestFinal_ex(md_ctx, md, NULL))
                                goto err;
                        memcpy(mask + outlen, md, len - outlen);
                        outlen = len;
                }
        }
+
        rv = 0;
+
  err:
-       EVP_MD_CTX_cleanup(&c);
+       EVP_MD_CTX_free(md_ctx);
+
        return rv;
 }
 LCRYPTO_ALIAS(PKCS1_MGF1);