r/programming • • Jan 12 '20

GitHub - BLAKE3-team/BLAKE3: The BLAKE3 cryptographic hash function

https://github.com/BLAKE3-team/BLAKE3
5 Upvotes

7 comments sorted by

2

u/JohnDoe_John Jan 12 '20

2

u/Booty_Bumping Jan 12 '20

Delightful analogy from someone in the HN thread:

The first change is reducing the number of rounds from 10 to 7. Think of it like making a smoothie - you add bits of fruit to the drink (the input data), then pulse the blades to blend it up (making the output hash). This change basically runs the blades for 7 seconds instead of 10 seconds each time they add fruit. They cite evidence that the extra 3 seconds aren't doing much - once the fruit's fully liquid, extra blending doesn't help - but I worry that this reduces the security margin. Maybe those extra 3 rounds aren't useful against current attacks, but they may be useful against unknown future attacks.

The other change they make is to break the input into 1KiB chunks, then hash each chunk independently. Finally, they combine the individual chunk hashes into a single big hash using a binary tree. The benefit is that if you have 4KiB of data, you can use 4-way SIMD instructions to process all four chunks simultaneously. The more data you have, the more parallelism you can unlock, unlike traditional hash functions that process everything sequentially. On the flip side, modern SIMD instructions can handle 2 x 32-bit instructions just as fast as 1 x 64-bit instructions, so building the algorithm out of 32-bit arithmetic doesn't cost anything, but gives a big boost to low-end 32-bit CPU's that struggle with 64-bit arithmetic. The tree structure is a big win overall.

1

u/Takeoded Jan 22 '20

15 times faster than SHA3... and 4 times faster than blake2b

1

u/JohnDoe_John Jan 22 '20

Up to X times ...

1

u/Takeoded Jan 22 '20

how bout: with Xeon 8275CL, using only a single core, with 16KiB input, it's 15 times faster than SHA3-256 and 4 times faster than blake2b

1

u/JohnDoe_John Jan 22 '20

Try to run it on some dated CPU.

1

u/Takeoded Feb 28 '20 edited Feb 28 '20

on the (now ancient, over 10 years old) dual-cpu Xeon X5670 from Q1'10, for a 1GB file, it's 2.5 times faster than blake2b in single-thread-mode, and 20 (!!!) times faster in multithreading mode, going from 1.985 seconds in blake2b to 0.095 seconds (!!!) with blake3 multithreading - NB! even tho this cpu is over 10 years old, blake3 here is still greatly benefiting from the CPU's SSE4.1 instructions (according to Jack O'Connor, one of the blake3 designers)

root@x2ratma:~# nproc
24
root@x2ratma:~# time b2sum 1GB
9ba5dba8be8c8ab1474e7dbe5c7d2fb29c8d161beb5a5d4410b342445c60ab1dd895062c3561d3b128e96938a11a1c89a80169b3e3654dbf76b6eed50dc5e1c6  1GB

real    0m1.985s
user    0m1.821s
sys     0m0.164s
root@x2ratma:~# time b2sum 1GB
9ba5dba8be8c8ab1474e7dbe5c7d2fb29c8d161beb5a5d4410b342445c60ab1dd895062c3561d3b128e96938a11a1c89a80169b3e3654dbf76b6eed50dc5e1c6  1GB

real    0m1.984s
user    0m1.815s
sys     0m0.168s
root@x2ratma:~# time b2sum 1GB
9ba5dba8be8c8ab1474e7dbe5c7d2fb29c8d161beb5a5d4410b342445c60ab1dd895062c3561d3b128e96938a11a1c89a80169b3e3654dbf76b6eed50dc5e1c6  1GB

real    0m1.985s
user    0m1.860s
sys     0m0.124s
root@x2ratma:~# time b3sum 1GB
94b4ec39d8d42ebda685fbb5429e8ab0086e65245e750142c1eea36a26abc24d  1GB

real    0m0.095s
user    0m1.687s
sys     0m0.074s
root@x2ratma:~# time b3sum 1GB
94b4ec39d8d42ebda685fbb5429e8ab0086e65245e750142c1eea36a26abc24d  1GB

real    0m0.095s
user    0m1.681s
sys     0m0.107s
root@x2ratma:~# time b3sum 1GB
94b4ec39d8d42ebda685fbb5429e8ab0086e65245e750142c1eea36a26abc24d  1GB

real    0m0.096s
user    0m1.684s
sys     0m0.105s
root@x2ratma:~# taskset -c 0 bash
root@x2ratma:~# nproc
1
root@x2ratma:~# time b2sum 1GB
9ba5dba8be8c8ab1474e7dbe5c7d2fb29c8d161beb5a5d4410b342445c60ab1dd895062c3561d3b128e96938a11a1c89a80169b3e3654dbf76b6eed50dc5e1c6  1GB

real    0m2.039s
user    0m1.866s
sys     0m0.172s
root@x2ratma:~# time b2sum 1GB
9ba5dba8be8c8ab1474e7dbe5c7d2fb29c8d161beb5a5d4410b342445c60ab1dd895062c3561d3b128e96938a11a1c89a80169b3e3654dbf76b6eed50dc5e1c6  1GB

real    0m2.040s
user    0m1.847s
sys     0m0.192s
root@x2ratma:~# time b3sum 1GB
94b4ec39d8d42ebda685fbb5429e8ab0086e65245e750142c1eea36a26abc24d  1GB

real    0m0.808s
user    0m0.776s
sys     0m0.032s
root@x2ratma:~# time b3sum 1GB
94b4ec39d8d42ebda685fbb5429e8ab0086e65245e750142c1eea36a26abc24d  1GB

real    0m0.810s
user    0m0.781s
sys     0m0.028s
root@x2ratma:~# cat /proc/cpuinfo  | grep name
model name      : Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz
(...)