performance_tests: add tests for sc_reduce32 and cn_fast_hash

This commit is contained in:
moneromooo-monero 2017-02-10 18:45:18 +00:00
parent 962c72b624
commit cadada2d65
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
3 changed files with 116 additions and 1 deletions

View File

@ -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<size_t bytes>
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<uint8_t, bytes> m_data;
};

View File

@ -1,4 +1,4 @@
// Copyright (c) 2014-2016, The Monero Project // Copyright (c) 2014-2017, The Monero Project
// //
// All rights reserved. // All rights reserved.
// //
@ -43,6 +43,8 @@
#include "generate_key_image_helper.h" #include "generate_key_image_helper.h"
#include "generate_keypair.h" #include "generate_keypair.h"
#include "is_out_to_acc.h" #include "is_out_to_acc.h"
#include "sc_reduce32.h"
#include "cn_fast_hash.h"
int main(int argc, char** argv) 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_derive_secret_key);
TEST_PERFORMANCE0(test_ge_frombytes_vartime); TEST_PERFORMANCE0(test_ge_frombytes_vartime);
TEST_PERFORMANCE0(test_generate_keypair); TEST_PERFORMANCE0(test_generate_keypair);
TEST_PERFORMANCE0(test_sc_reduce32);
TEST_PERFORMANCE0(test_cn_slow_hash); 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; std::cout << "Tests finished. Elapsed time: " << timer.elapsed_ms() / 1000 << " sec" << std::endl;

View File

@ -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<crypto::hash>();
return true;
}
bool test()
{
crypto::hash reduced = m_hash;
sc_reduce32((unsigned char*)reduced.data);
return true;
}
private:
crypto::hash m_hash;
};