diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 91c60ffe9..8d2639c96 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include diff --git a/libdevcore/SHA3.cpp b/libdevcore/Keccak256.cpp similarity index 63% rename from libdevcore/SHA3.cpp rename to libdevcore/Keccak256.cpp index e41a5e3b8..7933fc7e0 100644 --- a/libdevcore/SHA3.cpp +++ b/libdevcore/Keccak256.cpp @@ -19,7 +19,8 @@ * @date 2014 */ -#include "SHA3.h" +#include + #include #include #include @@ -31,7 +32,7 @@ using namespace dev; namespace dev { -namespace keccak +namespace { /** libkeccak-tiny @@ -43,26 +44,6 @@ namespace keccak * but not liability. */ -#define decshake(bits) \ - int shake##bits(uint8_t*, size_t, const uint8_t*, size_t); - -#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 ********/ /*** Constants. ***/ @@ -164,13 +145,15 @@ mkapply_sd(setout, dst[i] = src[i]) // setout } /** The sponge-based hash construction. **/ -static inline int hash(uint8_t* out, size_t outlen, - const uint8_t* in, size_t inlen, - size_t rate, uint8_t delim) { - if ((out == NULL) || ((in == NULL) && inlen != 0) || (rate >= Plen)) - { - return -1; - } +inline void hash( + uint8_t* out, + size_t outlen, + const uint8_t* in, + size_t inlen, + size_t rate, + uint8_t delim +) +{ uint8_t a[Plen] = {0}; // Absorb input. foldP(in, inlen, xorin); @@ -185,58 +168,19 @@ static inline int hash(uint8_t* out, size_t outlen, foldP(out, outlen, setout); setout(a, out, outlen); memset(a, 0, 200); - return 0; } -/*** Helper macros to define SHA3 and SHAKE instances. ***/ -#define defshake(bits) \ - int shake##bits(uint8_t* out, size_t outlen, \ - const uint8_t* in, size_t inlen) { \ - return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x1f); \ - } -#define defsha3(bits) \ - int sha3_##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), 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); \ - } - -/*** FIPS202 SHAKE VOFs ***/ -defshake(128) -defshake(256) - -/*** FIPS202 SHA3 FOFs ***/ -defsha3(224) -defsha3(256) -defsha3(384) -defsha3(512) - -/*** KECCAK FOFs ***/ -defkeccak(224) -defkeccak(256) -defkeccak(384) -defkeccak(512) - } -bool keccak256(bytesConstRef _input, bytesRef o_output) +h256 keccak256(bytesConstRef _input) { - // FIXME: What with unaligned memory? - if (o_output.size() != 32) - return false; - keccak::keccak256(o_output.data(), 32, _input.data(), _input.size()); -// keccak::keccak(ret.data(), 32, (uint64_t const*)_input.data(), _input.size()); - return true; + h256 output; + // Parameters used: + // The 0x01 is the specific padding for keccak (sha3 uses 0x06) and + // the way the round size (or window or whatever it was) is calculated. + // 200 - (256 / 4) is the "rate" + hash(output.data(), output.size, _input.data(), _input.size(), 200 - (256 / 4), 0x01); + return output; } } diff --git a/libdevcore/SHA3.h b/libdevcore/Keccak256.h similarity index 82% rename from libdevcore/SHA3.h rename to libdevcore/Keccak256.h index d1e2cc983..0d5f69bb7 100644 --- a/libdevcore/SHA3.h +++ b/libdevcore/Keccak256.h @@ -30,14 +30,8 @@ namespace dev { -// Keccak-256 convenience routines. - -/// Calculate Keccak-256 hash of the given input and load it into the given output. -/// @returns false if o_output.size() != 32. -bool keccak256(bytesConstRef _input, bytesRef o_output); - /// Calculate Keccak-256 hash of the given input, returning as a 256-bit hash. -inline h256 keccak256(bytesConstRef _input) { h256 ret; keccak256(_input, ret.ref()); return ret; } +h256 keccak256(bytesConstRef _input); /// Calculate Keccak-256 hash of the given input, returning as a 256-bit hash. inline h256 keccak256(bytes const& _input) { return keccak256(bytesConstRef(&_input)); } diff --git a/libdevcore/SwarmHash.cpp b/libdevcore/SwarmHash.cpp index 1c718200e..3b8d2f3e3 100644 --- a/libdevcore/SwarmHash.cpp +++ b/libdevcore/SwarmHash.cpp @@ -19,7 +19,7 @@ #include -#include +#include using namespace std; using namespace dev; diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index 2a29874e1..8ef369232 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include diff --git a/libevmasm/CommonSubexpressionEliminator.cpp b/libevmasm/CommonSubexpressionEliminator.cpp index 39485dd9d..04926986d 100644 --- a/libevmasm/CommonSubexpressionEliminator.cpp +++ b/libevmasm/CommonSubexpressionEliminator.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include diff --git a/libevmasm/KnownState.cpp b/libevmasm/KnownState.cpp index 7c593fc97..b6c1bcc9b 100644 --- a/libevmasm/KnownState.cpp +++ b/libevmasm/KnownState.cpp @@ -23,7 +23,7 @@ #include "KnownState.h" #include -#include +#include #include using namespace std; diff --git a/libevmasm/LinkerObject.cpp b/libevmasm/LinkerObject.cpp index a11f2378d..6eec54ea5 100644 --- a/libevmasm/LinkerObject.cpp +++ b/libevmasm/LinkerObject.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include using namespace dev; using namespace dev::eth; diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index d9264230f..3ae6bd6d9 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 6c3863e60..4b31d2e84 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 63faddd34..bdf91fbf9 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libsolidity/interface/GasEstimator.cpp b/libsolidity/interface/GasEstimator.cpp index e70e23a2e..1f20366ed 100644 --- a/libsolidity/interface/GasEstimator.cpp +++ b/libsolidity/interface/GasEstimator.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 8300e8db8..c8b03a94a 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include diff --git a/test/ExecutionFramework.h b/test/ExecutionFramework.h index e275147b0..d6de95a39 100644 --- a/test/ExecutionFramework.h +++ b/test/ExecutionFramework.h @@ -28,7 +28,7 @@ #include #include -#include +#include #include diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp index 72b867673..ec98026cc 100644 --- a/test/libsolidity/AnalysisFramework.cpp +++ b/test/libsolidity/AnalysisFramework.cpp @@ -29,7 +29,7 @@ #include -#include +#include #include diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 640bf4d0b..5ec010c7f 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -26,7 +26,7 @@ #include -#include +#include #include diff --git a/test/libsolidity/SolidityTypes.cpp b/test/libsolidity/SolidityTypes.cpp index ee6372617..6f9d4ce8c 100644 --- a/test/libsolidity/SolidityTypes.cpp +++ b/test/libsolidity/SolidityTypes.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include using namespace std;