1 /*
2 * rawsha1 cracker patch for JtR, common code. 2015 by JimF
3 * This file takes replicated but common code, shared between the CPU
4 * and the GPU formats, and places it into one common location
5 */
6
7 #include "arch.h"
8 #include "misc.h"
9 #include "common.h"
10 #include "formats.h"
11 #include "base64_convert.h"
12 #include "johnswap.h"
13 #include "rawSHA1_common.h"
14
15 struct fmt_tests rawsha1_common_tests[] = {
16 {"c3e337f070b64a50e9d31ac3f9eda35120e29d6c", "digipalmw221u"},
17 {"2fbf0eba37de1d1d633bc1ed943b907f9b360d4c", "azertyuiop1"},
18 {"A9993E364706816ABA3E25717850C26C9CD0D89D", "abc"},
19 {FORMAT_TAG "A9993E364706816ABA3E25717850C26C9CD0D89D", "abc"},
20 // repeat hash in exactly the same form that is used in john.pot (lower case)
21 {FORMAT_TAG "a9993e364706816aba3e25717850c26c9cd0d89d", "abc"},
22 {"f879f8090e92232ed07092ebed6dc6170457a21d", "azertyuiop2"},
23 {"1813c12f25e64931f3833b26e999e26e81f9ad24", "azertyuiop3"},
24 {"095bec1163897ac86e393fa16d6ae2c2fce21602", "7850"},
25 {"dd3fbb0ba9e133c4fd84ed31ac2e5bc597d61774", "7858"},
26 {"{SHA}MtEMe4z5ZXDKBM438qGdhCQNOok=", "abcdefghijklmnopqrstuvwxyz"},
27 {"{SHA}cMiB1KJphN3OeV9vcYF8nPRIDnk=", "aaaa"},
28 {"{SHA}iu0TIuVFC62weOH7YKgXod8loso=", "bbbb"},
29 {"{SHA}0ijZPTcJXMa+t2XnEbEwSOkvQu0=", "ccccccccc"},
30 {"{SHA}vNR9eUfJfcKmdkLDqNoKagho+qU=", "dddddddddd"},
31 {"{SHA}jLIjfQZ5yojbZGTqxg2pY0VROWQ=", "12345"},
32 {"{SHA}IOq+XWSw4hZ5boNPUtYf0LcDMvw=", "1234567"},
33 {"{SHA}fEqNCco3Yq9h5ZUglD3CZJT4lBs=", "123456"},
34 {"{SHA}d1u5YbgdocpJIXpI5TPIMsM3FUo=", "princess"},
35 {"{SHA}Y2fEjdGT1W6nsLqtJbGUVeUp9e4=", "abc123"},
36 {"{SHA}fCIvspJ9goryL1khNOiTJIBjfA0=", "12345678"},
37 {"{SHA}7o2HKPQ1/VUPg4Uqq6tSNM4dpSg=", "iloveyou"},
38 {"{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=", "password"},
39 {"{SHA}98O8HYCOBHMq32eZZczDTKeuNEE=", "123456789"},
40 {"{SHA}X+4AI5lA+IPUwoVOQcf5iedSeKM=", "nicole"},
41 {"{SHA}8c9lHOGiGRp2DAsvFhI095WOJuQ=", "rockyou"},
42 {"{SHA}PQ87ndys7DDEAIxeAw5sE6R4y08=", "daniel"},
43 {NULL}
44 };
45
46 struct fmt_tests axcrypt_common_tests[] = {
47 {"e5b1b15baef2fc90a5673262440a959200000000", "oHemeheme"},
48 {"2fbf0eba37de1d1d633bc1ed943b907f00000000", "azertyuiop1"},
49 {"ebb7d1eff90b09efb3b3dd996e33b967", "Fist0urs"},
50 {"c336d15500be1804021533cb9cc0ac2f", "enerveAPZ"},
51 {"2a53e6ef507fabede6032a934c21aafc", "gArich1g0"},
52 {"145595ef8b1d96d7bd9c5ea1c6d2876600000000", "BasicSHA1"},
53 {"{SHA}VaiuD3vBn9alvHyZcuPY0wAAAAA=", "base64test"},
54 {"{SHA}COqO1HN3nVE2Fh45LQs05wAAAAA=", "base64test0truncated"},
55 {NULL}
56 };
57
rawsha1_common_prepare(char * split_fields[10],struct fmt_main * self)58 char *rawsha1_common_prepare(char *split_fields[10], struct fmt_main *self)
59 {
60 static char out[CIPHERTEXT_LENGTH + 1];
61 char *ciphertext = split_fields[1];
62
63 if (strncmp(ciphertext, FORMAT_TAG_OLD, TAG_LENGTH_OLD))
64 return ciphertext;
65
66 ciphertext += TAG_LENGTH_OLD;
67
68 if (base64_valid_length(ciphertext, e_b64_mime,
69 flg_Base64_MIME_TRAIL_EQ_CNT, 0) != HASH_LENGTH_OLD)
70 return ciphertext;
71
72 strncpy(out, FORMAT_TAG, sizeof(out));
73 base64_convert(ciphertext, e_b64_mime, HASH_LENGTH_OLD,
74 &out[TAG_LENGTH], e_b64_hex, sizeof(out) - TAG_LENGTH,
75 flg_Base64_MIME_TRAIL_EQ, 0);
76
77 return out;
78 }
79
rawsha1_common_valid(char * ciphertext,struct fmt_main * self)80 int rawsha1_common_valid(char *ciphertext, struct fmt_main *self)
81 {
82 int extra;
83
84 if (!strncmp(ciphertext, FORMAT_TAG_OLD, TAG_LENGTH_OLD)) {
85 ciphertext += TAG_LENGTH_OLD;
86 if (base64_valid_length(ciphertext, e_b64_mime,
87 flg_Base64_MIME_TRAIL_EQ_CNT, 0) ==
88 HASH_LENGTH_OLD)
89 return 1;
90 return 0;
91 }
92 if (!strncmp(ciphertext, FORMAT_TAG, TAG_LENGTH))
93 ciphertext += TAG_LENGTH;
94 if (hexlen(ciphertext, &extra) == DIGEST_SIZE * 2 && !extra)
95 return 1;
96 return 0;
97 }
98
rawsha1_axcrypt_valid(char * ciphertext,struct fmt_main * self)99 int rawsha1_axcrypt_valid(char *ciphertext, struct fmt_main *self)
100 {
101 char out[41];
102 int extra;
103
104 if (hexlen(ciphertext, &extra) != 32 || extra)
105 return rawsha1_common_valid(ciphertext, self);
106 sprintf(out, "%s00000000", ciphertext);
107 return rawsha1_common_valid(out, self);
108 }
109
rawsha1_common_split(char * ciphertext,int index,struct fmt_main * self)110 char *rawsha1_common_split(char *ciphertext, int index, struct fmt_main *self)
111 {
112 static char out[CIPHERTEXT_LENGTH + 1];
113 extern int ldr_in_pot;
114
115 if (ldr_in_pot && !strncmp(ciphertext, FORMAT_TAG_OLD, TAG_LENGTH_OLD)) {
116 static char *fields[10];
117
118 fields[1] = ciphertext;
119 return rawsha1_common_prepare(fields, self);
120 }
121
122 if (!strncmp(ciphertext, FORMAT_TAG, TAG_LENGTH))
123 ciphertext += TAG_LENGTH;
124
125 strncpy(out, FORMAT_TAG, sizeof(out));
126 strnzcpylwr(&out[TAG_LENGTH], ciphertext, HASH_LENGTH + 1);
127
128 return out;
129 }
130
rawsha1_axcrypt_split(char * ciphertext,int index,struct fmt_main * self)131 char *rawsha1_axcrypt_split(char *ciphertext, int index, struct fmt_main *self)
132 {
133 static char out[41];
134 int extra;
135
136 if (hexlen(ciphertext, &extra) != 32 || extra)
137 return rawsha1_common_split(ciphertext, index, self);
138 sprintf(out, "%s00000000", ciphertext);
139 return rawsha1_common_split(out, index, self);
140 }
141
rawsha1_common_get_binary(char * ciphertext)142 void *rawsha1_common_get_binary(char *ciphertext)
143 {
144 static uint32_t out[DIGEST_SIZE / 4];
145 unsigned char *realcipher = (unsigned char*)out;
146
147 ciphertext += TAG_LENGTH;
148 base64_convert(ciphertext, e_b64_hex, HASH_LENGTH,
149 realcipher, e_b64_raw, DIGEST_SIZE,
150 flg_Base64_NO_FLAGS, 0);
151 return (void*)realcipher;
152 }
153