FK20 CUDA
g1test_fibonacci.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 
17 __global__ void G1TestFibonacci(testval_t *) {
18 
19  if ((blockIdx.x | blockIdx.y | blockIdx.z | threadIdx.x | threadIdx.y | threadIdx.z) == 0)
20  printf("=== RUN %s\n", __func__);
21 
22  bool pass = true;
23  size_t count = 0;
24 
25  g1p_t p, q, t;
26  fr_t k, l;
27 
28  g1p_inf(p); // p = 0
29  g1p_gen(q); // q = G
30 
31  fr_zero(k);
32  fr_one(l);
33 
34  for (int i=0; pass && i<100; i++) {
35 
36  fr_add(k, l);
37  g1p_add(p, q); // p += q
38 
39  g1p_gen(t);
40  g1p_mul(t, k); // kG
41 
42  if (g1p_neq(p, t)) {
43  pass = false;
44  }
45  ++count;
46 
47  if (!pass)
48  break;
49 
50  fr_add(l, k);
51  g1p_add(q, p); // q += p
52 
53  g1p_gen(t);
54  g1p_mul(t, l); // lG
55 
56  if (g1p_neq(q, t)) {
57  pass = false;
58  }
59  ++count;
60  }
61 
62  if (!pass || (blockIdx.x | blockIdx.y | blockIdx.z | threadIdx.x | threadIdx.y | threadIdx.z) == 0)
63  {
64  printf("%ld tests\n", count);
65 
66  PRINTPASS(pass);
67  }
68 }
69 
70 // vim: ts=4 et sw=4 si
__device__ __host__ void fr_zero(fr_t &z)
Sets the value of z to zero.
Definition: fr.cu:15
__device__ __host__ void fr_one(fr_t &z)
Sets the value of z to one.
Definition: fr.cu:26
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 fr_add(fr_t &z, const fr_t &x)
Computes the sum of two residues x and z modulo r and stores it in z. Device only function.
Definition: fr_add.cu:16
__device__ __host__ void g1p_inf(g1p_t &p)
Set p to the point-at-infinity (0,1,0)
Definition: g1p.cu:93
__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 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
__global__ void G1TestFibonacci(testval_t *)
Test addition and multiplication using a fibonacci sequence (cascading data dependency)
G1 point in projective coordinates.
Definition: g1.cuh:27
#define PRINTPASS(pass)
Definition: test.h:25