5#include "barretenberg/common/serialize.hpp"
8namespace crypto::schnorr {
19 using Fq =
typename G1::coordinate_field;
20 using Fr =
typename G1::subgroup_field;
21 using affine_element =
typename G1::affine_element;
22 using element =
typename G1::element;
26 std::array<uint8_t, 32> challenge;
28 Fr response = Fr::zero();
42 auto secret_key = account.private_key;
43 auto public_key = account.public_key;
52 Fr k = Fr::random_element();
54 affine_element R = G1::one * k;
56 auto challenge_bytes = generate_challenge(public_key, R);
57 std::copy(challenge_bytes.begin(), challenge_bytes.end(), challenge.begin());
59 Fr challenge_fr = Fr::serialize_from_buffer(&challenge_bytes[0]);
60 response = k - challenge_fr * secret_key;
69 bool verify(
const affine_element& public_key)
const
71 Fr challenge_fr = Fr::serialize_from_buffer(&challenge[0]);
73 if (response.is_zero())
76 if (!public_key.on_curve() || public_key.is_point_at_infinity())
80 affine_element R = element(public_key) * challenge_fr + G1::one * response;
81 if (R.is_point_at_infinity())
85 auto challenge_computed = generate_challenge(public_key, R);
86 return std::equal(challenge.begin(), challenge.end(), challenge_computed.begin(), challenge_computed.end());
100 const std::string domain_separator_pop(
"h_reg");
103 std::vector<uint8_t> challenge_buf;
106 std::copy(domain_separator_pop.begin(), domain_separator_pop.end(), std::back_inserter(challenge_buf));
109 serialize::write(challenge_buf, G1::affine_one);
112 serialize::write(challenge_buf, public_key);
113 serialize::write(challenge_buf, public_key);
116 serialize::write(challenge_buf, R);
119 return Hash::hash(challenge_buf);
123template <
typename B,
typename G1,
typename Hash>
124inline void read(B& it, ProofOfPossession<G1, Hash>& proof_of_possession)
126 read(it, proof_of_possession.challenge);
127 read(it, proof_of_possession.response);
130template <
typename B,
typename G1,
typename Hash>
131inline void write(B& buf, ProofOfPossession<G1, Hash>
const& proof_of_possession)
133 write(buf, proof_of_possession.challenge);
134 write(buf, proof_of_possession.response);
Definition: affine_element.hpp:11
A proof of possession is a Schnorr proof of knowledge of a secret key corresponding to a given public...
Definition: proof_of_possession.hpp:18
ProofOfPossession(const key_pair &account)
Create a new proof of possession for a given account.
Definition: proof_of_possession.hpp:40
bool verify(const affine_element &public_key) const
verifies that an unserialized signature is valid
Definition: proof_of_possession.hpp:69
Definition: schnorr.hpp:17