7#ifndef SECP256K1_SCALAR_IMPL_H
8#define SECP256K1_SCALAR_IMPL_H
17#if defined(EXHAUSTIVE_TEST_ORDER)
19#elif defined(SECP256K1_WIDEMUL_INT128)
21#elif defined(SECP256K1_WIDEMUL_INT64)
24#error "Please select wide multiplication implementation"
48#if defined(EXHAUSTIVE_TEST_ORDER)
50# if EXHAUSTIVE_TEST_ORDER == 7
51# define EXHAUSTIVE_TEST_LAMBDA 2
52# elif EXHAUSTIVE_TEST_ORDER == 13
53# define EXHAUSTIVE_TEST_LAMBDA 9
54# elif EXHAUSTIVE_TEST_ORDER == 199
55# define EXHAUSTIVE_TEST_LAMBDA 92
57# error No known lambda for the specified exhaustive test group order.
84 0x5363AD4CUL, 0xC05C30E0UL, 0xA5261C02UL, 0x8812645AUL,
85 0x122E22EAUL, 0x20816678UL, 0xDF02967CUL, 0x1B23BD72UL
145 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL,
146 0xE4437ED6UL, 0x010E8828UL, 0x6F547FA9UL, 0x0ABFE4C3UL
149 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFEUL,
150 0x8A280AC5UL, 0x0774346DUL, 0xD765CDA8UL, 0x3DB1562CUL
153 0x3086D221UL, 0xA7D46BCDUL, 0xE86C90E4UL, 0x9284EB15UL,
154 0x3DAA8A14UL, 0x71E8CA7FUL, 0xE893209AUL, 0x45DBB031UL
157 0xE4437ED6UL, 0x010E8828UL, 0x6F547FA9UL, 0x0ABFE4C4UL,
158 0x221208ACUL, 0x9DF506C6UL, 0x1571B4AEUL, 0x8AC47F71UL
178 secp256k1_scalar_split_lambda_verify(r1, r2,
k);
289 unsigned char buf1[32];
290 unsigned char buf2[32];
293 static const unsigned char k1_bound[32] = {
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295 0xa2, 0xa8, 0x91, 0x8c, 0xa8, 0x5b, 0xaf, 0xe2, 0x20, 0x16, 0xd0, 0xb9, 0x17, 0xe4, 0xdd, 0x77
299 static const unsigned char k2_bound[32] = {
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301 0x8a, 0x65, 0x28, 0x7b, 0xd4, 0x71, 0x79, 0xfb, 0x2b, 0xe0, 0x88, 0x46, 0xce, 0xa2, 0x67, 0xed
static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow)
Set a scalar from a big endian byte array.
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
Check whether a scalar equals zero.
static int secp256k1_scalar_eq(const secp256k1_scalar *a, const secp256k1_scalar *b)
Compare two scalars.
static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar *a)
Convert a scalar to a byte array.
static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Add two scalars together (modulo the group order).
#define SECP256K1_SCALAR_VERIFY(r)
static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Multiply two scalars (modulo the group order).
static void secp256k1_scalar_mul_shift_var(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b, unsigned int shift)
Multiply a and b (without taking the modulus!), divide by 2**shift, and round to the nearest integer.
static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a)
Compute the complement of a scalar (modulo the group order).
#define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0)
static SECP256K1_INLINE int secp256k1_scalar_check_overflow(const secp256k1_scalar *a)
static void secp256k1_scalar_verify(const secp256k1_scalar *r)
static SECP256K1_INLINE void secp256k1_scalar_clear(secp256k1_scalar *r)
static const secp256k1_scalar secp256k1_scalar_zero
static int secp256k1_scalar_set_b32_seckey(secp256k1_scalar *r, const unsigned char *bin)
static const secp256k1_scalar secp256k1_scalar_one
static const secp256k1_scalar secp256k1_const_lambda
The Secp256k1 curve has an endomorphism, where lambda * (x, y) = (beta * x, y), where lambda is:
static void secp256k1_scalar_split_lambda(secp256k1_scalar *SECP256K1_RESTRICT r1, secp256k1_scalar *SECP256K1_RESTRICT r2, const secp256k1_scalar *SECP256K1_RESTRICT k)
static SECP256K1_INLINE int secp256k1_memcmp_var(const void *s1, const void *s2, size_t n)
Semantics like memcmp.
static SECP256K1_INLINE void secp256k1_memclear(void *ptr, size_t len)
#define VERIFY_CHECK(cond)
#define SECP256K1_RESTRICT
A scalar modulo the group order of the secp256k1 curve.
#define EXHAUSTIVE_TEST_ORDER