From 2e14f263b096047719025f7f45f9b26fbe42b25d Mon Sep 17 00:00:00 2001 From: Kris Kwiatkowski Date: Thu, 22 Apr 2021 23:05:15 +0100 Subject: [PATCH] kyber512 benchmarks --- test/bench/kyber.cc | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/bench/kyber.cc b/test/bench/kyber.cc index 2fba7b29..889b25a1 100644 --- a/test/bench/kyber.cc +++ b/test/bench/kyber.cc @@ -10,6 +10,7 @@ extern "C" { #include "kem/kyber/kyber512/avx2/indcpa.h" + #include "kem/kyber/kyber512/avx2/kem.h" } auto cpucycle = [](benchmark::State &st, int64_t cycles) { @@ -30,4 +31,53 @@ static void BenchKyberMatK2(benchmark::State &st) { cpucycle(st, total); } +static void BenchKyberKeygen(benchmark::State &st) { + int64_t t, total = 0; + uint8_t sk[1632]; + uint8_t pk[800]; + for (auto _ : st) { + t = benchmark::cycleclock::Now(); + PQCLEAN_KYBER512_AVX2_crypto_kem_keypair(pk, sk); + total += benchmark::cycleclock::Now() - t; + benchmark::DoNotOptimize(pk); + benchmark::DoNotOptimize(sk); + } + cpucycle(st, total); +} + +static void BenchKyberEncaps(benchmark::State &st) { + int64_t t, total = 0; + uint8_t sk[1632]; + uint8_t pk[800]; + uint8_t ct[768]; + uint8_t ss[32]; + PQCLEAN_KYBER512_AVX2_crypto_kem_keypair(pk, sk); + for (auto _ : st) { + t = benchmark::cycleclock::Now(); + PQCLEAN_KYBER512_AVX2_crypto_kem_enc(ss, ct, pk); + total += benchmark::cycleclock::Now() - t; + benchmark::DoNotOptimize(pk); + } + cpucycle(st, total); +} + +static void BenchKyberDecaps(benchmark::State &st) { + int64_t t, total = 0; + uint8_t sk[1632]; + uint8_t pk[800]; + uint8_t ct[768]; + uint8_t ss[32]; + PQCLEAN_KYBER512_AVX2_crypto_kem_keypair(pk, sk); + PQCLEAN_KYBER512_AVX2_crypto_kem_enc(ss, ct, pk); + for (auto _ : st) { + t = benchmark::cycleclock::Now(); + PQCLEAN_KYBER512_AVX2_crypto_kem_dec(ss, ct, sk); + total += benchmark::cycleclock::Now() - t; + benchmark::DoNotOptimize(sk); + } + cpucycle(st, total); +} BENCHMARK(BenchKyberMatK2); +BENCHMARK(BenchKyberKeygen); +BENCHMARK(BenchKyberEncaps); +BENCHMARK(BenchKyberDecaps);