Monero
Loading...
Searching...
No Matches
crypto-ops.h
Go to the documentation of this file.
1// Copyright (c) 2014-2022, 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#include <stdint.h>
31
32#pragma once
33
34
35/* From fe.h */
36
37//this guy may throw errors in windows
38typedef int32_t fe[10];
39
40/* From ge.h */
41
42typedef struct {
43 fe X;
44 fe Y;
45 fe Z;
46} ge_p2;
47
48typedef struct {
49 fe X;
50 fe Y;
51 fe Z;
52 fe T;
53} ge_p3;
54
55typedef struct {
56 fe X;
57 fe Y;
58 fe Z;
59 fe T;
60} ge_p1p1;
61
62typedef struct {
63 fe yplusx;
64 fe yminusx;
65 fe xy2d;
67
68typedef struct {
69 fe YplusX;
70 fe YminusX;
71 fe Z;
72 fe T2d;
73} ge_cached;
74
75/* From ge_add.c */
76
77void ge_add(ge_p1p1 *, const ge_p3 *, const ge_cached *);
78
79/* From ge_double_scalarmult.c, modified */
80
81typedef ge_cached ge_dsmp[8];
82extern const ge_precomp ge_Bi[8];
83void ge_dsm_precomp(ge_dsmp r, const ge_p3 *s);
84void ge_double_scalarmult_base_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *);
85
86/* From ge_frombytes.c, modified */
87
88extern const fe fe_sqrtm1;
89extern const fe fe_d;
90int ge_frombytes_vartime(ge_p3 *, const unsigned char *);
91
92/* From ge_p1p1_to_p2.c */
93
94void ge_p1p1_to_p2(ge_p2 *, const ge_p1p1 *);
95
96/* From ge_p1p1_to_p3.c */
97
98void ge_p1p1_to_p3(ge_p3 *, const ge_p1p1 *);
99
100/* From ge_p2_dbl.c */
101
102void ge_p2_dbl(ge_p1p1 *, const ge_p2 *);
103
104/* From ge_p3_to_cached.c */
105
106extern const fe fe_d2;
107void ge_p3_to_cached(ge_cached *, const ge_p3 *);
108
109/* From ge_p3_to_p2.c */
110
111void ge_p3_to_p2(ge_p2 *, const ge_p3 *);
112
113/* From ge_p3_tobytes.c */
114
115void ge_p3_tobytes(unsigned char *, const ge_p3 *);
116
117/* From ge_scalarmult_base.c */
118
119extern const ge_precomp ge_base[32][8];
120void ge_scalarmult_base(ge_p3 *, const unsigned char *);
121
122/* From ge_tobytes.c */
123
124void ge_tobytes(unsigned char *, const ge_p2 *);
125
126/* From sc_reduce.c */
127
128void sc_reduce(unsigned char *);
129
130/* New code */
131
132void ge_scalarmult(ge_p2 *, const unsigned char *, const ge_p3 *);
133void ge_double_scalarmult_precomp_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *, const ge_dsmp);
134void ge_mul8(ge_p1p1 *, const ge_p2 *);
135extern const fe fe_ma2;
136extern const fe fe_ma;
137extern const fe fe_fffb1;
138extern const fe fe_fffb2;
139extern const fe fe_fffb3;
140extern const fe fe_fffb4;
141void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *);
142void sc_0(unsigned char *);
143void sc_reduce32(unsigned char *);
144void sc_add(unsigned char *, const unsigned char *, const unsigned char *);
145void sc_sub(unsigned char *, const unsigned char *, const unsigned char *);
146void sc_mulsub(unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *);
147int sc_check(const unsigned char *);
148int sc_isnonzero(const unsigned char *); /* Doesn't normalize */
#define s(x, c)
Definition aesb.c:47
#define fe(x)
Definition aesb.c:128
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
void sc_0(unsigned char *)
Definition crypto-ops.c:2426
ge_cached ge_dsmp[8]
Definition crypto-ops.h:78
void sc_reduce32(unsigned char *)
Definition crypto-ops.c:2433
void ge_dsm_precomp(ge_dsmp r, const ge_p3 *s)
Definition crypto-ops.c:1175
int ge_frombytes_vartime(ge_p3 *, const unsigned char *)
Definition crypto-ops.c:1334
void sc_sub(unsigned char *, const unsigned char *, const unsigned char *)
Definition crypto-ops.c:2687
void sc_mulsub(unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *)
Definition crypto-ops.c:2837
void ge_mul8(ge_p1p1 *, const ge_p2 *)
Definition crypto-ops.c:2301
int sc_check(const unsigned char *)
Definition crypto-ops.c:3814
void ge_double_scalarmult_base_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *)
Definition crypto-ops.c:1196
int sc_isnonzero(const unsigned char *)
Definition crypto-ops.c:3826
void sc_add(unsigned char *, const unsigned char *, const unsigned char *)
Definition crypto-ops.c:2548
void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *)
Definition crypto-ops.c:2310
void ge_scalarmult(ge_p2 *, const unsigned char *, const ge_p3 *)
Definition crypto-ops.c:2038
#define Z
Definition mdb.c:474
#define ge_scalarmult_base
Definition ge.h:71
#define ge_p1p1_to_p2
Definition ge.h:62
#define ge_p1p1_to_p3
Definition ge.h:63
#define ge_p3_tobytes
Definition ge.h:55
#define ge_p3_to_cached
Definition ge.h:61
#define ge_add
Definition ge.h:69
#define ge_p3_to_p2
Definition ge.h:60
#define ge_p2_dbl
Definition ge.h:64
#define ge_tobytes
Definition ge.h:54
#define sc_reduce
Definition sc.h:9
const fe fe_fffb4
Definition crypto-ops-data.c:872
const fe fe_d2
Definition crypto-ops-data.c:39
const fe fe_fffb3
Definition crypto-ops-data.c:871
const fe fe_ma2
Definition crypto-ops-data.c:867
const fe fe_ma
Definition crypto-ops-data.c:868
const ge_precomp ge_base[32][8]
Definition crypto-ops-data.c:42
const fe fe_d
Definition crypto-ops-data.c:37
const fe fe_fffb1
Definition crypto-ops-data.c:869
const ge_precomp ge_Bi[8]
Definition crypto-ops-data.c:846
const fe fe_sqrtm1
Definition crypto-ops-data.c:38
const fe fe_fffb2
Definition crypto-ops-data.c:870
signed int int32_t
Definition stdint.h:123
Definition crypto-ops.h:65
Definition crypto-ops.h:52
Definition crypto-ops.h:39
Definition crypto-ops.h:45
Definition crypto-ops.h:59
#define T(x)