avoid `burnMem` for `keccakHash` (#691)

We don't need to clear keccak context after hashing ethereum data since
it is already public - similar to
https://github.com/status-im/nimbus-eth2/pull/222.

Because we overwrite the result fully, we also don't need to zero first.
This commit is contained in:
Jacek Sieka 2024-06-07 16:27:38 +02:00 committed by GitHub
parent d935c0de47
commit c02e050db8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 4 deletions

View File

@ -30,10 +30,16 @@ template withKeccakHash*(body: untyped): KeccakHash =
body
finish(h)
func keccakHash*(input: openArray[byte]): KeccakHash =
keccak256.digest(input)
func keccakHash*(input: openArray[char]): KeccakHash =
keccak256.digest(input)
func keccakHash*(input: openArray[byte]): KeccakHash {.noinit.} =
# We use the init-update-finish interface to avoid
# the expensive burning/clearing memory (20~30% perf)
var ctx: keccak256
ctx.init()
ctx.update(input)
ctx.finish()
func keccakHash*(input: openArray[char]): KeccakHash {.noinit.} =
keccakHash(input.toOpenArrayByte(0, input.high()))
func keccakHash*(a, b: openArray[byte]): KeccakHash =
withKeccakHash: