mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 01:33:56 -06:00
crypto: Introduce SM3 hash hmac pbkdf algorithm
Introduce the SM3 cryptographic hash algorithm (GB/T 32905-2016). SM3 (GB/T 32905-2016) is a cryptographic standard issued by the Organization of State Commercial Cryptography Administration (OSCCA) as an authorized cryptographic algorithm for use within China. Detect the SM3 cryptographic hash algorithm and enable the feature silently if it is available. Signed-off-by: cheliequan <cheliequan@inspur.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
62eb377e0a
commit
d078da86d6
13 changed files with 135 additions and 1 deletions
|
@ -43,6 +43,9 @@
|
|||
"63b54e4cb2d2032b393994aa263c0dbb" \
|
||||
"e00a9f2fe9ef6037352232a1eec55ee7"
|
||||
#define OUTPUT_RIPEMD160 "f3d658fad3fdfb2b52c9369cf0d441249ddfa8a0"
|
||||
#ifdef CONFIG_CRYPTO_SM3
|
||||
#define OUTPUT_SM3 "d4a97db105b477b84c4f20ec9c31a6c814e2705a0b83a5a89748d75f0ef456a1"
|
||||
#endif
|
||||
|
||||
#define OUTPUT_MD5_B64 "Yo0gY3FWMDWrjvYvSSveyQ=="
|
||||
#define OUTPUT_SHA1_B64 "sudPJnWKOkIeUJzuBFJEt4dTzAI="
|
||||
|
@ -55,6 +58,10 @@
|
|||
"7sVe5w=="
|
||||
#define OUTPUT_RIPEMD160_B64 "89ZY+tP9+ytSyTac8NRBJJ3fqKA="
|
||||
|
||||
#ifdef CONFIG_CRYPTO_SM3
|
||||
#define OUTPUT_SM3_B64 "1Kl9sQW0d7hMTyDsnDGmyBTicFoLg6Wol0jXXw70VqE="
|
||||
#endif
|
||||
|
||||
static const char *expected_outputs[] = {
|
||||
[QCRYPTO_HASH_ALGO_MD5] = OUTPUT_MD5,
|
||||
[QCRYPTO_HASH_ALGO_SHA1] = OUTPUT_SHA1,
|
||||
|
@ -63,6 +70,9 @@ static const char *expected_outputs[] = {
|
|||
[QCRYPTO_HASH_ALGO_SHA384] = OUTPUT_SHA384,
|
||||
[QCRYPTO_HASH_ALGO_SHA512] = OUTPUT_SHA512,
|
||||
[QCRYPTO_HASH_ALGO_RIPEMD160] = OUTPUT_RIPEMD160,
|
||||
#ifdef CONFIG_CRYPTO_SM3
|
||||
[QCRYPTO_HASH_ALGO_SM3] = OUTPUT_SM3,
|
||||
#endif
|
||||
};
|
||||
static const char *expected_outputs_b64[] = {
|
||||
[QCRYPTO_HASH_ALGO_MD5] = OUTPUT_MD5_B64,
|
||||
|
@ -72,6 +82,9 @@ static const char *expected_outputs_b64[] = {
|
|||
[QCRYPTO_HASH_ALGO_SHA384] = OUTPUT_SHA384_B64,
|
||||
[QCRYPTO_HASH_ALGO_SHA512] = OUTPUT_SHA512_B64,
|
||||
[QCRYPTO_HASH_ALGO_RIPEMD160] = OUTPUT_RIPEMD160_B64,
|
||||
#ifdef CONFIG_CRYPTO_SM3
|
||||
[QCRYPTO_HASH_ALGO_SM3] = OUTPUT_SM3_B64,
|
||||
#endif
|
||||
};
|
||||
static const int expected_lens[] = {
|
||||
[QCRYPTO_HASH_ALGO_MD5] = 16,
|
||||
|
@ -81,6 +94,9 @@ static const int expected_lens[] = {
|
|||
[QCRYPTO_HASH_ALGO_SHA384] = 48,
|
||||
[QCRYPTO_HASH_ALGO_SHA512] = 64,
|
||||
[QCRYPTO_HASH_ALGO_RIPEMD160] = 20,
|
||||
#ifdef CONFIG_CRYPTO_SM3
|
||||
[QCRYPTO_HASH_ALGO_SM3] = 32,
|
||||
#endif
|
||||
};
|
||||
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
|
|
|
@ -76,6 +76,14 @@ static QCryptoHmacTestData test_data[] = {
|
|||
"94964ed4c1155b62b668c241d67279e5"
|
||||
"8a711676",
|
||||
},
|
||||
#ifdef CONFIG_CRYPTO_SM3
|
||||
{
|
||||
.alg = QCRYPTO_HASH_ALGO_SM3,
|
||||
.hex_digest =
|
||||
"760e3799332bc913819b930085360ddb"
|
||||
"c05529261313d5b15b75bab4fd7ae91e",
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
|
|
|
@ -325,6 +325,22 @@ static QCryptoPbkdfTestData test_data[] = {
|
|||
"\xce\xbf\x91\x14\x8b\x5c\x48\x41",
|
||||
.nout = 32
|
||||
},
|
||||
#ifdef CONFIG_CRYPTO_SM3
|
||||
{
|
||||
.path = "/crypto/pbkdf/nonrfc/sm3/iter2",
|
||||
.hash = QCRYPTO_HASH_ALGO_SM3,
|
||||
.iterations = 2,
|
||||
.key = "password",
|
||||
.nkey = 8,
|
||||
.salt = "ATHENA.MIT.EDUraeburn",
|
||||
.nsalt = 21,
|
||||
.out = "\x48\x71\x1b\x58\xa3\xcb\xce\x06"
|
||||
"\xba\xad\x77\xa8\xb5\xb9\xd8\x07"
|
||||
"\x6a\xe2\xb3\x5b\x95\xce\xc8\xce"
|
||||
"\xe7\xb1\xcb\xee\x61\xdf\x04\xea",
|
||||
.nout = 32
|
||||
},
|
||||
#endif
|
||||
#if 0
|
||||
{
|
||||
.path = "/crypto/pbkdf/nonrfc/whirlpool/iter1200",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue