crypto.sha3: add support for Keccak-256 and Keccak-512#23058
crypto.sha3: add support for Keccak-256 and Keccak-512#23058spytheman merged 9 commits intovlang:masterfrom
Conversation
|
@blackshirt, @kimshrier can you please review this PR? |
|
It would be good to add keccak-256 and keccak-512 tests to test_200_length_hash() so that there is more than one validation of the algorithm. Also, since the existing tests are against an empty string, that is potentially a degenerate case. Testing against a non-empty string will give us better confidence in the correctness of the implementation. |
|
Is it good to this |
There was a problem hiding this comment.
There are many duplicates here, likes new_keccak_digest and other specialized module level fns, even its just a thin wrapper for other function. Its seem (for me) there are many ways to do a same thing here, ..
I think @spytheman and others has more thinking in this area's
I'm personally like optional parameters with default to sha3 part. For example from standard math.big.integer_from_bytes accepts optional IntegerConfig as the last parameters. when its not supplied, its assumed signum to be positive 1.
something similar like this (just the raw idea)
@[params]
struct DigestOptions {
// currently, only single option
pad u8 = hash_pad // default to sha3
}
fn new_digest_common(absorption_rate int, hash_size int, opt DigestOptions) !&Digest {
if opt.pad != hash_pad && opt.pad != xof_pad && opt.pad != kecak_pad {
return error('bad pad')
}
// just performs other required check
d := Digest{
rate: absorption_rate
suffix: opt.pad
output_len: hash_size
s: State{}
}
return &d
}So, the others can use this single comon constructor, and eliminates non-required similar fns
pub fn new512keccak() !&Digest {
return new_digest_common(rate_512, size_512, pad: keccak_pad)!
}| } | ||
|
|
||
| // new_digest creates an initialized digest structure based on | ||
| // the hash size and whether or not you specify a MAC key. |
There was a problem hiding this comment.
Maybe you should add the function docs to elaborate the current behaviour of the new_digest, so the user know the created Digest was expected digest.
@spytheman what do you think ?
|
Can you please also adds some normal tests, that do import |
| @@ -1,5 +1,99 @@ | |||
| module sha3 | |||
|
|
|||
There was a problem hiding this comment.
Its doesn't import crypto.sha3 module at the top of your test file...
Just create normal usage test file with required import. For example, see poly1305 usage_test.v
blackshirt
left a comment
There was a problem hiding this comment.
I think overall changes is mostly acceptable now, with some notes on unhandled issues (maybe can be addressed on next iteration of pr), ie,
- is this
sha3.Digestshould adhere tohash.Hashinterface? I think its good if yes, because the standard stock ofsha1,sha256andsha512has already did it. - Its good to have
READMEfile for thissha3module. Its not yet availables at this time of writing, and for more crucial reasons, this module has support for several variant of hashing instead of standardsha3thats represented by this module name.
Good jobs guys...
Waiting for other review
|
Yes, it should adhere to the These new variants should also be added to the |
|
Yay - more |
it is fixed in master - the CI runs just happened to interleave |
|
I think that it is good to be merged - the remaining things are out of scope of this particular PR, and require changes to existing code. They are better to be done separately imho. |
Its good, the other concerns can be done on next pr |
Closes #23057
Huly®: V_0.6-21498