Skip to content

Commit

Permalink
Merge pull request #443 from mamonet/sha3-mb
Browse files Browse the repository at this point in the history
Change order of SHA3 Scalar/Simd256 parameters
  • Loading branch information
franziskuskiefer authored Jan 18, 2024
2 parents fee3dc1 + 856e97a commit ea5510b
Show file tree
Hide file tree
Showing 11 changed files with 6,336 additions and 2,652 deletions.
188 changes: 94 additions & 94 deletions benchmarks/sha3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Hacl_Sha3_224_Scalar(benchmark::State& state)
{
for (auto _ : state) {
Hacl_Hash_SHA3_Scalar_sha3_224(
input.size(), (uint8_t*)input.data(), digest224_0.data());
digest224_0.data(), (uint8_t*)input.data(), input.size());
}
if (digest224_0 != expected_digest_sha3_224) {
state.SkipWithError("Incorrect digest.");
Expand All @@ -85,15 +85,15 @@ Hacl_Sha3_224_Simd256(benchmark::State& state)
}

for (auto _ : state) {
Hacl_Hash_SHA3_Simd256_sha3_224(input.size(),
Hacl_Hash_SHA3_Simd256_sha3_224(digest224_0.data(),
digest224_1.data(),
digest224_2.data(),
digest224_3.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
digest224_0.data(),
digest224_1.data(),
digest224_2.data(),
digest224_3.data());
input.size());
}
if (digest224_0 != expected_digest_sha3_224 ||
digest224_1 != expected_digest_sha3_224 ||
Expand Down Expand Up @@ -132,12 +132,39 @@ Hacl_Sha3_256(benchmark::State& state)

BENCHMARK(Hacl_Sha3_256)->Setup(DoSetup);

#include "sha3.h"

static void
Digestif_sha3_256(benchmark::State& state)
{
bytes digest(32, 0);

for (auto _ : state) {

sha3_ctx ctx;
digestif_sha3_init(&ctx, 256);

for (auto chunk : chunk(input, chunk_len)) {
digestif_sha3_update(&ctx, chunk.data(), chunk.size());
}

digestif_sha3_finalize(&ctx, digest.data(), 0x06);
}

if (digest != expected_digest_sha3_256) {
state.SkipWithError("Incorrect digest.");
return;
}
}

BENCHMARK(Digestif_sha3_256)->Setup(DoSetup);

static void
Hacl_Sha3_256_Scalar(benchmark::State& state)
{
for (auto _ : state) {
Hacl_Hash_SHA3_Scalar_sha3_256(
input.size(), (uint8_t*)input.data(), digest256_0.data());
digest256_0.data(), (uint8_t*)input.data(), input.size());
}
if (digest256_0 != expected_digest_sha3_256) {
state.SkipWithError("Incorrect digest.");
Expand All @@ -157,15 +184,15 @@ Hacl_Sha3_256_Simd256(benchmark::State& state)
}

for (auto _ : state) {
Hacl_Hash_SHA3_Simd256_sha3_256(input.size(),
Hacl_Hash_SHA3_Simd256_sha3_256(digest256_0.data(),
digest256_1.data(),
digest256_2.data(),
digest256_3.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
digest256_0.data(),
digest256_1.data(),
digest256_2.data(),
digest256_3.data());
input.size());
}
if (digest256_0 != expected_digest_sha3_256 ||
digest256_1 != expected_digest_sha3_256 ||
Expand All @@ -179,33 +206,6 @@ Hacl_Sha3_256_Simd256(benchmark::State& state)
BENCHMARK(Hacl_Sha3_256_Simd256)->Setup(DoSetup);
#endif

#include "sha3.h"

static void
Digestif_sha3_256(benchmark::State& state)
{
bytes digest(32, 0);

for (auto _ : state) {

sha3_ctx ctx;
digestif_sha3_init(&ctx, 256);

for (auto chunk : chunk(input, chunk_len)) {
digestif_sha3_update(&ctx, chunk.data(), chunk.size());
}

digestif_sha3_finalize(&ctx, digest.data(), 0x06);
}

if (digest != expected_digest_sha3_256) {
state.SkipWithError("Incorrect digest.");
return;
}
}

BENCHMARK(Digestif_sha3_256)->Setup(DoSetup);

#ifndef NO_OPENSSL
BENCHMARK_CAPTURE(OpenSSL_hash_oneshot,
sha3_256,
Expand Down Expand Up @@ -236,7 +236,7 @@ Hacl_Sha3_384_Scalar(benchmark::State& state)
{
for (auto _ : state) {
Hacl_Hash_SHA3_Scalar_sha3_384(
input.size(), (uint8_t*)input.data(), digest384_0.data());
digest384_0.data(), (uint8_t*)input.data(), input.size());
}
if (digest384_0 != expected_digest_sha3_384) {
state.SkipWithError("Incorrect digest.");
Expand All @@ -256,15 +256,15 @@ Hacl_Sha3_384_Simd256(benchmark::State& state)
}

for (auto _ : state) {
Hacl_Hash_SHA3_Simd256_sha3_384(input.size(),
Hacl_Hash_SHA3_Simd256_sha3_384(digest384_0.data(),
digest384_1.data(),
digest384_2.data(),
digest384_3.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
digest384_0.data(),
digest384_1.data(),
digest384_2.data(),
digest384_3.data());
input.size());
}
if (digest384_0 != expected_digest_sha3_384 ||
digest384_1 != expected_digest_sha3_384 ||
Expand Down Expand Up @@ -303,12 +303,37 @@ Hacl_Sha3_512(benchmark::State& state)

BENCHMARK(Hacl_Sha3_512)->Setup(DoSetup);

static void
Digestif_sha3_512(benchmark::State& state)
{
bytes digest(64, 0);

for (auto _ : state) {

sha3_ctx ctx;
digestif_sha3_init(&ctx, 512);

for (auto chunk : chunk(input, chunk_len)) {
digestif_sha3_update(&ctx, chunk.data(), chunk.size());
}

digestif_sha3_finalize(&ctx, digest.data(), 0x06);
}

if (digest != expected_digest_sha3_512) {
state.SkipWithError("Incorrect digest.");
return;
}
}

BENCHMARK(Digestif_sha3_512)->Setup(DoSetup);

static void
Hacl_Sha3_512_Scalar(benchmark::State& state)
{
for (auto _ : state) {
Hacl_Hash_SHA3_Scalar_sha3_512(
input.size(), (uint8_t*)input.data(), digest512_0.data());
digest512_0.data(), (uint8_t*)input.data(), input.size());
}
if (digest512_0 != expected_digest_sha3_512) {
state.SkipWithError("Incorrect digest.");
Expand All @@ -328,15 +353,15 @@ Hacl_Sha3_512_Simd256(benchmark::State& state)
}

for (auto _ : state) {
Hacl_Hash_SHA3_Simd256_sha3_512(input.size(),
Hacl_Hash_SHA3_Simd256_sha3_512(digest512_0.data(),
digest512_1.data(),
digest512_2.data(),
digest512_3.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
digest512_0.data(),
digest512_1.data(),
digest512_2.data(),
digest512_3.data());
input.size());
}
if (digest512_0 != expected_digest_sha3_512 ||
digest512_1 != expected_digest_sha3_512 ||
Expand All @@ -350,31 +375,6 @@ Hacl_Sha3_512_Simd256(benchmark::State& state)
BENCHMARK(Hacl_Sha3_512_Simd256)->Setup(DoSetup);
#endif

static void
Digestif_sha3_512(benchmark::State& state)
{
bytes digest(64, 0);

for (auto _ : state) {

sha3_ctx ctx;
digestif_sha3_init(&ctx, 512);

for (auto chunk : chunk(input, chunk_len)) {
digestif_sha3_update(&ctx, chunk.data(), chunk.size());
}

digestif_sha3_finalize(&ctx, digest.data(), 0x06);
}

if (digest != expected_digest_sha3_512) {
state.SkipWithError("Incorrect digest.");
return;
}
}

BENCHMARK(Digestif_sha3_512)->Setup(DoSetup);

#ifndef NO_OPENSSL
BENCHMARK_CAPTURE(OpenSSL_hash_oneshot,
sha3_512,
Expand Down Expand Up @@ -469,10 +469,10 @@ static void
Hacl_Sha3_shake128_Scalar(benchmark::State& state)
{
for (auto _ : state) {
Hacl_Hash_SHA3_Scalar_shake128(input.size(),
(uint8_t*)input.data(),
Hacl_Hash_SHA3_Scalar_shake128(digest_shake_0.data(),
digest_shake_0.size(),
digest_shake_0.data());
(uint8_t*)input.data(),
input.size());
}
}

Expand All @@ -488,16 +488,16 @@ Hacl_Sha3_shake128_Simd256(benchmark::State& state)
}

for (auto _ : state) {
Hacl_Hash_SHA3_Simd256_shake128(input.size(),
Hacl_Hash_SHA3_Simd256_shake128(digest_shake_0.data(),
digest_shake_1.data(),
digest_shake_2.data(),
digest_shake_3.data(),
digest_shake_0.size(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
digest_shake_0.size(),
digest_shake_0.data(),
digest_shake_1.data(),
digest_shake_2.data(),
digest_shake_3.data());
input.size());
}
}

Expand All @@ -521,10 +521,10 @@ static void
Hacl_Sha3_shake256_Scalar(benchmark::State& state)
{
for (auto _ : state) {
Hacl_Hash_SHA3_Scalar_shake256(input.size(),
(uint8_t*)input.data(),
Hacl_Hash_SHA3_Scalar_shake256(digest_shake_0.data(),
digest_shake_0.size(),
digest_shake_0.data());
(uint8_t*)input.data(),
input.size());
}
}

Expand All @@ -540,16 +540,16 @@ Hacl_Sha3_shake256_Simd256(benchmark::State& state)
}

for (auto _ : state) {
Hacl_Hash_SHA3_Simd256_shake256(input.size(),
Hacl_Hash_SHA3_Simd256_shake256(digest_shake_0.data(),
digest_shake_1.data(),
digest_shake_2.data(),
digest_shake_3.data(),
digest_shake_0.size(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
(uint8_t*)input.data(),
digest_shake_0.size(),
digest_shake_0.data(),
digest_shake_1.data(),
digest_shake_2.data(),
digest_shake_3.data());
input.size());
}
}

Expand Down
Loading

0 comments on commit ea5510b

Please sign in to comment.