The glib backend for the hmac/hash code must have an explicit
initializer for every element, as the default static initializer
of zero maps to G_CHECKSUM_MD5 and will lead to incorrect
behaviour. This could potentially be a security through use of
the wrong hashing algorithm.

Fixes: https://gitlab.com/qemu-project/qemu/-/work_items/4786
Signed-off-by: Daniel P. Berrangé <[email protected]>
---
 crypto/hash-glib.c | 1 +
 crypto/hmac-glib.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/crypto/hash-glib.c b/crypto/hash-glib.c
index 809cef98aee..39040f1856e 100644
--- a/crypto/hash-glib.c
+++ b/crypto/hash-glib.c
@@ -33,6 +33,7 @@ static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALGO__MAX] = {
     [QCRYPTO_HASH_ALGO_SHA384] = G_CHECKSUM_SHA384,
     [QCRYPTO_HASH_ALGO_SHA512] = G_CHECKSUM_SHA512,
     [QCRYPTO_HASH_ALGO_RIPEMD160] = -1,
+    [QCRYPTO_HASH_ALGO_SM3] = -1,
 };
 
 gboolean qcrypto_hash_supports(QCryptoHashAlgo alg)
diff --git a/crypto/hmac-glib.c b/crypto/hmac-glib.c
index 1f17769c1c7..8f652c5064e 100644
--- a/crypto/hmac-glib.c
+++ b/crypto/hmac-glib.c
@@ -25,6 +25,7 @@ static int qcrypto_hmac_alg_map[QCRYPTO_HASH_ALGO__MAX] = {
     [QCRYPTO_HASH_ALGO_SHA224] = -1,
     [QCRYPTO_HASH_ALGO_SHA384] = -1,
     [QCRYPTO_HASH_ALGO_RIPEMD160] = -1,
+    [QCRYPTO_HASH_ALGO_SM3] = -1,
 };
 
 typedef struct QCryptoHmacGlib QCryptoHmacGlib;
-- 
2.56.0


Reply via email to