8 #ifndef SECP256K1_ECDSA_IMPL_H 9 #define SECP256K1_ECDSA_IMPL_H 32 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFEUL,
33 0xBAAEDCE6UL, 0xAF48A03BUL, 0xBFD25E8CUL, 0xD0364141UL
46 0, 0, 0, 1, 0x45512319UL, 0x50B75FC4UL, 0x402DA172UL, 0x2FC9BAEEUL
52 if (*sigp >= sigend) {
60 if ((b1 & 0x80) == 0) {
70 if (lenleft > sigend - *sigp) {
77 if ((
size_t)lenleft >
sizeof(size_t)) {
84 ret = (ret << 8) | **sigp;
85 if (ret + lenleft > (
size_t)(sigend - *sigp)) {
101 unsigned char ra[32] = {0};
104 if (*sig == sigend || **sig != 0x02) {
110 if (rlen <= 0 || (*sig) + rlen > sigend) {
114 if (**sig == 0x00 && rlen > 1 && (((*sig)[1]) & 0x80) == 0x00) {
118 if (**sig == 0xFF && rlen > 1 && (((*sig)[1]) & 0x80) == 0x80) {
122 if ((**sig & 0x80) == 0x80) {
126 while (rlen > 0 && **sig == 0) {
135 memcpy(ra + 32 - rlen, *sig, rlen);
146 const unsigned char *sigend = sig + size;
148 if (sig == sigend || *(sig++) != 0x30) {
153 if (rlen < 0 || sig + rlen > sigend) {
157 if (sig + rlen != sigend) {
178 unsigned char r[33] = {0}, s[33] = {0};
179 unsigned char *rp = r, *sp = s;
180 size_t lenR = 33, lenS = 33;
183 while (lenR > 1 && rp[0] == 0 && rp[1] < 0x80) { lenR--; rp++; }
184 while (lenS > 1 && sp[0] == 0 && sp[1] < 0x80) { lenS--; sp++; }
185 if (*size < 6+lenS+lenR) {
186 *size = 6 + lenS + lenR;
189 *size = 6 + lenS + lenR;
191 sig[1] = 4 + lenS + lenR;
197 memcpy(sig+lenR+6, sp, lenS);
204 #if !defined(EXHAUSTIVE_TEST_ORDER) 223 #if defined(EXHAUSTIVE_TEST_ORDER) static int secp256k1_scalar_eq(const secp256k1_scalar *a, const secp256k1_scalar *b)
static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
#define VERIFY_CHECK(cond)
Definition: util.h:67
static int secp256k1_gej_is_infinity(const secp256k1_gej *a)
Definition: field_10x26.h:12
static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp256k1_gej *r, const secp256k1_scalar *a)
static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar *sigr, const secp256k1_scalar *sigs, const secp256k1_ge *pubkey, const secp256k1_scalar *message)
Definition: ecdsa_impl.h:201
static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar *sigr, secp256k1_scalar *sigs, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid)
Definition: ecdsa_impl.h:271
static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a)
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *ar, const secp256k1_scalar *as)
Definition: ecdsa_impl.h:177
static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng)
static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow)
static const secp256k1_fe secp256k1_ecdsa_const_order_as_fe
Definition: ecdsa_impl.h:31
#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0)
Definition: field_10x26.h:40
static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *rr, secp256k1_scalar *rs, const unsigned char *sig, size_t size)
Definition: ecdsa_impl.h:145
static void secp256k1_fe_add(secp256k1_fe *r, const secp256k1_fe *a)
static int secp256k1_fe_is_odd(const secp256k1_fe *a)
static int secp256k1_der_read_len(const unsigned char **sigp, const unsigned char *sigend)
Definition: ecdsa_impl.h:49
static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar *a)
static int secp256k1_der_parse_integer(secp256k1_scalar *r, const unsigned char **sig, const unsigned char *sigend)
Definition: ecdsa_impl.h:99
static secp256k1_context * ctx
Definition: tests.c:46
static void secp256k1_ge_set_gej(secp256k1_ge *r, secp256k1_gej *a)
static void secp256k1_gej_clear(secp256k1_gej *r)
static int secp256k1_scalar_is_high(const secp256k1_scalar *a)
static void secp256k1_scalar_clear(secp256k1_scalar *r)
secp256k1_fe x
Definition: group.h:15
static int secp256k1_gej_eq_x_var(const secp256k1_fe *x, const secp256k1_gej *a)
static void secp256k1_ge_clear(secp256k1_ge *r)
Definition: ecmult_gen.h:13
Definition: scalar_4x64.h:13
static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar *a)
static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a)
static int secp256k1_fe_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b)
static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v)
static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_scalar *a)
void * memcpy(void *a, const void *b, size_t c)
Definition: glibc_compat.cpp:18
static void secp256k1_fe_normalize(secp256k1_fe *r)
static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a)
static void secp256k1_gej_set_ge(secp256k1_gej *r, const secp256k1_ge *a)
secp256k1_fe y
Definition: group.h:16
static const secp256k1_fe secp256k1_ecdsa_const_p_minus_order
Definition: ecdsa_impl.h:45