FK20 CUDA
g1.cuh
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 #ifndef G1_CUH
6 #define G1_CUH
7 
8 #include <stdint.h>
9 
10 #include "fp.cuh"
11 #include "fr.cuh"
12 
13 // Set this nonzero to allow any point at infinity, i.e. of the form (0, !0, 0)
14 #define G1P_ANYINF 1
15 
20 typedef struct {
21  fp_t x, y;
22 } g1a_t;
27 typedef struct {
28  fp_t x, y, z;
29 } g1p_t;
30 
31 extern __device__ __host__ void g1a_fromUint64(g1a_t &a, const uint64_t *x, const uint64_t *y);
32 extern __device__ __host__ void g1a_fromFp(g1a_t &a, const fp_t &x, const fp_t &y);
33 extern __device__ void g1a_fromG1p(g1a_t &a, const g1p_t &p);
34 extern __device__ __host__ void g1a_print(const char *s, const g1a_t &a);
35 extern __device__ __host__ void g1a_cpy(g1a_t &a, const g1a_t &b);
36 
37 extern __device__ void g1p_toUint64(const g1p_t &p, uint64_t *x, uint64_t *y, uint64_t *z);
38 extern __device__ __host__ void g1p_fromUint64(g1p_t &p, const uint64_t *x, const uint64_t *y, const uint64_t *z);
39 inline __device__ __host__ void g1p_fromFp(g1p_t &p, fp_t &x, fp_t &y, fp_t &z) {
40  g1p_fromUint64(p, x, y, z);
41 }
42 extern __device__ void g1p_fromG1a(g1p_t &p, const g1a_t &a);
43 extern __device__ __host__ void g1p_print(const char *s, const g1p_t &p);
44 extern __device__ __host__ void g1p_cpy(g1p_t &p, const g1p_t &q);
45 
46 extern __device__ bool g1p_eq(const g1p_t &p, const g1p_t &q);
47 extern __device__ bool g1p_neq(const g1p_t &p, const g1p_t &q);
48 extern __device__ bool g1p_isInf(const g1p_t &p);
49 extern __device__ bool g1p_isPoint(const g1p_t &p);
50 
51 extern __device__ void g1p_neg(g1p_t &p);
52 extern __device__ void g1p_scale(g1p_t &p, const fp_t &s);
53 extern __device__ void g1p_dbl(g1p_t &p);
54 extern __device__ void g1p_add(g1p_t &p, const g1p_t &q);
55 extern __device__ void g1p_sub(g1p_t &p, const g1p_t &q);
56 extern __device__ void g1p_addsub(g1p_t &p, g1p_t &q);
57 extern __device__ void g1p_mul(g1p_t &p, const fr_t &x);
58 
59 extern __device__ __host__ void g1a_inf(g1a_t &a);
60 extern __device__ __host__ void g1a_gen(g1a_t &a);
61 
62 extern __device__ __host__ void g1p_inf(g1p_t &p);
63 extern __device__ __host__ void g1p_gen(g1p_t &p);
64 
65 // Device-side FFT functions
66 
67 extern __device__ void g1p_fft(g1p_t *output, const g1p_t *input);
68 extern __device__ void g1p_ift(g1p_t *output, const g1p_t *input);
69 
70 // Kernel wrappers for device-side FFT functions
71 
72 __global__ void g1p_fft_wrapper(g1p_t *output, const g1p_t *input);
73 __global__ void g1p_ift_wrapper(g1p_t *output, const g1p_t *input);
74 __global__ void g1a_fromG1p_wrapper(g1a_t *a, size_t len, const g1p_t *p);
75 
76 // Debug helpers
77 
78 __global__ void g1p_eq_wrapper(uint8_t *output, size_t len, const g1p_t *p, const g1p_t *q);
79 
80 #endif
81 
82 // vim: ts=4 et sw=4 si
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
uint64_t fr_t[4]
Subgroup element stored as a 256-bit array (a 4-element little-endian array of uint64_t)....
Definition: fr.cuh:24
__device__ void g1p_fromG1a(g1p_t &p, const g1a_t &a)
Convert a point in affine coordinates to projective coordinates.
Definition: g1p.cu:51
__device__ void g1p_ift(g1p_t *output, const g1p_t *input)
Inverse FFT of size 512 over G1 with projective coordinates. Input and output arrays may overlap....
Definition: g1p_fft.cu:178
__device__ __host__ void g1p_fromFp(g1p_t &p, fp_t &x, fp_t &y, fp_t &z)
Definition: g1.cuh:39
__device__ void g1p_addsub(g1p_t &p, g1p_t &q)
Stores the sum and difference of p and q into p and q. Projective p and q, p,q ← p+q,...
Definition: g1p_addsub.cu:18
__device__ __host__ void g1p_inf(g1p_t &p)
Set p to the point-at-infinity (0,1,0)
Definition: g1p.cu:93
__device__ __host__ void g1a_fromUint64(g1a_t &a, const uint64_t *x, const uint64_t *y)
Converts arrays of uint64_t into a G1 point in affine coordinates. Each array must be uint64_t....
Definition: g1a.cu:21
__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__ void g1p_scale(g1p_t &p, const fp_t &s)
Scale the coordinates of a projective point. This operation multiplies each coordinate of p by s: (x,...
Definition: g1p_scale.cu:16
__global__ void g1p_fft_wrapper(g1p_t *output, const g1p_t *input)
wrapper for g1p_fft: FFT for arrays of g1p_t with length 512
Definition: g1p_fft.cu:336
__device__ void g1p_sub(g1p_t &p, const g1p_t &q)
Point subtraction using projective coordinates. p ← p-q.
Definition: g1p_sub.cu:17
__device__ void g1p_toUint64(const g1p_t &p, uint64_t *x, uint64_t *y, uint64_t *z)
Converts G1 point into arrays of uint64_t. Each array must be uint64_t[6] This function does not vali...
Definition: g1p.cu:21
__device__ __host__ void g1a_fromFp(g1a_t &a, const fp_t &x, const fp_t &y)
Converts Fp values into a point in G1 in affine coordinates. This function does not validate if the c...
Definition: g1a.cu:36
__device__ __host__ void g1a_inf(g1a_t &a)
Set a to the point-at-infinity (0,0)
Definition: g1a.cu:91
__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
__device__ void g1p_add(g1p_t &p, const g1p_t &q)
Computes the sum of two points q into p, using projective coordinates. and stores in p.
Definition: g1p_add.cu:29
__device__ __host__ void g1a_print(const char *s, const g1a_t &a)
Print a standard representation of a, preceded by the user-set string s.
Definition: g1a.cu:77
__device__ void g1p_fft(g1p_t *output, const g1p_t *input)
FFT of size 512 over G1 with projective coordinates. Input and output arrays may overlap....
Definition: g1p_fft.cu:24
__device__ void g1p_dbl(g1p_t &p)
G1 point doubling, with write back: p=2*p.
Definition: g1p_dbl.cu:23
__global__ void g1a_fromG1p_wrapper(g1a_t *a, size_t len, const g1p_t *p)
Kernel wrappers, host-callable conversion of points in projective coordinates into affine coordinates...
Definition: g1p.cu:166
__device__ void g1a_fromG1p(g1a_t &a, const g1p_t &p)
Converts a point in projective coordinates into affine coordinates.
Definition: g1a.cu:48
__device__ __host__ void g1p_gen(g1p_t &p)
Sets p to the generator point G1 of bls12_381.
Definition: g1p.cu:106
__device__ void g1p_mul(g1p_t &p, const fr_t &x)
p ← k·p Point multiplication by scalar, in projective coordinates. That result is stored back into p.
Definition: g1p_mul.cu:19
__device__ void g1p_neg(g1p_t &p)
Computes the negative of the point p. Due to negation map automorphism on Elliptic Curves in Weierstr...
Definition: g1p_neg.cu:16
__device__ __host__ void g1p_cpy(g1p_t &p, const g1p_t &q)
Copy from q into p.
Definition: g1p.cu:67
__global__ void g1p_ift_wrapper(g1p_t *output, const g1p_t *input)
wrapper for g1p_ift: inverse FFT for arrays of g1p_t with length 512
Definition: g1p_fft.cu:349
__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
__global__ void g1p_eq_wrapper(uint8_t *output, size_t len, const g1p_t *p, const g1p_t *q)
Kernel wrapper, host-callable comparison of arrays of g1p_t.
Definition: g1p.cu:140
__device__ __host__ void g1p_fromUint64(g1p_t &p, const uint64_t *x, const uint64_t *y, const uint64_t *z)
__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
__device__ __host__ void g1a_gen(g1a_t &a)
Sets a to the generator point G1 of bls12_381.
Definition: g1a.cu:102
__device__ __host__ void g1a_cpy(g1a_t &a, const g1a_t &b)
Copy from b into a.
Definition: g1a.cu:65
G1 point in affine coordinates.
Definition: g1.cuh:20
fp_t x
Definition: g1.cuh:21
G1 point in projective coordinates.
Definition: g1.cuh:27
fp_t x
Definition: g1.cuh:28