Skip to content

Commit ba0525c

Browse files
committed
formats.c: Check binary hash functions for salt-only/blob formats
Blob formats can't use the fmt_default_(binary|get)_hash_[0..6] functions but need more elaborate functions, or plain fmt_default_binary_hash. Salt-only formats doesn't even have a binary, but are allowed to use fmt_default_(binary|get)_hash (without the trailing _0[..6]). See #5736
1 parent 2f606a9 commit ba0525c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/formats.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* This file is part of John the Ripper password cracker,
33
* Copyright (c) 1996-2001,2006,2008,2010-2013,2015 by Solar Designer
4+
* Copyright (c) 2011-2025, magnum
5+
* Copyright (c) 2009-2018, JimF
46
*/
57

68
#if AC_BUILT
@@ -905,6 +907,30 @@ static char *fmt_self_test_body(struct fmt_main *format,
905907
}
906908
}
907909

910+
if (format->params.flags & FMT_BLOB) {
911+
/*
912+
* BLOB formats can't use the default binary_hash_[0-6] functions.
913+
*/
914+
if (format->methods.binary_hash[0] == fmt_default_binary_hash_0)
915+
return "default binary_hash_[0-6] method not allowed for FMT_BLOB";
916+
}
917+
918+
if (format->params.binary_size == 0) {
919+
for (size = 0; size < PASSWORD_HASH_SIZES; size++) {
920+
/*
921+
* Salt-only formats can't have binary hash functions.
922+
*/
923+
if (format->methods.binary_hash[size] &&
924+
format->methods.binary_hash[size] !=
925+
fmt_default_binary_hash)
926+
return "binary_hash method not allowed for salt-only formats";
927+
if (format->methods.get_hash[size] &&
928+
format->methods.get_hash[size] !=
929+
fmt_default_get_hash)
930+
return "get_hash method not allowed for salt-only formats";
931+
}
932+
}
933+
908934
if ((!format->methods.binary_hash[0] || format->methods.binary_hash[0] ==
909935
fmt_default_binary_hash) && format->params.salt_size > 512 &&
910936
!(format->params.flags & FMT_HUGE_INPUT))

0 commit comments

Comments
 (0)