diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-01-05 16:30:24 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-09-11 13:37:22 +0000 |
commit | 112f32f068e2e6d0b8e713ccf49090b73e542b5d (patch) | |
tree | 2c6cf07aa8001c63f38090f0a43ffd5b24b4e019 /tests/performance_tests/crypto_ops.h | |
parent | performance_tests: add bulletproofs (diff) | |
download | monero-112f32f068e2e6d0b8e713ccf49090b73e542b5d.tar.xz |
performance_tests: add crypto ops
Diffstat (limited to 'tests/performance_tests/crypto_ops.h')
-rw-r--r-- | tests/performance_tests/crypto_ops.h | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/tests/performance_tests/crypto_ops.h b/tests/performance_tests/crypto_ops.h new file mode 100644 index 000000000..852a6670d --- /dev/null +++ b/tests/performance_tests/crypto_ops.h @@ -0,0 +1,116 @@ +// 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 "ringct/rctOps.h" + +enum test_op +{ + op_sc_add, + op_sc_sub, + op_sc_mul, + op_ge_add_raw, + op_ge_add_p3_p3, + ops_fast, + + op_addKeys, + op_scalarmultBase, + op_scalarmultKey, + op_ge_double_scalarmult_base_vartime, + op_ge_double_scalarmult_precomp_vartime, + op_ge_double_scalarmult_precomp_vartime2, + op_addKeys2, + op_addKeys3, + op_addKeys3_2, +}; + +template<test_op op> +class test_crypto_ops +{ +public: + static const size_t loop_count = op < ops_fast ? 10000000 : 1000; + + bool init() + { + scalar0 = rct::skGen(); + scalar1 = rct::skGen(); + point0 = rct::scalarmultBase(rct::skGen()); + point1 = rct::scalarmultBase(rct::skGen()); + if (ge_frombytes_vartime(&p3_0, point0.bytes) != 0) + return false; + if (ge_frombytes_vartime(&p3_1, point1.bytes) != 0) + return false; + ge_p3_to_cached(&cached, &p3_0); + rct::precomp(precomp0, point0); + rct::precomp(precomp1, point1); + return true; + } + + bool test() + { + rct::key key; + ge_cached tmp_cached; + ge_p1p1 tmp_p1p1; + ge_p2 tmp_p2; + switch (op) + { + case op_sc_add: sc_add(key.bytes, scalar0.bytes, scalar1.bytes); break; + case op_sc_sub: sc_sub(key.bytes, scalar0.bytes, scalar1.bytes); break; + case op_sc_mul: sc_mul(key.bytes, scalar0.bytes, scalar1.bytes); break; + case op_ge_add_p3_p3: { + ge_p3_to_cached(&tmp_cached, &p3_0); + ge_add(&tmp_p1p1, &p3_1, &tmp_cached); + ge_p1p1_to_p3(&p3_1, &tmp_p1p1); + break; + } + case op_ge_add_raw: ge_add(&tmp_p1p1, &p3_1, &cached); break; + case op_addKeys: rct::addKeys(key, point0, point1); break; + case op_scalarmultBase: rct::scalarmultBase(scalar0); break; + case op_scalarmultKey: rct::scalarmultKey(point0, scalar0); break; + case op_ge_double_scalarmult_base_vartime: ge_double_scalarmult_base_vartime(&tmp_p2, scalar0.bytes, &p3_0, scalar1.bytes); break; + case op_ge_double_scalarmult_precomp_vartime: ge_double_scalarmult_precomp_vartime(&tmp_p2, scalar0.bytes, &p3_0, scalar1.bytes, precomp0); break; + case op_ge_double_scalarmult_precomp_vartime2: ge_double_scalarmult_precomp_vartime2(&tmp_p2, scalar0.bytes, precomp0, scalar1.bytes, precomp1); break; + case op_addKeys2: rct::addKeys2(key, scalar0, scalar1, point0); break; + case op_addKeys3: rct::addKeys3(key, scalar0, point0, scalar1, precomp1); break; + case op_addKeys3_2: rct::addKeys3(key, scalar0, precomp0, scalar1, precomp1); break; + default: return false; + } + return true; + } + +private: + rct::key scalar0, scalar1; + rct::key point0, point1; + ge_p3 p3_0, p3_1; + ge_cached cached; + ge_dsmp precomp0, precomp1; +}; |