-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrc5_aes.cpp
More file actions
89 lines (80 loc) · 4.21 KB
/
rc5_aes.cpp
File metadata and controls
89 lines (80 loc) · 4.21 KB
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
// Copyright 2020 The Division Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Author dietoad@gmail.com && firedtoad@gmail.com
#include <benchmark/benchmark.h>
#include <cryptopp/aes.h>
#include <cryptopp/chacha.h>
#include <cryptopp/des.h>
#include <cryptopp/modes.h>
#include <cryptopp/rc5.h>
#include <cryptopp/rc6.h>
#include <cryptopp/salsa.h>
#include <numeric>
#include <vector>
static unsigned char str_key[16];
template <typename T, size_t kLen = 16> static void BM_CRYPTO_NO_IV(benchmark::State &state)
{
T enc(str_key, kLen);
std::vector<uint8_t> in(state.range(0));
for (auto _ : state)
{
std::vector<uint8_t> out(state.range(0));
enc.ProcessData(out.data(), in.data(), in.size());
}
}
template <typename T,size_t kLen = 16> static void BM_CRYPTO(benchmark::State &state)
{
uint8_t iv[kLen];
T enc(str_key, kLen, iv);
std::vector<uint8_t> in(state.range(0));
for (auto _ : state)
{
std::vector<uint8_t> out(state.range(0));
enc.ProcessData(out.data(), in.data(), in.size());
}
}
BENCHMARK_TEMPLATE(BM_CRYPTO_NO_IV, CryptoPP::ECB_Mode<CryptoPP::RC5>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CBC_Mode<CryptoPP::RC5>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CFB_Mode<CryptoPP::RC5>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::OFB_Mode<CryptoPP::RC5>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CBC_CTS_Mode<CryptoPP::RC5>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CTR_Mode<CryptoPP::RC5>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO_NO_IV, CryptoPP::ECB_Mode<CryptoPP::RC6>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CBC_Mode<CryptoPP::RC6>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CFB_Mode<CryptoPP::RC6>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::OFB_Mode<CryptoPP::RC6>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CBC_CTS_Mode<CryptoPP::RC6>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CTR_Mode<CryptoPP::RC6>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO_NO_IV, CryptoPP::ECB_Mode<CryptoPP::DES>::Encryption,8)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CBC_Mode<CryptoPP::DES>::Encryption,8)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CFB_Mode<CryptoPP::DES>::Encryption,8)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::OFB_Mode<CryptoPP::DES>::Encryption,8)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CBC_CTS_Mode<CryptoPP::DES>::Encryption,8)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CTR_Mode<CryptoPP::DES>::Encryption,8)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO_NO_IV, CryptoPP::ECB_Mode<CryptoPP::AES>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::OFB_Mode<CryptoPP::AES>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CBC_CTS_Mode<CryptoPP::AES>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::CTR_Mode<CryptoPP::AES>::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::ChaCha::Encryption)->Range(16, 1024);
BENCHMARK_TEMPLATE(BM_CRYPTO, CryptoPP::Salsa20::Encryption)->Range(16, 1024);
int main(int argc, char **argv)
{
srand(time(nullptr));
std::iota(std::begin(str_key),std::end(str_key),rand());
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
return 0;
}