aboutsummaryrefslogtreecommitdiffstats
path: root/libdevcore
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2016-10-06 21:15:36 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2016-10-06 21:53:40 +0800
commitf77a4585ec0d4f13b6d672095cc242f59a79c65a (patch)
treee75aeedba9790e8bf603150dfe58b13f53c83e69 /libdevcore
parent53cbece3a608e62f61050362efa5a65486e4de7b (diff)
downloaddexon-solidity-f77a4585ec0d4f13b6d672095cc242f59a79c65a.tar
dexon-solidity-f77a4585ec0d4f13b6d672095cc242f59a79c65a.tar.gz
dexon-solidity-f77a4585ec0d4f13b6d672095cc242f59a79c65a.tar.bz2
dexon-solidity-f77a4585ec0d4f13b6d672095cc242f59a79c65a.tar.lz
dexon-solidity-f77a4585ec0d4f13b6d672095cc242f59a79c65a.tar.xz
dexon-solidity-f77a4585ec0d4f13b6d672095cc242f59a79c65a.tar.zst
dexon-solidity-f77a4585ec0d4f13b6d672095cc242f59a79c65a.zip
sha3: actually support both FIPS SHA3 and Keccak
Diffstat (limited to 'libdevcore')
-rw-r--r--libdevcore/SHA3.cpp23
1 files changed, 22 insertions, 1 deletions
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;
}