crypto: perform runtime check for hash/hmac support in gcrypt
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 30 Oct 2024 10:09:30 +0000 (10:09 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 5 Nov 2024 18:37:18 +0000 (18:37 +0000)
gcrypto has the ability to dynamically disable hash/hmac algorithms
at runtime, so QEMU must perform a runtime check.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
crypto/hash-gcrypt.c
crypto/hmac-gcrypt.c

index 476b7481951bda6c9600ec918d2a1d49b3d645f3..af61c4e75da5f6ddacfcabe4baec0b70ec9df3f1 100644 (file)
@@ -43,7 +43,7 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgo alg)
 {
     if (alg < G_N_ELEMENTS(qcrypto_hash_alg_map) &&
         qcrypto_hash_alg_map[alg] != GCRY_MD_NONE) {
-        return true;
+        return gcry_md_test_algo(qcrypto_hash_alg_map[alg]) == 0;
     }
     return false;
 }
index 090fe01c1e005144a25e8c95e5c50b40b1f84c5a..5273086eb9ac93a2011d039c9b49ada4cc61d871 100644 (file)
@@ -40,7 +40,7 @@ bool qcrypto_hmac_supports(QCryptoHashAlgo alg)
 {
     if (alg < G_N_ELEMENTS(qcrypto_hmac_alg_map) &&
         qcrypto_hmac_alg_map[alg] != GCRY_MAC_NONE) {
-        return true;
+        return gcry_mac_test_algo(qcrypto_hmac_alg_map[alg]) == 0;
     }
 
     return false;