ColumPaget / Hashrat

Hashing tool supporting md5,sha1,sha256,sha512,whirlpool,jh and hmac versions of these. Includes recursive file hashing and other features.
GNU General Public License v3.0
59 stars 9 forks source link

SHA-256 tests reported as broken #25

Open andreasstieger opened 2 months ago

andreasstieger commented 2 months ago

Seems to return incorrect SHA-256 hashes:

[   15s] + /usr/bin/make -O -j12 V=1 VERBOSE=1 check
[...]
[   29s]   FAIL    sha256 Hashing BROKEN
[...]
[   29s]   FAIL    Checking files BROKEN

More specifically:

$ hashrat --version
version: 1.20
$ echo -n "The sky above the port was the color of television, tuned to a dead channel. " | hashrat -sha256
a927bc13323e8ca451f70ec45454b1d2280eeb21de4cf219d070f99b9acc0180
$ echo -n "The sky above the port was the color of television, tuned to a dead channel. " | sha256sum
c7fadad016311a935a56dcdfb585cf5a4781073f7da13afa22177796e566434f  -

Apparently okay for the empty string:

$ echo -n "" | sha256sum
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  -
$ echo -n "" | hashrat -sha256
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

But fails for any non-empty string:

$ echo -n "." | sha256sum
cdb4ee2aea69cc6a83331bbe96dc2caa9a299d21329efb0336fc02a82e1839a8  -
$ echo -n "." | hashrat -sha256
56fac21a490135c35da5c96ce10e767fd0ad74425091e179f58a9605ef2bef44

openSUSE Tumbleweed, x86_64, gcc 14.1.0. Does not happen in gcc 13.2.1. Also does not happen when using a system libUseful 5.14.

ColumPaget commented 2 months ago

hi again andreas!

This is super odd. I'm getting "all checks passed" on my linux mint system when using statically linked libUseful-5.14. I did do a lot of work on 'make check' in this release, but it seems from your post like the issue is actually in hashrat/libUseful. I am suspicious that sha256 is a hash that is supported in-processor on some architectures, though I didn't think I'd added the feature to use that, so I'd think that can't be it.

I guess 'make check' has earned it's keep here, although I think this is going to be a tough one to debug. A I right in thinking that this only effects sha256?

Colum

ColumPaget commented 2 months ago

hang on... are sha384 and sha512 showing as failed too?

andreasstieger commented 2 months ago

The two failures are the only ones failing, the "files" test is using sha256 too.

ColumPaget commented 2 months ago

that's creepy, it's the same code path for all of them! I'm going to put more tests into 'make check' in the next release (which is coming soon) so we can see more.

ColumPaget commented 2 months ago

Has this been compiled with '--disable-ssl'? If not, could you try that?

andreasstieger commented 2 months ago

Same results with and without TLS/SSL.

ColumPaget commented 2 months ago

okay, I have a new version on the launchpad here, because I had an idea that it might be openssl. If compiled with openssl, hashrat can use openssl digest functions, and those can override the built in ones. But it sounds like this isn't the problem. The whole openssl thing is still a bit experimental, and I'm going to put it on a firmer footing. I'm also adding 'make check' for sha384 and sha512. Those should fail as well if the problem is the sha2 common code.