FK20 CUDA
g1p_compare.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 <stdio.h>
6 
7 #include "fp.cuh"
8 #include "fr.cuh"
9 #include "g1.cuh"
10 
23 __device__ bool g1p_eq(const g1p_t &p, const g1p_t &q) {
24  fp_t px, py, qx, qy;
25 
26 #ifndef NDEBUG
27  if (!g1p_isPoint(p) || !(g1p_isPoint(q))) {
28  // printf("ERROR in g1p_eq(): Invalid point(s)\n");
29  // g1p_print("p: ", p);
30  // g1p_print("q: ", q);
31 
32  return false;
33  }
34 #endif
35 
36  // (X1/Z1 == X2/Z2) && (Y1/Z1 == Y2/Z2)
37 
38  fp_cpy(px, p.x);
39  fp_cpy(py, p.y);
40 
41  fp_cpy(qx, q.x);
42  fp_cpy(qy, q.y);
43 
44  fp_mul(px, px, q.z); // X1*Z2
45  fp_mul(qx, qx, p.z); // X2*Z1
46 
47  if (fp_neq(px, qx))
48  return false;
49 
50  fp_mul(py, py, q.z); // Y1*Z2
51  fp_mul(qy, qy, p.z); // Y2*Z1
52 
53  return fp_eq(py, qy);
54 }
55 
68 __device__ bool g1p_neq(const g1p_t &p, const g1p_t &q) {
69 // observation: This function could be inlined, but
70 #ifndef NDEBUG
71  if (!g1p_isPoint(p) || !(g1p_isPoint(q))) {
72  printf("ERROR in g1p_neq(): Invalid point(s)\n");
73  g1p_print("p: ", p);
74  g1p_print("q: ", q);
75 
76  return true;
77  }
78 #endif
79 
80  return !g1p_eq(p, q);
81 }
82 
83 // vim: ts=4 et sw=4 si
__device__ bool fp_neq(const fp_t &x, const fp_t &y)
Compares two fp_t residues.
Definition: fp_neq.cu:14
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_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__ __host__ void g1p_print(const char *s, const g1p_t &p)
Print a standard representation of p, preceded by the user-set string s.
Definition: g1p.cu:80
__device__ bool g1p_eq(const g1p_t &p, const g1p_t &q)
Compares two projective points returns true when equal. This function compares if both parameters rep...
Definition: g1p_compare.cu:23
__device__ bool g1p_neq(const g1p_t &p, const g1p_t &q)
Compares two projective points, returns true when not equal. This function compares if both parameter...
Definition: g1p_compare.cu:68
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