Electroneum
crypto-ops.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2021, The Electroneum Project
2 // Copyrights(c) 2014-2019, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31 
32 #pragma once
33 
34 /* From fe.h */
35 
36 typedef int32_t fe[10];
37 
38 /* From ge.h */
39 
40 typedef struct {
41  fe X;
42  fe Y;
43  fe Z;
44 } ge_p2;
45 
46 typedef struct {
47  fe X;
48  fe Y;
49  fe Z;
50  fe T;
51 } ge_p3;
52 
53 typedef struct {
54  fe X;
55  fe Y;
56  fe Z;
57  fe T;
58 } ge_p1p1;
59 
60 typedef struct {
64 } ge_precomp;
65 
66 typedef struct {
69  fe Z;
71 } ge_cached;
72 
73 /* From ge_add.c */
74 
75 void ge_add(ge_p1p1 *, const ge_p3 *, const ge_cached *);
76 
77 /* From ge_double_scalarmult.c, modified */
78 
79 typedef ge_cached ge_dsmp[8];
80 extern const ge_precomp ge_Bi[8];
81 void ge_dsm_precomp(ge_dsmp r, const ge_p3 *s);
82 void ge_double_scalarmult_base_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *);
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_double_scalarmult_precomp_vartime2(ge_p2 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp);
135 void ge_double_scalarmult_precomp_vartime2_p3(ge_p3 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp);
136 void ge_mul8(ge_p1p1 *, const ge_p2 *);
137 extern const fe fe_ma2;
138 extern const fe fe_ma;
139 extern const fe fe_fffb1;
140 extern const fe fe_fffb2;
141 extern const fe fe_fffb3;
142 extern const fe fe_fffb4;
143 extern const ge_p3 ge_p3_identity;
144 extern const ge_p3 ge_p3_H;
145 void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *);
146 void sc_0(unsigned char *);
147 void sc_reduce32(unsigned char *);
148 void sc_add(unsigned char *, const unsigned char *, const unsigned char *);
149 void sc_sub(unsigned char *, const unsigned char *, const unsigned char *);
150 void sc_mulsub(unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *);
151 void sc_mul(unsigned char *, const unsigned char *, const unsigned char *);
152 void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c);
153 int sc_check(const unsigned char *);
154 int sc_isnonzero(const unsigned char *); /* Doesn't normalize */
155 
156 // internal
157 uint64_t load_3(const unsigned char *in);
158 uint64_t load_4(const unsigned char *in);
159 void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
160 void fe_add(fe h, const fe f, const fe g);
161 void fe_tobytes(unsigned char *, const fe);
162 void fe_invert(fe out, const fe z);
163 
164 int ge_p3_is_point_at_infinity(const ge_p3 *p);
const fe fe_d
const fe fe_ma
void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
void fe_add(fe h, const fe f, const fe g)
void ge_tobytes(unsigned char *, const ge_p2 *)
int sc_check(const unsigned char *)
int32_t fe[10]
Definition: crypto-ops.h:36
void sc_reduce(unsigned char *)
const fe fe_fffb4
void ge_double_scalarmult_base_vartime_p3(ge_p3 *, const unsigned char *, const ge_p3 *, const unsigned char *)
void sc_sub(unsigned char *, const unsigned char *, const unsigned char *)
void ge_scalarmult_base(ge_p3 *, const unsigned char *)
fe Z
Definition: crypto-ops.h:49
void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *)
void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c)
int sc_isnonzero(const unsigned char *)
const fe fe_fffb1
void ge_scalarmult_p3(ge_p3 *, const unsigned char *, const ge_p3 *)
const fe fe_fffb2
void ge_double_scalarmult_precomp_vartime2(ge_p2 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp)
void ge_p1p1_to_p2(ge_p2 *, const ge_p1p1 *)
void sc_reduce32(unsigned char *)
void ge_double_scalarmult_precomp_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *, const ge_dsmp)
const ge_precomp ge_Bi[8]
void sc_mulsub(unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *)
void ge_double_scalarmult_base_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *)
unsigned __int64 uint64_t
Definition: stdint.h:136
fe Z
Definition: crypto-ops.h:43
fe Y
Definition: crypto-ops.h:42
void ge_mul8(ge_p1p1 *, const ge_p2 *)
void sc_0(unsigned char *)
void fe_tobytes(unsigned char *, const fe)
void fe_invert(fe out, const fe z)
const fe fe_d2
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
void ge_p2_dbl(ge_p1p1 *, const ge_p2 *)
ge_cached ge_dsmp[8]
Definition: crypto-ops.h:79
const ge_p3 ge_p3_H
void ge_dsm_precomp(ge_dsmp r, const ge_p3 *s)
void ge_add(ge_p1p1 *, const ge_p3 *, const ge_cached *)
void ge_double_scalarmult_precomp_vartime2_p3(ge_p3 *, const unsigned char *, const ge_dsmp, const unsigned char *, const ge_dsmp)
const ge_p3 ge_p3_identity
void ge_p1p1_to_p3(ge_p3 *, const ge_p1p1 *)
uint64_t load_3(const unsigned char *in)
fe T
Definition: crypto-ops.h:50
void ge_scalarmult(ge_p2 *, const unsigned char *, const ge_p3 *)
int ge_frombytes_vartime(ge_p3 *, const unsigned char *)
int ge_p3_is_point_at_infinity(const ge_p3 *p)
const fe fe_ma2
signed int int32_t
Definition: stdint.h:123
const fe fe_sqrtm1
void sc_mul(unsigned char *, const unsigned char *, const unsigned char *)
void sc_add(unsigned char *, const unsigned char *, const unsigned char *)
uint64_t load_4(const unsigned char *in)
const ge_precomp ge_base[32][8]
fe X
Definition: crypto-ops.h:47
fe Y
Definition: crypto-ops.h:48
fe YminusX
Definition: crypto-ops.h:68
void ge_p3_tobytes(unsigned char *, const ge_p3 *)
fe X
Definition: crypto-ops.h:41
void ge_p3_to_p2(ge_p2 *, const ge_p3 *)
const fe fe_fffb3
void ge_p3_to_cached(ge_cached *, const ge_p3 *)