FK20 CUDA
g1p_ispoint.cu
Go to the documentation of this file.
1 // bls12_381: Arithmetic for BLS12-381
2 // Copyright 2022-2023 Dag Arne Osvik
3 // Copyright 2022-2023 Luan Cardoso dos Santos
4 
5 #include "fp.cuh"
6 #include "g1.cuh"
20 __device__ bool g1p_isInf(const g1p_t &p) {
21 #if G1P_ANYINF
22  return fp_iszero(p.x) && !fp_iszero(p.y) && fp_iszero(p.z);
23 #else
24  return fp_iszero(p.x) && fp_isone(p.y) && fp_iszero(p.z);
25 #endif
26 }
27 
34 __device__ bool g1p_isPoint(const g1p_t &p) {
35  if (g1p_isInf(p))
36  return true;
37 
38  if (fp_iszero(p.z))
39  return false;
40 
41  fp_t x, y, z;
42 
43  fp_cpy(x, p.x);
44  fp_cpy(y, p.y);
45  fp_cpy(z, p.z);
46 
47  fp_sqr(y, y); // Y^2
48  fp_mul(y, y, z); // Y^2*Z
49 
50  fp_sqr(x, x); // X^2
51  fp_mul(x, x, p.x); // X^3
52 
53  fp_sqr(z, z); // Z^2
54  fp_mul(z, z, p.z); // Z^3
55  fp_x4(z, z);
56 
57  fp_add(x, x, z); // X^3 + 4*Z^3
58 
59  return fp_eq(x, y);
60 }
61 
62 // vim: ts=4 et sw=4 si
__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.
Definition: fp_add.cu:17
__device__ bool fp_iszero(const fp_t &x)
Checks if the residue x modulo p is congruent to zero.
Definition: fp_iszero.cu:13
__device__ void fp_x4(fp_t &z, const fp_t &x)
Multiplies x by 4 and stores the result into z.
Definition: fp_x4.cu:15
__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.
Definition: fp_sqr.cu:16
uint64_t fp_t[6]
Residue modulo p. Any 384-bit representative of each residue is allowed, and stored as a 6-element li...
Definition: fp.cuh:14
__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.
Definition: fp_mul.cu:17
__device__ __host__ void fp_cpy(fp_t &z, const fp_t &x)
Copy from x into z.
Definition: fp_cpy.cu:14
__device__ bool fp_isone(const fp_t &x)
Checks if the residue x modulo p is congruent to one.
Definition: fp_isone.cu:13
__device__ bool fp_eq(const fp_t &x, const fp_t &y)
Compares two residues modulo p.
Definition: fp_eq.cu:14
__device__ bool g1p_isPoint(const g1p_t &p)
Check if the value stored in p is a valid point on the G1 curve.
Definition: g1p_ispoint.cu:34
__device__ bool g1p_isInf(const g1p_t &p)
Check if the value stored in p is the the/any point at infinity. This implementation uses (0,...
Definition: g1p_ispoint.cu:20
G1 point in projective coordinates.
Definition: g1.cuh:27
fp_t z
Definition: g1.cuh:28
fp_t x
Definition: g1.cuh:28
fp_t y
Definition: g1.cuh:28