7#ifndef SECP256K1_MODULE_RECOVERY_EXHAUSTIVE_TESTS_H
8#define SECP256K1_MODULE_RECOVERY_EXHAUSTIVE_TESTS_H
20 if (skip_section(&iter))
continue;
22 const int starting_k =
k;
27 unsigned char sk32[32], msg32[32];
31 secp256k1_scalar_set_int(&msg, i);
32 secp256k1_scalar_set_int(&sk, j);
33 secp256k1_scalar_get_b32(sk32, &sk);
34 secp256k1_scalar_get_b32(msg32, &msg);
40 r_from_k(&expected_r, group,
k, &overflow);
41 CHECK(r == expected_r);
50 expected_recid = overflow ? 2 : 0;
51 r_dot_y_normalized = group[
k].y;
59 CHECK(recid == expected_recid);
63 secp256k1_ecdsa_signature_load(ctx, &r, &s, &sig);
67 r_from_k(&expected_r, group,
k, NULL);
68 CHECK(r == expected_r);
97 unsigned char msg32[32];
99 if (skip_section(&iter))
continue;
101 secp256k1_scalar_set_int(&s_s, s);
102 secp256k1_scalar_set_int(&r_s, r);
103 secp256k1_scalar_set_int(&msg_s, msg);
104 secp256k1_scalar_set_int(&sk_s, key);
105 secp256k1_scalar_get_b32(msg32, &msg_s);
113 r_from_k(&check_x_s, group,
k, NULL);
114 if (r_s == check_x_s) {
115 secp256k1_scalar_set_int(&s_times_k_s,
k);
116 secp256k1_scalar_mul(&s_times_k_s, &s_times_k_s, &s_s);
117 secp256k1_scalar_mul(&msg_plus_r_times_sk_s, &r_s, &sk_s);
118 secp256k1_scalar_add(&msg_plus_r_times_sk_s, &msg_plus_r_times_sk_s, &msg_s);
119 should_verify |= secp256k1_scalar_eq(&s_times_k_s, &msg_plus_r_times_sk_s);
123 should_verify &= !secp256k1_scalar_is_high(&s_s);
133 memcpy(&nonconst_ge, &group[sk_s],
sizeof(nonconst_ge));
134 secp256k1_pubkey_save(&pk, &nonconst_ge);
135 CHECK(should_verify ==
#define secp256k1_fe_is_odd
#define secp256k1_fe_normalize
#define CHECK(cond)
Unconditional failure on condition failure.
static void secp256k1_ecdsa_recoverable_signature_save(secp256k1_ecdsa_recoverable_signature *sig, const secp256k1_scalar *r, const secp256k1_scalar *s, int recid)
static void secp256k1_ecdsa_recoverable_signature_load(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, int *recid, const secp256k1_ecdsa_recoverable_signature *sig)
static void test_exhaustive_recovery(const secp256k1_context *ctx, const secp256k1_ge *group)
static void test_exhaustive_recovery_sign(const secp256k1_context *ctx, const secp256k1_ge *group)
static void test_exhaustive_recovery_verify(const secp256k1_context *ctx, const secp256k1_ge *group)
struct secp256k1_context_struct secp256k1_context
Unless explicitly stated all pointer arguments must not be NULL.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const secp256k1_pubkey *pubkey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Verify an ECDSA signature.
SECP256K1_API int secp256k1_ecdsa_sign_recoverable(const secp256k1_context *ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msghash32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Create a recoverable ECDSA signature.
SECP256K1_API int secp256k1_ecdsa_recoverable_signature_convert(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const secp256k1_ecdsa_recoverable_signature *sigin) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Convert a recoverable signature into a normal signature.
Opaque data structure that holds a parsed ECDSA signature, supporting pubkey recovery.
Opaque data structure that holds a parsed ECDSA signature.
This field implementation represents the value as 10 uint32_t limbs in base 2^26.
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
Opaque data structure that holds a parsed and valid public key.
A scalar modulo the group order of the secp256k1 curve.
#define EXHAUSTIVE_TEST_ORDER