Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ecdsa.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8#include "../hashers/hashers.hpp"
10
12
14#include <array>
15#include <string>
16
17namespace bb::crypto {
18template <typename Fr, typename G1> struct ecdsa_key_pair {
20 typename G1::affine_element public_key;
21 // For serialization, update with any new fields
23};
24
26 std::array<uint8_t, 32> r;
27 std::array<uint8_t, 32> s;
28 uint8_t v;
29 // For serialization, update with any new fields
31};
32
33template <typename Hash, typename Fq, typename Fr, typename G1>
34ecdsa_signature ecdsa_construct_signature(const std::string& message, const ecdsa_key_pair<Fr, G1>& account);
35
36template <typename Hash, typename Fq, typename Fr, typename G1>
37typename G1::affine_element ecdsa_recover_public_key(const std::string& message, const ecdsa_signature& sig);
38
39// TODO(https://github.com/AztecProtocol/barretenberg/issues/659)
40template <typename Hash, typename Fq, typename Fr, typename G1>
41bool ecdsa_verify_signature(const std::string& message,
42 const typename G1::affine_element& public_key,
43 const ecdsa_signature& signature);
44
45inline bool operator==(ecdsa_signature const& lhs, ecdsa_signature const& rhs)
46{
47 return lhs.r == rhs.r && lhs.s == rhs.s && lhs.v == rhs.v;
48}
49
50inline std::ostream& operator<<(std::ostream& os, ecdsa_signature const& sig)
51{
52 os << "{ " << sig.r << ", " << sig.s << ", " << static_cast<uint32_t>(sig.v) << " }";
53 return os;
54}
55
56} // namespace bb::crypto
57
58#include "./ecdsa_impl.hpp"
G1::affine_element ecdsa_recover_public_key(const std::string &message, const ecdsa_signature &sig)
ecdsa_signature ecdsa_construct_signature(const std::string &message, const ecdsa_key_pair< Fr, G1 > &account)
bool operator==(ecdsa_signature const &lhs, ecdsa_signature const &rhs)
Definition ecdsa.hpp:45
std::ostream & operator<<(std::ostream &os, ecdsa_signature const &sig)
Definition ecdsa.hpp:50
bool ecdsa_verify_signature(const std::string &message, const typename G1::affine_element &public_key, const ecdsa_signature &signature)
MSGPACK_FIELDS(private_key, public_key)
G1::affine_element public_key
Definition ecdsa.hpp:20
std::array< uint8_t, 32 > r
Definition ecdsa.hpp:26
std::array< uint8_t, 32 > s
Definition ecdsa.hpp:27