[GH-ISSUE #652] haval-128-4 needs to store canonical hashes #312

Closed
opened 2026-10-14 03:00:45 +07:00 by bsakaguchi · 11 comments
Owner

Originally created by @frank-dittrich on GitHub (Jun 20, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/652

Similar to issue #644 (which was for MD2)

(bleeding-jumbo)run $ ./john --format=haval-128-4 --list=format-tests |cut -f 3 > haval-128-4.hashes
(bleeding-jumbo)run $ ./john --format=haval-128-4 --list=format-tests |cut -f 4 > haval-128-4.pw
(bleeding-jumbo)run $ ./john --format=haval-128-4 haval-128-4.hashes --wordlist=haval-128-4.pw
Loaded 2 password hashes with no different salts (haval-128-4, HAVAL 128-4 [32/64])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
                 (?)
                 (?)
2g 0:00:00:00 DONE (2014-06-20 13:10) 200.0g/s 100.0p/s 100.0c/s 200.0C/s 
Use the "--show" option to display all of the cracked passwords reliably
Session completed
(bleeding-jumbo)run $ ./john --format=haval-128-4 haval-128-4.hashes --show
?:

1 password hash cracked, 1 left
(bleeding-jumbo)run $ ./john --format=haval-128-4 haval-128-4.hashes --show=LEFT
?:$haval$EE6BBF4D6A46A679B3A856C88538BB98

1 password hash cracked, 1 left
(bleeding-jumbo)run $ cat john.pot 
EE6BBF4D6A46A679B3A856C88538BB98:
(bleeding-jumbo)run $ ./john --format=haval-128-4 haval-128-4.hashes --wordlist=haval-128-4.pw
Loaded 2 password hashes with no different salts (haval-128-4, HAVAL 128-4 [32/64])
Remaining 1 password hash
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
                 (?)
1g 0:00:00:00 DONE (2014-06-20 13:11) 100.0g/s 100.0p/s 100.0c/s 100.0C/s 
Use the "--show" option to display all of the cracked passwords reliably
Session completed
(bleeding-jumbo)run $ cat john.pot 
EE6BBF4D6A46A679B3A856C88538BB98:
$haval$EE6BBF4D6A46A679B3A856C88538BB98:

valid hashes should be converted into their canonical representation (with the haval prefix).

Originally created by @frank-dittrich on GitHub (Jun 20, 2014). Original GitHub issue: https://github.com/openwall/john/issues/652 Similar to issue #644 (which was for MD2) ``` (bleeding-jumbo)run $ ./john --format=haval-128-4 --list=format-tests |cut -f 3 > haval-128-4.hashes (bleeding-jumbo)run $ ./john --format=haval-128-4 --list=format-tests |cut -f 4 > haval-128-4.pw (bleeding-jumbo)run $ ./john --format=haval-128-4 haval-128-4.hashes --wordlist=haval-128-4.pw Loaded 2 password hashes with no different salts (haval-128-4, HAVAL 128-4 [32/64]) Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status (?) (?) 2g 0:00:00:00 DONE (2014-06-20 13:10) 200.0g/s 100.0p/s 100.0c/s 200.0C/s Use the "--show" option to display all of the cracked passwords reliably Session completed (bleeding-jumbo)run $ ./john --format=haval-128-4 haval-128-4.hashes --show ?: 1 password hash cracked, 1 left (bleeding-jumbo)run $ ./john --format=haval-128-4 haval-128-4.hashes --show=LEFT ?:$haval$EE6BBF4D6A46A679B3A856C88538BB98 1 password hash cracked, 1 left (bleeding-jumbo)run $ cat john.pot EE6BBF4D6A46A679B3A856C88538BB98: (bleeding-jumbo)run $ ./john --format=haval-128-4 haval-128-4.hashes --wordlist=haval-128-4.pw Loaded 2 password hashes with no different salts (haval-128-4, HAVAL 128-4 [32/64]) Remaining 1 password hash Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status (?) 1g 0:00:00:00 DONE (2014-06-20 13:11) 100.0g/s 100.0p/s 100.0c/s 100.0C/s Use the "--show" option to display all of the cracked passwords reliably Session completed (bleeding-jumbo)run $ cat john.pot EE6BBF4D6A46A679B3A856C88538BB98: $haval$EE6BBF4D6A46A679B3A856C88538BB98: ``` valid hashes should be converted into their canonical representation (with the $haval$ prefix).
bsakaguchi 2026-10-14 03:00:45 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@frank-dittrich commented on GitHub (Jun 20, 2014):

But (unlike the MD2 fix for #644) IMHO the conversion should be done in split(), not in prepare.

<!-- gh-comment-id:46668189 --> @frank-dittrich commented on GitHub (Jun 20, 2014): But (unlike the MD2 fix for #644) IMHO the conversion should be done in split(), not in prepare.
Author
Owner

@jfoug commented on GitHub (Jun 20, 2014):

I know you are making 1 off's for these, BUT this is an absolute bug, for most formats.

If a format handles this:

hash
$somesignature$hash

then it MUST have a prepare() function. It is simple as that. This is as basic as a format requiring a split function to fix the case if it is supposed to handle:

hash
HASH

The Haval format is certainly one of these, but there are probably a hundred or more. Using your method of --list=format-tests is NOT going to find them all. Yes, it will find some, but certainly NOT all.
About the only way to deal with this, is to look at code. The thing is, that it takes only a few seconds longer to add a 'proper' prepare, that it does to find out if a format requires one ;)
Jim.

<!-- gh-comment-id:46703255 --> @jfoug commented on GitHub (Jun 20, 2014): I know you are making 1 off's for these, BUT this is an absolute bug, for most formats. If a format handles this: hash $somesignature$hash then it MUST have a prepare() function. It is simple as that. This is as basic as a format requiring a split function to fix the case if it is supposed to handle: hash HASH The Haval format is certainly one of these, but there are probably a hundred or more. Using your method of --list=format-tests is NOT going to find them all. Yes, it will find some, but certainly NOT all. About the only way to deal with this, is to look at code. The thing is, that it takes only a few seconds longer to add a 'proper' prepare, that it does to find out if a format requires one ;) Jim.
Author
Owner

@frank-dittrich commented on GitHub (Jun 20, 2014):

Meanwhile I have finished all the CPU formats.
That means, all other CPU formats that do have the same hash in at least 2 different representations (once in a canonical representation, once in a more general representation, etc) work correctly (either split() or prepare() does the unification.

So, if there are other CPU formats with similar problems, they either don't have different representations in their test cases, or they do use different representations, but not for the same hash.

I'll also do the same tests for cuda and opencl.
But I expect at least those opencl and cuda implementations which have a broken CPU format to be broken in sinilar ways.

<!-- gh-comment-id:46706577 --> @frank-dittrich commented on GitHub (Jun 20, 2014): Meanwhile I have finished all the CPU formats. That means, all other CPU formats that do have the same hash in at least 2 different representations (once in a canonical representation, once in a more general representation, etc) work correctly (either split() or prepare() does the unification. So, if there are other CPU formats with similar problems, they either don't have different representations in their test cases, or they do use different representations, but not for the same hash. I'll also do the same tests for cuda and opencl. But I expect at least those opencl and cuda implementations which have a broken CPU format to be broken in sinilar ways.
Author
Owner

@jfoug commented on GitHub (Jun 20, 2014):

1eee4af fixes the prepare. Also, I split the valid function into 2 of them. I found problems when I had a 'mixed' file, containing both haval-128-4 and haval-256-3 strings. All would get accepted as valid, even though only the proper ones would work in the crypt function. With 2 valids (there still is a 'common' valid), then this does not happen, and with prepare, the format reduces to proper cannonical values.

<!-- gh-comment-id:46706765 --> @jfoug commented on GitHub (Jun 20, 2014): 1eee4af fixes the prepare. Also, I split the valid function into 2 of them. I found problems when I had a 'mixed' file, containing both haval-128-4 and haval-256-3 strings. All would get accepted as valid, even though only the proper ones would work in the crypt function. With 2 valids (there still is a 'common' valid), then this does not happen, and with prepare, the format reduces to proper cannonical values.
Author
Owner

@jfoug commented on GitHub (Jun 20, 2014):

ANY time we see code like this (in valid, salt, binary, etc), then we have a format that can do raw hashes, there are also other ways to do it, but this is one way I am seeing;

    if (!strncmp(p, FORMAT_TAG, TAG_LENGTH))
        p += TAG_LENGTH;
    if (strlen(p) != len)
        return 0;

The important part that shows 'raw hash' handling, is the p += TAG_LENGTH. The actual code may be a little different (ciphertext var name, vs p, some len var used instead of TAG_LENGTH, etc). But in general, this type of code SHOWS that this format has a format tag that is OPTIONAL. If it is optional, then there SHOULD be a prepare, that cannonizes the format.

Jim.

<!-- gh-comment-id:46707343 --> @jfoug commented on GitHub (Jun 20, 2014): ANY time we see code like this (in valid, salt, binary, etc), then we have a format that can do raw hashes, there are also other ways to do it, but this is one way I am seeing; ``` if (!strncmp(p, FORMAT_TAG, TAG_LENGTH)) p += TAG_LENGTH; if (strlen(p) != len) return 0; ``` The important part that shows 'raw hash' handling, is the p += TAG_LENGTH. The actual code may be a little different (ciphertext var name, vs p, some len var used instead of TAG_LENGTH, etc). But in general, this type of code SHOWS that this format has a format tag that is OPTIONAL. If it is optional, then there SHOULD be a prepare, that cannonizes the format. Jim.
Author
Owner

@jfoug commented on GitHub (Jun 20, 2014):

This is a good place to start (it will likely NOT be complete)

$ grep -l fmt_default_prepare `grep -l TAG_LENGTH *.c`
(not an issue) 7z_fmt_plug.c
(not an issue) androidfde_fmt_plug.c
(not an issue) blackberry_ES10_fmt_plug.c
(not an issue) blockchain_fmt_plug.c
(not an issue) django_scrypt_fmt_plug.c
(not an issue) ecryptfs_fmt_plug.c
(not an issue) efs_fmt_plug.c
(Already normalized in split function a50d2b6 added matching raw/tagged tests) gost_fmt_plug.c
(Already normalized in split function) krb5-18_fmt.c
(Already normalized in split function) krb5-23_fmt.c
(Added prepare, and matching raw hash 5e11b5c) net_md5_fmt_plug.c
(Added prepare, and matching raw hash 5e11b5c) net_sha1_fmt_plug.c
(not an issue) opencl_blockchain_fmt.c
(*** This one probably needs done) opencl_rakp_fmt.c
(Already normalized in split function) opencl_rawmd4_fmt.c
(Already normalized in split function) opencl_rawmd5_fmt.c
(Already normalized in split function) opencl_rawsha1_fmt.c
(not an issue) openssl_enc_fmt_plug.c
(FIxed in b2c6003) panama_fmt_plug.c
(*** This one probably needs done) rakp_fmt_plug.c
(not an issue)rar5_fmt_plug.c
(Already normalized in split function) rawKeccak_256_fmt_plug.c
(Already normalized in split function) rawMD4_fmt_plug.c
(Already normalized in split function) rawMD5_fmt_plug.c
(Already normalized in split function) rawSHA0_fmt.c
(Already normalized in split function) rawSHA1_fmt_plug.c

(Already normalized in split function) rawSHA1_linkedIn_fmt_plug.c  (*** Note, has a source failure if same hashes are raw and tagged.  This is due to the format getting 'hacked' under normal usage, BUT we have to have FULL hash string in self tests.   I am not sure this can be worked around.  But the split does properly cannonize

(Already normalized in split function) rawSHA224_fmt_plug.c
(Already normalized in split function) rawSHA256_ng_fmt.c
(Already normalized in split function) rawSHA256_ng_i_fmt.c
(Already normalized in split function) rawSHA384_fmt_plug.c
(Already normalized in split function) rawSHA512_fmt_plug.c
(Already normalized in split function) rawSHA512_ng_fmt.c
(Already normalized in split function) rawSHA512_ng_i_fmt.c
(FIxed in b2c6003) ripemd_fmt_plug.c
(FIxed inb2c6003) skein_fmt_plug.c
(FIxed in b2c6003) snefru_fmt_plug.c
(*** This one probably needs done) tcp_md5_fmt_plug.c
(FIxed in b2c6003) tiger_fmt_plug.c
(*** This one probably needs done) whirlpool_fmt_plug.c

NOTE, I am going to edit this file, as I check these files.

<!-- gh-comment-id:46708163 --> @jfoug commented on GitHub (Jun 20, 2014): This is a good place to start (it will likely NOT be complete) ``` $ grep -l fmt_default_prepare `grep -l TAG_LENGTH *.c` (not an issue) 7z_fmt_plug.c (not an issue) androidfde_fmt_plug.c (not an issue) blackberry_ES10_fmt_plug.c (not an issue) blockchain_fmt_plug.c (not an issue) django_scrypt_fmt_plug.c (not an issue) ecryptfs_fmt_plug.c (not an issue) efs_fmt_plug.c (Already normalized in split function a50d2b6 added matching raw/tagged tests) gost_fmt_plug.c (Already normalized in split function) krb5-18_fmt.c (Already normalized in split function) krb5-23_fmt.c (Added prepare, and matching raw hash 5e11b5c) net_md5_fmt_plug.c (Added prepare, and matching raw hash 5e11b5c) net_sha1_fmt_plug.c (not an issue) opencl_blockchain_fmt.c (*** This one probably needs done) opencl_rakp_fmt.c (Already normalized in split function) opencl_rawmd4_fmt.c (Already normalized in split function) opencl_rawmd5_fmt.c (Already normalized in split function) opencl_rawsha1_fmt.c (not an issue) openssl_enc_fmt_plug.c (FIxed in b2c6003) panama_fmt_plug.c (*** This one probably needs done) rakp_fmt_plug.c (not an issue)rar5_fmt_plug.c (Already normalized in split function) rawKeccak_256_fmt_plug.c (Already normalized in split function) rawMD4_fmt_plug.c (Already normalized in split function) rawMD5_fmt_plug.c (Already normalized in split function) rawSHA0_fmt.c (Already normalized in split function) rawSHA1_fmt_plug.c (Already normalized in split function) rawSHA1_linkedIn_fmt_plug.c (*** Note, has a source failure if same hashes are raw and tagged. This is due to the format getting 'hacked' under normal usage, BUT we have to have FULL hash string in self tests. I am not sure this can be worked around. But the split does properly cannonize (Already normalized in split function) rawSHA224_fmt_plug.c (Already normalized in split function) rawSHA256_ng_fmt.c (Already normalized in split function) rawSHA256_ng_i_fmt.c (Already normalized in split function) rawSHA384_fmt_plug.c (Already normalized in split function) rawSHA512_fmt_plug.c (Already normalized in split function) rawSHA512_ng_fmt.c (Already normalized in split function) rawSHA512_ng_i_fmt.c (FIxed in b2c6003) ripemd_fmt_plug.c (FIxed inb2c6003) skein_fmt_plug.c (FIxed in b2c6003) snefru_fmt_plug.c (*** This one probably needs done) tcp_md5_fmt_plug.c (FIxed in b2c6003) tiger_fmt_plug.c (*** This one probably needs done) whirlpool_fmt_plug.c ``` NOTE, I am going to edit this file, as I check these files.
Author
Owner

@ghost commented on GitHub (Jun 20, 2014):

rawSHA256_common.h too? At least, in this case there is a split() and a prepare().

<!-- gh-comment-id:46709721 --> @ghost commented on GitHub (Jun 20, 2014): rawSHA256_common.h too? At least, in this case there is a split() and a prepare().
Author
Owner

@jfoug commented on GitHub (Jun 20, 2014):

These are pretty much handled now. NOTE, these may still need to be looked into:

whirlpool_fmt_plug.c
tcp_md5_fmt_plug.c
rakp_fmt_plug.c
opencl_rakp_fmt.c

Some of these may simply want to bail from valid if the tag is not there. Whirlpool has issues, due to not having a default type for raw hashes.

I am leaving this one open for now.

<!-- gh-comment-id:46720942 --> @jfoug commented on GitHub (Jun 20, 2014): These are pretty much handled now. NOTE, these may still need to be looked into: whirlpool_fmt_plug.c tcp_md5_fmt_plug.c rakp_fmt_plug.c opencl_rakp_fmt.c Some of these may simply want to bail from valid if the tag is not there. Whirlpool has issues, due to not having a default type for raw hashes. I am leaving this one open for now.
Author
Owner

@jfoug commented on GitHub (Jun 20, 2014):

rawSHA256_common.h too? At least, in this case there is a split() and a prepare().

Yes, I looked at that one too. It simply was not in my grep. But it IS already handled by split.

<!-- gh-comment-id:46720997 --> @jfoug commented on GitHub (Jun 20, 2014): > rawSHA256_common.h too? At least, in this case there is a split() and a prepare(). Yes, I looked at that one too. It simply was not in my grep. But it IS already handled by split.
Author
Owner

@jfoug commented on GitHub (Jun 20, 2014):

These are the commits:

a50d2b6
5e11b5c
b2c6003

<!-- gh-comment-id:46721172 --> @jfoug commented on GitHub (Jun 20, 2014): These are the commits: a50d2b6 5e11b5c b2c6003
Author
Owner

@magnumripper commented on GitHub (Jun 24, 2014):

There are lots of bugs in HAVAL (and dozens of @kholia's other formats). First, a 2x too large binary size is announced for the 128-bit variation of the format. I'm pretty sure this means core can't reliably suppress dupes. Second, split() does not unify case but valid() accepts any case. This means some already cracked hashes will not be recognized as such. Third, none of the cmp_*() functions check the whole hash for the 256-bit version (just half of it). That might not be a very serious bug but it is indeed a bug. There are probably more problems, and this is just one format out of too many.

BTW the format should have several more test vectors, including one for a null string and one for max length.

I will commit some fixes soon.

<!-- gh-comment-id:47014231 --> @magnumripper commented on GitHub (Jun 24, 2014): There are lots of bugs in HAVAL (and dozens of @kholia's other formats). First, a 2x too large binary size is announced for the 128-bit variation of the format. I'm pretty sure this means core can't reliably suppress dupes. Second, split() does not unify case but valid() accepts any case. This means some already cracked hashes will not be recognized as such. Third, none of the cmp_*() functions check the whole hash for the 256-bit version (just half of it). That might not be a very serious bug but it is indeed a bug. There are probably more problems, and this is just one format out of too many. BTW the format should have several more test vectors, including one for a null string and one for max length. I will commit some fixes soon.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#312
No description provided.