aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2017-09-25 18:06:40 +0200
committerTobias Brunner <tobias@strongswan.org>2017-11-08 16:48:10 +0100
commit883e7fcd65659ffc8540229934a39795d8411e13 (patch)
tree8770340834262976013f936062681c467cde6c07 /src
parent3ce8b0556a33679f410073ef4577cc78f4282cbb (diff)
downloadstrongswan-883e7fcd65659ffc8540229934a39795d8411e13.tar.bz2
strongswan-883e7fcd65659ffc8540229934a39795d8411e13.tar.xz
xof: Add helper to determine MGF1 XOF type from hash algorithm
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/crypto/xofs/xof.c29
-rw-r--r--src/libstrongswan/crypto/xofs/xof.h9
2 files changed, 38 insertions, 0 deletions
diff --git a/src/libstrongswan/crypto/xofs/xof.c b/src/libstrongswan/crypto/xofs/xof.c
index 1e9c2834b..791598588 100644
--- a/src/libstrongswan/crypto/xofs/xof.c
+++ b/src/libstrongswan/crypto/xofs/xof.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2017 Tobias Brunner
* Copyright (C) 2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
@@ -25,3 +26,31 @@ ENUM(ext_out_function_names, XOF_UNDEFINED, XOF_CHACHA20,
"XOF_CHACHA20"
);
+/*
+ * Described in header
+ */
+ext_out_function_t xof_mgf1_from_hash_algorithm(hash_algorithm_t alg)
+{
+ switch (alg)
+ {
+ case HASH_SHA1:
+ return XOF_MGF1_SHA1;
+ case HASH_SHA256:
+ return XOF_MGF1_SHA256;
+ case HASH_SHA512:
+ return XOF_MGF1_SHA512;
+ case HASH_SHA224:
+ case HASH_SHA384:
+ case HASH_IDENTITY:
+ case HASH_UNKNOWN:
+ case HASH_MD2:
+ case HASH_MD4:
+ case HASH_MD5:
+ case HASH_SHA3_224:
+ case HASH_SHA3_256:
+ case HASH_SHA3_384:
+ case HASH_SHA3_512:
+ break;
+ }
+ return XOF_UNDEFINED;
+}
diff --git a/src/libstrongswan/crypto/xofs/xof.h b/src/libstrongswan/crypto/xofs/xof.h
index 8c9ae0131..83c9ab857 100644
--- a/src/libstrongswan/crypto/xofs/xof.h
+++ b/src/libstrongswan/crypto/xofs/xof.h
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2017 Tobias Brunner
* Copyright (C) 2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
@@ -111,4 +112,12 @@ struct xof_t {
void (*destroy)(xof_t *this);
};
+/**
+ * Determine an MGF1 XOF type for the given hash algorithm.
+ *
+ * @param alg hash algorithm to map
+ * @return MGF1 XOF type if available, XOF_UNDEFINED otherwise
+ */
+ext_out_function_t xof_mgf1_from_hash_algorithm(hash_algorithm_t alg);
+
#endif /** XOF_H_ @}*/