From f77a4585ec0d4f13b6d672095cc242f59a79c65a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 6 Oct 2016 14:15:36 +0100 Subject: sha3: actually support both FIPS SHA3 and Keccak --- libdevcore/SHA3.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'libdevcore/SHA3.cpp') diff --git a/libdevcore/SHA3.cpp b/libdevcore/SHA3.cpp index 64a66788..d4536a34 100644 --- a/libdevcore/SHA3.cpp +++ b/libdevcore/SHA3.cpp @@ -49,12 +49,19 @@ namespace keccak #define decsha3(bits) \ int sha3_##bits(uint8_t*, size_t, const uint8_t*, size_t); +#define deckeccak(bits) \ + int keccak##bits(uint8_t*, size_t, const uint8_t*, size_t); + decshake(128) decshake(256) decsha3(224) decsha3(256) decsha3(384) decsha3(512) +deckeccak(224) +deckeccak(256) +deckeccak(384) +deckeccak(512) /******** The Keccak-f[1600] permutation ********/ @@ -192,6 +199,14 @@ static inline int hash(uint8_t* out, size_t outlen, if (outlen > (bits/8)) { \ return -1; \ } \ + return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x06); \ + } +#define defkeccak(bits) \ + int keccak##bits(uint8_t* out, size_t outlen, \ + const uint8_t* in, size_t inlen) { \ + if (outlen > (bits/8)) { \ + return -1; \ + } \ return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x01); \ } @@ -205,6 +220,12 @@ defsha3(256) defsha3(384) defsha3(512) +/*** KECCAK FOFs ***/ +defkeccak(224) +defkeccak(256) +defkeccak(384) +defkeccak(512) + } bool keccak256(bytesConstRef _input, bytesRef o_output) @@ -212,7 +233,7 @@ bool keccak256(bytesConstRef _input, bytesRef o_output) // FIXME: What with unaligned memory? if (o_output.size() != 32) return false; - keccak::sha3_256(o_output.data(), 32, _input.data(), _input.size()); + keccak::keccak256(o_output.data(), 32, _input.data(), _input.size()); // keccak::keccak(ret.data(), 32, (uint64_t const*)_input.data(), _input.size()); return true; } -- cgit