-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
F compression function implementation for Blake2b #1
Conversation
F is a compression function for Blake2. It takes as an argument the state vector h, message block vector blocks, 2-bit offset counter t, final block indicator flag f, and the number of rounds to execute. The state vector is modified in-place by the function. Number of rounds can be anything from 0 to 12 (inclusive). The code has been borrowed from golang/crypto/blake2b and adjusted so that it can support any number of rounds between 0-12. Parameters have been also adjusted to match those in RFC 7693 https://tools.ietf.org/html/rfc7693 Test vectors were generated from those in golang/crypto/blake2b. The current test coverage is certainly not enough and we'll add some additional test vectors in the future.
The Zcash team has confirmed we're good on rounds and blocksize. I gave a shot at generating test vectors with |
Those test vectors were generated from golang.org/x/crypto/blake2b test hashes in the testHashashes function before and after each F execution.
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.
Interested in your thoughts on raising the round limit to make this more general @pdyraga
Just like in the original RFC (https://tools.ietf.org/html/rfc7693#section-3.2), f parameter is now represented as boolean. If it is enabled, bits are inverted.
We use test vectors generated from test functions in golang.org/x/crypto/blake2b. Each unique call to hashBlocks has been transformed into a test vector. Here, we add test vectors from TestHashes2X test function. We also moved test vectors generated from TestHashes test function into a separate file so that test vectors generated from individual test functions are stored separately.
I mistakenly changed it in one of the previous commits - fixing it now.
Extracted common test code to a separate function.
Message block vector length has to match block size (128) so that we don't blow up when evaluating m vector later. In the original implementation, F was an internal function and other public functions calling it were making sure the correct vector is passed. Here, after making F public, we need to carve this requirement in the interface.
@mhluongo All comments addressed, I am happy with what's here. It's ready for your review 👀. |
#3 will be covered in go-ethereum PR - each contract has benchmarks there. |
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// | ||
// Modified by KEEP SEZC to expose F compression function. |
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.
Going to touch this up after this PR
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.
Yeah, I had no idea what to put here. Worth double-checking if we do not have to alter LICENSE
as well.
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.
🚀 🚀 🚀
🎉 |
Closes: #1
F
is a compression function for Blake2. It takes as an argument thestate vector
h
, message block vectormb
, offset countert
,final block indicator flag
f
, and the number of roundsrounds
to execute.The state vector is modified in-place by the function.
The code has been borrowed from
golang/crypto/blake2b
and adjusted sothat this function can be safely exposed as public. Parameters have
been also adjusted to match those in RFC 7693
Test vectors were generated from those in
golang/crypto/blake2b