Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
schnorr.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
9#include <array>
10#include <memory.h>
11#include <string>
12
14
16
20
21namespace bb::crypto {
22template <typename Fr, typename G1> struct schnorr_key_pair {
24 typename G1::affine_element public_key;
25};
26
27// Raw representation of a Schnorr signature (e,s). We use the short variant of Schnorr
28// where we include the challenge hash `e` instead of the group element R representing
29// the provers initial message.
31
32 // `s` is a serialized field element (also 32 bytes), representing the prover's response to
33 // to the verifier challenge `e`.
34 // We do not enforce that `s` is canonical since signatures are verified inside a circuit,
35 // and are provided as private inputs. Malleability is not an issue in this case.
36 std::array<uint8_t, 32> s;
37 // `e` represents the verifier's challenge in the protocol. It is encoded as the 32-byte
38 // output of a hash function modeling a random oracle in the Fiat-Shamir transform.
39 std::array<uint8_t, 32> e;
41};
42
43template <typename Hash, typename Fq, typename Fr, typename G1>
44bool schnorr_verify_signature(const std::string& message,
45 const typename G1::affine_element& public_key,
46 const schnorr_signature& sig);
47
48template <typename Hash, typename Fq, typename Fr, typename G1>
50
51inline bool operator==(schnorr_signature const& lhs, schnorr_signature const& rhs)
52{
53 return lhs.s == rhs.s && lhs.e == rhs.e;
54}
55
56inline std::ostream& operator<<(std::ostream& os, schnorr_signature const& sig)
57{
58 os << "{ " << sig.s << ", " << sig.e << " }";
59 return os;
60}
61
62template <typename B> inline void read(B& it, schnorr_key_pair<grumpkin::fr, grumpkin::g1>& keypair)
63{
64 read(it, keypair.private_key);
65 read(it, keypair.public_key);
66}
67
68template <typename B> inline void write(B& buf, schnorr_key_pair<grumpkin::fr, grumpkin::g1> const& keypair)
69{
70 write(buf, keypair.private_key);
71 write(buf, keypair.public_key);
72}
73} // namespace bb::crypto
74#include "./schnorr.tcc"
uint8_t const * buf
Definition data_store.hpp:9
schnorr_signature schnorr_construct_signature(const std::string &message, const schnorr_key_pair< Fr, G1 > &account)
void read(B &it, SchnorrProofOfPossession< G1, Hash > &proof_of_possession)
void write(B &buf, SchnorrProofOfPossession< G1, Hash > const &proof_of_possession)
bool schnorr_verify_signature(const std::string &message, const typename G1::affine_element &public_key, const schnorr_signature &sig)
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
G1::affine_element public_key
Definition schnorr.hpp:24
std::array< uint8_t, 32 > s
Definition schnorr.hpp:36
std::array< uint8_t, 32 > e
Definition schnorr.hpp:39