Skip to content

Commit

Permalink
Check OPENSSL_NO_SM4 before using sm4 encryption (#11)
Browse files Browse the repository at this point in the history
apache/incubator-pegasus#1575

Cherry-pick from
tikv@9464766

In some env, user installed openssl by yum install, and the openssl
software may compiled with OPENSSL_NO_SM4 flag, so although the version
is >= 1.1.1, but we still could not use sm4 in that situation.

Signed-off-by: Jarvis Zheng <[email protected]>
  • Loading branch information
acelyc111 committed Aug 16, 2023
1 parent 0277015 commit 5efb80e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion encryption/encryption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Status NewAESCTRCipherStream(EncryptionMethod method, const std::string& key,
cipher = EVP_aes_256_ctr();
break;
case EncryptionMethod::kSM4_CTR:
#if OPENSSL_VERSION_NUMBER < 0x1010100fL
#if OPENSSL_VERSION_NUMBER < 0x1010100fL || defined(OPENSSL_NO_SM4)
return Status::InvalidArgument(
"Unsupport SM4 encryption method under OpenSSL version: " +
std::string(OPENSSL_VERSION_TEXT));
Expand Down
2 changes: 1 addition & 1 deletion encryption/encryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AESCTRCipherStream : public BlockAccessCipherStream {

size_t BlockSize() override {
// Openssl support SM4 after 1.1.1 release version.
#if OPENSSL_VERSION_NUMBER >= 0x1010100fL
#if OPENSSL_VERSION_NUMBER >= 0x1010100fL && !defined(OPENSSL_NO_SM4)
if (EVP_CIPHER_nid(cipher_) == NID_sm4_ctr) {
return SM4_BLOCK_SIZE;
}
Expand Down
4 changes: 2 additions & 2 deletions encryption/encryption_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class EncryptionTest
case EncryptionMethod::kAES256_CTR:
cipher = EVP_aes_256_ctr();
break;
#if OPENSSL_VERSION_NUMBER >= 0x1010100fL
#if OPENSSL_VERSION_NUMBER >= 0x1010100fL && !defined(OPENSSL_NO_SM4)
// Openssl support SM4 after 1.1.1 release version.
case EncryptionMethod::kSM4_CTR:
cipher = EVP_sm4_ctr();
Expand Down Expand Up @@ -153,7 +153,7 @@ TEST_P(EncryptionTest, EncryptionTest) {
}

// Openssl support SM4 after 1.1.1 release version.
#if OPENSSL_VERSION_NUMBER < 0x1010100fL
#if OPENSSL_VERSION_NUMBER < 0x1010100fL || defined(OPENSSL_NO_SM4)
INSTANTIATE_TEST_CASE_P(
EncryptionTestInstance, EncryptionTest,
testing::Combine(testing::Bool(),
Expand Down

0 comments on commit 5efb80e

Please sign in to comment.