danicoin/tests/PerformanceTests/CryptoNoteSlowHash.h

47 lines
1.2 KiB
C
Raw Normal View History

// Copyright (c) 2011-2016 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
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"
2015-07-30 15:22:07 +00:00
#include "CryptoNoteCore/CryptoNoteBasic.h"
2014-05-15 16:40:40 +00:00
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() {
2015-07-30 15:22:07 +00:00
size_t size;
2015-05-27 12:08:46 +00:00
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() {
2015-07-30 15:22:07 +00:00
Crypto::Hash hash;
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;
2015-07-30 15:22:07 +00:00
Crypto::Hash m_expected_hash;
Crypto::cn_context m_context;
2014-05-15 16:40:40 +00:00
};