aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_get_relative_performance.c
blob: 3759120aeabca4551d72d6eff1da04b7afe95aec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
	}
}