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: Completed, auditors: [Federico], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8#include "../hashers/hashers.hpp"
10
12
14#include <array>
15#include <string>
16
17namespace bb::crypto {
18
19static constexpr int ECDSA_RECOVERY_ID_OFFSET = 27;
20static constexpr int ECDSA_R_FINITENESS_OFFSET = 2;
21
22template <typename Fr, typename G1> struct ecdsa_key_pair {
24 G1::affine_element public_key;
25
26 // For serialization, update with any new fields
28};
29
31 std::array<uint8_t, 32> r;
32 std::array<uint8_t, 32> s;
33 uint8_t v;
34
35 // For serialization, update with any new fields
37};
38
43template <typename Hash, typename Fq, typename Fr, typename G1>
44ecdsa_signature ecdsa_construct_signature(const std::string& message, const ecdsa_key_pair<Fr, G1>& account);
45
65template <typename Hash, typename Fq, typename Fr, typename G1>
66typename G1::affine_element ecdsa_recover_public_key(const std::string& message, const ecdsa_signature& sig);
67
72template <typename Hash, typename Fq, typename Fr, typename G1>
73bool ecdsa_verify_signature(const std::string& message,
74 const typename G1::affine_element& public_key,
75 const ecdsa_signature& signature);
76
84template <typename Hash, typename Fr> Fr ecdsa_hash_message(const std::string& message);
85
86inline bool operator==(ecdsa_signature const& lhs, ecdsa_signature const& rhs)
87{
88 return lhs.r == rhs.r && lhs.s == rhs.s && lhs.v == rhs.v;
89}
90
91inline std::ostream& operator<<(std::ostream& os, ecdsa_signature const& sig)
92{
93 os << "{ " << sig.r << ", " << sig.s << ", " << static_cast<uint32_t>(sig.v) << " }";
94 return os;
95}
96
97} // namespace bb::crypto
98
99#include "ecdsa_impl.hpp"
G1::affine_element ecdsa_recover_public_key(const std::string &message, const ecdsa_signature &sig)
std::ostream & operator<<(std::ostream &os, schnorr_signature const &sig)
Definition schnorr.hpp:50
Fr ecdsa_hash_message(const std::string &message)
ecdsa_signature ecdsa_construct_signature(const std::string &message, const ecdsa_key_pair< Fr, G1 > &account)
Generate the ECDSA for the message using the provided account key pair and hash function.
bool ecdsa_verify_signature(const std::string &message, const typename G1::affine_element &public_key, const ecdsa_signature &sig)
bool operator==(schnorr_signature const &lhs, schnorr_signature const &rhs)
Definition schnorr.hpp:45
MSGPACK_FIELDS(private_key, public_key)
G1::affine_element public_key
Definition ecdsa.hpp:24
std::array< uint8_t, 32 > r
Definition ecdsa.hpp:31
std::array< uint8_t, 32 > s
Definition ecdsa.hpp:32