summaryrefslogtreecommitdiff
path: root/src/test/bench.c
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2015-12-18 22:15:01 +0000
committerYawning Angel <yawning@schwanenlied.me>2015-12-19 22:44:05 +0000
commit687f9b3bd7b55bcf4d984d745e978c2a03aeb4e1 (patch)
tree47ea7e28d46bb2faffddf0fd6911835ade87d425 /src/test/bench.c
parent5356eba6ca31c881032c028f4797a0b1ede28bae (diff)
downloadtor-687f9b3bd7b55bcf4d984d745e978c2a03aeb4e1.tar.gz
tor-687f9b3bd7b55bcf4d984d745e978c2a03aeb4e1.zip
Add the SHA-3 hash functions to common/crypto.h.
* DIGEST_SHA3_[256,512] added as supported algorithms, which do exactly what is said on the tin. * test/bench now benchmarks all of the supported digest algorithms, so it's possible to see just how slow SHA-3 is, though the message sizes could probably use tweaking since this is very dependent on the message size vs the SHA-3 rate.
Diffstat (limited to 'src/test/bench.c')
-rw-r--r--src/test/bench.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/bench.c b/src/test/bench.c
index 70ec025b7b..1ef54042b2 100644
--- a/src/test/bench.c
+++ b/src/test/bench.c
@@ -443,6 +443,45 @@ bench_siphash(void)
}
static void
+bench_digest(void)
+{
+ char buf[8192];
+ char out[DIGEST512_LEN];
+ const int lens[] = { 1, 16, 32, 64, 128, 512, 1024, 2048, -1 };
+ const int N = 300000;
+ uint64_t start, end;
+ crypto_rand(buf, sizeof(buf));
+
+ for (int alg = 0; alg < N_DIGEST_ALGORITHMS; alg++) {
+ for (int i = 0; lens[i] > 0; ++i) {
+ reset_perftime();
+ start = perftime();
+ for (int j = 0; j < N; ++j) {
+ switch (alg) {
+ case DIGEST_SHA1:
+ crypto_digest(out, buf, lens[i]);
+ break;
+ case DIGEST_SHA256:
+ case DIGEST_SHA3_256:
+ crypto_digest256(out, buf, lens[i], alg);
+ break;
+ case DIGEST_SHA512:
+ case DIGEST_SHA3_512:
+ crypto_digest512(out, buf, lens[i], alg);
+ break;
+ default:
+ tor_assert(0);
+ }
+ }
+ end = perftime();
+ printf("%s(%d): %.2f ns per call\n",
+ crypto_digest_algorithm_get_name(alg),
+ lens[i], NANOCOUNT(start,end,N));
+ }
+ }
+}
+
+static void
bench_cell_ops(void)
{
const int iters = 1<<16;
@@ -589,6 +628,7 @@ typedef struct benchmark_t {
static struct benchmark_t benchmarks[] = {
ENT(dmap),
ENT(siphash),
+ ENT(digest),
ENT(aes),
ENT(onion_TAP),
ENT(onion_ntor),