Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
schnorr.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory.h>
4
6
10
11namespace bb::crypto {
12template <typename Fr, typename G1> struct schnorr_key_pair {
14 typename G1::affine_element public_key;
15};
16
17// Short-Schnorr signature (s, e): include the challenge `e` instead of the group element R.
18//
19// `s` is the prover's response to the challenge, a scalar in the grumpkin scalar field.
20// `e` is the challenge hash. Conceptually a Poseidon2 output (which lives in the grumpkin base
21// field = `bb::fr`); since `bb::fr modulus < bb::fq modulus`, every challenge value embeds losslessly
22// into the grumpkin scalar field, so we store it as the same scalar type as `s`.
28
29template <typename Fr, typename G1>
30bool schnorr_verify_signature(const typename G1::Fq& message_field,
31 const typename G1::affine_element& public_key,
32 const schnorr_signature& sig);
33
34template <typename Fr, typename G1>
35schnorr_signature schnorr_construct_signature(const typename G1::Fq& message_field,
36 const schnorr_key_pair<Fr, G1>& account);
37
38inline bool operator==(schnorr_signature const& lhs, schnorr_signature const& rhs)
39{
40 return lhs.s == rhs.s && lhs.e == rhs.e;
41}
42
43inline std::ostream& operator<<(std::ostream& os, schnorr_signature const& sig)
44{
45 os << "{ " << sig.s << ", " << sig.e << " }";
46 return os;
47}
48
49template <typename B> inline void read(B& it, schnorr_key_pair<grumpkin::fr, grumpkin::g1>& keypair)
50{
51 read(it, keypair.private_key);
52 read(it, keypair.public_key);
53}
54
55template <typename B> inline void write(B& buf, schnorr_key_pair<grumpkin::fr, grumpkin::g1> const& keypair)
56{
57 write(buf, keypair.private_key);
58 write(buf, keypair.public_key);
59}
60} // namespace bb::crypto
61#include "./schnorr.tcc"
std::ostream & operator<<(std::ostream &os, schnorr_signature const &sig)
Definition schnorr.hpp:43
void write(B &buf, schnorr_key_pair< grumpkin::fr, grumpkin::g1 > const &keypair)
Definition schnorr.hpp:55
void read(B &it, schnorr_key_pair< grumpkin::fr, grumpkin::g1 > &keypair)
Definition schnorr.hpp:49
schnorr_signature schnorr_construct_signature(const typename G1::Fq &message_field, const schnorr_key_pair< Fr, G1 > &account)
bool schnorr_verify_signature(const typename G1::Fq &message_field, const typename G1::affine_element &public_key, const schnorr_signature &sig)
bool operator==(schnorr_signature const &lhs, schnorr_signature const &rhs)
Definition schnorr.hpp:38
G1::affine_element public_key
Definition schnorr.hpp:14