diff options
author | Richard Levitte <levitte@openssl.org> | 2020-12-04 09:34:25 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-12-05 11:06:05 +0100 |
commit | 030da84412c5e01c070a580ad237e713c2057626 (patch) | |
tree | b72cb2560df0d78bae045156c9a97ae46f96b091 /crypto/evp | |
parent | ecfbe2f0461b399b6bf99bdaa95c460ece8e693e (diff) |
EVP: Adjust EVP_PKEY_size(), EVP_PKEY_bits() and EVP_PKEY_security_bits()
These functions are documented to return 0 if the size they are
supposed to return 0 if the size isn't available. They needed a bit
of adjustment to actually do so, since the backend functions they call
might return negative numbers in that case.
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13611)
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/p_lib.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index b8c623f90a..f1eb859cef 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -55,24 +55,26 @@ static void evp_pkey_free_it(EVP_PKEY *key); int EVP_PKEY_bits(const EVP_PKEY *pkey) { + int size = 0; + if (pkey != NULL) { - if (pkey->ameth == NULL) - return pkey->cache.bits; - else if (pkey->ameth->pkey_bits) - return pkey->ameth->pkey_bits(pkey); + size = pkey->cache.bits; + if (pkey->ameth != NULL && pkey->ameth->pkey_bits != NULL) + size = pkey->ameth->pkey_bits(pkey); } - return 0; + return size < 0 ? 0 : size; } int EVP_PKEY_security_bits(const EVP_PKEY *pkey) { - if (pkey == NULL) - return 0; - if (pkey->ameth == NULL) - return pkey->cache.security_bits; - if (pkey->ameth->pkey_security_bits == NULL) - return -2; - return pkey->ameth->pkey_security_bits(pkey); + int size = 0; + + if (pkey != NULL) { + size = pkey->cache.security_bits; + if (pkey->ameth != NULL && pkey->ameth->pkey_security_bits != NULL) + size = pkey->ameth->pkey_security_bits(pkey); + } + return size < 0 ? 0 : size; } int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) @@ -1656,7 +1658,7 @@ int EVP_PKEY_size(const EVP_PKEY *pkey) size = pkey->ameth->pkey_size(pkey); #endif } - return size; + return size < 0 ? 0 : size; } void *evp_pkey_export_to_provider(EVP_PKEY *pk, OSSL_LIB_CTX *libctx, |