diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2021-12-25 13:38:23 +0100 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2023-05-30 22:02:10 +0200 |
commit | 36b91a198ae027c054ef128a35a268bc3c307f00 (patch) | |
tree | a47bf3a4c012fb34c51c8c34f973e15dc912f9b4 /crypto/evp | |
parent | fdef95716dbcc6127d05f8cfc90f389a84acaf9b (diff) |
CMS, PKCS7, and CRMF: simplify use of EVP_PKEY_decrypt() by helper function
Also remove needless constant_time_* and ERR_clear_error() calls
from OSSL_CRMF_ENCRYPTEDVALUE_get1_encCert().
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/17354)
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/asymcipher.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/crypto/evp/asymcipher.c b/crypto/evp/asymcipher.c index 3acf4d1dfd..ca2a8ebdf2 100644 --- a/crypto/evp/asymcipher.c +++ b/crypto/evp/asymcipher.c @@ -298,6 +298,24 @@ int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, return ctx->pmeth->decrypt(ctx, out, outlen, in, inlen); } +/* decrypt to new buffer of dynamic size, checking any pre-determined size */ +int evp_pkey_decrypt_alloc(EVP_PKEY_CTX *ctx, unsigned char **outp, + size_t *outlenp, size_t expected_outlen, + const unsigned char *in, size_t inlen) +{ + if (EVP_PKEY_decrypt(ctx, NULL, outlenp, in, inlen) <= 0 + || (*outp = OPENSSL_malloc(*outlenp)) == NULL) + return -1; + if (EVP_PKEY_decrypt(ctx, *outp, outlenp, in, inlen) <= 0 + || *outlenp == 0 + || (expected_outlen != 0 && *outlenp != expected_outlen)) { + ERR_raise(ERR_LIB_EVP, ERR_R_EVP_LIB); + OPENSSL_clear_free(*outp, *outlenp); + *outp = NULL; + return 0; + } + return 1; +} static EVP_ASYM_CIPHER *evp_asym_cipher_new(OSSL_PROVIDER *prov) { |