2016-01-18 15:33:29 +00:00
|
|
|
// Copyright (c) 2011-2016 The Cryptonote developers
|
2014-03-03 22:07:58 +00:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2013-11-14 22:28:17 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
#include <CryptoTypes.h>
|
2014-03-03 22:07:58 +00:00
|
|
|
#include "generic-ops.h"
|
2013-11-14 22:28:17 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
namespace Crypto {
|
2013-11-14 22:28:17 +00:00
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
extern "C" {
|
|
|
|
#include "hash-ops.h"
|
2013-11-14 22:28:17 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
/*
|
|
|
|
Cryptonight hash functions
|
|
|
|
*/
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
inline void cn_fast_hash(const void *data, size_t length, Hash &hash) {
|
2014-03-03 22:07:58 +00:00
|
|
|
cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
inline Hash cn_fast_hash(const void *data, size_t length) {
|
|
|
|
Hash h;
|
2014-03-03 22:07:58 +00:00
|
|
|
cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2014-06-25 17:21:42 +00:00
|
|
|
class cn_context {
|
|
|
|
public:
|
|
|
|
|
|
|
|
cn_context();
|
|
|
|
~cn_context();
|
|
|
|
#if !defined(_MSC_VER) || _MSC_VER >= 1800
|
|
|
|
cn_context(const cn_context &) = delete;
|
|
|
|
void operator=(const cn_context &) = delete;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void *data;
|
2015-07-30 15:22:07 +00:00
|
|
|
friend inline void cn_slow_hash(cn_context &, const void *, size_t, Hash &);
|
2014-06-25 17:21:42 +00:00
|
|
|
};
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
inline void cn_slow_hash(cn_context &context, const void *data, size_t length, Hash &hash) {
|
2014-06-25 17:21:42 +00:00
|
|
|
(*cn_slow_hash_f)(context.data, data, length, reinterpret_cast<void *>(&hash));
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
inline void tree_hash(const Hash *hashes, size_t count, Hash &root_hash) {
|
2014-03-03 22:07:58 +00:00
|
|
|
tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
|
|
|
|
}
|
2013-11-14 22:28:17 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
inline void tree_branch(const Hash *hashes, size_t count, Hash *branch) {
|
2014-08-13 10:51:37 +00:00
|
|
|
tree_branch(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char (*)[HASH_SIZE]>(branch));
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
inline void tree_hash_from_branch(const Hash *branch, size_t depth, const Hash &leaf, const void *path, Hash &root_hash) {
|
2014-08-13 10:51:37 +00:00
|
|
|
tree_hash_from_branch(reinterpret_cast<const char (*)[HASH_SIZE]>(branch), depth, reinterpret_cast<const char *>(&leaf), path, reinterpret_cast<char *>(&root_hash));
|
|
|
|
}
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
2013-11-14 22:28:17 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
CRYPTO_MAKE_HASHABLE(Hash)
|