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

Changing sha2 benchmarks to refer to the faster Hacl_SHA2_Streaming versions #362

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions benchmarks/sha2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
#include "EverCrypt_Hash.h"
#include "Hacl_Streaming_SHA2.h"

#ifdef HACL_CAN_COMPILE_VEC128
#include "Hacl_Hash_Blake2s_128.h"
#endif

#ifdef HACL_CAN_COMPILE_VEC256
#include "Hacl_Hash_Blake2b_256.h"
#endif

#include "util.h"

#define HACL_HASH_SHA2_224_DIGEST_LENGTH 28
Expand Down Expand Up @@ -59,6 +51,29 @@ HACL_Sha2_oneshot(benchmark::State& state, Args&&... args)
}
}


template<class... Args>
void
HACL_Sha2_new_oneshot(benchmark::State& state, Args&&... args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this function isn't used?
Please remove or use.

{
auto args_tuple = std::make_tuple(std::move(args)...);

auto digest_len = std::get<0>(args_tuple);
auto expected_digest = std::get<1>(args_tuple);
auto hash = std::get<2>(args_tuple);

bytes digest(digest_len, 0);

for (auto _ : state) {
hash(digest.data(), input.size(), (uint8_t*)input.data());
}

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

template<class... Args>
void
EverCrypt_Sha2_oneshot(benchmark::State& state, Args&&... args)
Expand Down Expand Up @@ -159,7 +174,7 @@ BENCHMARK_CAPTURE(HACL_Sha2_oneshot,
sha2_224,
HACL_HASH_SHA2_224_DIGEST_LENGTH,
expected_digest_sha2_224,
Hacl_Hash_SHA2_hash_224)
Hacl_Streaming_SHA2_sha224)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the benchmark pretend like the oneshot function exposed by the library have this performance. Which they don't
I agree that this should be used but a few things need to happen as well

  • remove the slow API
  • update the documentation to point consumers to the right API

I'm fine with doing this in follow-ups. But it either needs to be filed as follow-ups to tackle after this (maybe @duesee or @pnmadelaine can take care of this), or done here.

->Setup(DoSetup);

BENCHMARK_CAPTURE(EverCrypt_Sha2_oneshot,
Expand All @@ -182,7 +197,7 @@ BENCHMARK_CAPTURE(HACL_Sha2_oneshot,
sha2_256,
HACL_HASH_SHA2_256_DIGEST_LENGTH,
expected_digest_sha2_256,
Hacl_Hash_SHA2_hash_256)
Hacl_Streaming_SHA2_sha256)
->Setup(DoSetup);

BENCHMARK_CAPTURE(EverCrypt_Sha2_oneshot,
Expand All @@ -205,7 +220,7 @@ BENCHMARK_CAPTURE(HACL_Sha2_oneshot,
sha2_384,
HACL_HASH_SHA2_384_DIGEST_LENGTH,
expected_digest_sha2_384,
Hacl_Hash_SHA2_hash_384)
Hacl_Streaming_SHA2_sha384)
->Setup(DoSetup);

BENCHMARK_CAPTURE(EverCrypt_Sha2_oneshot,
Expand All @@ -228,7 +243,7 @@ BENCHMARK_CAPTURE(HACL_Sha2_oneshot,
sha2_512,
HACL_HASH_SHA2_512_DIGEST_LENGTH,
expected_digest_sha2_512,
Hacl_Hash_SHA2_hash_512)
Hacl_Streaming_SHA2_sha512)
->Setup(DoSetup);

BENCHMARK_CAPTURE(EverCrypt_Sha2_oneshot,
Expand Down