From 296ae46ed8f8f6e5f986f978febad302e3df231a Mon Sep 17 00:00:00 2001 From: Antonio Juarez Date: Mon, 3 Mar 2014 22:07:58 +0000 Subject: moved all stuff to github --- src/crypto/hash.h | 68 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 29 deletions(-) (limited to 'src/crypto/hash.h') diff --git a/src/crypto/hash.h b/src/crypto/hash.h index 32e8f4701..fb65494b6 100644 --- a/src/crypto/hash.h +++ b/src/crypto/hash.h @@ -1,40 +1,50 @@ +// Copyright (c) 2012-2013 The Cryptonote developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + #pragma once -#include -#include #include -#include - -#include "int-util.h" -static inline void *padd(void *p, size_t i) { - return (char *) p + i; -} +#include "common/pod-class.h" +#include "generic-ops.h" -static inline const void *cpadd(const void *p, size_t i) { - return (const char *) p + i; -} +namespace crypto { -static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8, "size_t must be 4 or 8 bytes long"); -static inline void place_length(uint8_t *buffer, size_t bufsize, size_t length) { - if (sizeof(size_t) == 4) { - *(uint32_t *) padd(buffer, bufsize - 4) = swap32be(length); - } else { - *(uint64_t *) padd(buffer, bufsize - 8) = swap64be(length); + extern "C" { +#include "hash-ops.h" } -} -struct keccak_state { - union { - uint8_t b[200]; - uint64_t w[25]; +#pragma pack(push, 1) + POD_CLASS hash { + char data[HASH_SIZE]; }; -}; +#pragma pack(pop) + + static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size"); + + /* + Cryptonight hash functions + */ + + inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) { + cn_fast_hash(data, length, reinterpret_cast(&hash)); + } + + inline hash cn_fast_hash(const void *data, std::size_t length) { + hash h; + cn_fast_hash(data, length, reinterpret_cast(&h)); + return h; + } + + inline void cn_slow_hash(const void *data, std::size_t length, hash &hash) { + cn_slow_hash(data, length, reinterpret_cast(&hash)); + } + + inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) { + tree_hash(reinterpret_cast(hashes), count, reinterpret_cast(&root_hash)); + } -enum { - HASH_SIZE = 32, - HASH_DATA_AREA = 136 -}; +} -void keccak(const void *data, size_t length, char *hash); -void keccak_permutation(struct keccak_state *state); \ No newline at end of file +CRYPTO_MAKE_HASHABLE(hash) -- cgit v1.2.3