9#include "../hmac/hmac.hpp"
15template <
typename Hash,
typename Fq,
typename Fr,
typename G1>
21 std::vector<uint8_t> pkey_buffer;
23 Fr k = crypto::get_unbiased_field_from_hmac<Hash, Fr>(message, pkey_buffer);
25 typename G1::affine_element R(G1::one * k);
28 std::vector<uint8_t> message_buffer;
30 auto ev = Hash::hash(message_buffer);
51 bool recovery_bit = y_parity ^ is_s_low;
52 constexpr uint8_t
offset = 27;
54 int value =
offset + recovery_bit +
static_cast<uint8_t
>(2) * !is_r_finite;
56 sig.
v =
static_cast<uint8_t
>(
value);
60template <
typename Hash,
typename Fq,
typename Fr,
typename G1>
69 const auto* r_buf = &sig.
r[0];
70 const auto* s_buf = &sig.
s[0];
71 const auto* v_buf = &sig.
v;
77 if ((r_uint >= mod) || (s_uint >= mod)) {
80 if ((r_uint == 0) || (s_uint == 0)) {
85 if (s_uint * 2 > mod) {
93 bool is_r_finite =
true;
95 if ((v_uint == 27) || (v_uint == 28)) {
97 }
else if ((v_uint == 29) || (v_uint == 30)) {
108 auto uncompressed_points = G1::affine_element::from_compressed_unsafe(r_uint);
109 typename G1::affine_element point_R = uncompressed_points[!is_r_finite];
113 if ((v_uint & 1) ^ y_parity_R) {
114 point_R.y = -point_R.y;
118 std::vector<uint8_t> message_buffer;
120 auto ev = Hash::hash(message_buffer);
125 Fr u1 = -(z * r_inv);
128 typename G1::affine_element recovered_public_key(
typename G1::element(point_R) * u2 + G1::one * u1);
129 return recovered_public_key;
132template <
typename Hash,
typename Fq,
typename Fr,
typename G1>
134 const typename G1::affine_element& public_key,
141 if (!public_key.on_curve()) {
144 const auto* r_buf = &sig.
r[0];
145 const auto* s_buf = &sig.
s[0];
149 if ((r_uint >= mod) || (s_uint >= mod)) {
152 if ((r_uint == 0) || (s_uint == 0)) {
157 if (s_uint * 2 > mod) {
164 std::vector<uint8_t> message_buffer;
166 auto ev = Hash::hash(message_buffer);
174 typename G1::affine_element R(
typename G1::element(public_key) * u2 + G1::one * u1);
#define BB_ASSERT_EQ(actual, expected,...)
#define BB_ASSERT_LTE(left, right,...)
#define BB_ASSERT_LT(left, right,...)
constexpr bool get_bit(uint64_t bit_index) const
G1::affine_element ecdsa_recover_public_key(const std::string &message, const ecdsa_signature &sig)
void read(B &it, SchnorrProofOfPossession< G1, Hash > &proof_of_possession)
ecdsa_signature ecdsa_construct_signature(const std::string &message, const ecdsa_key_pair< Fr, G1 > &account)
void write(B &buf, SchnorrProofOfPossession< G1, Hash > const &proof_of_possession)
bool ecdsa_verify_signature(const std::string &message, const typename G1::affine_element &public_key, const ecdsa_signature &signature)
void read(auto &it, msgpack_concepts::HasMsgPack auto &obj)
Automatically derived read for any object that defines .msgpack() (implicitly defined by MSGPACK_FIEL...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::array< uint8_t, 32 > r
std::array< uint8_t, 32 > s
static constexpr uint256_t modulus
constexpr field invert() const noexcept
static field serialize_from_buffer(const uint8_t *buffer)
static void serialize_to_buffer(const field &value, uint8_t *buffer)
void throw_or_abort(std::string const &err)