BLAKE3-team / BLAKE3

the official Rust and C implementations of the BLAKE3 cryptographic hash function
Apache License 2.0
4.71k stars 315 forks source link

How to modify the number of rounds for blake3? #393

Open ShallMate opened 1 month ago

ShallMate commented 1 month ago

Hello. Our current requirement is to reduce the number of rounds for Blake3 because our requirement is quite special. We may not need such a secure hash algorithm. The simplest way may be to reduce its number of rounds. How can I reduce the number of rounds in the code?

oconnor663 commented 1 month ago

If you just wanted to see what the hash output would be with a reduced number of rounds, you could remove some rounds from the reference implementation here. But making the same change in the high-performance implementation is a lot of sensitive work, because that number is hardcoded in many different places. There are separate implementation files for AVX-512, AVX2, SSE4.1, SSE2, NEON, and portable code. Most of those are assembly code, which comes in three different flavors (Unix, Windows MSVC, and Windows GNU). For example, to change the number of rounds in just the Unix AVX-512 implementation, you'd need to delete unrolled rounds here and here, and you'd need to change loop bounds in five different places that look like this.

ShallMate commented 1 month ago

@oconnor663 Thank you very much. I will try to make the modifications you pointed out. But actually, I have a doubt now. I am not familiar with the Rust language. Yesterday, I tried to comment out the code for the reference implementation, and then I recompiled the project. I see that the hash value obtained using b3sum has not changed, why is this? I am certain that I deleted the target folders under Blake3 and b3sum and rerun "cargo build -- release". And perform hash calculations on the same file using the regenerated b3sum.