From cadada2d652102adebbfb1ced82da27a9a691b56 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 10 Feb 2017 18:45:18 +0000 Subject: [PATCH] performance_tests: add tests for sc_reduce32 and cn_fast_hash --- tests/performance_tests/cn_fast_hash.h | 57 ++++++++++++++++++++++++++ tests/performance_tests/main.cpp | 7 +++- tests/performance_tests/sc_reduce32.h | 53 ++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tests/performance_tests/cn_fast_hash.h create mode 100644 tests/performance_tests/sc_reduce32.h diff --git a/tests/performance_tests/cn_fast_hash.h b/tests/performance_tests/cn_fast_hash.h new file mode 100644 index 00000000..24f2bc5e --- /dev/null +++ b/tests/performance_tests/cn_fast_hash.h @@ -0,0 +1,57 @@ +// Copyright (c) 2014-2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#pragma once + +#include "crypto/crypto.h" +#include "cryptonote_core/cryptonote_basic.h" + +template +class test_cn_fast_hash +{ +public: + static const size_t loop_count = bytes < 256 ? 100000 : bytes < 4096 ? 10000 : 1000; + + bool init() + { + crypto::rand(bytes, m_data.data()); + return true; + } + + bool test() + { + crypto::hash hash; + crypto::cn_fast_hash(&m_data, bytes, hash); + return true; + } + +private: + std::array m_data; +}; diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 1d3c79ca..cc9fe86e 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2016, The Monero Project +// Copyright (c) 2014-2017, The Monero Project // // All rights reserved. // @@ -43,6 +43,8 @@ #include "generate_key_image_helper.h" #include "generate_keypair.h" #include "is_out_to_acc.h" +#include "sc_reduce32.h" +#include "cn_fast_hash.h" int main(int argc, char** argv) { @@ -105,8 +107,11 @@ int main(int argc, char** argv) TEST_PERFORMANCE0(test_derive_secret_key); TEST_PERFORMANCE0(test_ge_frombytes_vartime); TEST_PERFORMANCE0(test_generate_keypair); + TEST_PERFORMANCE0(test_sc_reduce32); TEST_PERFORMANCE0(test_cn_slow_hash); + TEST_PERFORMANCE1(test_cn_fast_hash, 32); + TEST_PERFORMANCE1(test_cn_fast_hash, 16384); std::cout << "Tests finished. Elapsed time: " << timer.elapsed_ms() / 1000 << " sec" << std::endl; diff --git a/tests/performance_tests/sc_reduce32.h b/tests/performance_tests/sc_reduce32.h new file mode 100644 index 00000000..bb3ad169 --- /dev/null +++ b/tests/performance_tests/sc_reduce32.h @@ -0,0 +1,53 @@ +// Copyright (c) 2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +#include "crypto/crypto.h" + +class test_sc_reduce32 +{ +public: + static const size_t loop_count = 10000000; + + bool init() + { + m_hash = crypto::rand(); + return true; + } + + bool test() + { + crypto::hash reduced = m_hash; + sc_reduce32((unsigned char*)reduced.data); + return true; + } + +private: + crypto::hash m_hash; +};