mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
sha3: actually support both FIPS SHA3 and Keccak
This commit is contained in:
parent
53cbece3a6
commit
f77a4585ec
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user