FK20 CUDA
g1p_mul.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 
19 __device__ void g1p_mul(g1p_t &p, const fr_t &k) {
20  // TODO: Use 4-bit lookup table to reduce additions by a factor 4.
21 
22  if (!g1p_isPoint(p)) {
23  //g1p_print("ERROR in g1p_mul(): Invalid point ", p);
24 
25  // return invalid point as result
26  fp_zero(p.x);
27  fp_zero(p.y);
28  fp_zero(p.z);
29 
30  return;
31  }
32 
33  g1p_t q;
34 
35  g1p_inf(q); // q = inf
36 
37  for (int i=3; i>=0; i--) {
38  uint64_t
39  t = k[i],
40  j = 1ULL<<63;
41 
42  for (; j!=0; j>>=1) {
43  g1p_dbl(q);
44 
45  if ((t&j) != 0) {
46  g1p_add(q, p);
47  }
48  }
49  }
50 
51  g1p_cpy(p, q);
52 }
53 
54 // vim: ts=4 et sw=4 si
__device__ __host__ void fp_zero(fp_t &z)
Sets z to zero.
Definition: fp.cu:15
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__ __host__ void g1p_inf(g1p_t &p)
Set p to the point-at-infinity (0,1,0)
Definition: g1p.cu:93
__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__ void g1p_dbl(g1p_t &p)
G1 point doubling, with write back: p=2*p.
Definition: g1p_dbl.cu:23
__device__ __host__ void g1p_cpy(g1p_t &p, const g1p_t &q)
Copy from q into p.
Definition: g1p.cu:67
__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__ void g1p_mul(g1p_t &p, const fr_t &k)
p ← k·p Point multiplication by scalar, in projective coordinates. That result is stored back into p.
Definition: g1p_mul.cu:19
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