Bitcoin Core  0.20.99
P2P Digital Currency
Functions | Variables
field_impl.h File Reference
#include "util.h"
#include "num.h"
Include dependency graph for field_impl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static SECP256K1_INLINE int secp256k1_fe_equal (const secp256k1_fe *a, const secp256k1_fe *b)
 
static SECP256K1_INLINE int secp256k1_fe_equal_var (const secp256k1_fe *a, const secp256k1_fe *b)
 
static int secp256k1_fe_sqrt (secp256k1_fe *r, const secp256k1_fe *a)
 
static void secp256k1_fe_inv (secp256k1_fe *r, const secp256k1_fe *a)
 
static void secp256k1_fe_inv_var (secp256k1_fe *r, const secp256k1_fe *a)
 
static void secp256k1_fe_inv_all_var (secp256k1_fe *r, const secp256k1_fe *a, size_t len)
 
static int secp256k1_fe_is_quad_var (const secp256k1_fe *a)
 

Variables

static const secp256k1_fe secp256k1_fe_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1)
 

Function Documentation

◆ secp256k1_fe_equal()

static SECP256K1_INLINE int secp256k1_fe_equal ( const secp256k1_fe a,
const secp256k1_fe b 
)
static

Definition at line 25 of file field_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ secp256k1_fe_equal_var()

static SECP256K1_INLINE int secp256k1_fe_equal_var ( const secp256k1_fe a,
const secp256k1_fe b 
)
static

Definition at line 32 of file field_impl.h.

Here is the call graph for this function:

◆ secp256k1_fe_inv()

static void secp256k1_fe_inv ( secp256k1_fe r,
const secp256k1_fe a 
)
static

The binary representation of (p - 2) has 5 blocks of 1s, with lengths in { 1, 2, 22, 223 }. Use an addition chain to calculate 2^n - 1 for each block: [1], [2], 3, 6, 9, 11, [22], 44, 88, 176, 220, [223]

Definition at line 139 of file field_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ secp256k1_fe_inv_all_var()

static void secp256k1_fe_inv_all_var ( secp256k1_fe r,
const secp256k1_fe a,
size_t  len 
)
static

Definition at line 266 of file field_impl.h.

Here is the call graph for this function:

◆ secp256k1_fe_inv_var()

static void secp256k1_fe_inv_var ( secp256k1_fe r,
const secp256k1_fe a 
)
static

Definition at line 229 of file field_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ secp256k1_fe_is_quad_var()

static int secp256k1_fe_is_quad_var ( const secp256k1_fe a)
static

Definition at line 293 of file field_impl.h.

Here is the call graph for this function:

◆ secp256k1_fe_sqrt()

static int secp256k1_fe_sqrt ( secp256k1_fe r,
const secp256k1_fe a 
)
static

Given that p is congruent to 3 mod 4, we can compute the square root of a mod p as the (p+1)/4'th power of a.

As (p+1)/4 is an even number, it will have the same result for a and for (-a). Only one of these two numbers actually has a square root however, so we test at the end by squaring and comparing to the input. Also because (p+1)/4 is an even number, the computed square root is itself always a square (a ** ((p+1)/4) is the square of a ** ((p+1)/8)).

The binary representation of (p + 1)/4 has 3 blocks of 1s, with lengths in { 2, 22, 223 }. Use an addition chain to calculate 2^n - 1 for each block: 1, [2], 3, 6, 9, 11, [22], 44, 88, 176, 220, [223]

Definition at line 39 of file field_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ secp256k1_fe_one

const secp256k1_fe secp256k1_fe_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1)
static

Definition at line 318 of file field_impl.h.