| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#pragma once |
| 33 |
|
| 34 |
#include <vector> |
| 35 |
#include "ringct/rctOps.h" |
| 36 |
#include "ringct/multiexp.h" |
| 37 |
|
| 38 |
enum test_multiexp_algorithm |
| 39 |
{ |
| 40 |
multiexp_bos_coster, |
| 41 |
multiexp_straus, |
| 42 |
multiexp_straus_cached, |
| 43 |
multiexp_pippenger, |
| 44 |
multiexp_pippenger_cached, |
| 45 |
}; |
| 46 |
|
| 47 |
template<test_multiexp_algorithm algorithm, size_t npoints, size_t c=0> |
| 48 |
class test_multiexp |
| 49 |
{ |
| 50 |
public: |
| 51 |
static const size_t loop_count = npoints >= 1024 ? 10 : npoints < 256 ? 1000 : 100; |
| 52 |
|
| 53 |
bool init() |
| 54 |
{ |
| 55 |
data.resize(npoints); |
| 56 |
res = rct::identity(); |
| 57 |
for (size_t n = 0; n < npoints; ++n) |
| 58 |
{ |
| 59 |
data[n].scalar = rct::skGen(); |
| 60 |
rct::key point = rct::scalarmultBase(rct::skGen()); |
| 61 |
if (ge_frombytes_vartime(&data[n].point, point.bytes)) |
| 62 |
return false; |
| 63 |
rct::key kn = rct::scalarmultKey(point, data[n].scalar); |
| 64 |
res = rct::addKeys(res, kn); |
| 65 |
} |
| 66 |
straus_cache = rct::straus_init_cache(data); |
| 67 |
pippenger_cache = rct::pippenger_init_cache(data); |
| 68 |
return true; |
| 69 |
} |
| 70 |
|
| 71 |
bool test() |
| 72 |
{ |
| 73 |
switch (algorithm) |
| 74 |
{ |
| 75 |
case multiexp_bos_coster: |
| 76 |
return res == bos_coster_heap_conv_robust(data); |
| 77 |
case multiexp_straus: |
| 78 |
return res == straus(data); |
| 79 |
case multiexp_straus_cached: |
| 80 |
return res == straus(data, straus_cache); |
| 81 |
case multiexp_pippenger: |
| 82 |
return res == pippenger(data, NULL, 0, c); |
| 83 |
case multiexp_pippenger_cached: |
| 84 |
return res == pippenger(data, pippenger_cache, 0, c); |
| 85 |
default: |
| 86 |
return false; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
private: |
| 91 |
std::vector<rct::MultiexpData> data; |
| 92 |
std::shared_ptr<rct::straus_cached_data> straus_cache; |
| 93 |
std::shared_ptr<rct::pippenger_cached_data> pippenger_cache; |
| 94 |
rct::key res; |
| 95 |
}; |