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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*
* (C) 2015 Simon Warta (Kullo GmbH)
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include "speed.h"
using namespace Botan;
#if defined(BOTAN_HAS_NUMBERTHEORY)
#include <botan/numthry.h>
#include <chrono>
namespace {
const size_t RSA_EXP = 65537;
const size_t RSA_BITS = 2048;
const auto SAMPLE_DATA = std::vector<BigInt>{
BigInt("147572674850319649408425528388978190129147580193826207917614581140087181349813950149403694089438460074197915858493514824951402666113125007396293585089750170962882245605820159076002066981429137353341175732273168874025070408827561035943771554301600092787967626039381375658829078877390735440179859333066156895363"),
BigInt("147572674850319649408425528388978190129147580193826207917614581140087181349813950149403694089438460074197915858493514824951402666113125007396293585089750170962882245605820159076002066981429137353341175732273168874025070408827561035943771554301600092787967626039381375658829078877390735440179859333066156895377"),
BigInt("147572674850319649408425528388978190129147580193826207917614581140087181349813950149403694089438460074197915858493514824951402666113125007396293585089750170962882245605820159076002066981429137353341175732273168874025070408827561035943771554301600092787967626039381375658829078877390735440179859333066156895381"),
BigInt("147572674850319649408425528388978190129147580193826207917614581140087181349813950149403694089438460074197915858493514824951402666113125007396293585089750170962882245605820159076002066981429137353341175732273168874025070408827561035943771554301600092787967626039381375658829078877390735440179859333066156895389"),
BigInt("147572674850319649408425528388978190129147580193826207917614581140087181349813950149403694089438460074197915858493514824951402666113125007396293585089750170962882245605820159076002066981429137353341175732273168874025070408827561035943771554301600092787967626039381375658829078877390735440179859333066156895399"),
BigInt("147572674850319649408425528388978190129147580193826207917614581140087181349813950149403694089438460074197915858493514824951402666113125007396293585089750170962882245605820159076002066981429137353341175732273168874025070408827561035943771554301600092787967626039381375658829078877390735440179859333066156895401"),
BigInt("147572674850319649408425528388978190129147580193826207917614581140087181349813950149403694089438460074197915858493514824951402666113125007396293585089750170962882245605820159076002066981429137353341175732273168874025070408827561035943771554301600092787967626039381375658829078877390735440179859333066156895431"),
BigInt("147572674850319649408425528388978190129147580193826207917614581140087181349813950149403694089438460074197915858493514824951402666113125007396293585089750170962882245605820159076002066981429137353341175732273168874025070408827561035943771554301600092787967626039381375658829078877390735440179859333066156895441"),
BigInt("147572674850319649408425528388978190129147580193826207917614581140087181349813950149403694089438460074197915858493514824951402666113125007396293585089750170962882245605820159076002066981429137353341175732273168874025070408827561035943771554301600092787967626039381375658829078877390735440179859333066156895461"),
BigInt("147572674850319649408425528388978190129147580193826207917614581140087181349813950149403694089438460074197915858493514824951402666113125007396293585089750170962882245605820159076002066981429137353341175732273168874025070408827561035943771554301600092787967626039381375658829078877390735440179859333066156895471"),
};
}
#endif // BOTAN_HAS_NUMBERTHEORY
std::map<std::string, double> benchmark_is_prime(RandomNumberGenerator& rng,
const std::chrono::milliseconds runtime)
{
std::map<std::string, double> speeds;
#if defined(BOTAN_HAS_NUMBERTHEORY)
std::chrono::nanoseconds time_used(0);
size_t reps = 0;
auto start = std::chrono::high_resolution_clock::now();
while(time_used < runtime)
{
// main work
for (const BigInt &p : SAMPLE_DATA)
{
is_prime(p, rng, 64, true);
}
++reps;
time_used = std::chrono::high_resolution_clock::now() - start;
}
const double seconds_used = static_cast<double>(time_used.count()) / 1000000000;
speeds["base"] = reps / seconds_used; // ie, return ops per second
#endif // BOTAN_HAS_NUMBERTHEORY
return speeds;
}
std::map<std::string, double> benchmark_random_prime(RandomNumberGenerator& rng,
const std::chrono::milliseconds runtime)
{
std::map<std::string, double> speeds;
#if defined(BOTAN_HAS_NUMBERTHEORY)
std::chrono::nanoseconds time_used(0);
size_t reps = 0;
auto start = std::chrono::high_resolution_clock::now();
while(time_used < runtime)
{
// main work
random_prime(rng, (RSA_BITS + 1) / 2, RSA_EXP);
++reps;
time_used = std::chrono::high_resolution_clock::now() - start;
}
const double seconds_used = static_cast<double>(time_used.count()) / 1000000000;
speeds["base"] = reps / seconds_used; // ie, return ops per second
#endif // BOTAN_HAS_NUMBERTHEORY
return speeds;
}
|