forked from supranational/blst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields.h
116 lines (88 loc) · 4.21 KB
/
fields.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright Supranational LLC
* Licensed under the Apache License, Version 2.0, see LICENSE for details.
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __BLS12_381_ASM_FIELDS_H__
#define __BLS12_381_ASM_FIELDS_H__
#include "vect.h"
#include "consts.h"
/*
* BLS12-381-specific Fp shortcuts to assembly.
*/
static inline void add_fp(vec384 ret, const vec384 a, const vec384 b)
{ add_mod_384(ret, a, b, BLS12_381_P); }
static inline void sub_fp(vec384 ret, const vec384 a, const vec384 b)
{ sub_mod_384(ret, a, b, BLS12_381_P); }
static inline void mul_by_3_fp(vec384 ret, const vec384 a)
{ mul_by_3_mod_384(ret, a, BLS12_381_P); }
static inline void mul_by_8_fp(vec384 ret, const vec384 a)
{ mul_by_8_mod_384(ret, a, BLS12_381_P); }
static inline void lshift_fp(vec384 ret, const vec384 a, size_t count)
{ lshift_mod_384(ret, a, count, BLS12_381_P); }
static inline void rshift_fp(vec384 ret, const vec384 a, size_t count)
{ rshift_mod_384(ret, a, count, BLS12_381_P); }
static inline void div_by_2_fp(vec384 ret, const vec384 a)
{ div_by_2_mod_384(ret, a, BLS12_381_P); }
static inline void mul_fp(vec384 ret, const vec384 a, const vec384 b)
{ mul_mont_384(ret, a, b, BLS12_381_P, p0); }
static inline void sqr_fp(vec384 ret, const vec384 a)
{ sqr_mont_384(ret, a, BLS12_381_P, p0); }
static inline void cneg_fp(vec384 ret, const vec384 a, bool_t flag)
{ cneg_mod_384(ret, a, flag, BLS12_381_P); }
static inline void from_fp(vec384 ret, const vec384 a)
{ from_mont_384(ret, a, BLS12_381_P, p0); }
static inline void redc_fp(vec384 ret, const vec768 a)
{ redc_mont_384(ret, a, BLS12_381_P, p0); }
/*
* BLS12-381-specific Fp2 shortcuts to assembly.
*/
static inline void add_fp2(vec384x ret, const vec384x a, const vec384x b)
{ add_mod_384x(ret, a, b, BLS12_381_P); }
static inline void sub_fp2(vec384x ret, const vec384x a, const vec384x b)
{ sub_mod_384x(ret, a, b, BLS12_381_P); }
static inline void mul_by_3_fp2(vec384x ret, const vec384x a)
{ mul_by_3_mod_384x(ret, a, BLS12_381_P); }
static inline void mul_by_8_fp2(vec384x ret, const vec384x a)
{ mul_by_8_mod_384x(ret, a, BLS12_381_P); }
static inline void lshift_fp2(vec384x ret, const vec384x a, size_t count)
{
lshift_mod_384(ret[0], a[0], count, BLS12_381_P);
lshift_mod_384(ret[1], a[1], count, BLS12_381_P);
}
static inline void mul_fp2(vec384x ret, const vec384x a, const vec384x b)
{ mul_mont_384x(ret, a, b, BLS12_381_P, p0); }
static inline void sqr_fp2(vec384x ret, const vec384x a)
{ sqr_mont_384x(ret, a, BLS12_381_P, p0); }
static inline void cneg_fp2(vec384x ret, const vec384x a, bool_t flag)
{
cneg_mod_384(ret[0], a[0], flag, BLS12_381_P);
cneg_mod_384(ret[1], a[1], flag, BLS12_381_P);
}
#define vec_load_global vec_copy
static void reciprocal_fp(vec384 out, const vec384 inp);
static void flt_reciprocal_fp(vec384 out, const vec384 inp);
static bool_t recip_sqrt_fp(vec384 out, const vec384 inp);
static bool_t sqrt_fp(vec384 out, const vec384 inp);
static void reciprocal_fp2(vec384x out, const vec384x inp);
static void flt_reciprocal_fp2(vec384x out, const vec384x inp);
static bool_t recip_sqrt_fp2(vec384x out, const vec384x inp,
const vec384x recip_ZZZ, const vec384x magic_ZZZ);
static bool_t sqrt_fp2(vec384x out, const vec384x inp);
static bool_t sqrt_align_fp2(vec384x out, const vec384x ret,
const vec384x sqrt, const vec384x inp);
typedef vec384x vec384fp2;
typedef vec384fp2 vec384fp6[3];
typedef vec384fp6 vec384fp12[2];
static void sqr_fp12(vec384fp12 ret, const vec384fp12 a);
static void cyclotomic_sqr_fp12(vec384fp12 ret, const vec384fp12 a);
static void mul_fp12(vec384fp12 ret, const vec384fp12 a, const vec384fp12 b);
static void mul_by_xy00z0_fp12(vec384fp12 ret, const vec384fp12 a,
const vec384fp6 xy00z0);
static void conjugate_fp12(vec384fp12 a);
static void inverse_fp12(vec384fp12 ret, const vec384fp12 a);
/* caveat lector! |n| has to be non-zero and not more than 3! */
static void frobenius_map_fp12(vec384fp12 ret, const vec384fp12 a, size_t n);
#define neg_fp(r,a) cneg_fp((r),(a),1)
#define neg_fp2(r,a) cneg_fp2((r),(a),1)
#endif /* __BLS12_381_ASM_FIELDS_H__ */