Monero
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 
31 #pragma once
32 
33 #include "crypto/crypto.h"
34 #include "ringct/rctOps.h"
35 
36 enum test_op
37 {
45 
65 };
66 
67 template<test_op op>
69 {
70 public:
71  static const size_t loop_count = op < ops_fast ? 10000000 : 1000;
72 
73  bool init()
74  {
75  scalar0 = rct::skGen();
76  scalar1 = rct::skGen();
77  scalar2 = rct::skGen();
82  return false;
84  return false;
86  return false;
91  return true;
92  }
93 
94  bool test()
95  {
96  rct::key key;
97  ge_cached tmp_cached;
98  ge_p1p1 tmp_p1p1;
99  ge_p2 tmp_p2;
100  ge_dsmp dsmp;
101  switch (op)
102  {
103  case op_sc_add: sc_add(key.bytes, scalar0.bytes, scalar1.bytes); break;
104  case op_sc_sub: sc_sub(key.bytes, scalar0.bytes, scalar1.bytes); break;
105  case op_sc_mul: sc_mul(key.bytes, scalar0.bytes, scalar1.bytes); break;
106  case op_ge_add_p3_p3: {
107  ge_p3_to_cached(&tmp_cached, &p3_0);
108  ge_add(&tmp_p1p1, &p3_1, &tmp_cached);
109  ge_p1p1_to_p3(&p3_1, &tmp_p1p1);
110  break;
111  }
112  case op_ge_add_raw: ge_add(&tmp_p1p1, &p3_1, &cached); break;
113  case op_addKeys: rct::addKeys(key, point0, point1); break;
117  case op_scalarmult8: rct::scalarmult8(point0); break;
119  case op_ge_dsm_precomp: ge_dsm_precomp(dsmp, &p3_0); break;
131  case op_zeroCommitUncached: rct::zeroCommit(9001); break;
132  case op_zeroCommitCached: rct::zeroCommit(9000); break;
133  default: return false;
134  }
135  return true;
136  }
137 
138 private:
144 };
void ge_double_scalarmult_base_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b)
Definition: crypto-ops.c:1196
void addKeys_aAbBcC(key &aAbBcC, const key &a, const ge_dsmp A, const key &b, const ge_dsmp B, const key &c, const ge_dsmp C)
Definition: rctOps.cpp:526
Definition: crypto_ops.h:52
static const size_t loop_count
Definition: crypto_ops.h:71
Definition: crypto_ops.h:46
ge_dsmp precomp0
Definition: crypto_ops.h:143
Definition: crypto-ops.h:52
void precomp(ge_dsmp rv, const key &B)
Definition: rctOps.cpp:488
bool isInMainSubgroup(const key &A)
Definition: rctOps.cpp:424
Definition: crypto_ops.h:54
Definition: crypto-ops.h:39
Definition: crypto_ops.h:63
Definition: crypto_ops.h:58
bool test()
Definition: crypto_ops.h:94
void addKeys3(key &aAbB, const key &a, const key &A, const key &b, const ge_dsmp B)
Definition: rctOps.cpp:497
void scalarmultKey(key &aP, const key &P, const key &a)
Definition: rctOps.cpp:368
Definition: crypto_ops.h:39
Definition: crypto_ops.h:57
rct::key scalar1
Definition: crypto_ops.h:139
ge_p3 p3_1
Definition: crypto_ops.h:141
Definition: crypto-ops.h:45
void ge_double_scalarmult_precomp_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b, const ge_dsmp Bi)
Definition: crypto-ops.c:2294
rct::key scalar2
Definition: crypto_ops.h:139
const char * key
Definition: hmac_keccak.cpp:40
Definition: crypto_ops.h:62
int ge_frombytes_vartime(ge_p3 *h, const unsigned char *s)
Definition: crypto-ops.c:1334
ge_p3 p3_0
Definition: crypto_ops.h:141
Definition: crypto_ops.h:60
Definition: crypto_ops.h:42
void addKeys_aGbBcC(key &aGbBcC, const key &a, const key &b, const ge_dsmp B, const key &c, const ge_dsmp C)
Definition: rctOps.cpp:517
key zeroCommit(xmr_amount amount)
Definition: rctOps.cpp:322
rct::key point0
Definition: crypto_ops.h:140
void ge_triple_scalarmult_precomp_vartime(ge_p2 *r, const unsigned char *a, const ge_dsmp Ai, const unsigned char *b, const ge_dsmp Bi, const unsigned char *c, const ge_dsmp Ci)
Definition: crypto-ops.c:2202
Definition: crypto_ops.h:51
Definition: crypto_ops.h:44
ge_dsmp precomp2
Definition: crypto_ops.h:143
Definition: crypto_ops.h:61
void sc_mul(unsigned char *s, const unsigned char *a, const unsigned char *b)
Definition: crypto-ops.c:3168
Definition: crypto_ops.h:49
ge_cached cached
Definition: crypto_ops.h:142
Definition: crypto_ops.h:50
Definition: crypto-ops.h:65
void sc_add(unsigned char *s, const unsigned char *a, const unsigned char *b)
Definition: crypto-ops.c:2548
Definition: crypto_ops.h:47
Definition: rctTypes.h:79
rct::key point1
Definition: crypto_ops.h:140
key scalarmultH(const key &a)
Definition: rctOps.cpp:389
#define ge_p1p1_to_p3
Definition: ge.h:63
rct::key point2
Definition: crypto_ops.h:140
Definition: crypto_ops.h:43
bool init()
Definition: crypto_ops.h:73
Definition: crypto_ops.h:55
void sc_sub(unsigned char *s, const unsigned char *a, const unsigned char *b)
Definition: crypto-ops.c:2687
#define ge_add
Definition: ge.h:69
void ge_dsm_precomp(ge_dsmp r, const ge_p3 *s)
Definition: crypto-ops.c:1175
void skGen(key &sk)
Definition: rctOps.cpp:253
#define ge_p3_to_cached
Definition: ge.h:61
Definition: crypto_ops.h:68
Definition: crypto_ops.h:40
void scalarmultBase(key &aG, const key &a)
Definition: rctOps.cpp:350
ge_cached ge_dsmp[8]
Definition: crypto-ops.h:78
unsigned char bytes[32]
Definition: rctTypes.h:87
Definition: crypto_ops.h:41
void ge_triple_scalarmult_base_vartime(ge_p2 *r, const unsigned char *a, const unsigned char *b, const ge_dsmp Bi, const unsigned char *c, const ge_dsmp Ci)
Definition: crypto-ops.c:1238
void addKeys2(key &aGbB, const key &a, const key &b, const key &B)
Definition: rctOps.cpp:478
Definition: crypto_ops.h:38
key scalarmult8(const key &P)
Definition: rctOps.cpp:398
void ge_double_scalarmult_precomp_vartime2(ge_p2 *r, const unsigned char *a, const ge_dsmp Ai, const unsigned char *b, const ge_dsmp Bi)
Definition: crypto-ops.c:2162
ge_dsmp precomp1
Definition: crypto_ops.h:143
Definition: crypto_ops.h:56
Definition: crypto_ops.h:53
void addKeys(key &AB, const key &A, const key &B)
Definition: rctOps.cpp:432
Definition: crypto_ops.h:48
test_op
Definition: crypto_ops.h:36
ge_p3 p3_2
Definition: crypto_ops.h:141
Definition: crypto_ops.h:64
Definition: crypto_ops.h:59
rct::key scalar0
Definition: crypto_ops.h:139