Line | Count | Source |
1 | | /* |
2 | | * Copyright Supranational LLC |
3 | | * Licensed under the Apache License, Version 2.0, see LICENSE for details. |
4 | | * SPDX-License-Identifier: Apache-2.0 |
5 | | */ |
6 | | #ifndef __BLS12_381_ASM_FIELDS_H__ |
7 | | #define __BLS12_381_ASM_FIELDS_H__ |
8 | | |
9 | | #include "vect.h" |
10 | | #include "consts.h" |
11 | | |
12 | | /* |
13 | | * BLS12-381-specific Fp shortcuts to assembly. |
14 | | */ |
15 | | static inline void add_fp(vec384 ret, const vec384 a, const vec384 b) |
16 | 801k | { add_mod_384(ret, a, b, BLS12_381_P); } |
17 | | |
18 | | static inline void sub_fp(vec384 ret, const vec384 a, const vec384 b) |
19 | 1.55M | { sub_mod_384(ret, a, b, BLS12_381_P); } |
20 | | |
21 | | static inline void mul_by_3_fp(vec384 ret, const vec384 a) |
22 | 265k | { mul_by_3_mod_384(ret, a, BLS12_381_P); } |
23 | | |
24 | | static inline void mul_by_8_fp(vec384 ret, const vec384 a) |
25 | 222k | { mul_by_8_mod_384(ret, a, BLS12_381_P); } |
26 | | |
27 | | static inline void lshift_fp(vec384 ret, const vec384 a, size_t count) |
28 | 525 | { lshift_mod_384(ret, a, count, BLS12_381_P); } |
29 | | |
30 | | static inline void rshift_fp(vec384 ret, const vec384 a, size_t count) |
31 | 0 | { rshift_mod_384(ret, a, count, BLS12_381_P); } |
32 | | |
33 | | static inline void div_by_2_fp(vec384 ret, const vec384 a) |
34 | 192 | { div_by_2_mod_384(ret, a, BLS12_381_P); } |
35 | | |
36 | | static inline void mul_fp(vec384 ret, const vec384 a, const vec384 b) |
37 | 1.04M | { mul_mont_384(ret, a, b, BLS12_381_P, p0); } |
38 | | |
39 | | static inline void sqr_fp(vec384 ret, const vec384 a) |
40 | 1.33M | { sqr_mont_384(ret, a, BLS12_381_P, p0); } |
41 | | |
42 | | static inline void cneg_fp(vec384 ret, const vec384 a, bool_t flag) |
43 | 61.8k | { cneg_mod_384(ret, a, flag, BLS12_381_P); } |
44 | | |
45 | | static inline void from_fp(vec384 ret, const vec384 a) |
46 | 3.83k | { from_mont_384(ret, a, BLS12_381_P, p0); } |
47 | | |
48 | | static inline void redc_fp(vec384 ret, const vec768 a) |
49 | 0 | { redc_mont_384(ret, a, BLS12_381_P, p0); } |
50 | | |
51 | | /* |
52 | | * BLS12-381-specific Fp2 shortcuts to assembly. |
53 | | */ |
54 | | static inline void add_fp2(vec384x ret, const vec384x a, const vec384x b) |
55 | 748k | { add_mod_384x(ret, a, b, BLS12_381_P); } |
56 | | |
57 | | static inline void sub_fp2(vec384x ret, const vec384x a, const vec384x b) |
58 | 1.04M | { sub_mod_384x(ret, a, b, BLS12_381_P); } |
59 | | |
60 | | static inline void mul_by_3_fp2(vec384x ret, const vec384x a) |
61 | 169k | { mul_by_3_mod_384x(ret, a, BLS12_381_P); } |
62 | | |
63 | | static inline void mul_by_8_fp2(vec384x ret, const vec384x a) |
64 | 140k | { mul_by_8_mod_384x(ret, a, BLS12_381_P); } |
65 | | |
66 | | static inline void lshift_fp2(vec384x ret, const vec384x a, size_t count) |
67 | 819 | { |
68 | 819 | lshift_mod_384(ret[0], a[0], count, BLS12_381_P); |
69 | 819 | lshift_mod_384(ret[1], a[1], count, BLS12_381_P); |
70 | 819 | } |
71 | | |
72 | | static inline void mul_fp2(vec384x ret, const vec384x a, const vec384x b) |
73 | 699k | { mul_mont_384x(ret, a, b, BLS12_381_P, p0); } |
74 | | |
75 | | static inline void sqr_fp2(vec384x ret, const vec384x a) |
76 | 860k | { sqr_mont_384x(ret, a, BLS12_381_P, p0); } |
77 | | |
78 | | static inline void cneg_fp2(vec384x ret, const vec384x a, bool_t flag) |
79 | 32.9k | { |
80 | 32.9k | cneg_mod_384(ret[0], a[0], flag, BLS12_381_P); |
81 | 32.9k | cneg_mod_384(ret[1], a[1], flag, BLS12_381_P); |
82 | 32.9k | } |
83 | | |
84 | | #define vec_load_global vec_copy |
85 | | |
86 | | static void reciprocal_fp(vec384 out, const vec384 inp); |
87 | | static void flt_reciprocal_fp(vec384 out, const vec384 inp); |
88 | | static bool_t recip_sqrt_fp(vec384 out, const vec384 inp); |
89 | | static bool_t sqrt_fp(vec384 out, const vec384 inp); |
90 | | |
91 | | static void reciprocal_fp2(vec384x out, const vec384x inp); |
92 | | static void flt_reciprocal_fp2(vec384x out, const vec384x inp); |
93 | | static bool_t recip_sqrt_fp2(vec384x out, const vec384x inp, |
94 | | const vec384x recip_ZZZ, const vec384x magic_ZZZ); |
95 | | static bool_t sqrt_fp2(vec384x out, const vec384x inp); |
96 | | static bool_t sqrt_align_fp2(vec384x out, const vec384x ret, |
97 | | const vec384x sqrt, const vec384x inp); |
98 | | |
99 | | typedef vec384x vec384fp2; |
100 | | typedef vec384fp2 vec384fp6[3]; |
101 | | typedef vec384fp6 vec384fp12[2]; |
102 | | |
103 | | static void sqr_fp12(vec384fp12 ret, const vec384fp12 a); |
104 | | static void cyclotomic_sqr_fp12(vec384fp12 ret, const vec384fp12 a); |
105 | | static void mul_fp12(vec384fp12 ret, const vec384fp12 a, const vec384fp12 b); |
106 | | static void mul_by_xy00z0_fp12(vec384fp12 ret, const vec384fp12 a, |
107 | | const vec384fp6 xy00z0); |
108 | | static void conjugate_fp12(vec384fp12 a); |
109 | | static void inverse_fp12(vec384fp12 ret, const vec384fp12 a); |
110 | | /* caveat lector! |n| has to be non-zero and not more than 3! */ |
111 | | static void frobenius_map_fp12(vec384fp12 ret, const vec384fp12 a, size_t n); |
112 | | |
113 | 428 | #define neg_fp(r,a) cneg_fp((r),(a),1) |
114 | 1.09k | #define neg_fp2(r,a) cneg_fp2((r),(a),1) |
115 | | |
116 | | #endif /* __BLS12_381_ASM_FIELDS_H__ */ |