This repository has been archived by the owner on Jul 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ff_p.hpp
69 lines (62 loc) · 2.24 KB
/
ff_p.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <CL/sycl.hpp>
// Prime modulas of selected field, F_p,
// where p = 2 ** 64 - 2 ** 32 + 1
inline constexpr uint64_t MOD =
((((uint64_t)1 << 63) - ((uint64_t)1 << 31)) << 1) + 1;
// modular addition of two prime field elements
//
// note: operands doesn't necessarily need to ∈ F_p
// but second operand will be made `b % MOD`
//
// return value may ∉ F_p, it's function invoker's
// responsibility to perform ret % MOD
SYCL_EXTERNAL uint64_t ff_p_add(uint64_t a, uint64_t b);
// modular subtraction of two prime field elements
//
// note: operands doesn't necessarily need to ∈ F_p
// but second operand will be made `b % MOD`
//
// return value may ∉ F_p, it's function invoker's
// responsibility to perform ret % MOD
SYCL_EXTERNAL uint64_t ff_p_sub(uint64_t a, uint64_t b);
// modular mulitiplication of two prime field elements
//
// note: operands doesn't necessarily need to ∈ F_p
// but second operand will be made `b % MOD`
//
// return value may ∉ F_p, it's function invoker's
// responsibility to perform ret % MOD
SYCL_EXTERNAL uint64_t ff_p_mult(uint64_t a, uint64_t b);
// modular exponentiation of prime field element by unsigned integer
//
// note: operands doesn't necessarily need to ∈ F_p
//
// return value may ∉ F_p, it's function invoker's
// responsibility to perform ret % MOD
SYCL_EXTERNAL uint64_t ff_p_pow(uint64_t a, const uint64_t b);
// finds multiplicative inverse of field element, given that it's
// not additive identity
//
// note: if operand is not ∈ F_p, it's made so by performing
// modulo operation
//
// this function uses the fact a ** -1 = 1 / a = a ** (p - 2) ( mod p )
// where p = prime field modulas
//
// it raises operand to (p - 2)-th power, which is multiplicative
// inverse of operand
//
// return value may ∉ F_p, it's function invoker's
// responsibility to perform ret % MOD
SYCL_EXTERNAL uint64_t ff_p_inv(uint64_t a);
// modular division of one prime field element by another one
//
// note: operands doesn't necessarily need to ∈ F_p
//
// it computes a * (b ** -1), uses already defined multiplicative
// inverse finder function
//
// return value may ∉ F_p, it's function invoker's
// responsibility to perform ret % MOD
SYCL_EXTERNAL uint64_t ff_p_div(uint64_t a, uint64_t b);