diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | libhashsum.h | 30 | ||||
-rw-r--r-- | libhashsum_get_relative_performance.c | 74 | ||||
-rw-r--r-- | libhashsum_init_blake224_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_blake256_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_blake2b_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_blake2s_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_blake384_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_blake512_hasher.c | 1 | ||||
-rw-r--r-- | libhashsum_init_keccak__.c | 20 | ||||
-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 | 1 |
20 files changed, 93 insertions, 48 deletions
@@ -28,6 +28,7 @@ OBJ_PUBLIC =\ libhashsum_init_hasher.o\ libhashsum_get_algorithm_from_string.o\ libhashsum_init_hasher_from_string.o\ + libhashsum_get_relative_performance.o\ libhashsum_init_md2_hasher.o\ libhashsum_init_md4_hasher.o\ libhashsum_init_md5_hasher.o\ diff --git a/libhashsum.h b/libhashsum.h index 7673a74..01d8fbd 100644 --- a/libhashsum.h +++ b/libhashsum.h @@ -9,10 +9,12 @@ # define LIBHASHSUM_USERET_ __attribute__((__warn_unused_result__)) # define LIBHASHSUM_1_NONNULL_ __attribute__((__nonnull__(1))) # define LIBHASHSUM_NONNULL_ __attribute__((__nonnull__)) +# define LIBHASHSUM_PURE_ __attribute__((__pure__)) #else # define LIBHASHSUM_USERET_ # define LIBHASHSUM_1_NONNULL_ # define LIBHASHSUM_NONNULL_ +# define LIBHASHSUM_PURE_ #endif @@ -481,18 +483,6 @@ struct libhashsum_hasher { unsigned char hash_excess_bits; /* TODO test */ /** - * Estimate, approximate performance relative to - * some unspecified reference point - * - * Higher is faster - * - * If the value is zero, no estimate is available - * - * @since 1.1 - */ - uint64_t relative_performance; /* TODO man */ - - /** * Update the hash state given additional * input data * @@ -697,6 +687,22 @@ LIBHASHSUM_NONNULL_ int libhashsum_init_hasher_from_string(struct libhashsum_hasher *this, const char *algorithm); /** + * Get an estimate, approximate performance relative, + * to some unspecified reference point, for a configured + * hash function + * + * Higher is faster + * + * @param this The hash function details + * @return Estimate, approximate performance value, + * 0 no estimate is available + * + * @since 1.1 + */ +LIBHASHSUM_NONNULL_ LIBHASHSUM_PURE_ +uint64_t libhashsum_get_relative_performance(struct libhashsum_hasher *this); + +/** * Create an initialised state for MD2 * hashing and return hash functions and details * diff --git a/libhashsum_get_relative_performance.c b/libhashsum_get_relative_performance.c new file mode 100644 index 0000000..3759120 --- /dev/null +++ b/libhashsum_get_relative_performance.c @@ -0,0 +1,74 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +#ifdef LIBHASHSUM_INCLUDE_LIBKECCAK_STATE +LIBHASHSUM_NONNULL_ LIBHASHSUM_PURE_ +static uint64_t +estimate_performance_keccak(const struct libhashsum_hasher *this) +{ + long int bitrate = this->state.keccak.s.r; + long int statesize = this->state.keccak.s.b; + uint64_t base = 22517998136852480ULL / (uint64_t)bitrate; + switch (statesize) { + case 1600: + return base / 368ULL; + case 800: + return base / 2042ULL; + case 400: + return base / 1858ULL; + case 200: + return base / 1747ULL; + default: + return 0; + } +} +#else +# define estimate_performance_keccak(...) 0 +#endif + + +uint64_t +libhashsum_get_relative_performance(struct libhashsum_hasher *this) +{ + switch (this->algorithm) { + case LIBHASHSUM_MD2: return 636028372060772ULL; + case LIBHASHSUM_MD4: return 45941107656992312ULL; + case LIBHASHSUM_MD5: return 28263143931935570ULL; + case LIBHASHSUM_RIPEMD_128: return 21773847511300567ULL; + case LIBHASHSUM_RIPEMD_160: return 12306656764693412ULL; + case LIBHASHSUM_RIPEMD_256: return 24811564606436716ULL; + case LIBHASHSUM_RIPEMD_320: return 12450536920018911ULL; + case LIBHASHSUM_SHA0: return 54814763498234941ULL; + case LIBHASHSUM_SHA1: return 259304505616284017ULL; /* TODO this value applies when x86-optimisation is used */ + case LIBHASHSUM_SHA_224: + case LIBHASHSUM_SHA_256: return 277891737809888154ULL; /* TODO this value applies when x86-optimisation is used */ + case LIBHASHSUM_SHA_384: + case LIBHASHSUM_SHA_512: + case LIBHASHSUM_SHA_512_224: + case LIBHASHSUM_SHA_512_256: return 32055903736688859ULL; + case LIBHASHSUM_BLAKE224: + case LIBHASHSUM_BLAKE256: return 13377838180743567ULL; + case LIBHASHSUM_BLAKE384: + case LIBHASHSUM_BLAKE512: return 21062754517124396ULL; + case LIBHASHSUM_BLAKE2S: return 16309869015413425ULL; + case LIBHASHSUM_BLAKE2B: return 24633935505133251ULL; + case LIBHASHSUM_KECCAK: + case LIBHASHSUM_KECCAK_224: + case LIBHASHSUM_KECCAK_256: + case LIBHASHSUM_KECCAK_384: + case LIBHASHSUM_KECCAK_512: + case LIBHASHSUM_SHA3_224: + case LIBHASHSUM_SHA3_256: + case LIBHASHSUM_SHA3_384: + case LIBHASHSUM_SHA3_512: + case LIBHASHSUM_SHAKE128: + case LIBHASHSUM_SHAKE256: + case LIBHASHSUM_SHAKE512: + case LIBHASHSUM_RAWSHAKE128: + case LIBHASHSUM_RAWSHAKE256: + case LIBHASHSUM_RAWSHAKE512: return estimate_performance_keccak(this); + default: + return 0; + } +} diff --git a/libhashsum_init_blake224_hasher.c b/libhashsum_init_blake224_hasher.c index 2c982d5..b78b12a 100644 --- a/libhashsum_init_blake224_hasher.c +++ b/libhashsum_init_blake224_hasher.c @@ -108,7 +108,6 @@ libhashsum_init_blake224_hasher(struct libhashsum_hasher *this, const void *salt this->standard_partial_byte_input_encoding = LIBHASHSUM_MOST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 13377838180743567ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_blake256_hasher.c b/libhashsum_init_blake256_hasher.c index 1e8c101..1b89eb2 100644 --- a/libhashsum_init_blake256_hasher.c +++ b/libhashsum_init_blake256_hasher.c @@ -108,7 +108,6 @@ libhashsum_init_blake256_hasher(struct libhashsum_hasher *this, const void *salt this->standard_partial_byte_input_encoding = LIBHASHSUM_MOST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 13377838180743567ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_blake2b_hasher.c b/libhashsum_init_blake2b_hasher.c index 17ebf31..9a78419 100644 --- a/libhashsum_init_blake2b_hasher.c +++ b/libhashsum_init_blake2b_hasher.c @@ -170,7 +170,6 @@ libhashsum_init_blake2b_hasher(struct libhashsum_hasher *this, size_t hashbits, this->standard_partial_byte_input_encoding = LIBHASHSUM_UNSUPPORTED; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 24633935505133251ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_blake2s_hasher.c b/libhashsum_init_blake2s_hasher.c index 6762888..7758006 100644 --- a/libhashsum_init_blake2s_hasher.c +++ b/libhashsum_init_blake2s_hasher.c @@ -170,7 +170,6 @@ libhashsum_init_blake2s_hasher(struct libhashsum_hasher *this, size_t hashbits, this->standard_partial_byte_input_encoding = LIBHASHSUM_UNSUPPORTED; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 16309869015413425ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_blake384_hasher.c b/libhashsum_init_blake384_hasher.c index d4d60a7..a507593 100644 --- a/libhashsum_init_blake384_hasher.c +++ b/libhashsum_init_blake384_hasher.c @@ -108,7 +108,6 @@ libhashsum_init_blake384_hasher(struct libhashsum_hasher *this, const void *salt this->standard_partial_byte_input_encoding = LIBHASHSUM_MOST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 21062754517124396ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_blake512_hasher.c b/libhashsum_init_blake512_hasher.c index 37aff97..b80d4e8 100644 --- a/libhashsum_init_blake512_hasher.c +++ b/libhashsum_init_blake512_hasher.c @@ -108,7 +108,6 @@ libhashsum_init_blake512_hasher(struct libhashsum_hasher *this, const void *salt this->standard_partial_byte_input_encoding = LIBHASHSUM_MOST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 21062754517124396ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_keccak__.c b/libhashsum_init_keccak__.c index 53a9e52..f9c8be1 100644 --- a/libhashsum_init_keccak__.c +++ b/libhashsum_init_keccak__.c @@ -140,25 +140,6 @@ destroy(struct libhashsum_hasher *this) } -static uint64_t -estimate_performance(long int r, long int c) -{ - uint64_t base = 22517998136852480ULL / (uint64_t)r; - switch (r + c) { - case 1600: - return base / 368ULL; - case 800: - return base / 2042ULL; - case 400: - return base / 1858ULL; - case 200: - return base / 1747ULL; - default: - return 0; - } -} - - int libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void *spec_, size_t squeezes, const char *suffix) { @@ -189,7 +170,6 @@ libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void * } this->input_block_size = libkeccak_zerocopy_chunksize(&this->state.keccak.s); - this->relative_performance = estimate_performance(spec->bitrate, spec->capacity); this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_md2_hasher.c b/libhashsum_init_md2_hasher.c index 35d00ac..2fb1668 100644 --- a/libhashsum_init_md2_hasher.c +++ b/libhashsum_init_md2_hasher.c @@ -142,7 +142,6 @@ libhashsum_init_md2_hasher(struct libhashsum_hasher *this) this->standard_partial_byte_input_encoding = LIBHASHSUM_UNSUPPORTED; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 636028372060772ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_md4_hasher.c b/libhashsum_init_md4_hasher.c index 6472309..d5f7876 100644 --- a/libhashsum_init_md4_hasher.c +++ b/libhashsum_init_md4_hasher.c @@ -187,7 +187,6 @@ libhashsum_init_md4_hasher(struct libhashsum_hasher *this) this->standard_partial_byte_input_encoding = LIBHASHSUM_MOST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 45941107656992312ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_md5_hasher.c b/libhashsum_init_md5_hasher.c index dd74ebb..737bb49 100644 --- a/libhashsum_init_md5_hasher.c +++ b/libhashsum_init_md5_hasher.c @@ -202,7 +202,6 @@ libhashsum_init_md5_hasher(struct libhashsum_hasher *this) this->standard_partial_byte_input_encoding = LIBHASHSUM_MOST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 28263143931935570ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_ripemd_128_hasher.c b/libhashsum_init_ripemd_128_hasher.c index 0caf5c4..e27f72a 100644 --- a/libhashsum_init_ripemd_128_hasher.c +++ b/libhashsum_init_ripemd_128_hasher.c @@ -223,7 +223,6 @@ libhashsum_init_ripemd_128_hasher(struct libhashsum_hasher *this) this->standard_partial_byte_input_encoding = LIBHASHSUM_MOST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 21773847511300567ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_ripemd_160_hasher.c b/libhashsum_init_ripemd_160_hasher.c index 3316aa7..8b55546 100644 --- a/libhashsum_init_ripemd_160_hasher.c +++ b/libhashsum_init_ripemd_160_hasher.c @@ -226,7 +226,6 @@ libhashsum_init_ripemd_160_hasher(struct libhashsum_hasher *this) this->standard_partial_byte_input_encoding = LIBHASHSUM_MOST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 12306656764693412ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_ripemd_256_hasher.c b/libhashsum_init_ripemd_256_hasher.c index 65d3e35..c08c262 100644 --- a/libhashsum_init_ripemd_256_hasher.c +++ b/libhashsum_init_ripemd_256_hasher.c @@ -234,7 +234,6 @@ libhashsum_init_ripemd_256_hasher(struct libhashsum_hasher *this) this->standard_partial_byte_input_encoding = LIBHASHSUM_MOST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 24811564606436716ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_ripemd_320_hasher.c b/libhashsum_init_ripemd_320_hasher.c index 92360fb..b513620 100644 --- a/libhashsum_init_ripemd_320_hasher.c +++ b/libhashsum_init_ripemd_320_hasher.c @@ -240,7 +240,6 @@ libhashsum_init_ripemd_320_hasher(struct libhashsum_hasher *this) this->standard_partial_byte_input_encoding = LIBHASHSUM_MOST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 12450536920018911ULL; this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; diff --git a/libhashsum_init_sha0_hasher.c b/libhashsum_init_sha0_hasher.c index 69cd7c6..379d7db 100644 --- a/libhashsum_init_sha0_hasher.c +++ b/libhashsum_init_sha0_hasher.c @@ -68,7 +68,6 @@ libhashsum_init_sha0_hasher(struct libhashsum_hasher *this) this->standard_partial_byte_input_encoding = LIBHASHSUM_LEAST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 54814763498234941ULL; 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 df7d2aa..3be6428 100644 --- a/libhashsum_init_sha1_hasher.c +++ b/libhashsum_init_sha1_hasher.c @@ -68,7 +68,6 @@ libhashsum_init_sha1_hasher(struct libhashsum_hasher *this) this->standard_partial_byte_input_encoding = LIBHASHSUM_LEAST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = 259304505616284017ULL; 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 index dc9d0f2..e6aab61 100644 --- a/libhashsum_init_sha2_hasher.c +++ b/libhashsum_init_sha2_hasher.c @@ -97,7 +97,6 @@ libhashsum_init_sha2_hasher(struct libhashsum_hasher *this, unsigned algobits, s this->standard_partial_byte_input_encoding = LIBHASHSUM_LEAST_SIGNIFICANT; this->standard_partial_byte_output_encoding = LIBHASHSUM_UNSUPPORTED; this->hash_excess_bits = 0; - this->relative_performance = (algobits == 32U ? 277891737809888154ULL : 32055903736688859ULL); this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; |