Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change order of SHA3 Scalar/Simd256 parameters #443

Merged
merged 8 commits into from
Jan 18, 2024
Merged
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
45 changes: 35 additions & 10 deletions include/Hacl_Hash_SHA3_Scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,52 @@ extern "C" {

void
Hacl_Hash_SHA3_Scalar_shake128(
uint32_t inputByteLen,
uint8_t *input,
uint8_t *output,
uint32_t outputByteLen,
uint8_t *output
uint8_t *input,
uint32_t inputByteLen
);

void
Hacl_Hash_SHA3_Scalar_shake256(
uint32_t inputByteLen,
uint8_t *input,
uint8_t *output,
uint32_t outputByteLen,
uint8_t *output
uint8_t *input,
uint32_t inputByteLen
);

void Hacl_Hash_SHA3_Scalar_sha3_224(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
void Hacl_Hash_SHA3_Scalar_sha3_224(uint8_t *output, uint8_t *input, uint32_t inputByteLen);

void Hacl_Hash_SHA3_Scalar_sha3_256(uint8_t *output, uint8_t *input, uint32_t inputByteLen);

void Hacl_Hash_SHA3_Scalar_sha3_256(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
void Hacl_Hash_SHA3_Scalar_sha3_384(uint8_t *output, uint8_t *input, uint32_t inputByteLen);

void Hacl_Hash_SHA3_Scalar_sha3_384(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
void Hacl_Hash_SHA3_Scalar_sha3_512(uint8_t *output, uint8_t *input, uint32_t inputByteLen);

void Hacl_Hash_SHA3_Scalar_sha3_512(uint32_t inputByteLen, uint8_t *input, uint8_t *output);
uint64_t *Hacl_Hash_SHA3_Scalar_state_malloc(void);

void Hacl_Hash_SHA3_Scalar_state_free(uint64_t *s);

void
Hacl_Hash_SHA3_Scalar_shake128_absorb_nblocks(
franziskuskiefer marked this conversation as resolved.
Show resolved Hide resolved
uint64_t *state,
uint8_t *input,
uint32_t inputByteLen
);

void
Hacl_Hash_SHA3_Scalar_shake128_absorb_final(
uint64_t *state,
uint8_t *input,
uint32_t inputByteLen
);

void
Hacl_Hash_SHA3_Scalar_shake128_squeeze_nblocks(
uint64_t *state,
uint8_t *output,
uint32_t outputByteLen
);

#if defined(__cplusplus)
}
Expand Down
Loading
Loading