diff options
-rw-r--r-- | libdevcore/CommonData.cpp | 2 | ||||
-rw-r--r-- | libdevcore/Keccak256.cpp (renamed from libdevcore/SHA3.cpp) | 96 | ||||
-rw-r--r-- | libdevcore/Keccak256.h (renamed from libdevcore/SHA3.h) | 8 | ||||
-rw-r--r-- | libdevcore/SwarmHash.cpp | 2 | ||||
-rw-r--r-- | libevmasm/Assembly.h | 2 | ||||
-rw-r--r-- | libevmasm/CommonSubexpressionEliminator.cpp | 2 | ||||
-rw-r--r-- | libevmasm/KnownState.cpp | 2 | ||||
-rw-r--r-- | libevmasm/LinkerObject.cpp | 2 | ||||
-rw-r--r-- | libsolidity/ast/AST.cpp | 2 | ||||
-rw-r--r-- | libsolidity/ast/Types.cpp | 2 | ||||
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 2 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 3 | ||||
-rw-r--r-- | libsolidity/interface/GasEstimator.cpp | 2 | ||||
-rw-r--r-- | libsolidity/interface/StandardCompiler.cpp | 2 | ||||
-rw-r--r-- | libyul/YulString.h | 12 | ||||
-rw-r--r-- | test/ExecutionFramework.h | 2 | ||||
-rw-r--r-- | test/libsolidity/AnalysisFramework.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityTypes.cpp | 2 | ||||
-rw-r--r-- | test/libyul/YulOptimizerTest.cpp | 2 |
20 files changed, 51 insertions, 100 deletions
diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 91c60ffe..8d2639c9 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -22,7 +22,7 @@ #include <libdevcore/CommonData.h> #include <libdevcore/Exceptions.h> #include <libdevcore/Assertions.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <boost/algorithm/string.hpp> diff --git a/libdevcore/SHA3.cpp b/libdevcore/Keccak256.cpp index e41a5e3b..7933fc7e 100644 --- a/libdevcore/SHA3.cpp +++ b/libdevcore/Keccak256.cpp @@ -19,7 +19,8 @@ * @date 2014 */ -#include "SHA3.h" +#include <libdevcore/Keccak256.h> + #include <cstdint> #include <cstdio> #include <cstdlib> @@ -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 index d1e2cc98..0d5f69bb 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 1c718200..3b8d2f3e 100644 --- a/libdevcore/SwarmHash.cpp +++ b/libdevcore/SwarmHash.cpp @@ -19,7 +19,7 @@ #include <libdevcore/SwarmHash.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> using namespace std; using namespace dev; diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index 2a29874e..8ef36923 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -27,7 +27,7 @@ #include <libdevcore/Common.h> #include <libdevcore/Assertions.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <json/json.h> diff --git a/libevmasm/CommonSubexpressionEliminator.cpp b/libevmasm/CommonSubexpressionEliminator.cpp index 39485dd9..04926986 100644 --- a/libevmasm/CommonSubexpressionEliminator.cpp +++ b/libevmasm/CommonSubexpressionEliminator.cpp @@ -23,7 +23,7 @@ #include <functional> #include <boost/range/adaptor/reversed.hpp> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <libevmasm/CommonSubexpressionEliminator.h> #include <libevmasm/AssemblyItem.h> diff --git a/libevmasm/KnownState.cpp b/libevmasm/KnownState.cpp index 7c593fc9..b6c1bcc9 100644 --- a/libevmasm/KnownState.cpp +++ b/libevmasm/KnownState.cpp @@ -23,7 +23,7 @@ #include "KnownState.h" #include <functional> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <libevmasm/AssemblyItem.h> using namespace std; diff --git a/libevmasm/LinkerObject.cpp b/libevmasm/LinkerObject.cpp index a11f2378..6eec54ea 100644 --- a/libevmasm/LinkerObject.cpp +++ b/libevmasm/LinkerObject.cpp @@ -21,7 +21,7 @@ #include <libevmasm/LinkerObject.h> #include <libdevcore/CommonData.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> using namespace dev; using namespace dev::eth; diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index d9264230..3ae6bd6d 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -24,7 +24,7 @@ #include <libsolidity/ast/ASTVisitor.h> #include <libsolidity/ast/AST_accept.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <boost/algorithm/string.hpp> diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 6c3863e6..4b31d2e8 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -26,7 +26,7 @@ #include <libdevcore/CommonIO.h> #include <libdevcore/CommonData.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <libdevcore/UTF8.h> #include <libdevcore/Algorithms.h> diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 63faddd3..bdf91fbf 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -25,7 +25,7 @@ #include <boost/range/adaptor/reversed.hpp> #include <boost/algorithm/string/replace.hpp> #include <libdevcore/Common.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <libsolidity/ast/AST.h> #include <libsolidity/codegen/ExpressionCompiler.h> #include <libsolidity/codegen/CompilerContext.h> diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 1f58245f..e0909eb3 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -47,6 +47,8 @@ #include <libevmasm/Exceptions.h> +#include <libyul/YulString.h> + #include <libdevcore/SwarmHash.h> #include <libdevcore/JSON.h> @@ -104,6 +106,7 @@ void CompilerStack::reset(bool _keepSources) m_stackState = Empty; m_sources.clear(); } + yul::YulStringRepository::instance().reset(); m_libraries.clear(); m_evmVersion = EVMVersion(); m_optimize = false; diff --git a/libsolidity/interface/GasEstimator.cpp b/libsolidity/interface/GasEstimator.cpp index e70e23a2..1f20366e 100644 --- a/libsolidity/interface/GasEstimator.cpp +++ b/libsolidity/interface/GasEstimator.cpp @@ -24,7 +24,7 @@ #include <map> #include <functional> #include <memory> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <libevmasm/ControlFlowGraph.h> #include <libevmasm/KnownState.h> #include <libevmasm/PathGasMeter.h> diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 8300e8db..c8b03a94 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -25,7 +25,7 @@ #include <libsolidity/ast/ASTJsonConverter.h> #include <libevmasm/Instruction.h> #include <libdevcore/JSON.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <boost/algorithm/string.hpp> diff --git a/libyul/YulString.h b/libyul/YulString.h index ae01c83f..a8015239 100644 --- a/libyul/YulString.h +++ b/libyul/YulString.h @@ -35,9 +35,9 @@ namespace yul class YulStringRepository: boost::noncopyable { public: - YulStringRepository(): m_strings{std::make_shared<std::string>()} + YulStringRepository() { - m_ids[std::string{}] = 0; + reset(); } static YulStringRepository& instance() { @@ -61,6 +61,14 @@ public: return *m_strings.at(_id); } + void reset() + { + m_strings.clear(); + m_ids.clear(); + m_strings.emplace_back(std::make_shared<std::string>()); + m_ids[std::string{}] = 0; + } + private: std::vector<std::shared_ptr<std::string>> m_strings; std::map<std::string, size_t> m_ids; diff --git a/test/ExecutionFramework.h b/test/ExecutionFramework.h index e275147b..d6de95a3 100644 --- a/test/ExecutionFramework.h +++ b/test/ExecutionFramework.h @@ -28,7 +28,7 @@ #include <libsolidity/interface/EVMVersion.h> #include <libdevcore/FixedHash.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <functional> diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp index 72b86767..ec98026c 100644 --- a/test/libsolidity/AnalysisFramework.cpp +++ b/test/libsolidity/AnalysisFramework.cpp @@ -29,7 +29,7 @@ #include <libsolidity/parsing/Scanner.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <boost/test/unit_test.hpp> diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 640bf4d0..5ec010c7 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -26,7 +26,7 @@ #include <libsolidity/ast/AST.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <boost/test/unit_test.hpp> diff --git a/test/libsolidity/SolidityTypes.cpp b/test/libsolidity/SolidityTypes.cpp index ee637261..6f9d4ce8 100644 --- a/test/libsolidity/SolidityTypes.cpp +++ b/test/libsolidity/SolidityTypes.cpp @@ -22,7 +22,7 @@ #include <libsolidity/ast/Types.h> #include <libsolidity/ast/AST.h> -#include <libdevcore/SHA3.h> +#include <libdevcore/Keccak256.h> #include <boost/test/unit_test.hpp> using namespace std; diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 03cd6446..162b167c 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -90,6 +90,8 @@ YulOptimizerTest::YulOptimizerTest(string const& _filename) bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted) { + yul::YulStringRepository::instance().reset(); + assembly::AsmPrinter printer{m_yul}; shared_ptr<Block> ast; shared_ptr<assembly::AsmAnalysisInfo> analysisInfo; |