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 if ((ret >> ((
sizeof(
size_t) - 1) * 8)) != 0) {
86 ret = (ret << 8) | **sigp;
87 if (ret + lenleft > (
size_t)(sigend - *sigp)) {
103 unsigned char ra[32] = {0};
106 if (*sig == sigend || **sig != 0x02) {
112 if (rlen <= 0 || (*sig) + rlen > sigend) {
116 if (**sig == 0x00 && rlen > 1 && (((*sig)[1]) & 0x80) == 0x00) {
120 if (**sig == 0xFF && rlen > 1 && (((*sig)[1]) & 0x80) == 0x80) {
124 if ((**sig & 0x80) == 0x80) {
128 while (rlen > 0 && **sig == 0) {
137 memcpy(ra + 32 - rlen, *sig, rlen);
148 const unsigned char *sigend = sig + size;
150 if (sig == sigend || *(sig++) != 0x30) {
155 if (rlen < 0 || sig + rlen > sigend) {
159 if (sig + rlen != sigend) {
180 unsigned char r[33] = {0}, s[33] = {0};
181 unsigned char *rp = r, *sp = s;
182 size_t lenR = 33, lenS = 33;
185 while (lenR > 1 && rp[0] == 0 && rp[1] < 0x80) { lenR--; rp++; }
186 while (lenS > 1 && sp[0] == 0 && sp[1] < 0x80) { lenS--; sp++; }
187 if (*size < 6+lenS+lenR) {
188 *size = 6 + lenS + lenR;
191 *size = 6 + lenS + lenR;
193 sig[1] = 4 + lenS + lenR;
199 memcpy(sig+lenR+6, sp, lenS);
static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
static int secp256k1_gej_is_infinity(const secp256k1_gej *a)
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)
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)
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)
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
#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0)
static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *rr, secp256k1_scalar *rs, const unsigned char *sig, size_t size)
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)
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)
static secp256k1_context * ctx
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)
static int secp256k1_gej_eq_x_var(const secp256k1_fe *x, const secp256k1_gej *a)
static void secp256k1_ge_clear(secp256k1_ge *r)
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)
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)
static const secp256k1_fe secp256k1_ecdsa_const_p_minus_order