diff options
-rw-r--r-- | common.h | 8 | ||||
-rw-r--r-- | libhashsum.h | 11 | ||||
-rw-r--r-- | libhashsum_init_md2_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_md4_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_md5_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_ripemd_128_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_ripemd_160_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_ripemd_256_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_ripemd_320_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_sha0_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_sha1_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_sha2_hasher.c | 6 |
12 files changed, 34 insertions, 0 deletions
@@ -89,6 +89,14 @@ run_tests(const char *name, enum libhashsum_algorithm algorithm, size_t hash_siz fprintf(stderr, "libhashsum_init_hasher returned unexpected value in .algorithm\n"); return 2; } + if (!hasher.algorithm_string) { + fprintf(stderr, "libhashsum_init_hasher returned NULL pointer in .algorithm_string\n"); + return 2; + } + if (strcmp(hasher.algorithm_string, name)) { + fprintf(stderr, "libhashsum_init_hasher returned unexpected value in .algorithm_string\n"); + return 2; + } if (hasher.hash_size != hash_size) { fprintf(stderr, "libhashsum_init_hasher returned unexpected value in .hash_size\n"); return 2; diff --git a/libhashsum.h b/libhashsum.h index 1e453b3..203ec10 100644 --- a/libhashsum.h +++ b/libhashsum.h @@ -263,6 +263,17 @@ struct libhashsum_hasher { enum libhashsum_algorithm algorithm; /** + * A string describing the used hash + * algorithm and parameters + * + * This may be pointer to a buffer in + * `.state` + * + * @since 1.0 + */ + const char *algorithm_string; + + /** * The number of bytes required for each * call to `.process_block` * diff --git a/libhashsum_init_md2_hasher.c b/libhashsum_init_md2_hasher.c index dd20429..6ea2063 100644 --- a/libhashsum_init_md2_hasher.c +++ b/libhashsum_init_md2_hasher.c @@ -134,6 +134,7 @@ int libhashsum_init_md2_hasher(struct libhashsum_hasher *this) { this->algorithm = LIBHASHSUM_MD2; + this->algorithm_string = "MD2"; this->input_block_size = 16U; this->hash_size = sizeof(this->state.md2.sum); this->hash_output = NULL; diff --git a/libhashsum_init_md4_hasher.c b/libhashsum_init_md4_hasher.c index fc4d5d9..22626a9 100644 --- a/libhashsum_init_md4_hasher.c +++ b/libhashsum_init_md4_hasher.c @@ -177,6 +177,7 @@ int libhashsum_init_md4_hasher(struct libhashsum_hasher *this) { this->algorithm = LIBHASHSUM_MD4; + this->algorithm_string = "MD4"; this->input_block_size = 64U; this->hash_size = sizeof(this->state.md4.h.sum); this->hash_output = NULL; diff --git a/libhashsum_init_md5_hasher.c b/libhashsum_init_md5_hasher.c index 8c06527..6888f6e 100644 --- a/libhashsum_init_md5_hasher.c +++ b/libhashsum_init_md5_hasher.c @@ -192,6 +192,7 @@ int libhashsum_init_md5_hasher(struct libhashsum_hasher *this) { this->algorithm = LIBHASHSUM_MD5; + this->algorithm_string = "MD5"; this->input_block_size = 64U; this->hash_size = sizeof(this->state.md5.h.sum); this->hash_output = NULL; diff --git a/libhashsum_init_ripemd_128_hasher.c b/libhashsum_init_ripemd_128_hasher.c index 699de97..39c5f1c 100644 --- a/libhashsum_init_ripemd_128_hasher.c +++ b/libhashsum_init_ripemd_128_hasher.c @@ -213,6 +213,7 @@ int libhashsum_init_ripemd_128_hasher(struct libhashsum_hasher *this) { this->algorithm = LIBHASHSUM_RIPEMD_128; + this->algorithm_string = "RIPEMD-128"; this->input_block_size = 64U; this->hash_size = sizeof(this->state.ripemd_128.h.sum); this->hash_output = NULL; diff --git a/libhashsum_init_ripemd_160_hasher.c b/libhashsum_init_ripemd_160_hasher.c index b37aec8..8b37b0a 100644 --- a/libhashsum_init_ripemd_160_hasher.c +++ b/libhashsum_init_ripemd_160_hasher.c @@ -216,6 +216,7 @@ int libhashsum_init_ripemd_160_hasher(struct libhashsum_hasher *this) { this->algorithm = LIBHASHSUM_RIPEMD_160; + this->algorithm_string = "RIPEMD-160"; this->input_block_size = 64U; this->hash_size = sizeof(this->state.ripemd_160.h.sum); this->hash_output = NULL; diff --git a/libhashsum_init_ripemd_256_hasher.c b/libhashsum_init_ripemd_256_hasher.c index beda29f..6ba8aa0 100644 --- a/libhashsum_init_ripemd_256_hasher.c +++ b/libhashsum_init_ripemd_256_hasher.c @@ -224,6 +224,7 @@ int libhashsum_init_ripemd_256_hasher(struct libhashsum_hasher *this) { this->algorithm = LIBHASHSUM_RIPEMD_256; + this->algorithm_string = "RIPEMD-256"; this->input_block_size = 64U; this->hash_size = sizeof(this->state.ripemd_256.h.sum); this->hash_output = NULL; diff --git a/libhashsum_init_ripemd_320_hasher.c b/libhashsum_init_ripemd_320_hasher.c index c9cda07..2bb2383 100644 --- a/libhashsum_init_ripemd_320_hasher.c +++ b/libhashsum_init_ripemd_320_hasher.c @@ -230,6 +230,7 @@ int libhashsum_init_ripemd_320_hasher(struct libhashsum_hasher *this) { this->algorithm = LIBHASHSUM_RIPEMD_320; + this->algorithm_string = "RIPEMD-320"; this->input_block_size = 64U; this->hash_size = sizeof(this->state.ripemd_320.h.sum); this->hash_output = NULL; diff --git a/libhashsum_init_sha0_hasher.c b/libhashsum_init_sha0_hasher.c index 6efd8fc..eddb750 100644 --- a/libhashsum_init_sha0_hasher.c +++ b/libhashsum_init_sha0_hasher.c @@ -58,6 +58,7 @@ int libhashsum_init_sha0_hasher(struct libhashsum_hasher *this) { this->algorithm = LIBHASHSUM_SHA0; + this->algorithm_string = "SHA0"; this->input_block_size = 64U; this->hash_size = sizeof(this->state.sha0.sum); this->hash_output = NULL; diff --git a/libhashsum_init_sha1_hasher.c b/libhashsum_init_sha1_hasher.c index a3aef8e..023e856 100644 --- a/libhashsum_init_sha1_hasher.c +++ b/libhashsum_init_sha1_hasher.c @@ -58,6 +58,7 @@ int libhashsum_init_sha1_hasher(struct libhashsum_hasher *this) { this->algorithm = LIBHASHSUM_SHA1; + this->algorithm_string = "SHA1"; this->input_block_size = 64U; this->hash_size = sizeof(this->state.sha1.sum); this->hash_output = NULL; diff --git a/libhashsum_init_sha2_hasher.c b/libhashsum_init_sha2_hasher.c index 9246e48..b76f059 100644 --- a/libhashsum_init_sha2_hasher.c +++ b/libhashsum_init_sha2_hasher.c @@ -62,21 +62,27 @@ libhashsum_init_sha2_hasher(struct libhashsum_hasher *this, unsigned algobits, s if (algobits == 32U && hashbits == 224U) { this->algorithm = LIBHASHSUM_SHA_224; algo = LIBSHA2_224; + this->algorithm_string = "SHA-224"; } else if (algobits == 32U && hashbits == 256U) { this->algorithm = LIBHASHSUM_SHA_256; algo = LIBSHA2_256; + this->algorithm_string = "SHA-256"; } else if (algobits == 64U && hashbits == 384U) { this->algorithm = LIBHASHSUM_SHA_384; algo = LIBSHA2_384; + this->algorithm_string = "SHA-384"; } else if (algobits == 64U && hashbits == 512U) { this->algorithm = LIBHASHSUM_SHA_512; algo = LIBSHA2_512; + this->algorithm_string = "SHA-512"; } else if (algobits == 64U && hashbits == 224U) { this->algorithm = LIBHASHSUM_SHA_512_224; algo = LIBSHA2_512_224; + this->algorithm_string = "SHA-512/224"; } else if (algobits == 64U && hashbits == 256U) { this->algorithm = LIBHASHSUM_SHA_512_256; algo = LIBSHA2_512_256; + this->algorithm_string = "SHA-512/256"; } else { errno = EINVAL; return -1; |