Crypto: add a built-in Ed25519 backend (closes #52)
This commit is contained in:
1 parent
06641947bd
commit
86cb94c844
3 files changed
+539
-66
No files matched your search
@@ -123,35 +123,8 @@ Void::Testing::Test crypto_ed25519_signing_vectors_and_boundaries()
|
||||
{
|
||||
using namespace Void::Crypto;
|
||||
|
||||
if (!has_openssl_backend()) {
|
||||
auto gen_unavail = Ed25519PrivateKey::generate();
|
||||
Void::Testing::require(!gen_unavail.has_value());
|
||||
Void::Testing::expect_eq(
|
||||
gen_unavail.error().code().value,
|
||||
static_cast<std::int32_t>(CryptoErrorCode::unsupported_algorithm));
|
||||
|
||||
const std::array<std::byte, Ed25519PublicKeySize> dummy_pub{};
|
||||
const std::array<std::byte, Ed25519SignatureSize> dummy_sig{};
|
||||
for (const std::size_t bad_key_len : {0U, 1U, 31U, 33U, 64U}) {
|
||||
std::vector<std::byte> bad_key(bad_key_len, std::byte{0x11});
|
||||
auto r = verifyEd25519({}, dummy_sig, bad_key);
|
||||
Void::Testing::require(!r.has_value());
|
||||
Void::Testing::expect_eq(
|
||||
r.error().code().value,
|
||||
static_cast<std::int32_t>(CryptoErrorCode::invalid_key_size));
|
||||
}
|
||||
for (const std::size_t bad_sig_len : {0U, 1U, 63U, 65U}) {
|
||||
std::vector<std::byte> bad_sig(bad_sig_len, std::byte{0x22});
|
||||
auto r = verifyEd25519({}, bad_sig, dummy_pub);
|
||||
Void::Testing::require(!r.has_value());
|
||||
Void::Testing::expect_eq(
|
||||
r.error().code().value,
|
||||
static_cast<std::int32_t>(
|
||||
CryptoErrorCode::invalid_signature_size));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Runs on the OpenSSL backend and on the portable built-in backend, so
|
||||
// the same RFC 8032 vectors qualify both.
|
||||
struct Rfc8032Vector {
|
||||
std::string_view seed_hex;
|
||||
std::string_view pub_hex;
|
||||
@@ -286,19 +259,6 @@ Void::Testing::Test crypto_ed25519_convenience_api()
|
||||
"e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e06522490155"
|
||||
"5fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b");
|
||||
|
||||
if (!has_openssl_backend()) {
|
||||
auto keypair = ed25519_keypair();
|
||||
Void::Testing::require(!keypair.has_value());
|
||||
Void::Testing::expect_eq(
|
||||
keypair.error().code().value,
|
||||
static_cast<std::int32_t>(CryptoErrorCode::unsupported_algorithm));
|
||||
auto signature = ed25519_sign(seed, {});
|
||||
Void::Testing::require(!signature.has_value());
|
||||
auto verified = ed25519_verify(public_key, {}, expected_signature);
|
||||
Void::Testing::require(!verified.has_value());
|
||||
return;
|
||||
}
|
||||
|
||||
auto signature = ed25519_sign(seed, {});
|
||||
Void::Testing::require(signature.has_value());
|
||||
Void::Testing::expect_eq(to_hex(signature->view()),
|
||||
|
||||
Reference in new issue
Block a user