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

[std::span] some pubkey things #3993

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions src/lib/pubkey/curve25519/curve25519.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace {

void size_check(size_t size, const char* thing) {
if(size != 32) {
throw Decoding_Error(fmt("Invalid size {} for Curve2551 {}", size, thing));
throw Decoding_Error(fmt("Invalid size {} for Curve25519 {}", size, thing));
}
}

Expand All @@ -44,8 +44,11 @@ bool Curve25519_PublicKey::check_key(RandomNumberGenerator& /*rng*/, bool /*stro
return true; // no tests possible?
}

Curve25519_PublicKey::Curve25519_PublicKey(const AlgorithmIdentifier& /*unused*/, std::span<const uint8_t> key_bits) {
m_public.assign(key_bits.begin(), key_bits.end());
Curve25519_PublicKey::Curve25519_PublicKey(const AlgorithmIdentifier& /*unused*/, std::span<const uint8_t> key_bits) :
Curve25519_PublicKey(key_bits) {}

Curve25519_PublicKey::Curve25519_PublicKey(std::span<const uint8_t> pub) {
m_public.assign(pub.begin(), pub.end());

size_check(m_public.size(), "public key");
}
Expand Down
8 changes: 1 addition & 7 deletions src/lib/pubkey/curve25519/curve25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ class BOTAN_PUBLIC_API(2, 0) Curve25519_PublicKey : public virtual Public_Key {
* Create a Curve25519 Public Key.
* @param pub 32-byte raw public key
*/
explicit Curve25519_PublicKey(const std::vector<uint8_t>& pub) : m_public(pub) {}

/**
* Create a Curve25519 Public Key.
* @param pub 32-byte raw public key
*/
explicit Curve25519_PublicKey(const secure_vector<uint8_t>& pub) : m_public(pub.begin(), pub.end()) {}
explicit Curve25519_PublicKey(std::span<const uint8_t> pub);

protected:
Curve25519_PublicKey() = default;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/pubkey/ec_group/ec_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,7 @@ EC_Point BOTAN_PUBLIC_API(2, 0) OS2ECP(const uint8_t data[], size_t data_len, co
std::pair<BigInt, BigInt> BOTAN_UNSTABLE_API
OS2ECP(const uint8_t data[], size_t data_len, const BigInt& curve_p, const BigInt& curve_a, const BigInt& curve_b);

template <typename Alloc>
EC_Point OS2ECP(const std::vector<uint8_t, Alloc>& data, const CurveGFp& curve) {
inline EC_Point OS2ECP(std::span<const uint8_t> data, const CurveGFp& curve) {
return OS2ECP(data.data(), data.size(), curve);
}

Expand Down
3 changes: 1 addition & 2 deletions src/lib/pubkey/ed25519/ed25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class BOTAN_PUBLIC_API(2, 2) Ed25519_PublicKey : public virtual Public_Key {
*/
Ed25519_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);

template <typename Alloc>
Ed25519_PublicKey(const std::vector<uint8_t, Alloc>& pub) : Ed25519_PublicKey(pub.data(), pub.size()) {}
Ed25519_PublicKey(std::span<const uint8_t> pub) : Ed25519_PublicKey(pub.data(), pub.size()) {}

Ed25519_PublicKey(const uint8_t pub_key[], size_t len);

Expand Down
Loading