libgcrypt < 1.10.2 returns wrong sha3 hashes for inputs > 4 GiB
Affects | Status | Importance | Assigned to | Milestone | ||
---|---|---|---|---|---|---|
libgcrypt20 (Ubuntu) | Status tracked in Noble | |||||
Jammy |
Fix Committed
|
Undecided
|
Unassigned | |||
Lunar |
Fix Released
|
Undecided
|
Unassigned | |||
Mantic |
Fix Released
|
Undecided
|
Unassigned | |||
Noble |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
[ Impact ]
SHA3 produces wrong results for inputs bigger than 4 GiB
[ Test Plan ]
Calculate sha3 hash of a big input file and compare with output of
another implementation like OpenSSL.
Expected behavior: same output
Actual behavior: different output
Run reproducer attached below (if your machine can afford to allocate 5G RAM
at once) and see that the patch fixes the assertion error.
[ Where problems could occur ]
People relying on the broken hash might be surprised by the new fixed
result. The impact is hopefully low since SHA3 from libgcrypt is not
too widely used, especially not with this input size.
[ Other Info ]
From upstream bug report:
The SHA3 functions give wrong results for inputs larger than 4GB, because the originally size_t argument handled as unsigned int in keccak_write and leads to integer overflows. This does not happen if the data is fed into the md_write by smaller chunks. More information and reproducers are available from Clemens in the attached bug.
The fix that should solve the problem (use of the size_t) is available now at gitlab: https:/
I was considering updating the some of the hash tests to capture this issue, but did not find a simple way to do that yet so I will keep it on you to decide if you believe some regression test is needed here.
Upstream Bug: https:/
Upstream Fix: https:/
[ WARNING ]
!!! Warning !!!
hashtest.c reproducer allocates 5GB of RAM, do not run on 32-bit architectures.
Do not run if you don't have that much RAM free, as it will likely trigger OOM and may kill your machine.
!!! Warning !!!
Attached is a reproducer adapted from the regression test included with newer libgcrypt versions. Compiled with `cc -o hashtest hashtest.c -lgcrypt` it will die with an assertion in the error case.
Bad: cipher/ keccak. c:864:keccak_ write)
$ ./hashtest
Ohhhh jeeee: Assertion `count < bsize' failed (../../
Aborted (core dumped)
$
Good:
$ ./hashtest
$