RustCrypto / hashes

Collection of cryptographic hash functions written in pure Rust
1.89k stars 257 forks source link

Blake2: add missing types of common digest sizes #564

Closed HeCorr closed 7 months ago

HeCorr commented 9 months ago

See comment #67.

This PR adds the following common fixed digest sizes:

Unsure if I should also add the Mac variants, please let me know!

HeCorr commented 9 months ago

Also, I've noticed that only the BLAKE2b-512 fixed variant is tested, but I've just recently started learning Rust so I'm not sure how to write tests for the other variants (specifically how to generate the .blb files).

Any guidance on this would be very welcome!

newpavlov commented 7 months ago

Could you please link cases where those variations are used in practice?

only the BLAKE2b-512 fixed variant is tested

We could add tests for other variants, but we would have to generate tests ourselves. Ideally, we would use "official" test vectors, but we probably couldn't find them at the time.

HeCorr commented 7 months ago

Could you please link cases where those variations are used in practice?

I can't, but I personally always use either 256 or 128 if I need the hash to be shorter. What I can link you though are other projects which do include them and even other less common sizes (160, 384..):

CyberChef Go standard lib

StackOverflowExcept1on commented 7 months ago

I have similar problem that I need hash of 256 bit size, but this crate does not provide BLAKE2b-256.

HeCorr commented 7 months ago

this crate does not provide BLAKE2b-256.

@StackOverflowExcept1on this is how you can currently generate a Blake2b-256 hash:

use blake2::{Blake2b, Digest, digest::consts::U32};

type Blake2b256 = Blake2b<U32>;

let mut hasher = Blake2b256::new();
hasher.update(b"my_input");
let res = hasher.finalize();