Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
multiexp.h
Go to the documentation of this file.
1
// Copyright (c) 2018, 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 <vector>
34
#include "
ringct/rctOps.h
"
35
#include "
ringct/multiexp.h
"
36
37
enum
test_multiexp_algorithm
38
{
39
multiexp_bos_coster
,
40
multiexp_straus
,
41
multiexp_straus_cached
,
42
multiexp_pippenger
,
43
multiexp_pippenger_cached
,
44
};
45
46
template
<test_multiexp_algorithm algorithm,
size_t
npo
int
s,
size_t
c=0>
47
class
test_multiexp
48
{
49
public
:
50
static
const
size_t
loop_count
= npoints >= 1024 ? 10 : npoints < 256 ? 1000 : 100;
51
52
bool
init
()
53
{
54
data.resize(npoints);
55
res =
rct::identity
();
56
for
(
size_t
n = 0; n < npoints; ++n)
57
{
58
data[n].scalar =
rct::skGen
();
59
rct::key
point =
rct::scalarmultBase
(
rct::skGen
());
60
if
(
ge_frombytes_vartime
(&data[n].point, point.
bytes
))
61
return
false
;
62
rct::key
kn =
rct::scalarmultKey
(point, data[n].scalar);
63
res =
rct::addKeys
(res, kn);
64
}
65
straus_cache =
rct::straus_init_cache
(data);
66
pippenger_cache =
rct::pippenger_init_cache
(data);
67
return
true
;
68
}
69
70
bool
test
()
71
{
72
switch
(algorithm)
73
{
74
case
multiexp_bos_coster
:
75
return
res == bos_coster_heap_conv_robust(data);
76
case
multiexp_straus
:
77
return
res == straus(data);
78
case
multiexp_straus_cached
:
79
return
res == straus(data, straus_cache);
80
case
multiexp_pippenger
:
81
return
res == pippenger(data, NULL, 0, c);
82
case
multiexp_pippenger_cached
:
83
return
res == pippenger(data, pippenger_cache, 0, c);
84
default
:
85
return
false
;
86
}
87
}
88
89
private
:
90
std::vector<rct::MultiexpData> data;
91
std::shared_ptr<rct::straus_cached_data> straus_cache;
92
std::shared_ptr<rct::pippenger_cached_data> pippenger_cache;
93
rct::key
res
;
94
};
test_multiexp
Definition
multiexp.h:48
test_multiexp::test
bool test()
Definition
multiexp.h:70
test_multiexp::loop_count
static const size_t loop_count
Definition
multiexp.h:50
test_multiexp::init
bool init()
Definition
multiexp.h:52
ge_frombytes_vartime
int ge_frombytes_vartime(ge_p3 *, const unsigned char *)
res
const char * res
Definition
hmac_keccak.cpp:41
rct::scalarmultBase
void scalarmultBase(key &aG, const key &a)
Definition
rctOps.cpp:350
rct::skGen
key skGen()
Definition
rctOps.cpp:258
rct::pippenger_init_cache
std::shared_ptr< pippenger_cached_data > pippenger_init_cache(const std::vector< MultiexpData > &data, size_t start_offset=0, size_t N=0)
rct::scalarmultKey
void scalarmultKey(key &aP, const key &P, const key &a)
Definition
rctOps.cpp:368
rct::addKeys
void addKeys(key &AB, const key &A, const key &B)
Definition
rctOps.cpp:420
rct::straus_init_cache
std::shared_ptr< straus_cached_data > straus_init_cache(const std::vector< MultiexpData > &data, size_t N=0)
rct::skGen
void skGen(key &sk)
Definition
rctOps.cpp:253
rct::identity
key identity()
Definition
rctOps.h:73
rctOps.h
multiexp.h
rct::key
Definition
rctTypes.h:78
rct::key::bytes
unsigned char bytes[32]
Definition
rctTypes.h:86
test_multiexp_algorithm
test_multiexp_algorithm
Definition
multiexp.h:38
multiexp_pippenger
@ multiexp_pippenger
Definition
multiexp.h:42
multiexp_pippenger_cached
@ multiexp_pippenger_cached
Definition
multiexp.h:43
multiexp_straus_cached
@ multiexp_straus_cached
Definition
multiexp.h:41
multiexp_bos_coster
@ multiexp_bos_coster
Definition
multiexp.h:39
multiexp_straus
@ multiexp_straus
Definition
multiexp.h:40
tests
performance_tests
multiexp.h
Generated on
for Electroneum by
1.17.0