-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add crypto benchmarks for iroha-ed25519 and Ursa
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
- Loading branch information
Showing
5 changed files
with
175 additions
and
1 deletion.
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
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,68 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <ed25519/ed25519.h> | ||
|
||
#include <cstdlib> | ||
#include <vector> | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
auto ConstructRandomVector(size_t size) { | ||
using T = unsigned char; | ||
std::vector<T> v; | ||
v.reserve(size); | ||
for (size_t i = 0; i < size; ++i) { | ||
v.push_back(static_cast<T>(std::rand() % size)); | ||
} | ||
return v; | ||
} | ||
|
||
static void BM_CreateKeypair(benchmark::State &state) { | ||
public_key_t pub{}; | ||
private_key_t priv{}; | ||
|
||
while (state.KeepRunning()) { | ||
ed25519_create_keypair(&priv, &pub); | ||
} | ||
} | ||
BENCHMARK(BM_CreateKeypair); | ||
|
||
static void BM_Sign(benchmark::State &state) { | ||
public_key_t pub{}; | ||
private_key_t priv{}; | ||
signature_t sig{}; | ||
|
||
ed25519_create_keypair(&priv, &pub); | ||
|
||
while (state.KeepRunning()) { | ||
state.PauseTiming(); | ||
auto data = ConstructRandomVector(state.range(0)); | ||
state.ResumeTiming(); | ||
|
||
ed25519_sign(&sig, data.data(), data.size(), &pub, &priv); | ||
} | ||
} | ||
BENCHMARK(BM_Sign)->RangeMultiplier(2)->Range(1 << 10, 1 << 18); | ||
|
||
static void BM_Verify(benchmark::State &state) { | ||
public_key_t pub{}; | ||
private_key_t priv{}; | ||
signature_t sig{}; | ||
|
||
ed25519_create_keypair(&priv, &pub); | ||
|
||
while (state.KeepRunning()) { | ||
state.PauseTiming(); | ||
auto data = ConstructRandomVector(state.range(0)); | ||
ed25519_sign(&sig, data.data(), data.size(), &pub, &priv); | ||
state.ResumeTiming(); | ||
|
||
ed25519_verify(&sig, data.data(), data.size(), &pub); | ||
} | ||
} | ||
BENCHMARK(BM_Verify)->RangeMultiplier(2)->Range(1 << 10, 1 << 18); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "ursa_crypto.h" | ||
|
||
#include <cstdlib> | ||
#include <vector> | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
auto ConstructRandomVector(size_t size) { | ||
using T = std::remove_pointer_t<decltype(ByteBuffer::data)>; | ||
std::vector<T> v; | ||
v.reserve(size); | ||
for (size_t i = 0; i < size; ++i) { | ||
v.push_back(static_cast<T>(std::rand() % size)); | ||
} | ||
return v; | ||
} | ||
|
||
static void BM_KeypairNew(benchmark::State &state) { | ||
ByteBuffer pub{}, priv{}; | ||
ExternError err{}; | ||
|
||
while (state.KeepRunning()) { | ||
ursa_ed25519_keypair_new(&pub, &priv, &err); | ||
|
||
ursa_ed25519_bytebuffer_free(pub); | ||
ursa_ed25519_bytebuffer_free(priv); | ||
ursa_ed25519_string_free(err.message); | ||
} | ||
} | ||
BENCHMARK(BM_KeypairNew); | ||
|
||
static void BM_Sign(benchmark::State &state) { | ||
ByteBuffer pub{}, priv{}, sig{}, msg{}; | ||
ExternError err{}; | ||
|
||
ursa_ed25519_keypair_new(&pub, &priv, &err); | ||
|
||
while (state.KeepRunning()) { | ||
state.PauseTiming(); | ||
auto data = ConstructRandomVector(state.range(0)); | ||
msg.data = data.data(); | ||
msg.len = data.size(); | ||
state.ResumeTiming(); | ||
|
||
ursa_ed25519_sign(&msg, &priv, &sig, &err); | ||
|
||
ursa_ed25519_bytebuffer_free(sig); | ||
ursa_ed25519_string_free(err.message); | ||
} | ||
|
||
ursa_ed25519_bytebuffer_free(pub); | ||
ursa_ed25519_bytebuffer_free(priv); | ||
} | ||
BENCHMARK(BM_Sign)->RangeMultiplier(2)->Range(1 << 10, 1 << 18); | ||
|
||
static void BM_Verify(benchmark::State &state) { | ||
ByteBuffer pub{}, priv{}, sig{}, msg{}; | ||
ExternError err{}; | ||
|
||
ursa_ed25519_keypair_new(&pub, &priv, &err); | ||
|
||
while (state.KeepRunning()) { | ||
state.PauseTiming(); | ||
auto data = ConstructRandomVector(state.range(0)); | ||
msg.data = data.data(); | ||
msg.len = data.size(); | ||
ursa_ed25519_sign(&msg, &priv, &sig, &err); | ||
state.ResumeTiming(); | ||
|
||
ursa_ed25519_verify(&msg, &sig, &pub, &err); | ||
|
||
ursa_ed25519_bytebuffer_free(sig); | ||
ursa_ed25519_string_free(err.message); | ||
} | ||
|
||
ursa_ed25519_bytebuffer_free(pub); | ||
ursa_ed25519_bytebuffer_free(priv); | ||
} | ||
BENCHMARK(BM_Verify)->RangeMultiplier(2)->Range(1 << 10, 1 << 18); | ||
|
||
BENCHMARK_MAIN(); |