From 78ca7157465258c7d43f2892ec58f8412badc16c Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 24 Sep 2020 14:21:46 +0300 Subject: [PATCH] Add AES CBC benchmark. GitOrigin-RevId: 1341d108549c70d9d0b35904eb6389e7589452fc --- benchmark/bench_crypto.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/benchmark/bench_crypto.cpp b/benchmark/bench_crypto.cpp index eaca9c8e2..d957c2272 100644 --- a/benchmark/bench_crypto.cpp +++ b/benchmark/bench_crypto.cpp @@ -206,14 +206,40 @@ class AesCtrOpenSSLBench : public td::Benchmark { } }; -class AesCbcBench : public td::Benchmark { +class AesCbcDecryptBench : 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 CBC OpenSSL [" << (DATA_SIZE >> 10) << "KB]"; + return PSTRING() << "AES CBC Decrypt OpenSSL [" << (DATA_SIZE >> 10) << "KB]"; + } + + void start_up() override { + for (int i = 0; i < DATA_SIZE; i++) { + data[i] = 123; + } + td::Random::secure_bytes(as_slice(key)); + td::Random::secure_bytes(as_slice(iv)); + } + + void run(int n) override { + td::MutableSlice data_slice(data, DATA_SIZE); + for (int i = 0; i < n; i++) { + td::aes_cbc_decrypt(as_slice(key), as_slice(iv), data_slice, data_slice); + } + } +}; + +class AesCbcEncryptBench : 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 CBC Encrypt OpenSSL [" << (DATA_SIZE >> 10) << "KB]"; } void start_up() override { @@ -391,6 +417,8 @@ int main() { td::bench(AesCtrBench()); td::bench(AesCtrOpenSSLBench()); + td::bench(AesCbcDecryptBench()); + td::bench(AesCbcEncryptBench()); td::bench(AesIgeShortBench()); td::bench(AesIgeShortBench()); td::bench(AesIgeEncryptBench());