danicoin/tests/performance_tests/cn_slow_hash.h

60 lines
1.7 KiB
C
Raw Normal View History

2015-05-27 12:08:46 +00:00
// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
2014-08-13 10:38:35 +00:00
//
// This file is part of Bytecoin.
//
// Bytecoin is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Bytecoin is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
2014-05-15 16:40:40 +00:00
#pragma once
2015-05-27 12:08:46 +00:00
#include "Common/StringTools.h"
2014-05-15 16:40:40 +00:00
#include "crypto/crypto.h"
#include "cryptonote_core/cryptonote_basic.h"
2015-05-27 12:08:46 +00:00
class test_cn_slow_hash {
2014-05-15 16:40:40 +00:00
public:
static const size_t loop_count = 10;
#pragma pack(push, 1)
2015-05-27 12:08:46 +00:00
struct data_t {
2014-05-15 16:40:40 +00:00
char data[13];
};
#pragma pack(pop)
static_assert(13 == sizeof(data_t), "Invalid structure size");
2015-05-27 12:08:46 +00:00
bool init() {
std::size_t size;
if (!Common::fromHex("63617665617420656d70746f72", &m_data, sizeof(m_data), size) || size != sizeof(m_data)) {
2014-05-15 16:40:40 +00:00
return false;
2015-05-27 12:08:46 +00:00
}
2014-05-15 16:40:40 +00:00
2015-05-27 12:08:46 +00:00
if (!Common::fromHex("bbec2cacf69866a8e740380fe7b818fc78f8571221742d729d9d02d7f8989b87", &m_expected_hash, sizeof(m_expected_hash), size) || size != sizeof(m_expected_hash)) {
2014-05-15 16:40:40 +00:00
return false;
2015-05-27 12:08:46 +00:00
}
2014-05-15 16:40:40 +00:00
return true;
}
2015-05-27 12:08:46 +00:00
bool test() {
2014-05-15 16:40:40 +00:00
crypto::hash hash;
2014-06-25 17:21:42 +00:00
crypto::cn_slow_hash(m_context, &m_data, sizeof(m_data), hash);
2014-05-15 16:40:40 +00:00
return hash == m_expected_hash;
}
private:
data_t m_data;
crypto::hash m_expected_hash;
2014-06-25 17:21:42 +00:00
crypto::cn_context m_context;
2014-05-15 16:40:40 +00:00
};