diff options
Diffstat (limited to '')
-rw-r--r-- | libhashsum_get_relative_performance.c | 74 |
1 files changed, 74 insertions, 0 deletions
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; + } +} |