Skip to content

Commit

Permalink
Fix format for adding sm4
Browse files Browse the repository at this point in the history
Signed-off-by: Jarvis Zheng <jiayang@hust.edu.cn>
  • Loading branch information
jiayang-zheng committed Jul 11, 2022
1 parent f91651f commit e6e7b40
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions encryption/encryption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,12 @@ Status NewAESCTRCipherStream(EncryptionMethod method, const std::string& key,
cipher = EVP_aes_256_ctr();
break;
case EncryptionMethod::kSM4_CTR:
// Openssl support SM4 after 1.1.1 release version.
#if OPENSSL_VERSION_NUMBER < 0x1010100fL
return Status::InvalidArgument("Unsupport SM4 encryption method under OpenSSL version: " +
std::string(OPENSSL_VERSION_TEXT));
return Status::InvalidArgument(
"Unsupport SM4 encryption method under OpenSSL version: " +
std::string(OPENSSL_VERSION_TEXT));
#else
// Openssl support SM4 after 1.1.1 release version.
cipher = EVP_sm4_ctr();
break;
#endif
Expand Down
3 changes: 2 additions & 1 deletion encryption/encryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ namespace encryption {
// TODO: OpenSSL Lib does not export SM4_BLOCK_SIZE by now.
// Need to remove SM4_BLOCK_Size once Openssl lib support the definition.
// SM4 uses 128-bit block size as AES.
// Ref: https://github.com/openssl/openssl/blob/OpenSSL_1_1_1-stable/include/crypto/sm4.h#L24
// Ref:
// https://github.com/openssl/openssl/blob/OpenSSL_1_1_1-stable/include/crypto/sm4.h#L24
#define SM4_BLOCK_SIZE 16

class AESCTRCipherStream : public BlockAccessCipherStream {
Expand Down
2 changes: 1 addition & 1 deletion encryption/encryption_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class EncryptionTest
case EncryptionMethod::kAES256_CTR:
cipher = EVP_aes_256_ctr();
break;
// Openssl support SM4 after 1.1.1 release version.
#if OPENSSL_VERSION_NUMBER >= 0x1010100fL
// Openssl support SM4 after 1.1.1 release version.
case EncryptionMethod::kSM4_CTR:
cipher = EVP_sm4_ctr();
break;
Expand Down

0 comments on commit e6e7b40

Please sign in to comment.