Monero
crypto-ops.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2020, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30 
31 #pragma once
32 
33 /* From fe.h */
34 
35 typedef int32_t fe[10];
36 
37 /* From ge.h */
38 
39 typedef struct {
40  fe X;
41  fe Y;
42  fe Z;
43 } ge_p2;
44 
45 typedef struct {
46  fe X;
47  fe Y;
48  fe Z;
49  fe T;
50 } ge_p3;
51 
52 typedef struct {
53  fe X;
54  fe Y;
55  fe Z;
56  fe T;
57 } ge_p1p1;
58 
59 typedef struct {
63 } ge_precomp;
64 
65 typedef struct {
68  fe Z;
70 } ge_cached;
71 
72 /* From ge_add.c */
73 
74 void ge_add(ge_p1p1 *, const ge_p3 *, const ge_cached *);
75 
76 /* From ge_double_scalarmult.c, modified */
77 
78 typedef ge_cached ge_dsmp[8];
79 extern const ge_precomp ge_Bi[8];
80 void ge_dsm_precomp(ge_dsmp r, const ge_p3 *s);
81 void ge_double_scalarmult_base_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *);
82 void ge_triple_scalarmult_base_vartime(ge_p2 *, const unsigned char *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp);
83 void ge_double_scalarmult_base_vartime_p3(ge_p3 *, const unsigned char *, const ge_p3 *, const unsigned char *);
84 
85 /* From ge_frombytes.c, modified */
86 
87 extern const fe fe_sqrtm1;
88 extern const fe fe_d;
89 int ge_frombytes_vartime(ge_p3 *, const unsigned char *);
90 
91 /* From ge_p1p1_to_p2.c */
92 
93 void ge_p1p1_to_p2(ge_p2 *, const ge_p1p1 *);
94 
95 /* From ge_p1p1_to_p3.c */
96 
97 void ge_p1p1_to_p3(ge_p3 *, const ge_p1p1 *);
98 
99 /* From ge_p2_dbl.c */
100 
101 void ge_p2_dbl(ge_p1p1 *, const ge_p2 *);
102 
103 /* From ge_p3_to_cached.c */
104 
105 extern const fe fe_d2;
106 void ge_p3_to_cached(ge_cached *, const ge_p3 *);
107 
108 /* From ge_p3_to_p2.c */
109 
110 void ge_p3_to_p2(ge_p2 *, const ge_p3 *);
111 
112 /* From ge_p3_tobytes.c */
113 
114 void ge_p3_tobytes(unsigned char *, const ge_p3 *);
115 
116 /* From ge_scalarmult_base.c */
117 
118 extern const ge_precomp ge_base[32][8];
119 void ge_scalarmult_base(ge_p3 *, const unsigned char *);
120 
121 /* From ge_tobytes.c */
122 
123 void ge_tobytes(unsigned char *, const ge_p2 *);
124 
125 /* From sc_reduce.c */
126 
127 void sc_reduce(unsigned char *);
128 
129 /* New code */
130 
131 void ge_scalarmult(ge_p2 *, const unsigned char *, const ge_p3 *);
132 void ge_scalarmult_p3(ge_p3 *, const unsigned char *, const ge_p3 *);
133 void ge_double_scalarmult_precomp_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *, const ge_dsmp);
134 void ge_triple_scalarmult_precomp_vartime(ge_p2 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp);
135 void ge_double_scalarmult_precomp_vartime2(ge_p2 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp);
136 void ge_double_scalarmult_precomp_vartime2_p3(ge_p3 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp);
137 void ge_mul8(ge_p1p1 *, const ge_p2 *);
138 extern const fe fe_ma2;
139 extern const fe fe_ma;
140 extern const fe fe_fffb1;
141 extern const fe fe_fffb2;
142 extern const fe fe_fffb3;
143 extern const fe fe_fffb4;
144 extern const ge_p3 ge_p3_identity;
145 extern const ge_p3 ge_p3_H;
146 void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *);
147 void sc_0(unsigned char *);
148 void sc_reduce32(unsigned char *);
149 void sc_add(unsigned char *, const unsigned char *, const unsigned char *);
150 void sc_sub(unsigned char *, const unsigned char *, const unsigned char *);
151 void sc_mulsub(unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *);
152 void sc_mul(unsigned char *, const unsigned char *, const unsigned char *);
153 void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c);
154 int sc_check(const unsigned char *);
155 int sc_isnonzero(const unsigned char *); /* Doesn't normalize */
156 
157 // internal
158 uint64_t load_3(const unsigned char *in);
159 uint64_t load_4(const unsigned char *in);
160 void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
161 void fe_add(fe h, const fe f, const fe g);
162 void fe_tobytes(unsigned char *, const fe);
163 void fe_invert(fe out, const fe z);
164 
165 int ge_p3_is_point_at_infinity(const ge_p3 *p);
ge_triple_scalarmult_base_vartime
void ge_triple_scalarmult_base_vartime(ge_p2 *, const unsigned char *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp)
Definition: crypto-ops.c:1238
ge_p3::Z
fe Z
Definition: crypto-ops.h:48
sc_add
void sc_add(unsigned char *, const unsigned char *, const unsigned char *)
Definition: crypto-ops.c:2548
ge_base
const ge_precomp ge_base[32][8]
Definition: crypto-ops-data.c:42
ge_p1p1::T
fe T
Definition: crypto-ops.h:56
ge_scalarmult
void ge_scalarmult(ge_p2 *, const unsigned char *, const ge_p3 *)
Definition: crypto-ops.c:2038
base.q
int q
Definition: base.py:2
sc_check
int sc_check(const unsigned char *)
Definition: crypto-ops.c:3814
ge_p1p1
Definition: crypto-ops.h:52
fe_d
const fe fe_d
Definition: crypto-ops-data.c:37
ge_p2::Y
fe Y
Definition: crypto-ops.h:41
sc_reduce
void sc_reduce(unsigned char *)
Definition: crypto-ops.c:1728
sc_isnonzero
int sc_isnonzero(const unsigned char *)
Definition: crypto-ops.c:3826
sc_sub
void sc_sub(unsigned char *, const unsigned char *, const unsigned char *)
Definition: crypto-ops.c:2687
ge_p3_to_cached
void ge_p3_to_cached(ge_cached *, const ge_p3 *)
Definition: crypto-ops.c:1545
ge_tobytes
void ge_tobytes(unsigned char *, const ge_p2 *)
Definition: crypto-ops.c:1704
ge_cached
Definition: crypto-ops.h:65
fe_add
void fe_add(fe h, const fe f, const fe g)
Definition: crypto-ops.c:121
fe_fffb1
const fe fe_fffb1
Definition: crypto-ops-data.c:869
sc_mulsub
void sc_mulsub(unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *)
Definition: crypto-ops.c:2837
ge_fromfe_frombytes_vartime
void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *)
Definition: crypto-ops.c:2310
fe_fffb4
const fe fe_fffb4
Definition: crypto-ops-data.c:872
ge_precomp::xy2d
fe xy2d
Definition: crypto-ops.h:62
ge_p3::Y
fe Y
Definition: crypto-ops.h:47
ge_scalarmult_base
void ge_scalarmult_base(ge_p3 *, const unsigned char *)
Definition: crypto-ops.c:1639
ge_double_scalarmult_base_vartime_p3
void ge_double_scalarmult_base_vartime_p3(ge_p3 *, const unsigned char *, const ge_p3 *, const unsigned char *)
Definition: crypto-ops.c:1287
s
#define s(x, c)
Definition: aesb.c:47
ge_precomp
Definition: crypto-ops.h:59
ge_double_scalarmult_base_vartime
void ge_double_scalarmult_base_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *)
Definition: crypto-ops.c:1196
fe
int32_t fe[10]
Definition: crypto-ops.h:35
ge_mul8
void ge_mul8(ge_p1p1 *, const ge_p2 *)
Definition: crypto-ops.c:2301
ge_p3
Definition: crypto-ops.h:45
base.b
int b
Definition: base.py:1
ge_cached::T2d
fe T2d
Definition: crypto-ops.h:69
ge_cached::Z
fe Z
Definition: crypto-ops.h:68
ge_add
void ge_add(ge_p1p1 *, const ge_p3 *, const ge_cached *)
Definition: crypto-ops.c:1126
fe_fffb2
const fe fe_fffb2
Definition: crypto-ops-data.c:870
ge_p2
Definition: crypto-ops.h:39
sc_muladd
void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c)
Definition: crypto-ops.c:3489
ge_scalarmult_p3
void ge_scalarmult_p3(ge_p3 *, const unsigned char *, const ge_p3 *)
Definition: crypto-ops.c:2098
ge_double_scalarmult_precomp_vartime2
void ge_double_scalarmult_precomp_vartime2(ge_p2 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp)
Definition: crypto-ops.c:2162
ge_p3_identity
const ge_p3 ge_p3_identity
Definition: crypto-ops-data.c:873
ge_p3_H
const ge_p3 ge_p3_H
Definition: crypto-ops-data.c:874
ge_dsm_precomp
void ge_dsm_precomp(ge_dsmp r, const ge_p3 *s)
Definition: crypto-ops.c:1175
fe_tobytes
void fe_tobytes(unsigned char *, const fe)
Definition: crypto-ops.c:1032
sc_reduce32
void sc_reduce32(unsigned char *)
Definition: crypto-ops.c:2433
fe_invert
void fe_invert(fe out, const fe z)
Definition: crypto-ops.c:259
ge_p1p1_to_p3
void ge_p1p1_to_p3(ge_p3 *, const ge_p1p1 *)
Definition: crypto-ops.c:1484
sc_mul
void sc_mul(unsigned char *, const unsigned char *, const unsigned char *)
Definition: crypto-ops.c:3168
ge_double_scalarmult_precomp_vartime
void ge_double_scalarmult_precomp_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *, const ge_dsmp)
Definition: crypto-ops.c:2294
ge_dsmp
ge_cached ge_dsmp[8]
Definition: crypto-ops.h:78
ge_precomp::yminusx
fe yminusx
Definition: crypto-ops.h:61
ge_p3_tobytes
void ge_p3_tobytes(unsigned char *, const ge_p3 *)
Definition: crypto-ops.c:1566
ge_triple_scalarmult_precomp_vartime
void ge_triple_scalarmult_precomp_vartime(ge_p2 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp)
Definition: crypto-ops.c:2202
ge_p3::X
fe X
Definition: crypto-ops.h:46
fe_ma2
const fe fe_ma2
Definition: crypto-ops-data.c:867
ge_p2::Z
fe Z
Definition: crypto-ops.h:42
ge_p3::T
fe T
Definition: crypto-ops.h:49
ge_p1p1_to_p2
void ge_p1p1_to_p2(ge_p2 *, const ge_p1p1 *)
Definition: crypto-ops.c:1472
sc_0
void sc_0(unsigned char *)
Definition: crypto-ops.c:2426
ge_Bi
const ge_precomp ge_Bi[8]
Definition: crypto-ops-data.c:846
ge_p1p1::X
fe X
Definition: crypto-ops.h:53
MakeCryptoOps.a
string a
Definition: MakeCryptoOps.py:15
ge_p1p1::Y
fe Y
Definition: crypto-ops.h:54
ge_p3_is_point_at_infinity
int ge_p3_is_point_at_infinity(const ge_p3 *p)
Definition: crypto-ops.c:3833
fe_fffb3
const fe fe_fffb3
Definition: crypto-ops-data.c:871
ge_p3_to_p2
void ge_p3_to_p2(ge_p2 *, const ge_p3 *)
Definition: crypto-ops.c:1558
ge_cached::YplusX
fe YplusX
Definition: crypto-ops.h:66
ge_p1p1::Z
fe Z
Definition: crypto-ops.h:55
ge_double_scalarmult_precomp_vartime2_p3
void ge_double_scalarmult_precomp_vartime2_p3(ge_p3 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp)
Definition: crypto-ops.c:2251
load_4
uint64_t load_4(const unsigned char *in)
Definition: crypto-ops.c:59
ge_p2::X
fe X
Definition: crypto-ops.h:40
fe_ma
const fe fe_ma
Definition: crypto-ops-data.c:868
fe_d2
const fe fe_d2
Definition: crypto-ops-data.c:39
ge_sub
void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
Definition: crypto-ops.c:1687
load_3
uint64_t load_3(const unsigned char *in)
Definition: crypto-ops.c:51
ge_p2_dbl
void ge_p2_dbl(ge_p1p1 *, const ge_p2 *)
Definition: crypto-ops.c:1505
ge_precomp::yplusx
fe yplusx
Definition: crypto-ops.h:60
ge_frombytes_vartime
int ge_frombytes_vartime(ge_p3 *, const unsigned char *)
Definition: crypto-ops.c:1334
ge_cached::YminusX
fe YminusX
Definition: crypto-ops.h:67
fe_sqrtm1
const fe fe_sqrtm1
Definition: crypto-ops-data.c:38