Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

scalar_4x64_impl.h File Reference

Go to the source code of this file.

Macros

#define SECP256K1_N_0   ((uint64_t)0xBFD25E8CD0364141ULL)
 
#define SECP256K1_N_1   ((uint64_t)0xBAAEDCE6AF48A03BULL)
 
#define SECP256K1_N_2   ((uint64_t)0xFFFFFFFFFFFFFFFEULL)
 
#define SECP256K1_N_3   ((uint64_t)0xFFFFFFFFFFFFFFFFULL)
 
#define SECP256K1_N_C_0   (~SECP256K1_N_0 + 1)
 
#define SECP256K1_N_C_1   (~SECP256K1_N_1)
 
#define SECP256K1_N_C_2   (1)
 
#define SECP256K1_N_H_0   ((uint64_t)0xDFE92F46681B20A0ULL)
 
#define SECP256K1_N_H_1   ((uint64_t)0x5D576E7357A4501DULL)
 
#define SECP256K1_N_H_2   ((uint64_t)0xFFFFFFFFFFFFFFFFULL)
 
#define SECP256K1_N_H_3   ((uint64_t)0x7FFFFFFFFFFFFFFFULL)
 
#define muladd(a, b)
 Add a*b to the number defined by (c0,c1,c2). More...
 
#define muladd_fast(a, b)
 Add a*b to the number defined by (c0,c1). More...
 
#define muladd2(a, b)
 Add 2*a*b to the number defined by (c0,c1,c2). More...
 
#define sumadd(a)
 Add a to the number defined by (c0,c1,c2). More...
 
#define sumadd_fast(a)
 Add a to the number defined by (c0,c1). More...
 
#define extract(n)
 Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits. More...
 
#define extract_fast(n)
 Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits. More...
 

Functions

static SECP256K1_INLINE void secp256k1_scalar_clear (secp256k1_scalar *r)
 
static SECP256K1_INLINE void secp256k1_scalar_set_int (secp256k1_scalar *r, unsigned int v)
 
static SECP256K1_INLINE unsigned int secp256k1_scalar_get_bits (const secp256k1_scalar *a, unsigned int offset, unsigned int count)
 
static SECP256K1_INLINE unsigned int secp256k1_scalar_get_bits_var (const secp256k1_scalar *a, unsigned int offset, unsigned int count)
 
static SECP256K1_INLINE int secp256k1_scalar_check_overflow (const secp256k1_scalar *a)
 
static SECP256K1_INLINE int secp256k1_scalar_reduce (secp256k1_scalar *r, unsigned int overflow)
 
static int secp256k1_scalar_add (secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
 
static void secp256k1_scalar_cadd_bit (secp256k1_scalar *r, unsigned int bit, int flag)
 
static void secp256k1_scalar_set_b32 (secp256k1_scalar *r, const unsigned char *b32, int *overflow)
 
static void secp256k1_scalar_get_b32 (unsigned char *bin, const secp256k1_scalar *a)
 
static SECP256K1_INLINE int secp256k1_scalar_is_zero (const secp256k1_scalar *a)
 
static void secp256k1_scalar_negate (secp256k1_scalar *r, const secp256k1_scalar *a)
 
static SECP256K1_INLINE int secp256k1_scalar_is_one (const secp256k1_scalar *a)
 
static int secp256k1_scalar_is_high (const secp256k1_scalar *a)
 
static int secp256k1_scalar_cond_negate (secp256k1_scalar *r, int flag)
 
static void secp256k1_scalar_reduce_512 (secp256k1_scalar *r, const uint64_t *l)
 
static void secp256k1_scalar_mul_512 (uint64_t l[8], const secp256k1_scalar *a, const secp256k1_scalar *b)
 
static void secp256k1_scalar_sqr_512 (uint64_t l[8], const secp256k1_scalar *a)
 
static void secp256k1_scalar_mul (secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
 
static int secp256k1_scalar_shr_int (secp256k1_scalar *r, int n)
 
static void secp256k1_scalar_sqr (secp256k1_scalar *r, const secp256k1_scalar *a)
 
static SECP256K1_INLINE int secp256k1_scalar_eq (const secp256k1_scalar *a, const secp256k1_scalar *b)
 
static SECP256K1_INLINE void secp256k1_scalar_mul_shift_var (secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b, unsigned int shift)
 

Macro Definition Documentation

◆ extract

#define extract (   n)
Value:
{ \
(n) = c0; \
c0 = c1; \
c1 = c2; \
c2 = 0; \
}

Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits.

Definition at line 255 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_mul_512(), secp256k1_scalar_reduce_512(), and secp256k1_scalar_sqr_512().

◆ extract_fast

#define extract_fast (   n)
Value:
{ \
(n) = c0; \
c0 = c1; \
c1 = 0; \
VERIFY_CHECK(c2 == 0); \
}

Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits.

c2 is required to be zero.

Definition at line 263 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_mul_512(), secp256k1_scalar_reduce_512(), and secp256k1_scalar_sqr_512().

◆ muladd

#define muladd (   a,
 
)
Value:
{ \
uint64_t tl, th; \
{ \
uint128_t t = (uint128_t)a * b; \
th = t >> 64; /* at most 0xFFFFFFFFFFFFFFFE */ \
tl = t; \
} \
c0 += tl; /* overflow is handled on the next line */ \
th += (c0 < tl) ? 1 : 0; /* at most 0xFFFFFFFFFFFFFFFF */ \
c1 += th; /* overflow is handled on the next line */ \
c2 += (c1 < th) ? 1 : 0; /* never overflows by contract (verified in the next line) */ \
VERIFY_CHECK((c1 >= th) || (c2 != 0)); \
}

Add a*b to the number defined by (c0,c1,c2).

c2 must never overflow.

Definition at line 187 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_mul_512(), secp256k1_scalar_reduce_512(), and secp256k1_scalar_sqr_512().

◆ muladd2

#define muladd2 (   a,
 
)
Value:
{ \
uint64_t tl, th, th2, tl2; \
{ \
uint128_t t = (uint128_t)a * b; \
th = t >> 64; /* at most 0xFFFFFFFFFFFFFFFE */ \
tl = t; \
} \
th2 = th + th; /* at most 0xFFFFFFFFFFFFFFFE (in case th was 0x7FFFFFFFFFFFFFFF) */ \
c2 += (th2 < th) ? 1 : 0; /* never overflows by contract (verified the next line) */ \
VERIFY_CHECK((th2 >= th) || (c2 != 0)); \
tl2 = tl + tl; /* at most 0xFFFFFFFFFFFFFFFE (in case the lowest 63 bits of tl were 0x7FFFFFFFFFFFFFFF) */ \
th2 += (tl2 < tl) ? 1 : 0; /* at most 0xFFFFFFFFFFFFFFFF */ \
c0 += tl2; /* overflow is handled on the next line */ \
th2 += (c0 < tl2) ? 1 : 0; /* second overflow is handled on the next line */ \
c2 += (c0 < tl2) & (th2 == 0); /* never overflows by contract (verified the next line) */ \
VERIFY_CHECK((c0 >= tl2) || (th2 != 0) || (c2 != 0)); \
c1 += th2; /* overflow is handled on the next line */ \
c2 += (c1 < th2) ? 1 : 0; /* never overflows by contract (verified the next line) */ \
VERIFY_CHECK((c1 >= th2) || (c2 != 0)); \
}

Add 2*a*b to the number defined by (c0,c1,c2).

c2 must never overflow.

Definition at line 216 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_sqr_512().

◆ muladd_fast

#define muladd_fast (   a,
 
)
Value:
{ \
uint64_t tl, th; \
{ \
uint128_t t = (uint128_t)a * b; \
th = t >> 64; /* at most 0xFFFFFFFFFFFFFFFE */ \
tl = t; \
} \
c0 += tl; /* overflow is handled on the next line */ \
th += (c0 < tl) ? 1 : 0; /* at most 0xFFFFFFFFFFFFFFFF */ \
c1 += th; /* never overflows by contract (verified in the next line) */ \
VERIFY_CHECK(c1 >= th); \
}

Add a*b to the number defined by (c0,c1).

c1 must never overflow.

Definition at line 202 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_mul_512(), secp256k1_scalar_reduce_512(), and secp256k1_scalar_sqr_512().

◆ SECP256K1_N_0

#define SECP256K1_N_0   ((uint64_t)0xBFD25E8CD0364141ULL)

◆ SECP256K1_N_1

#define SECP256K1_N_1   ((uint64_t)0xBAAEDCE6AF48A03BULL)

◆ SECP256K1_N_2

#define SECP256K1_N_2   ((uint64_t)0xFFFFFFFFFFFFFFFEULL)

◆ SECP256K1_N_3

#define SECP256K1_N_3   ((uint64_t)0xFFFFFFFFFFFFFFFFULL)

◆ SECP256K1_N_C_0

#define SECP256K1_N_C_0   (~SECP256K1_N_0 + 1)

Definition at line 17 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_reduce(), and secp256k1_scalar_reduce_512().

◆ SECP256K1_N_C_1

#define SECP256K1_N_C_1   (~SECP256K1_N_1)

Definition at line 18 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_reduce(), and secp256k1_scalar_reduce_512().

◆ SECP256K1_N_C_2

#define SECP256K1_N_C_2   (1)

Definition at line 19 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_reduce().

◆ SECP256K1_N_H_0

#define SECP256K1_N_H_0   ((uint64_t)0xDFE92F46681B20A0ULL)

Definition at line 22 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_is_high().

◆ SECP256K1_N_H_1

#define SECP256K1_N_H_1   ((uint64_t)0x5D576E7357A4501DULL)

Definition at line 23 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_is_high().

◆ SECP256K1_N_H_2

#define SECP256K1_N_H_2   ((uint64_t)0xFFFFFFFFFFFFFFFFULL)

Definition at line 24 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_is_high().

◆ SECP256K1_N_H_3

#define SECP256K1_N_H_3   ((uint64_t)0x7FFFFFFFFFFFFFFFULL)

Definition at line 25 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_is_high().

◆ sumadd

#define sumadd (   a)
Value:
{ \
unsigned int over; \
c0 += (a); /* overflow is handled on the next line */ \
over = (c0 < (a)) ? 1 : 0; \
c1 += over; /* overflow is handled on the next line */ \
c2 += (c1 < over) ? 1 : 0; /* never overflows by contract */ \
}

Add a to the number defined by (c0,c1,c2).

c2 must never overflow.

Definition at line 238 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_reduce_512().

◆ sumadd_fast

#define sumadd_fast (   a)
Value:
{ \
c0 += (a); /* overflow is handled on the next line */ \
c1 += (c0 < (a)) ? 1 : 0; /* never overflows by contract (verified the next line) */ \
VERIFY_CHECK((c1 != 0) | (c0 >= (a))); \
VERIFY_CHECK(c2 == 0); \
}

Add a to the number defined by (c0,c1).

c1 must never overflow, c2 must be zero.

Definition at line 247 of file scalar_4x64_impl.h.

Referenced by secp256k1_scalar_reduce_512().

Function Documentation

◆ secp256k1_scalar_add()

static int secp256k1_scalar_add ( secp256k1_scalar r,
const secp256k1_scalar a,
const secp256k1_scalar b 
)
static

◆ secp256k1_scalar_cadd_bit()

static void secp256k1_scalar_cadd_bit ( secp256k1_scalar r,
unsigned int  bit,
int  flag 
)
static

◆ secp256k1_scalar_check_overflow()

◆ secp256k1_scalar_clear()

static SECP256K1_INLINE void secp256k1_scalar_clear ( secp256k1_scalar r)
static

Definition at line 27 of file scalar_4x64_impl.h.

References secp256k1_scalar::d.

◆ secp256k1_scalar_cond_negate()

static int secp256k1_scalar_cond_negate ( secp256k1_scalar r,
int  flag 
)
static

◆ secp256k1_scalar_eq()

static SECP256K1_INLINE int secp256k1_scalar_eq ( const secp256k1_scalar a,
const secp256k1_scalar b 
)
static

Definition at line 928 of file scalar_4x64_impl.h.

References secp256k1_scalar::d.

◆ secp256k1_scalar_get_b32()

static void secp256k1_scalar_get_b32 ( unsigned char *  bin,
const secp256k1_scalar a 
)
static

Definition at line 129 of file scalar_4x64_impl.h.

References secp256k1_scalar::d.

◆ secp256k1_scalar_get_bits()

static SECP256K1_INLINE unsigned int secp256k1_scalar_get_bits ( const secp256k1_scalar a,
unsigned int  offset,
unsigned int  count 
)
static

Definition at line 41 of file scalar_4x64_impl.h.

References count, secp256k1_scalar::d, and VERIFY_CHECK.

Referenced by secp256k1_scalar_get_bits_var().

◆ secp256k1_scalar_get_bits_var()

static SECP256K1_INLINE unsigned int secp256k1_scalar_get_bits_var ( const secp256k1_scalar a,
unsigned int  offset,
unsigned int  count 
)
static

◆ secp256k1_scalar_is_high()

static int secp256k1_scalar_is_high ( const secp256k1_scalar a)
static

◆ secp256k1_scalar_is_one()

static SECP256K1_INLINE int secp256k1_scalar_is_one ( const secp256k1_scalar a)
static

Definition at line 152 of file scalar_4x64_impl.h.

References secp256k1_scalar::d.

◆ secp256k1_scalar_is_zero()

static SECP256K1_INLINE int secp256k1_scalar_is_zero ( const secp256k1_scalar a)
static

Definition at line 136 of file scalar_4x64_impl.h.

References secp256k1_scalar::d.

Referenced by secp256k1_scalar_cond_negate(), and secp256k1_scalar_negate().

◆ secp256k1_scalar_mul()

static void secp256k1_scalar_mul ( secp256k1_scalar r,
const secp256k1_scalar a,
const secp256k1_scalar b 
)
static

◆ secp256k1_scalar_mul_512()

static void secp256k1_scalar_mul_512 ( uint64_t  l[8],
const secp256k1_scalar a,
const secp256k1_scalar b 
)
static

◆ secp256k1_scalar_mul_shift_var()

static SECP256K1_INLINE void secp256k1_scalar_mul_shift_var ( secp256k1_scalar r,
const secp256k1_scalar a,
const secp256k1_scalar b,
unsigned int  shift 
)
static

◆ secp256k1_scalar_negate()

static void secp256k1_scalar_negate ( secp256k1_scalar r,
const secp256k1_scalar a 
)
static

◆ secp256k1_scalar_reduce()

static SECP256K1_INLINE int secp256k1_scalar_reduce ( secp256k1_scalar r,
unsigned int  overflow 
)
static

◆ secp256k1_scalar_reduce_512()

static void secp256k1_scalar_reduce_512 ( secp256k1_scalar r,
const uint64_t *  l 
)
static

◆ secp256k1_scalar_set_b32()

static void secp256k1_scalar_set_b32 ( secp256k1_scalar r,
const unsigned char *  b32,
int *  overflow 
)
static

◆ secp256k1_scalar_set_int()

static SECP256K1_INLINE void secp256k1_scalar_set_int ( secp256k1_scalar r,
unsigned int  v 
)
static

Definition at line 34 of file scalar_4x64_impl.h.

References secp256k1_scalar::d.

◆ secp256k1_scalar_shr_int()

static int secp256k1_scalar_shr_int ( secp256k1_scalar r,
int  n 
)
static

Definition at line 897 of file scalar_4x64_impl.h.

References secp256k1_scalar::d, and VERIFY_CHECK.

◆ secp256k1_scalar_sqr()

static void secp256k1_scalar_sqr ( secp256k1_scalar r,
const secp256k1_scalar a 
)
static

◆ secp256k1_scalar_sqr_512()

static void secp256k1_scalar_sqr_512 ( uint64_t  l[8],
const secp256k1_scalar a 
)
static
Released under the MIT license