-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from cryspen/shake-benchmarks
Added CIRCL and BoringSSL shake benchmarks.
- Loading branch information
Showing
10 changed files
with
107 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <stdlib.h> | ||
#include <string> | ||
|
||
#include "crypto/kyber/internal.h" | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#define SHAKE128_BYTES_TO_OUTPUT 840 | ||
|
||
static void BM_SHAKE128(benchmark::State &state) { | ||
uint8_t input[34] = {0}; | ||
for (uint8_t i = 0; i < sizeof(input); i++) { | ||
input[i] = i; | ||
} | ||
|
||
uint8_t output[SHAKE128_BYTES_TO_OUTPUT]; | ||
|
||
for (auto _ : state) { | ||
BORINGSSL_keccak(output, SHAKE128_BYTES_TO_OUTPUT, input, sizeof(input), | ||
boringssl_shake128); | ||
} | ||
} | ||
|
||
#define SHAKE256_BYTES_TO_OUTPUT 128 | ||
|
||
static void BM_SHAKE256(benchmark::State &state) { | ||
uint8_t input[33] = {0}; | ||
for (uint8_t i = 0; i < sizeof(input); i++) { | ||
input[i] = i; | ||
} | ||
|
||
uint8_t output[SHAKE256_BYTES_TO_OUTPUT]; | ||
|
||
for (auto _ : state) { | ||
BORINGSSL_keccak(output, SHAKE256_BYTES_TO_OUTPUT, input, sizeof(input), | ||
boringssl_shake256); | ||
} | ||
} | ||
|
||
BENCHMARK(BM_SHAKE128); | ||
BENCHMARK(BM_SHAKE256); | ||
|
||
BENCHMARK_MAIN(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
bench-ref: | ||
env GODEBUG=cpu.avx2=off go test -bench=. | ||
bench-kyber-ref: | ||
env GODEBUG=cpu.avx2=off go test -bench='Kyber768' | ||
|
||
bench-shake-ref: | ||
env GODEBUG=cpu.avx2=off go test -bench='SHAKE' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/cloudflare/circl/xof" | ||
"testing" | ||
) | ||
|
||
func BenchmarkSHAKE128(b *testing.B) { | ||
input := make([]byte, 0, 34) | ||
for i := 0; i < len(input); i++ { | ||
input[i] = byte(i) | ||
} | ||
|
||
bytesToOutput := 840 | ||
output := make([]byte, bytesToOutput) | ||
|
||
xof := xof.SHAKE128.New() | ||
_, err := xof.Write([]byte(input)) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
|
||
for i := 0; i < b.N; i++ { | ||
_, _ = xof.Read(output) | ||
} | ||
} | ||
|
||
func BenchmarkSHAKE256(b *testing.B) { | ||
input := make([]byte, 0, 33) | ||
for i := 0; i < len(input); i++ { | ||
input[i] = byte(i) | ||
} | ||
|
||
bytesToOutput := 128 | ||
output := make([]byte, bytesToOutput) | ||
|
||
xof := xof.SHAKE256.New() | ||
_, err := xof.Write([]byte(input)) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
|
||
for i := 0; i < b.N; i++ { | ||
_, _ = xof.Read(output) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters