@@ -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,46 +34,29 @@ 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+ * $sisha1$<iter>$<hex_salt><hex_hash>
45+ *
46+ * No separator between salt and hash.
4747 */
48- char * iterated_sha1_prepare (char * fields [ 10 ] , struct fmt_main * self )
48+ int iterated_sha1_valid (char * ciphertext , struct fmt_main * self )
4949{
50- static char out [FORMAT_TAG_LEN + 4 + 1 + 2 * 8 + 40 + 1 ];
51-
52- if (!strncasecmp (fields [1 ], FORMAT_TAG , FORMAT_TAG_LEN ))
53- return fields [1 ];
50+ if (strncasecmp (ciphertext , FORMAT_TAG , FORMAT_TAG_LEN )) {
51+ /* Handle XSHA, untagged 48 chars uc hex */
52+ int extra ;
5453
55- int len = strnlen (fields [1 ], 56 + 1 );
56- int iter , extra ;
57-
58- if (len < MIN_CIPHERTEXT_LEN || len > MAX_CIPHERTEXT_LEN )
59- return fields [1 ];
60- if (hexlenl (fields [1 ], & extra ) != len || extra )
61- return fields [1 ];
62-
63- if (len == 48 ) // XSHA
64- iter = 1 ;
65- else
66- iter = 1024 ;
67-
68- sprintf (out , "%s%d$%s" , FORMAT_TAG , iter , fields [1 ]);
69- return out ;
70- }
54+ if (strnlen (ciphertext , 48 + 1 ) == 48 && hexlenu (ciphertext , & extra ) == 48 && !extra )
55+ return 1 ;
7156
72- int iterated_sha1_valid (char * ciphertext , struct fmt_main * self )
73- {
74- if (strncasecmp (ciphertext , FORMAT_TAG , FORMAT_TAG_LEN ))
7557 return 0 ;
58+ }
59+
7660 ciphertext += FORMAT_TAG_LEN ;
7761
7862 int iter = getdec (ciphertext , '$' );
@@ -82,11 +66,11 @@ int iterated_sha1_valid(char *ciphertext, struct fmt_main *self)
8266 ciphertext = strchr (ciphertext , '$' ) + 1 ;
8367
8468 int len = strnlen (ciphertext , MAX_CIPHERTEXT_LEN + 1 );
85- if (len & 1 || len > MAX_CIPHERTEXT_LEN )
69+ if (len & 1 || len < MIN_CIPHERTEXT_LEN || len > MAX_CIPHERTEXT_LEN )
8670 return 0 ;
8771
8872 int extra ;
89- if (hexlenl (ciphertext , & extra ) < MIN_CIPHERTEXT_LEN || extra )
73+ if (hexlenl (ciphertext , & extra ) != len || extra )
9074 return 0 ;
9175
9276 return 1 ;
@@ -95,8 +79,10 @@ int iterated_sha1_valid(char *ciphertext, struct fmt_main *self)
9579void * iterated_sha1_get_binary (char * ciphertext )
9680{
9781 static uint8_t binary [BINARY_SIZE ];
82+ int len = strlen (ciphertext );
83+
84+ ciphertext += len - 2 * BINARY_SIZE ;
9885
99- ciphertext += strlen (ciphertext ) - 2 * BINARY_SIZE ;
10086 base64_convert (ciphertext , e_b64_hex , 2 * BINARY_SIZE , binary , e_b64_raw , BINARY_SIZE , flg_Base64_DONOT_NULL_TERMINATE , 0 );
10187
10288#if defined(SIMD_COEF_32 ) && ARCH_LITTLE_ENDIAN
@@ -112,10 +98,12 @@ void* iterated_sha1_get_salt(char* ciphertext)
11298
11399 memset (& salt_blob , 0 , sizeof (salt_blob ));
114100
115- ciphertext += FORMAT_TAG_LEN ;
116-
117- salt_blob .iter = atoi (ciphertext );
118- ciphertext = strchr (ciphertext , '$' ) + 1 ;
101+ if (!strncasecmp (ciphertext , FORMAT_TAG , FORMAT_TAG_LEN )) {
102+ ciphertext += FORMAT_TAG_LEN ;
103+ salt_blob .iter = atoi (ciphertext );
104+ ciphertext = strchr (ciphertext , '$' ) + 1 ;
105+ } else /* XSHA */
106+ salt_blob .iter = 1 ;
119107
120108 char * bin = ciphertext + strlen (ciphertext ) - 40 ;
121109 salt_blob .len = (bin - ciphertext ) / 2 ;
0 commit comments