diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2016-03-11 18:33:08 +0000 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2016-07-04 15:52:36 +0100 |
commit | 9164b89762224db414676973172c26994aa9e2e5 (patch) | |
tree | db509ee669f5195c4d240b45929854ab7a06a1f3 /crypto | |
parent | 0c16c056a4f9dec18fdd56feec82a5db9ff3c15e (diff) |
crypto: implement sha224, sha384, sha512 and ripemd160 hashes
Wire up the nettle and gcrypt hash backends so that they can
support the sha224, sha384, sha512 and ripemd160 hash algorithms.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/hash-gcrypt.c | 4 | ||||
-rw-r--r-- | crypto/hash-nettle.c | 29 | ||||
-rw-r--r-- | crypto/hash.c | 4 |
3 files changed, 37 insertions, 0 deletions
diff --git a/crypto/hash-gcrypt.c b/crypto/hash-gcrypt.c index e0456897ac..8ea5aff4ee 100644 --- a/crypto/hash-gcrypt.c +++ b/crypto/hash-gcrypt.c @@ -27,7 +27,11 @@ static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALG__MAX] = { [QCRYPTO_HASH_ALG_MD5] = GCRY_MD_MD5, [QCRYPTO_HASH_ALG_SHA1] = GCRY_MD_SHA1, + [QCRYPTO_HASH_ALG_SHA224] = GCRY_MD_SHA224, [QCRYPTO_HASH_ALG_SHA256] = GCRY_MD_SHA256, + [QCRYPTO_HASH_ALG_SHA384] = GCRY_MD_SHA384, + [QCRYPTO_HASH_ALG_SHA512] = GCRY_MD_SHA512, + [QCRYPTO_HASH_ALG_RIPEMD160] = GCRY_MD_RMD160, }; gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg) diff --git a/crypto/hash-nettle.c b/crypto/hash-nettle.c index 8ec5572aff..4c6f50b65d 100644 --- a/crypto/hash-nettle.c +++ b/crypto/hash-nettle.c @@ -23,6 +23,7 @@ #include "crypto/hash.h" #include <nettle/md5.h> #include <nettle/sha.h> +#include <nettle/ripemd160.h> typedef void (*qcrypto_nettle_init)(void *ctx); typedef void (*qcrypto_nettle_write)(void *ctx, @@ -35,7 +36,11 @@ typedef void (*qcrypto_nettle_result)(void *ctx, union qcrypto_hash_ctx { struct md5_ctx md5; struct sha1_ctx sha1; + struct sha224_ctx sha224; struct sha256_ctx sha256; + struct sha384_ctx sha384; + struct sha512_ctx sha512; + struct ripemd160_ctx ripemd160; }; struct qcrypto_hash_alg { @@ -56,12 +61,36 @@ struct qcrypto_hash_alg { .result = (qcrypto_nettle_result)sha1_digest, .len = SHA1_DIGEST_SIZE, }, + [QCRYPTO_HASH_ALG_SHA224] = { + .init = (qcrypto_nettle_init)sha224_init, + .write = (qcrypto_nettle_write)sha224_update, + .result = (qcrypto_nettle_result)sha224_digest, + .len = SHA224_DIGEST_SIZE, + }, [QCRYPTO_HASH_ALG_SHA256] = { .init = (qcrypto_nettle_init)sha256_init, .write = (qcrypto_nettle_write)sha256_update, .result = (qcrypto_nettle_result)sha256_digest, .len = SHA256_DIGEST_SIZE, }, + [QCRYPTO_HASH_ALG_SHA384] = { + .init = (qcrypto_nettle_init)sha384_init, + .write = (qcrypto_nettle_write)sha384_update, + .result = (qcrypto_nettle_result)sha384_digest, + .len = SHA384_DIGEST_SIZE, + }, + [QCRYPTO_HASH_ALG_SHA512] = { + .init = (qcrypto_nettle_init)sha512_init, + .write = (qcrypto_nettle_write)sha512_update, + .result = (qcrypto_nettle_result)sha512_digest, + .len = SHA512_DIGEST_SIZE, + }, + [QCRYPTO_HASH_ALG_RIPEMD160] = { + .init = (qcrypto_nettle_init)ripemd160_init, + .write = (qcrypto_nettle_write)ripemd160_update, + .result = (qcrypto_nettle_result)ripemd160_digest, + .len = RIPEMD160_DIGEST_SIZE, + }, }; gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg) diff --git a/crypto/hash.c b/crypto/hash.c index aa2a26e8a6..0f1ceac66a 100644 --- a/crypto/hash.c +++ b/crypto/hash.c @@ -25,7 +25,11 @@ static size_t qcrypto_hash_alg_size[QCRYPTO_HASH_ALG__MAX] = { [QCRYPTO_HASH_ALG_MD5] = 16, [QCRYPTO_HASH_ALG_SHA1] = 20, + [QCRYPTO_HASH_ALG_SHA224] = 28, [QCRYPTO_HASH_ALG_SHA256] = 32, + [QCRYPTO_HASH_ALG_SHA384] = 48, + [QCRYPTO_HASH_ALG_SHA512] = 64, + [QCRYPTO_HASH_ALG_RIPEMD160] = 20, }; size_t qcrypto_hash_digest_len(QCryptoHashAlgorithm alg) |