aboutsummaryrefslogtreecommitdiffstats
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
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--Makefile53
-rw-r--r--common.h34
-rw-r--r--config.mk41
-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
-rw-r--r--md2.c11
-rw-r--r--md4.c11
-rw-r--r--md5.c11
l---------mk/md2=no.mk1
-rw-r--r--mk/md2=yes.mk1
l---------mk/md4=no.mk1
-rw-r--r--mk/md4=yes.mk1
l---------mk/md5=no.mk1
-rw-r--r--mk/md5=yes.mk1
-rw-r--r--mk/no0
l---------mk/ripemd-128=no.mk1
-rw-r--r--mk/ripemd-128=yes.mk1
l---------mk/ripemd-160=no.mk1
-rw-r--r--mk/ripemd-160=yes.mk1
l---------mk/ripemd-256=no.mk1
-rw-r--r--mk/ripemd-256=yes.mk1
l---------mk/ripemd-320=no.mk1
-rw-r--r--mk/ripemd-320=yes.mk1
l---------mk/sha1=no.mk1
-rw-r--r--mk/sha1=yes.mk2
l---------mk/sha2=no.mk1
-rw-r--r--mk/sha2=yes.mk2
-rw-r--r--ripemd-128.c11
-rw-r--r--ripemd-160.c11
-rw-r--r--ripemd-256.c11
-rw-r--r--ripemd-320.c11
-rw-r--r--sha0.c11
-rw-r--r--sha1.c15
-rw-r--r--sha_224.c15
-rw-r--r--sha_256.c11
-rw-r--r--sha_384.c11
-rw-r--r--sha_512.c15
-rw-r--r--sha_512_224.c11
-rw-r--r--sha_512_256.c11
48 files changed, 416 insertions, 65 deletions
diff --git a/Makefile b/Makefile
index f1cfb34..eb9004c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,21 @@
.POSIX:
+
+# This are overwritten in $(CONFIGFILE), however they
+# are added so that they are always defined even if
+# the use has an out of date version of config.mk
+DEFAULT_SUPPORT = yes
+SUPPORT_SHA1 = $(DEFAULT_SUPPORT)
+SUPPORT_SHA2 = $(DEFAULT_SUPPORT)
+SUPPORT_MD2 = $(DEFAULT_SUPPORT)
+SUPPORT_MD4 = $(DEFAULT_SUPPORT)
+SUPPORT_MD5 = $(DEFAULT_SUPPORT)
+SUPPORT_RIPEMD_128 = $(DEFAULT_SUPPORT)
+SUPPORT_RIPEMD_160 = $(DEFAULT_SUPPORT)
+SUPPORT_RIPEMD_256 = $(DEFAULT_SUPPORT)
+SUPPORT_RIPEMD_320 = $(DEFAULT_SUPPORT)
+
+
CONFIGFILE = config.mk
include $(CONFIGFILE)
@@ -16,6 +32,35 @@ LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR)
LIB_NAME = hashsum
+include mk/md2=$(SUPPORT_MD2).mk
+include mk/md4=$(SUPPORT_MD4).mk
+include mk/md5=$(SUPPORT_MD5).mk
+include mk/ripemd-128=$(SUPPORT_RIPEMD_128).mk
+include mk/ripemd-160=$(SUPPORT_RIPEMD_160).mk
+include mk/ripemd-256=$(SUPPORT_RIPEMD_256).mk
+include mk/ripemd-320=$(SUPPORT_RIPEMD_320).mk
+include mk/sha1=$(SUPPORT_SHA1).mk
+include mk/sha2=$(SUPPORT_SHA2).mk
+
+
+CPPFLAGS_FULL =\
+ $(CPPFLAGS)\
+ $(CPPFLAGS_MD2)\
+ $(CPPFLAGS_MD4)\
+ $(CPPFLAGS_MD5)\
+ $(CPPFLAGS_RIPEMD_128)\
+ $(CPPFLAGS_RIPEMD_160)\
+ $(CPPFLAGS_RIPEMD_256)\
+ $(CPPFLAGS_RIPEMD_320)\
+ $(CPPFLAGS_SHA1)\
+ $(CPPFLAGS_SHA2)
+
+LDFLAGS_FULL =\
+ $(LDFLAGS)\
+ $(LDFLAGS_SHA1)\
+ $(LDFLAGS_SHA2)
+
+
OBJ =\
libhashsum_init_hasher.o\
libhashsum_init_md2_hasher.o\
@@ -68,16 +113,16 @@ $(TOBJ): $(HDR)
$(TEST): libhashsum.a
.c.o:
- $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS)
+ $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS_FULL)
.c.lo:
- $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS)
+ $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS_FULL)
.c.t:
- $(CC) -o $@ $< libhashsum.a $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
+ $(CC) -o $@ $< libhashsum.a $(CFLAGS) $(CPPFLAGS_FULL) $(LDFLAGS_FULL)
.o.t:
- $(CC) -o $@ $< libhashsum.a $(LDFLAGS)
+ $(CC) -o $@ $< libhashsum.a $(LDFLAGS_FULL)
libhashsum.a: $(OBJ)
@rm -f -- $@
diff --git a/common.h b/common.h
index 3d0972c..f41ef53 100644
--- a/common.h
+++ b/common.h
@@ -160,17 +160,17 @@ run_tests(const char *name, enum libhashsum_algorithm algorithm, size_t hash_siz
*p = '\0';
}
if (testcases[i].input_repeat == 1)
- printf("[\033[1;%s\033[m] %s(\"%s\"%s) = %s\n",
- caseok ? "32mPASS" : "31mFAIL", name, input, bitstr, hexsum);
+ fprintf(stderr, "[\033[1;%s\033[m] %s(\"%s\"%s) = %s\n",
+ caseok ? "32mPASS" : "31mFAIL", name, input, bitstr, hexsum);
else if (!testcases[i].input_repeat && *bitstr)
- printf("[\033[1;%s\033[m] %s(%s) = %s\n",
- caseok ? "32mPASS" : "31mFAIL", name, &bitstr[3], hexsum);
+ fprintf(stderr, "[\033[1;%s\033[m] %s(%s) = %s\n",
+ caseok ? "32mPASS" : "31mFAIL", name, &bitstr[3], hexsum);
else if (!testcases[i].input_repeat)
- printf("[\033[1;%s\033[m] %s(\"\") = %s\n",
- caseok ? "32mPASS" : "31mFAIL", name, hexsum);
+ fprintf(stderr, "[\033[1;%s\033[m] %s(\"\") = %s\n",
+ caseok ? "32mPASS" : "31mFAIL", name, hexsum);
else
- printf("[\033[1;%s\033[m] %s(%zu * \"%s\"%s) = %s\n",
- caseok ? "32mPASS" : "31mFAIL", name, testcases[i].input_repeat, input, bitstr, hexsum);
+ fprintf(stderr, "[\033[1;%s\033[m] %s(%zu * \"%s\"%s) = %s\n",
+ caseok ? "32mPASS" : "31mFAIL", name, testcases[i].input_repeat, input, bitstr, hexsum);
free(input);
}
return !ok;
@@ -182,3 +182,21 @@ run_tests(const char *name, enum libhashsum_algorithm algorithm, size_t hash_siz
testcases, sizeof(testcases) / sizeof(*testcases), hexsum)
#endif
+
+
+#ifdef TEST_UNSUPPORTED
+# include <stdio.h>
+
+# define TEST_MAIN(NAME, ID)\
+ struct libhashsum_hasher hasher;\
+ if (!libhashsum_init_hasher(&hasher, LIBHASHSUM_##ID)) {\
+ fprintf(stderr, "expected libhashsum_init_hasher to fail, but it returned successfully\n");\
+ return 2;\
+ }\
+ if (errno != ENOSYS) {\
+ perror("expected libhashsum_init_hasher to set errno to ENOSYS, but got");\
+ return 2;\
+ }\
+ return 0;
+
+#endif
diff --git a/config.mk b/config.mk
index ff855ca..5b5e94f 100644
--- a/config.mk
+++ b/config.mk
@@ -5,4 +5,43 @@ CC = c99
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
CFLAGS =
-LDFLAGS = -lsha1 -lsha2
+LDFLAGS =
+
+
+LDFLAGS_LIBSHA1 = -lsha1
+CPPFLAGS_LIBSHA1 =
+
+LDFLAGS_LIBSHA2 = -lsha2
+CPPFLAGS_LIBSHA2 =
+
+
+DEFAULT_SUPPORT = yes
+# Shall either be "yes" or "no", the same applies below where this macro is used
+
+
+SUPPORT_SHA1 = $(DEFAULT_SUPPORT)
+# Includes SHA0 and SHA1, requires libsha1
+
+SUPPORT_SHA2 = $(DEFAULT_SUPPORT)
+# Includes SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256, requires libsha2
+
+SUPPORT_MD2 = $(DEFAULT_SUPPORT)
+# Support is built in
+
+SUPPORT_MD4 = $(DEFAULT_SUPPORT)
+# Support is built in
+
+SUPPORT_MD5 = $(DEFAULT_SUPPORT)
+# Support is built in
+
+SUPPORT_RIPEMD_128 = $(DEFAULT_SUPPORT)
+# Support is built in
+
+SUPPORT_RIPEMD_160 = $(DEFAULT_SUPPORT)
+# Support is built in
+
+SUPPORT_RIPEMD_256 = $(DEFAULT_SUPPORT)
+# Support is built in
+
+SUPPORT_RIPEMD_320 = $(DEFAULT_SUPPORT)
+# Support is built in
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
diff --git a/md2.c b/md2.c
index baa2039..9c15cea 100644
--- a/md2.c
+++ b/md2.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_MD2
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -18,6 +19,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/md4.c b/md4.c
index 948b848..065ca26 100644
--- a/md4.c
+++ b/md4.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_MD4
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -18,6 +19,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/md5.c b/md5.c
index 2ff159d..a56ecfc 100644
--- a/md5.c
+++ b/md5.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_MD5
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -109,6 +110,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/mk/md2=no.mk b/mk/md2=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/md2=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/md2=yes.mk b/mk/md2=yes.mk
new file mode 100644
index 0000000..b387519
--- /dev/null
+++ b/mk/md2=yes.mk
@@ -0,0 +1 @@
+CPPFLAGS_MD2 = -DSUPPORT_MD2
diff --git a/mk/md4=no.mk b/mk/md4=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/md4=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/md4=yes.mk b/mk/md4=yes.mk
new file mode 100644
index 0000000..71ea9db
--- /dev/null
+++ b/mk/md4=yes.mk
@@ -0,0 +1 @@
+CPPFLAGS_MD4 = -DSUPPORT_MD4
diff --git a/mk/md5=no.mk b/mk/md5=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/md5=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/md5=yes.mk b/mk/md5=yes.mk
new file mode 100644
index 0000000..4a537e7
--- /dev/null
+++ b/mk/md5=yes.mk
@@ -0,0 +1 @@
+CPPFLAGS_MD5 = -DSUPPORT_MD5
diff --git a/mk/no b/mk/no
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mk/no
diff --git a/mk/ripemd-128=no.mk b/mk/ripemd-128=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/ripemd-128=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/ripemd-128=yes.mk b/mk/ripemd-128=yes.mk
new file mode 100644
index 0000000..20ccc01
--- /dev/null
+++ b/mk/ripemd-128=yes.mk
@@ -0,0 +1 @@
+CPPFLAGS_RIPEMD_128 = -DSUPPORT_RIPEMD_128
diff --git a/mk/ripemd-160=no.mk b/mk/ripemd-160=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/ripemd-160=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/ripemd-160=yes.mk b/mk/ripemd-160=yes.mk
new file mode 100644
index 0000000..a7bdaef
--- /dev/null
+++ b/mk/ripemd-160=yes.mk
@@ -0,0 +1 @@
+CPPFLAGS_RIPEMD_160 = -DSUPPORT_RIPEMD_160
diff --git a/mk/ripemd-256=no.mk b/mk/ripemd-256=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/ripemd-256=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/ripemd-256=yes.mk b/mk/ripemd-256=yes.mk
new file mode 100644
index 0000000..5ad2c42
--- /dev/null
+++ b/mk/ripemd-256=yes.mk
@@ -0,0 +1 @@
+CPPFLAGS_RIPEMD_256 = -DSUPPORT_RIPEMD_256
diff --git a/mk/ripemd-320=no.mk b/mk/ripemd-320=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/ripemd-320=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/ripemd-320=yes.mk b/mk/ripemd-320=yes.mk
new file mode 100644
index 0000000..fefe259
--- /dev/null
+++ b/mk/ripemd-320=yes.mk
@@ -0,0 +1 @@
+CPPFLAGS_RIPEMD_320 = -DSUPPORT_RIPEMD_320
diff --git a/mk/sha1=no.mk b/mk/sha1=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/sha1=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/sha1=yes.mk b/mk/sha1=yes.mk
new file mode 100644
index 0000000..c15ebc3
--- /dev/null
+++ b/mk/sha1=yes.mk
@@ -0,0 +1,2 @@
+CPPFLAGS_SHA1 = $(CPPFLAGS_LIBSHA1) -DSUPPORT_SHA0 -DSUPPORT_SHA1
+LDFLAGS_SHA1 = $(LDFLAGS_LIBSHA1)
diff --git a/mk/sha2=no.mk b/mk/sha2=no.mk
new file mode 120000
index 0000000..54299a4
--- /dev/null
+++ b/mk/sha2=no.mk
@@ -0,0 +1 @@
+no \ No newline at end of file
diff --git a/mk/sha2=yes.mk b/mk/sha2=yes.mk
new file mode 100644
index 0000000..cb26c08
--- /dev/null
+++ b/mk/sha2=yes.mk
@@ -0,0 +1,2 @@
+CPPFLAGS_SHA2 = $(CPPFLAGS_LIBSHA2) -DSUPPORT_SHA2
+LDFLAGS_SHA2 = $(LDFLAGS_LIBSHA2)
diff --git a/ripemd-128.c b/ripemd-128.c
index 8e15e07..993c031 100644
--- a/ripemd-128.c
+++ b/ripemd-128.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_RIPEMD_128
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -16,6 +17,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/ripemd-160.c b/ripemd-160.c
index a5c4111..9f3f4dd 100644
--- a/ripemd-160.c
+++ b/ripemd-160.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_RIPEMD_160
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -16,6 +17,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/ripemd-256.c b/ripemd-256.c
index 06f45ef..a892b2b 100644
--- a/ripemd-256.c
+++ b/ripemd-256.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_RIPEMD_256
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -25,6 +26,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/ripemd-320.c b/ripemd-320.c
index ea39bc6..6d9b954 100644
--- a/ripemd-320.c
+++ b/ripemd-320.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_RIPEMD_320
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -25,6 +26,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/sha0.c b/sha0.c
index 5ce216a..3627f61 100644
--- a/sha0.c
+++ b/sha0.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_SHA0
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -8,6 +9,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/sha1.c b/sha1.c
index faeea45..eca40ba 100644
--- a/sha1.c
+++ b/sha1.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_SHA1
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -14,11 +15,11 @@ static struct testcase testcases[] = {
{1, 0, "abc", "a9993e364706816aba3e25717850c26c9cd0d89d"},
{1, 0, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"84983e441c3bd26ebaae4aa1f95129e5e54670f1"},
-#ifdef MASSIVE_TESTS
+# ifdef MASSIVE_TESTS
{0x20000000UL, 0, "A", "df3f26fce8fa7bec2c61d0506749a320ac7dc942"},
{0x41000000UL, 8, "\0", "320c617b0b6ee1b6f9c3271eae135f40cae22c10"},
{0x6000003FUL, 0, "\x84", "b20aa99b62e6a480fd93b4d24b2c19ffac649bb8"},
-#endif
+# endif
{1000000UL, 8, "\0", "bef3595266a65a2ff36b700a75e8ed95c68210b6"},
{0, 1, "\x00", "bb6b3e18f0115b57925241676f5b1ae88747b08a"},
{0, 2, "\x01", "ec6b39952e1a3ec3ab3507185cf756181c84bbe2"},
@@ -30,6 +31,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/sha_224.c b/sha_224.c
index bffca4c..f0a9287 100644
--- a/sha_224.c
+++ b/sha_224.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_SHA2
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -12,11 +13,11 @@ static struct testcase testcases[] = {
{1000UL, 0, "A", "a8d0c66b5c6fdfd836eb3c6d04d32dfe66c3b1f168b488bf4c9c66ce"},
{1005UL, 0, "\x99", "cb00ecd03788bf6c0908401e0eb053ac61f35e7e20a2cfd7bd96d640"},
{1000000UL, 8, "\0", "3a5d74b68f14f3a4b2be9289b8d370672d0b3d2f53bc303c59032df3"},
-#ifdef MASSIVE_TESTS
+# ifdef MASSIVE_TESTS
{0x20000000UL, 0, "A", "c4250083cf8230bf21065b3014baaaf9f76fecefc21f91cf237dedc9"},
{0x41000000UL, 8, "\0", "014674abc5cb980199935695af22fab683748f4261d4c6492b77c543"},
{0x6000003FUL, 0, "\x84", "a654b50b767a8323c5b519f467d8669837142881dc7ad368a7d5ef8f"},
-#endif
+# endif
{1, 0, "abc", "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7"},
{1, 0, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525"},
@@ -30,6 +31,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/sha_256.c b/sha_256.c
index 23bf526..17dda3a 100644
--- a/sha_256.c
+++ b/sha_256.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_SHA2
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -26,6 +27,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/sha_384.c b/sha_384.c
index 754d8d1..802ace0 100644
--- a/sha_384.c
+++ b/sha_384.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_SHA2
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -37,6 +38,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/sha_512.c b/sha_512.c
index c3d07f1..01b9460 100644
--- a/sha_512.c
+++ b/sha_512.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_SHA2
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -31,7 +32,7 @@ static struct testcase testcases[] = {
{1000000UL, 8, "\0",
"ce044bc9fd43269d5bbc946cbebc3bb711341115cc4abdf2edbc3ff2c57ad4b1"
"5deb699bda257fea5aef9c6e55fcf4cf9dc25a8c3ce25f2efe90908379bff7ed"},
-#ifdef MASSIVE_TESTS
+# ifdef MASSIVE_TESTS
{0x20000000UL, 0, "Z",
"da172279f3ebbda95f6b6e1e5f0ebec682c25d3d93561a1624c2fa9009d64c7e"
"9923f3b46bcaf11d39a531f43297992ba4155c7e827bd0f1e194ae7ed6de4cac"},
@@ -41,7 +42,7 @@ static struct testcase testcases[] = {
{0x6000003EUL, 0, "B",
"fd05e13eb771f05190bd97d62647157ea8f1f6949a52bb6daaedbad5f578ec59"
"b1b8d6c4a7ecb2feca6892b4dc138771670a0f3bd577eea326aed40ab7dd58b1"},
-#endif
+# endif
{1, 0, "abc",
"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a"
"2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"},
@@ -52,6 +53,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/sha_512_224.c b/sha_512_224.c
index 8771f88..a95bf92 100644
--- a/sha_512_224.c
+++ b/sha_512_224.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_SHA2
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -12,6 +13,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{
diff --git a/sha_512_256.c b/sha_512_256.c
index 1f41597..f4b168b 100644
--- a/sha_512_256.c
+++ b/sha_512_256.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
-#define TEST
-#include "common.h"
+#ifdef SUPPORT_SHA2
+# define TEST
+# include "common.h"
static struct testcase testcases[] = {
@@ -12,6 +13,12 @@ static struct testcase testcases[] = {
};
+#else
+# define TEST_UNSUPPORTED
+# include "common.h"
+#endif
+
+
int
main(void)
{