-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Implement EIP-152: Add Blake2 compression function F precompile #5751
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5751 +/- ##
========================================
Coverage ? 63.8%
========================================
Files ? 358
Lines ? 30604
Branches ? 3403
========================================
Hits ? 19526
Misses ? 9848
Partials ? 1230 |
libdevcrypto/Blake2.cpp
Outdated
uint64_t w; | ||
memcpy(&w, src, sizeof w); | ||
return w; | ||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chfast Should we care about big endian platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
libdevcrypto/Blake2.cpp
Outdated
|
||
s.t[0] = load64(_t0.data()); | ||
s.t[1] = load64(_t1.data()); | ||
s.t[0] = *reinterpret_cast<uint64_t const*>(_t0.data()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should stay load64
because otherwise this is undefined behavior if the memory is not aligned to 8 bytes.
libdevcrypto/Blake2.cpp
Outdated
BLAKE2B_BLOCKBYTES = 128, | ||
}; | ||
|
||
typedef struct blake2b_state__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop typedef
.
libdevcrypto/Blake2.cpp
Outdated
|
||
enum blake2b_constant | ||
{ | ||
BLAKE2B_BLOCKBYTES = 128, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert to constexpr
.
libdevcrypto/Blake2.cpp
Outdated
} blake2b_state; | ||
|
||
// clang-format off | ||
const uint64_t blake2b_IV[8] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr
.
libdevcrypto/Blake2.cpp
Outdated
return w; | ||
} | ||
|
||
inline uint64_t rotr64(const uint64_t w, const unsigned c) noexcept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline uint64_t rotr64(const uint64_t w, const unsigned c) noexcept | |
inline constexpr uint64_t rotr64(uint64_t w, unsigned c) noexcept |
libdevcrypto/Blake2.cpp
Outdated
{ | ||
uint64_t m[16]; | ||
uint64_t v[16]; | ||
size_t i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move i
to loops.
|
||
#include <libdevcore/Exceptions.h> | ||
|
||
// The Blake 2 F compression function implemenation is based on the reference implementation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chfast do we need any kind of license note here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not required because the reference implementation is in public domain, but I think it is nice to leave it here.
benchmarking test vectors from EIP (+ another one for 1200 rounds) currently looks like this to me
|
This passes state tests from ethereum/tests#619, so I'm going to merge soon |
https://eips.ethereum.org/EIPS/eip-152