crypto: misc gcrypt hash/hmac fixes
cover crypto: misc gcrypt hash/hmac fixes
This fixes the test suite when gcrypt disables some algorithms at runtime.
Daniel P. Berrangé (2):
crypto: fix error check on gcry_md_open
crypto: perform runtime check for hash/hmac support in gcrypt
crypto/hash-gcrypt.c | 6 +++--- crypto/hmac-gcrypt.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.46.0
PATCH 1/2 crypto: fix error check on gcry_md_open
Gcrypt does not return negative values on error, it returns non-zero values. This caused QEMU not to detect failure to open an unsupported hash, resulting in a later crash trying to use a NULL context.
--- crypto/hash-gcrypt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
crypto/hash-gcrypt.c +2 -2
@@ -49,7 +49,7 @@ staticQCryptoHash *qcrypto_gcrypt_hash_new (QCryptoHashAlgo alg,Error **errp) {QCryptoHash *hash; -int ret; +gcry_error_t ret; hash =g_new (QCryptoHash,1 ); hash->alg = alg;
@@ -57,7 +57,7 @@ QCryptoHash *qcrypto_gcrypt_hash_new(QCryptoHashAlgo alg, Error **errp) ret =gcry_md_open ((gcry_md_hd_t *) hash->opaque, qcrypto_hash_alg_map[alg],0 ); -if (ret <0 ) { +if (ret !=0 ) {error_setg (errp,"Unable to initialize hash algorithm: %s" ,gcry_strerror (ret));
Signature · 1 line
2.46.0
Re: [PATCH 1/2] crypto: fix error check on gcry_md_open
Quoted 8 lines · Daniel P. Berrangé
Gcrypt does not return negative values on error, it returns non-zero values. This caused QEMU not to detect failure to open an unsupported hash, resulting in a later crash trying to use a NULL context.
Signed-off-by Daniel P. Berrangé <[email protected]>--- crypto/hash-gcrypt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
PATCH 2/2 crypto: perform runtime check for hash/hmac support in gcrypt
In reply to Daniel P. Berrangégcrypto has the ability to dynamically disable hash/hmac algorithms at runtime, so QEMU must perform a runtime check.
--- crypto/hash-gcrypt.c | 2 +- crypto/hmac-gcrypt.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
crypto/hash-gcrypt.c +1 -1
@@ -40,7 +40,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; }
crypto/hmac-gcrypt.c +1 -1
@@ -37,7 +37,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;
Signature · 1 line
2.46.0
Re: [PATCH 2/2] crypto: perform runtime check for hash/hmac support in gcrypt
Quoted 8 lines · Daniel P. Berrangé
gcrypto has the ability to dynamically disable hash/hmac algorithms at runtime, so QEMU must perform a runtime check.
Signed-off-by Daniel P. Berrangé <[email protected]>--- crypto/hash-gcrypt.c | 2 +- crypto/hmac-gcrypt.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)