aboutsummaryrefslogtreecommitdiffhomepage
path: root/benchmark/bench_crypto.cpp
diff options
context:
space:
mode:
authorArseny Smirnov <arseny30@gmail.com>2020-06-12 19:40:17 +0300
committerArseny Smirnov <arseny30@gmail.com>2020-06-12 19:40:17 +0300
commite913c3126bcd7121998464dce818538869140da7 (patch)
tree8f32ec96b5d84ea5b421ebc630b3ffe7d1b8a423 /benchmark/bench_crypto.cpp
parent55ca575af546095f9c36a2616d968a513fd22127 (diff)
tdutils: optimize aes ctr
GitOrigin-RevId: 09c6df45c0bf2683507a0f279769471efc859ecb
Diffstat (limited to 'benchmark/bench_crypto.cpp')
-rw-r--r--benchmark/bench_crypto.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/benchmark/bench_crypto.cpp b/benchmark/bench_crypto.cpp
index 6536fa613..369506884 100644
--- a/benchmark/bench_crypto.cpp
+++ b/benchmark/bench_crypto.cpp
@@ -71,13 +71,42 @@ class AesBench : public td::Benchmark {
state.init(td::as_slice(key), true);
td::MutableSlice data_slice(data, DATA_SIZE);
for (int i = 0; i <= n; i++) {
- for (size_t offset = 0; offset + 16 <= data_slice.size(); offset += 16) {
- state.encrypt(data_slice.ubegin() + offset, data_slice.ubegin() + offset);
+ size_t step = 16;
+ for (size_t offset = 0; offset + 16 <= data_slice.size(); offset += step) {
+ state.encrypt(data_slice.ubegin() + offset, data_slice.ubegin() + offset, (int)step);
}
}
}
};
+class AesCtrBench : public td::Benchmark {
+ public:
+ alignas(64) unsigned char data[DATA_SIZE];
+ td::UInt256 key;
+ td::UInt128 iv;
+
+ std::string get_description() const override {
+ return PSTRING() << "AES CTR OpenSSL [" << (DATA_SIZE >> 10) << "KB]";
+ }
+
+ void start_up() override {
+ for (int i = 0; i < DATA_SIZE; i++) {
+ data[i] = 123;
+ }
+ td::Random::secure_bytes(key.raw, sizeof(key));
+ td::Random::secure_bytes(iv.raw, sizeof(iv));
+ }
+
+ void run(int n) override {
+ td::AesCtrState state;
+ state.init(as_slice(key), as_slice(iv));
+ td::MutableSlice data_slice(data, DATA_SIZE);
+ for (int i = 0; i < n; i++) {
+ state.encrypt(data_slice, data_slice);
+ }
+ }
+};
+
class AESBench : public td::Benchmark {
public:
alignas(64) unsigned char data[DATA_SIZE];
@@ -227,6 +256,7 @@ class Crc64Bench : public td::Benchmark {
int main() {
td::init_openssl_threads();
+ td::bench(AesCtrBench());
td::bench(AesBench());
td::bench(AESBench());