-/* $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.
*
{
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;
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);