RHash icon indicating copy to clipboard operation
RHash copied to clipboard

Incorrect hash type auto-detection when checking hashes

Open Markus74a opened this issue 2 years ago • 3 comments

This bug happens with RHash 1.4.3 and with the lastest GitHub version, both on Windows and Linux.

Contents of manjaro-kde-22.0.1-230124-linux61.iso.sha1:

9d041139d6966a16f2ea83af295afd2d02c00c73  manjaro-kde-22.0.1-230124-linux61.iso

Executed shell commands:

cp manjaro-kde-22.0.1-230124-linux61.iso.sha1 manjaro-kde-22.0.1-230124-linux61.sha1

rhash -c manjaro-kde-22.0.1-230124-linux61.iso.sha1 --sha1
rhash -c manjaro-kde-22.0.1-230124-linux61.iso.sha1
rhash -c manjaro-kde-22.0.1-230124-linux61.sha1
  • The first call to rhash only calculates the SHA1 hash since it is specified on the shell (speed 1.1 GB/s)
  • The second call to rhash calculates the hash of every supported 160-bit hash simultaneously (speed 170 MB/s)
  • The third call to rhash auto-detects the hash and only calculates SHA1, even if not specified on the shell (speed 1.1 GB/s)

The contents of the *.sha1 file stay the same, only its name changes.

Markus74a avatar Feb 02 '23 17:02 Markus74a

The same happens with:

rhash --percents --speed -c manjaro-kde-22.0.3-230213-linux61.iso.sha512 --sha512
rhash --percents --speed -c manjaro-kde-22.0.3-230213-linux61.iso.sha512
rhash --percents --speed -c manjaro-kde-22.0.3-230213-linux61.sha512

1st and 3rd command lines achieve 430 MB/s, 2nd command line only 36 MB/s

Markus74a avatar Feb 17 '23 19:02 Markus74a

Hello. I can't reproduce the bug with the latest version from the master branch.

To simplify testing, I've added the feature 9a6c70c95066d31dc89d4f4d614e79527fd06780 to print all the hash functions being calculated on the very verbose (-vv) log level:

rhash -vvc manjaro-kde-22.0.1-230124-linux61.iso.sha1

--( Verifying manjaro-kde-22.0.1-230124-linux61.iso.sha1 )----------------------
Calculating: SHA1
manjaro-kde-22.0.1-230124-linux61.iso               OK
--------------------------------------------------------------------------------
Everything OK

rhash avatar Mar 01 '23 01:03 rhash

I just did a fresh installation of MSYS2 on Windows 11, installed the UCRT64 environment, switched to the mintty.exe / bash.exe shell and executed:

git clone https://github.com/rhash/RHash.git
cd RHash
./configure --enable-static --disable-gettext --enable-openssl
make

Then I switched to a WindowsTerminal.exe / cmd.exe shell and executed:

C:\Users\me\Downloads>C:\msys64\home\me\RHash\rhash.exe --percents --speed -vvc manjaro-xfce-22.0.3-230213-linux61.iso.sha512  
                                                                                                                               
--( Verifying manjaro-xfce-22.0.3-230213-linux61.iso.sha512 )-------------------                                               
Calculating: WHIRLPOOL, GOST12-512, SHA-512, EDON-R512, SHA3-512, BLAKE2B                                                      
manjaro-xfce-22.0.3-230213-linux61.iso              OK                                                                         
Calculated in 95,705 sec, 40,24 MBps                                                                                           
--------------------------------------------------------------------------------                                               
  • Reordering the parameters or putting the file name into quotation marks doesn't change anything.
  • Copying the .iso and .sha512 files to the MSYS2 installation folder and executing the command directly within mintty.exe / bash.exe also calculates all 512-bit hashes.
  • Combinations with powershell.exe shell and conhost.exe, WindowsTerminal.exe, ConEmu64.exe terminals show the same behavior
  • I did not test the newest commit on a Linux system today, but two weeks ago it also calculated all hash functions of the same hash length (using Ubuntu LTS 22.04 as build environment)

Markus74a avatar Mar 01 '23 12:03 Markus74a