summaryrefslogtreecommitdiff
path: root/crypto/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/hash.c')
-rw-r--r--crypto/hash.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/crypto/hash.c b/crypto/hash.c
index 81e74de868..6e83f43e4a 100644
--- a/crypto/hash.c
+++ b/crypto/hash.c
@@ -24,12 +24,18 @@
#include <gnutls/gnutls.h>
#include <gnutls/crypto.h>
-static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALG_LAST] = {
+static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALG__MAX] = {
[QCRYPTO_HASH_ALG_MD5] = GNUTLS_DIG_MD5,
[QCRYPTO_HASH_ALG_SHA1] = GNUTLS_DIG_SHA1,
[QCRYPTO_HASH_ALG_SHA256] = GNUTLS_DIG_SHA256,
};
+static size_t qcrypto_hash_alg_size[QCRYPTO_HASH_ALG__MAX] = {
+ [QCRYPTO_HASH_ALG_MD5] = 16,
+ [QCRYPTO_HASH_ALG_SHA1] = 20,
+ [QCRYPTO_HASH_ALG_SHA256] = 32,
+};
+
gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg)
{
if (alg < G_N_ELEMENTS(qcrypto_hash_alg_map)) {
@@ -38,6 +44,15 @@ gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg)
return false;
}
+size_t qcrypto_hash_digest_len(QCryptoHashAlgorithm alg)
+{
+ if (alg >= G_N_ELEMENTS(qcrypto_hash_alg_size)) {
+ return 0;
+ }
+ return qcrypto_hash_alg_size[alg];
+}
+
+
int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg,
const struct iovec *iov,
size_t niov,