aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile17
-rw-r--r--config.mk2
-rw-r--r--libhashsum.h185
-rw-r--r--libhashsum_init_hasher.c12
-rw-r--r--libhashsum_init_sha0_hasher.c2
-rw-r--r--libhashsum_init_sha1_hasher.c2
-rw-r--r--libhashsum_init_sha2_hasher.c93
-rw-r--r--libhashsum_init_sha_224_hasher.c9
-rw-r--r--libhashsum_init_sha_256_hasher.c9
-rw-r--r--libhashsum_init_sha_384_hasher.c9
-rw-r--r--libhashsum_init_sha_512_224_hasher.c9
-rw-r--r--libhashsum_init_sha_512_256_hasher.c9
-rw-r--r--libhashsum_init_sha_512_hasher.c9
-rw-r--r--sha1.c1
-rw-r--r--sha_224.c28
-rw-r--r--sha_256.c31
-rw-r--r--sha_384.c42
-rw-r--r--sha_512.c43
-rw-r--r--sha_512_224.c19
-rw-r--r--sha_512_256.c19
20 files changed, 518 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index dc4acb4..73df328 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,14 @@ OBJ =\
libhashsum_init_ripemd_256_hasher.o\
libhashsum_init_ripemd_320_hasher.o\
libhashsum_init_sha0_hasher.o\
- libhashsum_init_sha1_hasher.o
+ libhashsum_init_sha1_hasher.o\
+ libhashsum_init_sha_224_hasher.o\
+ libhashsum_init_sha_256_hasher.o\
+ libhashsum_init_sha_384_hasher.o\
+ libhashsum_init_sha_512_hasher.o\
+ libhashsum_init_sha_512_224_hasher.o\
+ libhashsum_init_sha_512_256_hasher.o\
+ libhashsum_init_sha2_hasher.o
HDR =\
libhashsum.h\
@@ -41,7 +48,13 @@ TEST =\
ripemd-256.t\
ripemd-320.t\
sha0.t\
- sha1.t
+ sha1.t\
+ sha_224.t\
+ sha_256.t\
+ sha_384.t\
+ sha_512.t\
+ sha_512_256.t\
+ sha_512_256.t
LOBJ = $(OBJ:.o=.lo)
TOBJ = $(TEST:.t=.o)
diff --git a/config.mk b/config.mk
index cdc8b8c..ff855ca 100644
--- a/config.mk
+++ b/config.mk
@@ -5,4 +5,4 @@ CC = c99
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
CFLAGS =
-LDFLAGS = -lsha1
+LDFLAGS = -lsha1 -lsha2
diff --git a/libhashsum.h b/libhashsum.h
index 600a2c0..8bf38c7 100644
--- a/libhashsum.h
+++ b/libhashsum.h
@@ -6,6 +6,7 @@
#include <stdint.h>
#include <libsha1.h>
+#include <libsha2.h>
#if defined(__GNUC__)
@@ -21,15 +22,21 @@
* Hashing algorithm
*/
enum libhashsum_algorithm {
- LIBHASHSUM_MD2, /**< MD2 */
- LIBHASHSUM_MD4, /**< MD4 */
- LIBHASHSUM_MD5, /**< MD5 */
- LIBHASHSUM_RIPEMD_128, /**< RIPEMD-128 */
- LIBHASHSUM_RIPEMD_160, /**< RIPEMD-160 */
- LIBHASHSUM_RIPEMD_256, /**< RIPEMD-256 */
- LIBHASHSUM_RIPEMD_320, /**< RIPEMD-320 */
- LIBHASHSUM_SHA0, /**< SHA0 */
- LIBHASHSUM_SHA1 /**< SHA1 */
+ LIBHASHSUM_MD2, /**< MD2 */
+ LIBHASHSUM_MD4, /**< MD4 */
+ LIBHASHSUM_MD5, /**< MD5 */
+ LIBHASHSUM_RIPEMD_128, /**< RIPEMD-128 */
+ LIBHASHSUM_RIPEMD_160, /**< RIPEMD-160 */
+ LIBHASHSUM_RIPEMD_256, /**< RIPEMD-256 */
+ LIBHASHSUM_RIPEMD_320, /**< RIPEMD-320 */
+ LIBHASHSUM_SHA0, /**< SHA0 */
+ LIBHASHSUM_SHA1, /**< SHA1 */
+ LIBHASHSUM_SHA_224, /**< SHA-224 (SHA2) */
+ LIBHASHSUM_SHA_256, /**< SHA-256 (SHA2) */
+ LIBHASHSUM_SHA_384, /**< SHA-384 (SHA2) */
+ LIBHASHSUM_SHA_512, /**< SHA-512 (SHA2) */
+ LIBHASHSUM_SHA_512_224, /**< SHA-512/224 (SHA2) */
+ LIBHASHSUM_SHA_512_256 /**< SHA-512/256 (SHA2) */
};
@@ -78,6 +85,36 @@ enum libhashsum_algorithm {
*/
#define LIBHASHSUM_SHA1_HASH_SIZE 20
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA_224`
+ */
+#define LIBHASHSUM_SHA_224_HASH_SIZE 28
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA_256`
+ */
+#define LIBHASHSUM_SHA_256_HASH_SIZE 32
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA_384`
+ */
+#define LIBHASHSUM_SHA_384_HASH_SIZE 48
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA_512`
+ */
+#define LIBHASHSUM_SHA_512_HASH_SIZE 64
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA_512_224`
+ */
+#define LIBHASHSUM_SHA_512_224_HASH_SIZE 28
+
+/**
+ * The value of `struct libhashsum_hasher.hash_size` for `LIBHASHSUM_SHA_512_256`
+ */
+#define LIBHASHSUM_SHA_512_256_HASH_SIZE 32
+
/**
* Hash state
@@ -171,6 +208,11 @@ union libhashsum_state {
struct libsha1_state s;
uint8_t sum[20];
} sha0, sha1;
+
+ struct {
+ struct libsha2_state s;
+ uint8_t sum[64];
+ } sha2;
};
@@ -279,8 +321,8 @@ LIBHASHSUM_1_NONNULL_
int libhashsum_init_hasher(struct libhashsum_hasher *this, enum libhashsum_algorithm algorithm);
/**
- * Create an initialised state for a MD2
- * and return hash functions and details
+ * Create an initialised state for MD2
+ * hashing and return hash functions and details
*
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
@@ -291,8 +333,8 @@ LIBHASHSUM_1_NONNULL_
int libhashsum_init_md2_hasher(struct libhashsum_hasher *this);
/**
- * Create an initialised state for a MD4
- * and return hash functions and details
+ * Create an initialised state for MD4
+ * hashing and return hash functions and details
*
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
@@ -303,8 +345,8 @@ LIBHASHSUM_1_NONNULL_
int libhashsum_init_md4_hasher(struct libhashsum_hasher *this);
/**
- * Create an initialised state for a MD5
- * and return hash functions and details
+ * Create an initialised state for MD5
+ * hashing and return hash functions and details
*
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
@@ -315,8 +357,8 @@ LIBHASHSUM_1_NONNULL_
int libhashsum_init_md5_hasher(struct libhashsum_hasher *this);
/**
- * Create an initialised state for a RIPEMD-128
- * and return hash functions and details
+ * Create an initialised state for RIPEMD-128
+ * hashing and return hash functions and details
*
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
@@ -327,8 +369,8 @@ LIBHASHSUM_1_NONNULL_
int libhashsum_init_ripemd_128_hasher(struct libhashsum_hasher *this);
/**
- * Create an initialised state for a RIPEMD-160
- * and return hash functions and details
+ * Create an initialised state for RIPEMD-160
+ * hashing and return hash functions and details
*
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
@@ -339,8 +381,8 @@ LIBHASHSUM_1_NONNULL_
int libhashsum_init_ripemd_160_hasher(struct libhashsum_hasher *this);
/**
- * Create an initialised state for a RIPEMD-256
- * and return hash functions and details
+ * Create an initialised state for RIPEMD-256
+ * hashing and return hash functions and details
*
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
@@ -351,8 +393,8 @@ LIBHASHSUM_1_NONNULL_
int libhashsum_init_ripemd_256_hasher(struct libhashsum_hasher *this);
/**
- * Create an initialised state for a RIPEMD-320
- * and return hash functions and details
+ * Create an initialised state for RIPEMD-320
+ * hashing and return hash functions and details
*
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
@@ -363,8 +405,8 @@ LIBHASHSUM_1_NONNULL_
int libhashsum_init_ripemd_320_hasher(struct libhashsum_hasher *this);
/**
- * Create an initialised state for a SHA0
- * and return hash functions and details
+ * Create an initialised state for SHA0
+ * hashing and return hash functions and details
*
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
@@ -375,8 +417,8 @@ LIBHASHSUM_1_NONNULL_
int libhashsum_init_sha0_hasher(struct libhashsum_hasher *this);
/**
- * Create an initialised state for a SHA1
- * and return hash functions and details
+ * Create an initialised state for SHA1
+ * hashing and return hash functions and details
*
* @param this The output parameter for the functions, details, and state
* @return 0 on success, -1 on failure
@@ -386,5 +428,94 @@ int libhashsum_init_sha0_hasher(struct libhashsum_hasher *this);
LIBHASHSUM_1_NONNULL_
int libhashsum_init_sha1_hasher(struct libhashsum_hasher *this);
+/**
+ * Create an initialised state for SHA-224 (SHA2)
+ * hashing and return hash functions and details
+ *
+ * @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
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha_224_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for SHA-256 (SHA2)
+ * hashing and return hash functions and details
+ *
+ * @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
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha_256_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for SHA-384 (SHA2)
+ * hashing and return hash functions and details
+ *
+ * @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
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha_384_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for SHA-512 (SHA2)
+ * hashing and return hash functions and details
+ *
+ * @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
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha_512_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for SHA-512/224 (SHA2)
+ * hashing and return hash functions and details
+ *
+ * @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
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha_512_224_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for SHA-512/256 (SHA2)
+ * hashing and return hash functions and details
+ *
+ * @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
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha_512_256_hasher(struct libhashsum_hasher *this);
+
+/**
+ * Create an initialised state for SHA2
+ * hashing and return hash functions and details
+ *
+ * @param this The output parameter for the functions, details, and state
+ * @param algobits 32 for a 32-bit algorithm, 64 for a 64-bit algorithm
+ * @param hashbits Hash output size in bits
+ * @return 0 on success, -1 on failure
+ *
+ * @throws EINVAL `algobits` is invalid (neither 32 nor 64)
+ * @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)
+ */
+LIBHASHSUM_1_NONNULL_
+int libhashsum_init_sha2_hasher(struct libhashsum_hasher *this, unsigned algobits, size_t hashbits);
+
#endif
diff --git a/libhashsum_init_hasher.c b/libhashsum_init_hasher.c
index 91689ca..d747e52 100644
--- a/libhashsum_init_hasher.c
+++ b/libhashsum_init_hasher.c
@@ -24,6 +24,18 @@ libhashsum_init_hasher(struct libhashsum_hasher *hasher, enum libhashsum_algorit
return libhashsum_init_sha0_hasher(hasher);
case LIBHASHSUM_SHA1:
return libhashsum_init_sha1_hasher(hasher);
+ case LIBHASHSUM_SHA_224:
+ return libhashsum_init_sha_224_hasher(hasher);
+ case LIBHASHSUM_SHA_256:
+ return libhashsum_init_sha_256_hasher(hasher);
+ case LIBHASHSUM_SHA_384:
+ return libhashsum_init_sha_384_hasher(hasher);
+ case LIBHASHSUM_SHA_512:
+ return libhashsum_init_sha_512_hasher(hasher);
+ case LIBHASHSUM_SHA_512_224:
+ return libhashsum_init_sha_512_224_hasher(hasher);
+ case LIBHASHSUM_SHA_512_256:
+ return libhashsum_init_sha_512_256_hasher(hasher);
default:
errno = EINVAL;
return -1;
diff --git a/libhashsum_init_sha0_hasher.c b/libhashsum_init_sha0_hasher.c
index 3ed5744..e9c0ea4 100644
--- a/libhashsum_init_sha0_hasher.c
+++ b/libhashsum_init_sha0_hasher.c
@@ -60,7 +60,7 @@ libhashsum_init_sha0_hasher(struct libhashsum_hasher *this)
this->input_block_size = 64U;
this->hash_size = sizeof(this->state.sha0.sum);
this->hash_output = NULL;
- this->supports_non_whole_bytes = 0;
+ this->supports_non_whole_bytes = 1;
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
diff --git a/libhashsum_init_sha1_hasher.c b/libhashsum_init_sha1_hasher.c
index 6058b73..25c7496 100644
--- a/libhashsum_init_sha1_hasher.c
+++ b/libhashsum_init_sha1_hasher.c
@@ -60,7 +60,7 @@ libhashsum_init_sha1_hasher(struct libhashsum_hasher *this)
this->input_block_size = 64U;
this->hash_size = sizeof(this->state.sha1.sum);
this->hash_output = NULL;
- this->supports_non_whole_bytes = 0;
+ this->supports_non_whole_bytes = 1;
this->process = &process;
this->finalise_const = &finalise_const;
this->finalise = &finalise;
diff --git a/libhashsum_init_sha2_hasher.c b/libhashsum_init_sha2_hasher.c
new file mode 100644
index 0000000..ab64517
--- /dev/null
+++ b/libhashsum_init_sha2_hasher.c
@@ -0,0 +1,93 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+LIBHASHSUM_1_NONNULL_
+static size_t
+process(struct libhashsum_hasher *this, const void *data, size_t bytes)
+{
+ const uint8_t *m = data;
+ int i;
+ bytes -= bytes & (this->input_block_size - 1U);
+ if (bytes > SIZE_MAX >> 3) {
+ for (i = 0; i < 8; i++) {
+ libsha2_update(&this->state.sha2.s, m, bytes);
+ m = &m[bytes >> 3];
+ }
+ } else if (bytes) {
+ libsha2_update(&this->state.sha2.s, m, bytes << 3);
+ }
+ return bytes;
+}
+
+
+LIBHASHSUM_1_NONNULL_
+static int
+finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, unsigned extra_bits)
+{
+ const uint8_t *m = data;
+ size_t r;
+
+ if (extra_bits > 7U) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ r = process(this, m, bytes);
+ m = &m[r];
+ bytes -= r;
+
+ libsha2_digest(&this->state.sha2.s, data, (bytes << 3) | extra_bits, this->state.sha2.sum);
+ memset(&this->state.sha2.s, 0, sizeof(this->state.sha2.s));
+ this->hash_output = this->state.sha2.sum;
+ return 0;
+}
+
+
+LIBHASHSUM_1_NONNULL_
+static int
+finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extra_bits, size_t size)
+{
+ (void) size;
+ return finalise_const(this, data, bytes, extra_bits);
+}
+
+
+int
+libhashsum_init_sha2_hasher(struct libhashsum_hasher *this, unsigned algobits, size_t hashbits)
+{
+ enum libsha2_algorithm algo;
+
+ if (algobits == 32U && hashbits == 224U) {
+ this->algorithm = LIBHASHSUM_SHA_224;
+ algo = LIBSHA2_224;
+ } else if (algobits == 32U && hashbits == 256U) {
+ this->algorithm = LIBHASHSUM_SHA_256;
+ algo = LIBSHA2_256;
+ } else if (algobits == 64U && hashbits == 384U) {
+ this->algorithm = LIBHASHSUM_SHA_384;
+ algo = LIBSHA2_384;
+ } else if (algobits == 64U && hashbits == 512U) {
+ this->algorithm = LIBHASHSUM_SHA_512;
+ algo = LIBSHA2_512;
+ } else if (algobits == 64U && hashbits == 224U) {
+ this->algorithm = LIBHASHSUM_SHA_512_224;
+ algo = LIBSHA2_512_224;
+ } else if (algobits == 64U && hashbits == 256U) {
+ this->algorithm = LIBHASHSUM_SHA_512_256;
+ algo = LIBSHA2_512_256;
+ } else {
+ errno = EINVAL;
+ return -1;
+ }
+
+ this->input_block_size = (size_t)algobits << 1;
+ this->hash_size = hashbits >> 3;
+ this->hash_output = NULL;
+ this->supports_non_whole_bytes = 1;
+ this->process = &process;
+ this->finalise_const = &finalise_const;
+ this->finalise = &finalise;
+ libsha2_init(&this->state.sha2.s, algo);
+ return 0;
+}
diff --git a/libhashsum_init_sha_224_hasher.c b/libhashsum_init_sha_224_hasher.c
new file mode 100644
index 0000000..cbeb5bb
--- /dev/null
+++ b/libhashsum_init_sha_224_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_sha_224_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_sha2_hasher(this, 32, 224);
+}
diff --git a/libhashsum_init_sha_256_hasher.c b/libhashsum_init_sha_256_hasher.c
new file mode 100644
index 0000000..213cbd1
--- /dev/null
+++ b/libhashsum_init_sha_256_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_sha_256_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_sha2_hasher(this, 32, 256);
+}
diff --git a/libhashsum_init_sha_384_hasher.c b/libhashsum_init_sha_384_hasher.c
new file mode 100644
index 0000000..605f181
--- /dev/null
+++ b/libhashsum_init_sha_384_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_sha_384_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_sha2_hasher(this, 64, 384);
+}
diff --git a/libhashsum_init_sha_512_224_hasher.c b/libhashsum_init_sha_512_224_hasher.c
new file mode 100644
index 0000000..b74a6ab
--- /dev/null
+++ b/libhashsum_init_sha_512_224_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_sha_512_224_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_sha2_hasher(this, 64, 224);
+}
diff --git a/libhashsum_init_sha_512_256_hasher.c b/libhashsum_init_sha_512_256_hasher.c
new file mode 100644
index 0000000..22da9a8
--- /dev/null
+++ b/libhashsum_init_sha_512_256_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_sha_512_256_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_sha2_hasher(this, 64, 256);
+}
diff --git a/libhashsum_init_sha_512_hasher.c b/libhashsum_init_sha_512_hasher.c
new file mode 100644
index 0000000..a626fe7
--- /dev/null
+++ b/libhashsum_init_sha_512_hasher.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libhashsum_init_sha_512_hasher(struct libhashsum_hasher *this)
+{
+ return libhashsum_init_sha2_hasher(this, 64, 512);
+}
diff --git a/sha1.c b/sha1.c
index 3ab0776..ebba4ca 100644
--- a/sha1.c
+++ b/sha1.c
@@ -4,6 +4,7 @@
static struct testcase testcases[] = {
+ {1, 0, "", "da39a3ee5e6b4b0d3255bfef95601890afd80709"},
{1, 0, "\xff", "85e53271e14006f0265921d02d4d736cdc580b0b"},
{1, 0, "\xe5\xe0\x99\x24", "d1dffbc8a175dd8eebe0da87b1792b6dc1018e82"},
{56UL, 8, "\0", "9438e360f578e12c0e0e8ed28e2c125c1cefee16"},
diff --git a/sha_224.c b/sha_224.c
new file mode 100644
index 0000000..3634da9
--- /dev/null
+++ b/sha_224.c
@@ -0,0 +1,28 @@
+/* See LICENSE file for copyright and license details. */
+#define TEST
+#include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "", "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f"},
+ {1, 0, "\xff", "e33f9d75e6ae1369dbabf81b96b4591ae46bba30b591a6b6c62542b5"},
+ {1, 0, "\xe5\xe0\x99$", "fd19e74690d291467ce59f077df311638f1c3a46e510d0e49a67062d"},
+ {56UL, 8, "\0", "5c3e25b69d0ea26f260cfae87e23759e1eca9d1ecc9fbf3c62266804"},
+ {1000UL, 0, "Q", "3706197f66890a41779dc8791670522e136fafa24874685715bd0a8a"},
+ {1000UL, 0, "A", "a8d0c66b5c6fdfd836eb3c6d04d32dfe66c3b1f168b488bf4c9c66ce"},
+ {1005UL, 0, "\x99", "cb00ecd03788bf6c0908401e0eb053ac61f35e7e20a2cfd7bd96d640"},
+ {1000000UL, 8, "\0", "3a5d74b68f14f3a4b2be9289b8d370672d0b3d2f53bc303c59032df3"},
+ {0x20000000UL, 0, "A", "c4250083cf8230bf21065b3014baaaf9f76fecefc21f91cf237dedc9"},
+ {0x41000000UL, 8, "\0", "014674abc5cb980199935695af22fab683748f4261d4c6492b77c543"},
+ {0x6000003FUL, 0, "\x84", "a654b50b767a8323c5b519f467d8669837142881dc7ad368a7d5ef8f"},
+ {1, 0, "abc", "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7"},
+ {1, 0, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525"}
+};
+
+
+int
+main(void)
+{
+ TEST_MAIN("SHA-224", SHA_224);
+}
diff --git a/sha_256.c b/sha_256.c
new file mode 100644
index 0000000..d072a95
--- /dev/null
+++ b/sha_256.c
@@ -0,0 +1,31 @@
+/* See LICENSE file for copyright and license details. */
+#define TEST
+#include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
+ {1, 0, "\xbd", "68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b"},
+ {1, 0, "\xc9\x8c\x8eU", "7abc22c0ae5af26ce93dbb94433a0e0b2e119d014f8e7f65bd56c61ccccd9504"},
+ {55UL, 8, "\0", "02779466cdec163811d078815c633f21901413081449002f24aa3e80f0b88ef7"},
+ {56UL, 8, "\0", "d4817aa5497628e7c77e6b606107042bbba3130888c5f47a375e6179be789fbb"},
+ {57UL, 8, "\0", "65a16cb7861335d5ace3c60718b5052e44660726da4cd13bb745381b235a1785"},
+ {64UL, 8, "\0", "f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b"},
+ {1000UL, 8, "\0", "541b3e9daa09b20bf85fa273e5cbd3e80185aa4ec298e765db87742b70138a53"},
+ {1000UL, 0, "A", "c2e686823489ced2017f6059b8b239318b6364f6dcd835d0a519105a1eadd6e4"},
+ {1005UL, 0, "U", "f4d62ddec0f3dd90ea1380fa16a5ff8dc4c54b21740650f24afc4120903552b0"},
+ {1000000UL, 8, "\0", "d29751f2649b32ff572b5e0a9f541ea660a50f94ff0beedfb0b692b924cc8025"},
+ {0x20000000UL, 0, "Z", "15a1868c12cc53951e182344277447cd0979536badcc512ad24c67e9b2d4f3dd"},
+ {0x41000000UL, 8, "\0", "461c19a93bd4344f9215f5ec64357090342bc66b15a148317d276e31cbc20b53"},
+ {0x6000003EUL, 0, "B", "c23ce8a7895f4b21ec0daf37920ac0a262a220045a03eb2dfed48ef9b05aabea"},
+ {1, 0, "abc", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"},
+ {1, 0, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"}
+};
+
+
+int
+main(void)
+{
+ TEST_MAIN("SHA-256", SHA_256);
+}
diff --git a/sha_384.c b/sha_384.c
new file mode 100644
index 0000000..51a747e
--- /dev/null
+++ b/sha_384.c
@@ -0,0 +1,42 @@
+/* See LICENSE file for copyright and license details. */
+#define TEST
+#include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "",
+ "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"},
+ {111UL, 8, "\0",
+ "435770712c611be7293a66dd0dc8d1450dc7ff7337bfe115bf058ef2eb9bed09cee85c26963a5bcc0905dc2df7cc6a76"},
+ {112UL, 8, "\0",
+ "3e0cbf3aee0e3aa70415beae1bd12dd7db821efa446440f12132edffce76f635e53526a111491e75ee8e27b9700eec20"},
+ {113UL, 8, "\0",
+ "6be9af2cf3cd5dd12c8d9399ec2b34e66034fbd699d4e0221d39074172a380656089caafe8f39963f94cc7c0a07e3d21"},
+ {122UL, 8, "\0",
+ "12a72ae4972776b0db7d73d160a15ef0d19645ec96c7f816411ab780c794aa496a22909d941fe671ed3f3caee900bdd5"},
+ {1000UL, 8, "\0",
+ "aae017d4ae5b6346dd60a19d52130fb55194b6327dd40b89c11efc8222292de81e1a23c9b59f9f58b7f6ad463fa108ca"},
+ {1000UL, 0, "A",
+ "7df01148677b7f18617eee3a23104f0eed6bb8c90a6046f715c9445ff43c30d69e9e7082de39c3452fd1d3afd9ba0689"},
+ {1005UL, 0, "U",
+ "1bb8e256da4a0d1e87453528254f223b4cb7e49c4420dbfa766bba4adba44eeca392ff6a9f565bc347158cc970ce44ec"},
+ {1000000UL, 8, "\0",
+ "8a1979f9049b3fff15ea3a43a4cf84c634fd14acad1c333fecb72c588b68868b66a994386dc0cd1687b9ee2e34983b81"},
+ {0x20000000UL, 0, "Z",
+ "18aded227cc6b562cc7fb259e8f404549e52914531aa1c5d85167897c779cc4b25d0425fd1590e40bd763ec3f4311c1a"},
+ {0x41000000UL, 8, "\0",
+ "83ab05ca483abe3faa597ad524d31291ae827c5be2b3efcb6391bfed31ccd937b6135e0378c6c7f598857a7c516f207a"},
+ {0x6000003EUL, 0, "B",
+ "cf852304f8d80209351b37ce69ca7dcf34972b4edb7817028ec55ab67ad3bc96eecb8241734258a85d2afce65d4571e2"},
+ {1, 0, "abc",
+ "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7"},
+ {1, 0, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
+ "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039"}
+};
+
+
+int
+main(void)
+{
+ TEST_MAIN("SHA-384", SHA_384);
+}
diff --git a/sha_512.c b/sha_512.c
new file mode 100644
index 0000000..36e7c81
--- /dev/null
+++ b/sha_512.c
@@ -0,0 +1,43 @@
+/* See LICENSE file for copyright and license details. */
+#define TEST
+#include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "",
+ "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce"
+ "47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"},
+ {111UL, 8, "\0",
+ "77ddd3a542e530fd047b8977c657ba6ce72f1492e360b2b2212cd264e75ec03882e4ff0525517ab4207d14c70c2259ba88d4d335ee0e7e20543d22102ab1788c"},
+ {112UL, 8, "\0",
+ "2be2e788c8a8adeaa9c89a7f78904cacea6e39297d75e0573a73c756234534d6627ab4156b48a6657b29ab8beb73334040ad39ead81446bb09c70704ec707952"},
+ {113UL, 8, "\0",
+ "0e67910bcf0f9ccde5464c63b9c850a12a759227d16b040d98986d54253f9f34322318e56b8feb86c5fb2270ed87f31252f7f68493ee759743909bd75e4bb544"},
+ {122UL, 8, "\0",
+ "4f3f095d015be4a7a7cc0b8c04da4aa09e74351e3a97651f744c23716ebd9b3e822e5077a01baa5cc0ed45b9249e88ab343d4333539df21ed229da6f4a514e0f"},
+ {1000UL, 8, "\0",
+ "ca3dff61bb23477aa6087b27508264a6f9126ee3a004f53cb8db942ed345f2f2d229b4b59c859220a1cf1913f34248e3803bab650e849a3d9a709edc09ae4a76"},
+ {1000UL, 0, "A",
+ "329c52ac62d1fe731151f2b895a00475445ef74f50b979c6f7bb7cae349328c1d4cb4f7261a0ab43f936a24b000651d4a824fcdd577f211aef8f806b16afe8af"},
+ {1005UL, 0, "U",
+ "59f5e54fe299c6a8764c6b199e44924a37f59e2b56c3ebad939b7289210dc8e4c21b9720165b0f4d4374c90f1bf4fb4a5ace17a1161798015052893a48c3d161"},
+ {1000000UL, 8, "\0",
+ "ce044bc9fd43269d5bbc946cbebc3bb711341115cc4abdf2edbc3ff2c57ad4b15deb699bda257fea5aef9c6e55fcf4cf9dc25a8c3ce25f2efe90908379bff7ed"},
+ {0x20000000UL, 0, "Z",
+ "da172279f3ebbda95f6b6e1e5f0ebec682c25d3d93561a1624c2fa9009d64c7e9923f3b46bcaf11d39a531f43297992ba4155c7e827bd0f1e194ae7ed6de4cac"},
+ {0x41000000UL, 8, "\0",
+ "14b1be901cb43549b4d831e61e5f9df1c791c85b50e85f9d6bc64135804ad43ce8402750edbe4e5c0fc170b99cf78b9f4ecb9c7e02a157911d1bd1832d76784f"},
+ {0x6000003EUL, 0, "B",
+ "fd05e13eb771f05190bd97d62647157ea8f1f6949a52bb6daaedbad5f578ec59b1b8d6c4a7ecb2feca6892b4dc138771670a0f3bd577eea326aed40ab7dd58b1"},
+ {1, 0, "abc",
+ "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"},
+ {1, 0, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
+ "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909"}
+};
+
+
+int
+main(void)
+{
+ TEST_MAIN("SHA-512", SHA_512);
+}
diff --git a/sha_512_224.c b/sha_512_224.c
new file mode 100644
index 0000000..8771f88
--- /dev/null
+++ b/sha_512_224.c
@@ -0,0 +1,19 @@
+/* See LICENSE file for copyright and license details. */
+#define TEST
+#include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "", "6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4"},
+ {1000UL, 0, "A", "3000c31a7ab8e9c760257073c4d3be370fab6d1d28eb027c6d874f29"},
+ {1, 0, "abc", "4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa"},
+ {1, 0, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
+ "23fec5bb94d60b23308192640b0c453335d664734fe40e7268674af9"}
+};
+
+
+int
+main(void)
+{
+ TEST_MAIN("SHA-512/224", SHA_512_224);
+}
diff --git a/sha_512_256.c b/sha_512_256.c
new file mode 100644
index 0000000..1f41597
--- /dev/null
+++ b/sha_512_256.c
@@ -0,0 +1,19 @@
+/* See LICENSE file for copyright and license details. */
+#define TEST
+#include "common.h"
+
+
+static struct testcase testcases[] = {
+ {1, 0, "", "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a"},
+ {1000UL, 0, "A", "6ad592c8991fa0fc0fc78b6c2e73f3b55db74afeb1027a5aeacb787fb531e64a"},
+ {1, 0, "abc", "53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23"},
+ {1, 0, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
+ "3928e184fb8690f840da3988121d31be65cb9d3ef83ee6146feac861e19b563a"}
+};
+
+
+int
+main(void)
+{
+ TEST_MAIN("SHA-512/256", SHA_512_256);
+}