diff --git a/crypto/cipher_extra/cipher_test.cc b/crypto/cipher_extra/cipher_test.cc index 1981b05a3a..5290a69f23 100644 --- a/crypto/cipher_extra/cipher_test.cc +++ b/crypto/cipher_extra/cipher_test.cc @@ -1107,6 +1107,9 @@ TEST(CipherTest, GetCipher) { EXPECT_FALSE(EVP_get_cipherbyname(nullptr)); EXPECT_FALSE(EVP_get_cipherbyname("vigenère")); EXPECT_FALSE(EVP_get_cipherbynid(-1)); + EXPECT_FALSE(EVP_CIPHER_block_size(nullptr)); + EXPECT_FALSE(EVP_CIPHER_key_length(nullptr)); + EXPECT_FALSE(EVP_CIPHER_iv_length(nullptr)); } // Test the AES-GCM EVP_CIPHER's internal IV management APIs. OpenSSH uses these diff --git a/crypto/fipsmodule/cipher/cipher.c b/crypto/fipsmodule/cipher/cipher.c index d3a13921de..8a10429dd6 100644 --- a/crypto/fipsmodule/cipher/cipher.c +++ b/crypto/fipsmodule/cipher/cipher.c @@ -689,18 +689,32 @@ int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, unsigned key_len) { return 1; } -int EVP_CIPHER_nid(const EVP_CIPHER *cipher) { return cipher->nid; } +int EVP_CIPHER_nid(const EVP_CIPHER *cipher) { + if (cipher != NULL) { + return cipher->nid; + } + return 0; +} unsigned EVP_CIPHER_block_size(const EVP_CIPHER *cipher) { - return cipher->block_size; + if (cipher != NULL) { + return cipher->block_size; + } + return 0; } unsigned EVP_CIPHER_key_length(const EVP_CIPHER *cipher) { - return cipher->key_len; + if (cipher != NULL) { + return cipher->key_len; + } + return 0; } unsigned EVP_CIPHER_iv_length(const EVP_CIPHER *cipher) { - return cipher->iv_len; + if (cipher != NULL) { + return cipher->iv_len; + } + return 0; } uint32_t EVP_CIPHER_flags(const EVP_CIPHER *cipher) {