aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-24 11:26:42 +0200
committerMattias Andrée <maandree@kth.se>2024-08-24 11:26:42 +0200
commit3a73ab675a19e2ea29b4cb1385db0188ce4997f8 (patch)
treeb010de454a833b01fe2ed469fd4f0fd699c59e50 /libhashsum
parentTest partial byte support in SHA1 and SHA-224 (diff)
downloadlibhashsum-3a73ab675a19e2ea29b4cb1385db0188ce4997f8.tar.gz
libhashsum-3a73ab675a19e2ea29b4cb1385db0188ce4997f8.tar.bz2
libhashsum-3a73ab675a19e2ea29b4cb1385db0188ce4997f8.tar.xz
Make algorithms optional
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libhashsum.h34
-rw-r--r--libhashsum_init_md2_hasher.c12
-rw-r--r--libhashsum_init_md4_hasher.c12
-rw-r--r--libhashsum_init_md5_hasher.c12
-rw-r--r--libhashsum_init_ripemd_128_hasher.c12
-rw-r--r--libhashsum_init_ripemd_160_hasher.c12
-rw-r--r--libhashsum_init_ripemd_256_hasher.c12
-rw-r--r--libhashsum_init_ripemd_320_hasher.c12
-rw-r--r--libhashsum_init_sha0_hasher.c12
-rw-r--r--libhashsum_init_sha1_hasher.c12
-rw-r--r--libhashsum_init_sha2_hasher.c14
11 files changed, 140 insertions, 16 deletions
diff --git a/libhashsum.h b/libhashsum.h
index 0bfb48a..1e453b3 100644
--- a/libhashsum.h
+++ b/libhashsum.h
@@ -382,7 +382,8 @@ struct libhashsum_hasher {
* @param algorithm The hashing algorithm
* @return 0 on success, -1 on failure
*
- * @throws EINVAL `algorithm` is unsupported
+ * @throws EINVAL `algorithm` is not recognised
+ * @throws ENOSYS Support for `algorithm` was excluded at compile time
*
* @since 1.0
*/
@@ -396,7 +397,7 @@ int libhashsum_init_hasher(struct libhashsum_hasher *this, enum libhashsum_algor
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -410,7 +411,7 @@ int libhashsum_init_md2_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -424,7 +425,7 @@ int libhashsum_init_md4_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -438,7 +439,7 @@ int libhashsum_init_md5_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -452,7 +453,7 @@ int libhashsum_init_ripemd_128_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -466,7 +467,7 @@ int libhashsum_init_ripemd_160_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -480,7 +481,7 @@ int libhashsum_init_ripemd_256_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -494,7 +495,7 @@ int libhashsum_init_ripemd_320_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -508,7 +509,7 @@ int libhashsum_init_sha0_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -522,7 +523,7 @@ int libhashsum_init_sha1_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -536,7 +537,7 @@ int libhashsum_init_sha_224_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -550,7 +551,7 @@ int libhashsum_init_sha_256_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -564,7 +565,7 @@ int libhashsum_init_sha_384_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -578,7 +579,7 @@ int libhashsum_init_sha_512_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -592,7 +593,7 @@ int libhashsum_init_sha_512_224_hasher(struct libhashsum_hasher *this);
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
*
- * Failure isn't actually possible, so this function always return 0
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
@@ -612,6 +613,7 @@ int libhashsum_init_sha_512_256_hasher(struct libhashsum_hasher *this);
* @throws EINVAL `hashbits` is invalid (neither 224, 256, 384, nor 512)
* @throws EINVAL The combination of `algobits` and `hashbits` is invalid
* (`hashbits` is 384 or 512 but `algobits` is 32)
+ * @throws ENOSYS Support was excluded at compile time
*
* @since 1.0
*/
diff --git a/libhashsum_init_md2_hasher.c b/libhashsum_init_md2_hasher.c
index e3e929e..dd20429 100644
--- a/libhashsum_init_md2_hasher.c
+++ b/libhashsum_init_md2_hasher.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
+#ifdef SUPPORT_MD2
static const unsigned char S[] = {
@@ -143,3 +144,14 @@ libhashsum_init_md2_hasher(struct libhashsum_hasher *this)
memset(&this->state.md2, 0, sizeof(this->state.md2));
return 0;
}
+
+
+#else
+int
+libhashsum_init_md2_hasher(struct libhashsum_hasher *this)
+{
+ (void) this;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_md4_hasher.c b/libhashsum_init_md4_hasher.c
index f3c26ac..fc4d5d9 100644
--- a/libhashsum_init_md4_hasher.c
+++ b/libhashsum_init_md4_hasher.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
+#ifdef SUPPORT_MD4
#define LETO32(X)\
@@ -190,3 +191,14 @@ libhashsum_init_md4_hasher(struct libhashsum_hasher *this)
this->state.md4.h.h32[3] = UINT32_C(0x10325476);
return 0;
}
+
+
+#else
+int
+libhashsum_init_md4_hasher(struct libhashsum_hasher *this)
+{
+ (void) this;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_md5_hasher.c b/libhashsum_init_md5_hasher.c
index 7bf19af..8c06527 100644
--- a/libhashsum_init_md5_hasher.c
+++ b/libhashsum_init_md5_hasher.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
+#ifdef SUPPORT_MD5
static const uint32_t S[64] = {
@@ -205,3 +206,14 @@ libhashsum_init_md5_hasher(struct libhashsum_hasher *this)
this->state.md5.h.h32[3] = UINT32_C(0x10325476);
return 0;
}
+
+
+#else
+int
+libhashsum_init_md5_hasher(struct libhashsum_hasher *this)
+{
+ (void) this;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_ripemd_128_hasher.c b/libhashsum_init_ripemd_128_hasher.c
index ef9f215..699de97 100644
--- a/libhashsum_init_ripemd_128_hasher.c
+++ b/libhashsum_init_ripemd_128_hasher.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
+#ifdef SUPPORT_RIPEMD_128
#define LETO32(X)\
@@ -226,3 +227,14 @@ libhashsum_init_ripemd_128_hasher(struct libhashsum_hasher *this)
this->state.ripemd_128.h.h32[3] = UINT32_C(0x10325476);
return 0;
}
+
+
+#else
+int
+libhashsum_init_ripemd_128_hasher(struct libhashsum_hasher *this)
+{
+ (void) this;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_ripemd_160_hasher.c b/libhashsum_init_ripemd_160_hasher.c
index 001cbb8..b37aec8 100644
--- a/libhashsum_init_ripemd_160_hasher.c
+++ b/libhashsum_init_ripemd_160_hasher.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
+#ifdef SUPPORT_RIPEMD_160
#define LETO32(X)\
@@ -230,3 +231,14 @@ libhashsum_init_ripemd_160_hasher(struct libhashsum_hasher *this)
this->state.ripemd_160.h.h32[4] = UINT32_C(0xc3d2e1f0);
return 0;
}
+
+
+#else
+int
+libhashsum_init_ripemd_160_hasher(struct libhashsum_hasher *this)
+{
+ (void) this;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_ripemd_256_hasher.c b/libhashsum_init_ripemd_256_hasher.c
index f08acf7..beda29f 100644
--- a/libhashsum_init_ripemd_256_hasher.c
+++ b/libhashsum_init_ripemd_256_hasher.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
+#ifdef SUPPORT_RIPEMD_256
#define LETO32(X)\
@@ -241,3 +242,14 @@ libhashsum_init_ripemd_256_hasher(struct libhashsum_hasher *this)
this->state.ripemd_256.h.h32[7] = UINT32_C(0x01234567);
return 0;
}
+
+
+#else
+int
+libhashsum_init_ripemd_256_hasher(struct libhashsum_hasher *this)
+{
+ (void) this;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_ripemd_320_hasher.c b/libhashsum_init_ripemd_320_hasher.c
index 2f09ce7..c9cda07 100644
--- a/libhashsum_init_ripemd_320_hasher.c
+++ b/libhashsum_init_ripemd_320_hasher.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
+#ifdef SUPPORT_RIPEMD_320
#define LETO32(X)\
@@ -249,3 +250,14 @@ libhashsum_init_ripemd_320_hasher(struct libhashsum_hasher *this)
this->state.ripemd_320.h.h32[9] = UINT32_C(0x3c2d1e0f);
return 0;
}
+
+
+#else
+int
+libhashsum_init_ripemd_320_hasher(struct libhashsum_hasher *this)
+{
+ (void) this;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_sha0_hasher.c b/libhashsum_init_sha0_hasher.c
index 8f5854a..6efd8fc 100644
--- a/libhashsum_init_sha0_hasher.c
+++ b/libhashsum_init_sha0_hasher.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
+#ifdef SUPPORT_SHA0
LIBHASHSUM_1_NONNULL_
@@ -67,3 +68,14 @@ libhashsum_init_sha0_hasher(struct libhashsum_hasher *this)
libsha1_init(&this->state.sha0.s, LIBSHA1_0);
return 0;
}
+
+
+#else
+int
+libhashsum_init_sha0_hasher(struct libhashsum_hasher *this)
+{
+ (void) this;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_sha1_hasher.c b/libhashsum_init_sha1_hasher.c
index 8287429..a3aef8e 100644
--- a/libhashsum_init_sha1_hasher.c
+++ b/libhashsum_init_sha1_hasher.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
+#ifdef SUPPORT_SHA1
LIBHASHSUM_1_NONNULL_
@@ -67,3 +68,14 @@ libhashsum_init_sha1_hasher(struct libhashsum_hasher *this)
libsha1_init(&this->state.sha1.s, LIBSHA1_1);
return 0;
}
+
+
+#else
+int
+libhashsum_init_sha1_hasher(struct libhashsum_hasher *this)
+{
+ (void) this;
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/libhashsum_init_sha2_hasher.c b/libhashsum_init_sha2_hasher.c
index ab64517..9246e48 100644
--- a/libhashsum_init_sha2_hasher.c
+++ b/libhashsum_init_sha2_hasher.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
+#ifdef SUPPORT_SHA2
LIBHASHSUM_1_NONNULL_
@@ -91,3 +92,16 @@ libhashsum_init_sha2_hasher(struct libhashsum_hasher *this, unsigned algobits, s
libsha2_init(&this->state.sha2.s, algo);
return 0;
}
+
+
+#else
+int
+libhashsum_init_sha2_hasher(struct libhashsum_hasher *this, unsigned algobits, size_t hashbits)
+{
+ (void) this;
+ (void) algobits;
+ (void) hashbits;
+ errno = ENOSYS;
+ return -1;
+}
+#endif