FK20 CUDA
g1test_dbl.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 "g1.cuh"
8 #include "fr.cuh"
9 #include "g1test.cuh"
10 
18 __global__ void G1TestDbl(testval_t *) {
19 
20  if ((blockIdx.x | blockIdx.y | blockIdx.z | threadIdx.x | threadIdx.y | threadIdx.z) == 0)
21  printf("=== RUN %s\n", __func__);
22 
23  bool pass = true;
24  size_t count = 0;
25 
26  g1p_t p, q, u, v;
27 
28  g1p_gen(p); // p = G
29  g1p_gen(q); // q = G
30 
31  for (int i=0; pass && i<20000; i++) {
32 
33  g1p_cpy(u, p);
34  g1p_cpy(v, q);
35 
36  g1p_add(p, p); // p += p
37  g1p_dbl(q); // q *= 2
38 
39  if (g1p_neq(p, q)) {
40  pass = false;
41 
42  printf("%d: FAILED\n", i);
43  g1p_print("u = ", u);
44  g1p_print("v = ", v);
45  g1p_print("u+u = ", p);
46  g1p_print("2v = ", q);
47  }
48  ++count;
49  }
50 
51  if (!pass || (blockIdx.x | blockIdx.y | blockIdx.z | threadIdx.x | threadIdx.y | threadIdx.z) == 0)
52  {
53  printf("%ld tests\n", count);
54 
55  PRINTPASS(pass);
56  }
57 }
58 
59 // vim: ts=4 et sw=4 si
__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__ void g1p_dbl(g1p_t &p)
G1 point doubling, with write back: p=2*p.
Definition: g1p_dbl.cu:23
__device__ __host__ void g1p_gen(g1p_t &p)
Sets p to the generator point G1 of bls12_381.
Definition: g1p.cu:106
__device__ __host__ void g1p_cpy(g1p_t &p, const g1p_t &q)
Copy from q into p.
Definition: g1p.cu:67
__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 G1TestDbl(testval_t *)
Test for point doubling in G1:
Definition: g1test_dbl.cu:18
G1 point in projective coordinates.
Definition: g1.cuh:27
#define PRINTPASS(pass)
Definition: test.h:25