@@ -25,6 +25,7 @@ struct fmt_tests iterated_sha1_tests[] = {
2525 // 8 bytes salt, 1024 iterations
2626 {"$sisha1$1024$6f77746f6f77746f5fa823ad3c2dc9b58893df73d52b2108b2efce45" , "magnum" },
2727 {"$sisha1$1024$6a6f686e72697070a3a2baadacf154dca88a9ea31400481748e253bb" , "password" },
28+ {"$sisha1$1024$6a6f686e72697070a48cd538757a88deaf12b93f4758e27017852ba3" , "John the Ripper" },
2829 // 6 bytes salt, 512 iterations
2930 {"$sisha1$512$cafe80babe000cd885f153e249671f703039a5dce8a4ad771175" , "ripper" },
3031 // 3 bytes salt, 2 iterations
@@ -33,17 +34,15 @@ struct fmt_tests iterated_sha1_tests[] = {
3334 {"$sisha1$1$73616c74d46dd115de9a2f3bf32d42b38d1b437e5f8b92a7" , "clear" },
3435 // Raw SHA-1 (just for testing)
3536 {"$sisha1$1$2fbf0eba37de1d1d633bc1ed943b907f9b360d4c" , "azertyuiop1" },
36- // Raw ciphertexts:
37- // 1024 iterations (default)
38- {"6a6f686e72697070a48cd538757a88deaf12b93f4758e27017852ba3" , "John the Ripper" },
39- // XSHA: 4 bytes salt, 1 iteration (implicit for length 48 only)
40- {"474379622bd7b9f84bd6e4bb52abf9d01705efb0a2426655" , "passWOrd" },
37+
38+ // XSHA: uppercase, 4 bytes salt, 1 iteration (implicit for length 48 only)
39+ {"474379622BD7B9F84BD6E4BB52ABF9D01705EFB0A2426655" , "passWOrd" },
4140 {NULL }
4241};
4342
4443/*
45- * Convert raw ciphertext to canonical ciphertext with inferred salt length
46- * and 1024 iterations (with exception for XSHA) .
44+ * Convert raw XSHA ciphertext to canonical ciphertext. Other lengths
45+ * or iterations need to be in canonical, tagged, format .
4746 */
4847char * iterated_sha1_prepare (char * fields [10 ], struct fmt_main * self )
4948{
@@ -52,23 +51,25 @@ char *iterated_sha1_prepare(char *fields[10], struct fmt_main *self)
5251 if (!strncasecmp (fields [1 ], FORMAT_TAG , FORMAT_TAG_LEN ))
5352 return fields [1 ];
5453
55- int len = strnlen (fields [1 ], 56 + 1 );
56- int iter , extra ;
54+ int len = strnlen (fields [1 ], 48 + 1 );
55+ int extra ;
5756
58- if (len < MIN_CIPHERTEXT_LEN || len > MAX_CIPHERTEXT_LEN )
59- return fields [1 ];
60- if (hexlenl (fields [1 ], & extra ) != len || extra )
57+ if (len != 48 )
6158 return fields [1 ];
6259
63- if (len == 48 ) // XSHA
64- iter = 1 ;
65- else
66- iter = 1024 ;
60+ if (hexlenu (fields [1 ], & extra ) != 48 || extra )
61+ return fields [1 ];
6762
68- sprintf (out , "%s%d$%s" , FORMAT_TAG , iter , fields [1 ]);
63+ sprintf (out , "%s1$%s" , FORMAT_TAG , fields [1 ]);
64+ strlwr (out );
6965 return out ;
7066}
7167
68+ /*
69+ * $sisha1$<iter>$<hex_salt><hex_hash>
70+ *
71+ * No separator between salt and hash.
72+ */
7273int iterated_sha1_valid (char * ciphertext , struct fmt_main * self )
7374{
7475 if (strncasecmp (ciphertext , FORMAT_TAG , FORMAT_TAG_LEN ))
@@ -86,7 +87,7 @@ int iterated_sha1_valid(char *ciphertext, struct fmt_main *self)
8687 return 0 ;
8788
8889 int extra ;
89- if (hexlenl (ciphertext , & extra ) < MIN_CIPHERTEXT_LEN || extra )
90+ if (hexlen (ciphertext , & extra ) < MIN_CIPHERTEXT_LEN || extra )
9091 return 0 ;
9192
9293 return 1 ;
0 commit comments