|
__device__ __host__ void | fp_fromUint64 (fp_t &z, const uint64_t *x) |
| Converts uint64_t[6] to fp_t. After this operation, z represents x mod p. More...
|
|
__device__ void | fp_toUint64 (uint64_t *z, const fp_t &x) |
| Converts from residue modulo p (fp_t) to uint64_t[6]. The converted value is in canonical form. More...
|
|
__device__ __host__ void | fp_cpy (fp_t &z, const fp_t &x) |
| Copy from x into z. More...
|
|
__device__ void | fp_reduce6 (fp_t &z) |
| Narrow reduction of a residue modulo p, reducing to the canonical representation. More...
|
|
__device__ void | fp_neg (fp_t &z, const fp_t &x) |
| Compute an additive inverse of a residue x modulo p. Stores in z. Subtracts x from the highest multiple of p less than 2^384, then adds p in case of underflow. More...
|
|
__device__ void | fp_x2 (fp_t &z, const fp_t &x) |
| Multiplies x by 2 and stores the result into z. More...
|
|
__device__ void | fp_x3 (fp_t &z, const fp_t &x) |
| Multiplies x by 3 and stores the result into z. More...
|
|
__device__ void | fp_x4 (fp_t &z, const fp_t &x) |
| Multiplies x by 4 and stores the result into z. More...
|
|
__device__ void | fp_x8 (fp_t &z, const fp_t &x) |
| Multiplies x by 8 and stores the result into z. More...
|
|
__device__ void | fp_x12 (fp_t &z, const fp_t &x) |
| Multiplies the residue mod p x by 12 and stores the result into z. More...
|
|
__device__ void | fp_add (fp_t &z, const fp_t &x, const fp_t &y) |
| Computes the sum of two residues x and y modulo p and stores it in z. Device only function. More...
|
|
__device__ void | fp_sub (fp_t &z, const fp_t &x, const fp_t &y) |
| Calculates the difference of two residues modulo p and stores it into z. More...
|
|
__device__ void | fp_sqr (fp_t &z, const fp_t &x) |
| Computes the square of the residue x modulo p and stores it in z. More...
|
|
__device__ void | fp_mul (fp_t &z, const fp_t &x, const fp_t &y) |
| Multiplies two Fp residues x and y, stores in z. More...
|
|
__device__ void | fp_mma (fp_t &z, const fp_t &v, const fp_t &w, const fp_t &x, const fp_t &y) |
| Fp multiply-multiply-add. Fast execution of z = (v*w + x*y) mod p The double-wide products are added before reduction, saving one reduction. More...
|
|
__device__ void | fp_inv (fp_t &z, const fp_t &x) |
| Calculates the multiplicative inverse of x and stores in z. More...
|
|
__device__ __host__ void | fp_zero (fp_t &z) |
| Sets z to zero. More...
|
|
__device__ __host__ void | fp_one (fp_t &z) |
| Sets z to one. More...
|
|
__device__ bool | fp_eq (const fp_t &x, const fp_t &y) |
| Compares two residues modulo p. More...
|
|
__device__ bool | fp_neq (const fp_t &x, const fp_t &y) |
| Compares two fp_t residues. More...
|
|
__device__ bool | fp_nonzero (const fp_t &x) |
| Check if the reduced input x is different from zero. More...
|
|
__device__ bool | fp_iszero (const fp_t &x) |
| Checks if the residue x modulo p is congruent to zero. More...
|
|
__device__ bool | fp_isone (const fp_t &x) |
| Checks if the residue x modulo p is congruent to one. More...
|
|
__device__ void | fp_print (const char *s, const fp_t &x) |
| Prints the canonical representation of x to STDOUT. More...
|
|
__device__ void fp_inv |
( |
fp_t & |
z, |
|
|
const fp_t & |
x |
|
) |
| |
Calculates the multiplicative inverse of x and stores in z.
- This function calculates the multiplicative inverse of the argument. An integer a is the inverse of z if a*z mod r == 1
Normally, the inverse is found by using the Extended Euclidean Algorithm, to find integers (z,y) to satisfy the Bézout's identity: a*z + r*y == gcd(a, r) == 1 which can be rewritten as: az-1 == (-y)*m which follows that a*z mod r == 1. This approach has complexity in the order of O(log2(r)).
This implementation uses Euler's theorem, calculating the inverse as z^(phi(r)-1). where phi is Euler's totient function. For the special case where r is prime, phi(r) = r-1. Therefore, the inverse here is calculated as z^(r-2). Although this is asymptotically worse than EEA, this implementation avoid flow divergence and uses 279 squarings and 128 multiplications. Furthermore, since curve operations are done in projective coordinates, inversions are needed only at the very end when projective coordinates are translated into affine coordinates.
- Parameters
-
- Returns
- void
Definition at line 33 of file fp_inv.cu.