Skip to content

Commit

Permalink
benchmarks: DRBG.
Browse files Browse the repository at this point in the history
  • Loading branch information
duesee committed Jan 16, 2023
1 parent 87c3405 commit 3c6ce7d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
81 changes: 81 additions & 0 deletions benchmarks/drbg.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2022 Cryspen Sarl
*
* Licensed under the Apache License, Version 2.0 or MIT.
* - http://www.apache.org/licenses/LICENSE-2.0
* - http://opensource.org/licenses/MIT
*/

#include "Hacl_HMAC_DRBG.h"

#include "util.h"

static bytes entropy_input = from_hex("98AD3A7FE9E908452A633AA3B9E46E7E324766");
static bytes nonce = from_hex("6DF336AB15C2BED6AC6FC793705EBBAAFE");
static bytes personalization_string =
from_hex("AF65C375F0850AF29CC3FE6C0C1D31F4");
static bytes additional_input = from_hex("1CA8F61C");
static bytes output(128);

inline void
Drbg_complete(benchmark::State& state, Spec_Hash_Definitions_hash_alg algorithm)
{
for (auto _ : state) {
Hacl_HMAC_DRBG_state state = Hacl_HMAC_DRBG_create_in(algorithm);
Hacl_HMAC_DRBG_instantiate(algorithm,
state,
entropy_input.size(),
entropy_input.data(),
nonce.size(),
nonce.data(),
personalization_string.size(),
personalization_string.data());

Hacl_HMAC_DRBG_generate(algorithm,
output.data(),
state,
output.size(),
additional_input.size(),
additional_input.data());

Hacl_HMAC_DRBG_free(Spec_Hash_Definitions_SHA2_256, state);
}
}

// ----- SHA-2 256 -------------------------------------------------------------

static void Drbg_SHA2_256_complete(benchmark::State& state)
{
Drbg_complete(state, Spec_Hash_Definitions_SHA2_256);
}

BENCHMARK(Drbg_SHA2_256_complete);

// ----- SHA-2 384 -------------------------------------------------------------

static void Drbg_SHA2_384_complete(benchmark::State& state)
{
Drbg_complete(state, Spec_Hash_Definitions_SHA2_384);
}

BENCHMARK(Drbg_SHA2_384_complete);

// ----- SHA-2 512 -------------------------------------------------------------

static void Drbg_SHA2_512_complete(benchmark::State& state)
{
Drbg_complete(state, Spec_Hash_Definitions_SHA2_512);
}

BENCHMARK(Drbg_SHA2_512_complete);

// ----- SHA-1 -----------------------------------------------------------------

static void Drbg_SHA1_complete(benchmark::State& state)
{
Drbg_complete(state, Spec_Hash_Definitions_SHA1);
}

BENCHMARK(Drbg_SHA1_complete);

BENCHMARK_MAIN();
3 changes: 3 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@
],
"kdf": [
"kdf.cc"
],
"drbg": [
"drbg.cc"
]
}
}

0 comments on commit 3c6ce7d

Please sign in to comment.