[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3] crypto: Introduce SM4 symmetric cipher algorithm
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH v3] crypto: Introduce SM4 symmetric cipher algorithm |
Date: |
Wed, 29 Nov 2023 19:12:32 +0100 |
User-agent: |
Mozilla Thunderbird |
On 29/11/23 16:17, Hyman Huang wrote:
Introduce the SM4 cipher algorithms (OSCCA GB/T 32907-2016).
SM4 (GBT.32907-2016) is a cryptographic standard issued by the
Organization of State Commercial Administration of China (OSCCA)
as an authorized cryptographic algorithms for the use within China.
Use the crypto-sm4 meson build option to explicitly control the
feature, which would be detected by default.
Signed-off-by: Hyman Huang <yong.huang@smartx.com>
---
crypto/block-luks.c | 11 ++++++++
crypto/cipher-gcrypt.c.inc | 8 ++++++
crypto/cipher-nettle.c.inc | 49 +++++++++++++++++++++++++++++++++
crypto/cipher.c | 6 ++++
meson.build | 42 ++++++++++++++++++++++++++++
meson_options.txt | 2 ++
qapi/crypto.json | 5 +++-
scripts/meson-buildoptions.sh | 3 ++
tests/unit/test-crypto-cipher.c | 13 +++++++++
9 files changed, 138 insertions(+), 1 deletion(-)
diff --git a/meson.build b/meson.build
index ec01f8b138..765f9c9f50 100644
--- a/meson.build
+++ b/meson.build
@@ -1480,6 +1480,7 @@ endif
gcrypt = not_found
nettle = not_found
hogweed = not_found
+crypto_sm4 = not_found
xts = 'none'
if get_option('nettle').enabled() and get_option('gcrypt').enabled()
@@ -1505,6 +1506,28 @@ if not gnutls_crypto.found()
cc.find_library('gpg-error', required: true)],
version: gcrypt.version())
endif
+ crypto_sm4 = gcrypt
+ # SM4 ALG is available in libgcrypt >= 1.9
+ if gcrypt.found() and not cc.links('''
+ #include <gcrypt.h>
+ int main(void) {
+ gcry_cipher_hd_t handler;
+ gcry_cipher_open(&handler, GCRY_CIPHER_SM4, GCRY_CIPHER_MODE_ECB, 0);
+ return 0;
+ }''', dependencies: gcrypt)
+ crypto_sm4 = not_found
+ if get_option('crypto_sm4').enabled()
+ error('could not link sm4')
'could not link libsm4'? Up to the maintainer.
+ else
+ warning('could not link sm4, disabling')
+ endif
+ endif
+ if crypto_sm4.found() and get_option('prefer_static')
+ crypto_sm4 = declare_dependency(dependencies: [
+ gcrypt,
+ cc.find_library('gpg-error', required: true)],
+ version: gcrypt.version())
+ endif
endif
if (not get_option('nettle').auto() or have_system) and not gcrypt.found()
nettle = dependency('nettle', version: '>=3.4',
@@ -1513,6 +1536,23 @@ if not gnutls_crypto.found()
if nettle.found() and not cc.has_header('nettle/xts.h', dependencies:
nettle)
xts = 'private'
endif
+ crypto_sm4 = nettle
+ # SM4 ALG is available in nettle >= 3.9
+ if nettle.found() and not cc.links('''
+ #include <nettle/sm4.h>
+ int main(void) {
+ struct sm4_ctx ctx;
+ unsigned char key[16] = {0};
+ sm4_set_encrypt_key(&ctx, key);
+ return 0;
+ }''', dependencies: nettle)
+ crypto_sm4 = not_found
+ if get_option('crypto_sm4').enabled()
+ error('could not link sm4')
Ditto, otherwise:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
+ else
+ warning('could not link sm4, disabling')
+ endif
+ endif
endif
endif