Skip to content

Commit 9423af6

Browse files
authored
Merge pull request openwall#2196 from magnumripper/pot-chop-common-code
.pot chopped file valid() processing moved into common code in loader.c
2 parents 7832ac9 + 17eef1b commit 9423af6

File tree

304 files changed

+1410
-905
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+1410
-905
lines changed

src/7z_fmt_plug.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ john_register_one(&fmt_sevenzip);
3737
#define FORMAT_LABEL "7z"
3838
#define FORMAT_NAME "7-Zip"
3939
#define FORMAT_TAG "$7z$"
40-
#define TAG_LENGTH 4
40+
#define TAG_LENGTH (sizeof(FORMAT_TAG)-1)
4141
#define BENCHMARK_COMMENT " (512K iterations)"
4242
#define BENCHMARK_LENGTH 0
4343
#define BINARY_SIZE 0
@@ -185,9 +185,6 @@ static int valid(char *ciphertext, struct fmt_main *self)
185185

186186
if (strncmp(ciphertext, FORMAT_TAG, TAG_LENGTH) != 0)
187187
return 0;
188-
/* handle 'chopped' .pot lines */
189-
if (ldr_isa_pot_source(ciphertext))
190-
return 1;
191188

192189
ctcopy = strdup(ciphertext);
193190
keeptr = ctcopy;
@@ -272,7 +269,7 @@ static void *get_salt(char *ciphertext)
272269

273270
memset(cs, 0, SALT_SIZE);
274271

275-
ctcopy += 4;
272+
ctcopy += TAG_LENGTH;
276273
p = strtokm(ctcopy, "$");
277274
cs->type = atoi(p);
278275
p = strtokm(NULL, "$");
@@ -656,6 +653,7 @@ struct fmt_main fmt_sevenzip = {
656653
{
657654
"iteration count",
658655
},
656+
{ FORMAT_TAG },
659657
sevenzip_tests
660658
}, {
661659
init,

src/AFS_fmt.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#define FORMAT_LABEL "AFS"
2222
#define FORMAT_NAME "Kerberos AFS"
23+
#define FORMAT_TAG "$K4$"
24+
#define FORMAT_TAG_LEN (sizeof(FORMAT_TAG)-1)
2325

2426
#define BENCHMARK_COMMENT ""
2527
#define BENCHMARK_LENGTH 8
@@ -127,9 +129,9 @@ static int valid(char *ciphertext, struct fmt_main *self)
127129
int index, count;
128130
unsigned int value;
129131

130-
if (strncmp(ciphertext, "$K4$", 4)) return 0;
132+
if (strncmp(ciphertext, FORMAT_TAG, FORMAT_TAG_LEN)) return 0;
131133

132-
for (pos = &ciphertext[4]; atoi16l[ARCH_INDEX(*pos)] != 0x7F; pos++);
134+
for (pos = &ciphertext[FORMAT_TAG_LEN]; atoi16l[ARCH_INDEX(*pos)] != 0x7F; pos++);
133135
if (*pos != ',' || pos - ciphertext != CIPHERTEXT_LENGTH) return 0;
134136

135137
for (index = 0; index < 16; index += 2) {
@@ -159,10 +161,11 @@ static void *get_binary(char *ciphertext)
159161
out[0] = out[1] = 0;
160162
strcpy(base64, AFS_SALT);
161163
known_long = 0;
164+
ciphertext += FORMAT_TAG_LEN;
162165

163166
for (index = 0; index < 16; index += 2) {
164-
value = atoi16[ARCH_INDEX(ciphertext[index + 4])] << 4;
165-
value |= atoi16[ARCH_INDEX(ciphertext[index + 5])];
167+
value = atoi16[ARCH_INDEX(ciphertext[index])] << 4;
168+
value |= atoi16[ARCH_INDEX(ciphertext[index+1])];
166169

167170
out[index >> 3] |= (value | 1) << ((index << 2) & 0x18);
168171

@@ -457,6 +460,7 @@ struct fmt_main fmt_AFS = {
457460
MAX_KEYS_PER_CRYPT,
458461
FMT_CASE | FMT_8_BIT,
459462
{ NULL },
463+
{ FORMAT_TAG },
460464
tests
461465
}, {
462466
init,

src/AzureAD_common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "formats.h"
1717

1818
#define FORMAT_TAG "v1;PPH1_MD4,"
19-
#define TAG_LENGTH 12
19+
#define TAG_LENGTH (sizeof(FORMAT_TAG)-1)
2020

2121
#define HASH_LENGTH 64
2222
#define SALT_HASH_LEN 20

src/AzureAD_fmt_plug.c

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ struct fmt_main fmt_AzureAD = {
237237
#endif
238238
FMT_CASE | FMT_8_BIT | FMT_SPLIT_UNIFIES_CASE | FMT_OMP | FMT_UNICODE | FMT_UTF8,
239239
{ NULL },
240+
{ FORMAT_TAG },
240241
AzureAD_common_tests
241242
}, {
242243
init,

src/BFEgg_fmt_plug.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ struct fmt_main fmt_BFEgg = {
226226
MIN_KEYS_PER_CRYPT,
227227
MAX_KEYS_PER_CRYPT,
228228
FMT_CASE | FMT_8_BIT | FMT_OMP,
229-
{ NULL },
229+
{ NULL },
230+
{ NULL },
230231
tests
231232
}, {
232233
init,

src/BF_common.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ int BF_common_valid(char *ciphertext, struct fmt_main *self)
7979
int rounds;
8080
char *pos;
8181

82-
if (strncmp(ciphertext, "$2a$", 4) &&
83-
strncmp(ciphertext, "$2b$", 4) &&
84-
strncmp(ciphertext, "$2x$", 4) &&
85-
strncmp(ciphertext, "$2y$", 4))
82+
if (strncmp(ciphertext, FORMAT_TAG, FORMAT_TAG_LEN) &&
83+
strncmp(ciphertext, FORMAT_TAG2, FORMAT_TAG_LEN) &&
84+
strncmp(ciphertext, FORMAT_TAG3, FORMAT_TAG_LEN) &&
85+
strncmp(ciphertext, FORMAT_TAG4, FORMAT_TAG_LEN))
8686
return 0;
8787

8888
if (ciphertext[4] < '0' || ciphertext[4] > '9') return 0;

src/BF_common.h

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ extern struct fmt_tests BF_common_tests[];
1515
/* Number of Blowfish rounds, this is also hardcoded into a few places */
1616
#define BF_ROUNDS 16
1717

18+
#define FORMAT_TAG "$2a$"
19+
#define FORMAT_TAG_LEN (sizeof(FORMAT_TAG)-1)
20+
#define FORMAT_TAG2 "$2y$"
21+
#define FORMAT_TAG3 "$2x$"
22+
#define FORMAT_TAG4 "$2b$"
23+
1824
typedef ARCH_WORD_32 BF_word;
1925

2026
/*

src/BF_fmt.c

+6
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ struct fmt_main fmt_BF = {
197197
{
198198
"iteration count",
199199
},
200+
{
201+
FORMAT_TAG,
202+
FORMAT_TAG2,
203+
FORMAT_TAG3,
204+
FORMAT_TAG4
205+
},
200206
BF_common_tests
201207
}, {
202208
init,

src/BSDI_fmt.c

+1
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ struct fmt_main fmt_BSDI = {
429429
{
430430
"iteration count",
431431
},
432+
{ NULL },
432433
tests
433434
}, {
434435
init,

src/DES_fmt.c

+1
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ struct fmt_main fmt_DES = {
380380
#endif
381381
FMT_TRUNC | FMT_CASE,
382382
{ NULL },
383+
{ NULL },
383384
tests
384385
}, {
385386
init,

src/DMD5_fmt_plug.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ john_register_one(&fmt_DMD5);
4040
#define FORMAT_LABEL "dmd5"
4141
#define FORMAT_NAME "DIGEST-MD5 C/R"
4242
#define ALGORITHM_NAME "MD5 32/" ARCH_BITS_STR
43+
#define FORMAT_TAG "$DIGEST-MD5$"
44+
#define FORMAT_TAG_LEN (sizeof(FORMAT_TAG)-1)
4345

4446
#define BENCHMARK_COMMENT ""
4547
#define BENCHMARK_LENGTH -1
@@ -135,9 +137,9 @@ static void done(void)
135137

136138
static int valid(char *ciphertext, struct fmt_main *self)
137139
{
138-
char *p, *data = ciphertext + 12;
140+
char *p, *data = ciphertext + FORMAT_TAG_LEN;
139141

140-
if (strncmp(ciphertext, "$DIGEST-MD5$", 12) != 0)
142+
if (strncmp(ciphertext, FORMAT_TAG, FORMAT_TAG_LEN) != 0)
141143
return 0;
142144

143145
if (strlen(ciphertext) > CIPHERTEXT_LENGTH)
@@ -185,7 +187,7 @@ static void *get_binary(char *ciphertext)
185187
static ARCH_WORD_32 out[BINARY_SIZE/4];
186188
char response[MD5_HEX_SIZE + 1];
187189
unsigned int i;
188-
char *p, *data = ciphertext + 12;
190+
char *p, *data = ciphertext + FORMAT_TAG_LEN;
189191

190192
p = strchr(data, '$'); data = p + 1;
191193
p = strchr(data, '$'); data = p + 1;
@@ -221,7 +223,7 @@ static void *get_salt(char *ciphertext)
221223
char authzid[8];
222224
unsigned char *ptr_src, *ptr_dst, v, i;
223225
char *ccopy = strdup(ciphertext);
224-
char *p, *data = ccopy + 12;
226+
char *p, *data = ccopy + FORMAT_TAG_LEN;
225227
MD5_CTX ctx;
226228
char A2[DSIZE];
227229
unsigned char hash[BINARY_SIZE];
@@ -417,6 +419,7 @@ struct fmt_main fmt_DMD5 = {
417419
MAX_KEYS_PER_CRYPT,
418420
FMT_CASE | FMT_8_BIT | FMT_OMP,
419421
{ NULL },
422+
{ FORMAT_TAG },
420423
tests
421424
},
422425
{

src/DOMINOSEC8_fmt_plug.c

+1
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ struct fmt_main fmt_DOMINOSEC8 = {
770770
MAX_KEYS_PER_CRYPT,
771771
FMT_CASE | FMT_8_BIT | FMT_OMP,
772772
{ NULL },
773+
{ NULL },
773774
tests
774775
},
775776
{

src/DOMINOSEC_fmt_plug.c

+1
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ struct fmt_main fmt_DOMINOSEC = {
750750
MAX_KEYS_PER_CRYPT,
751751
FMT_CASE | FMT_8_BIT | FMT_OMP,
752752
{ NULL },
753+
{ NULL },
753754
tests
754755
},
755756
{

src/EPI_fmt_plug.c

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ struct fmt_main fmt_EPI =
234234
MAX_KEYS_PER_CRYPT,
235235
FMT_CASE | FMT_8_BIT | FMT_OMP,
236236
{ NULL },
237+
{ NULL },
237238
global_tests
238239
},
239240
{ // fmt_methods

src/FGT_fmt_plug.c

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ struct fmt_main fmt_FGT = {
255255
MAX_KEYS_PER_CRYPT,
256256
FMT_CASE | FMT_8_BIT | FMT_OMP ,
257257
{ NULL },
258+
{ NULL },
258259
fgt_tests
259260
}, {
260261
init,

src/HDAA_fmt_plug.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static unsigned int omp_t = 1;
8484
#define SEPARATOR '$'
8585

8686
#define MAGIC "$response$"
87+
#define MAGIC_LEN (sizeof(MAGIC)-1)
8788
#define SIZE_TAB 12
8889

8990
// This is 8 x 64 bytes, so in MMX/SSE2 we support up to 9 limbs of MD5
@@ -194,11 +195,11 @@ static int valid(char *ciphertext, struct fmt_main *self)
194195
{
195196
char *ctcopy, *keeptr, *p;
196197

197-
if (strncmp(ciphertext, MAGIC, sizeof(MAGIC) - 1) != 0)
198+
if (strncmp(ciphertext, MAGIC, MAGIC_LEN) != 0)
198199
return 0;
199200
ctcopy = strdup(ciphertext);
200201
keeptr = ctcopy;
201-
ctcopy += sizeof(MAGIC)-1;
202+
ctcopy += MAGIC_LEN;
202203

203204
if ((p = strtokm(ctcopy, "$")) == NULL) /* hash */
204205
goto err;
@@ -729,6 +730,7 @@ struct fmt_main fmt_HDAA = {
729730
#endif
730731
FMT_CASE | FMT_8_BIT,
731732
{ NULL },
733+
{ MAGIC },
732734
tests
733735
}, {
734736
init,

src/IPB2_fmt_plug.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ static unsigned int omp_t = 1;
4646

4747
#define FORMAT_LABEL "ipb2"
4848
#define FORMAT_NAME "Invision Power Board 2.x"
49+
#define FORMAT_TAG "$IPB2$"
50+
#define FORMAT_TAG_LEN (sizeof(FORMAT_TAG)-1)
4951

5052
#define ALGORITHM_NAME "MD5 " MD5_ALGORITHM_NAME
5153

@@ -189,7 +191,7 @@ static void done(void)
189191

190192
static int valid(char *ciphertext, struct fmt_main *self)
191193
{
192-
if (strncmp(ciphertext, "$IPB2$", 6) != 0)
194+
if (strncmp(ciphertext, FORMAT_TAG, FORMAT_TAG_LEN) != 0)
193195
return 0;
194196

195197
if (strlen(ciphertext) != CIPHERTEXT_LENGTH)
@@ -230,7 +232,7 @@ static void *get_salt(char *ciphertext)
230232
static MD5_CTX ctx;
231233
int i;
232234

233-
ciphertext += 6;
235+
ciphertext += FORMAT_TAG_LEN;
234236
for (i = 0; i < SALT_LENGTH; ++i)
235237
binary_salt[i] =
236238
(atoi16[ARCH_INDEX(ciphertext[i*2])] << 4)
@@ -492,6 +494,7 @@ struct fmt_main fmt_IPB2 = {
492494
MAX_KEYS_PER_CRYPT,
493495
FMT_CASE | FMT_8_BIT | FMT_OMP,
494496
{ NULL },
497+
{ FORMAT_TAG },
495498
tests
496499
},
497500
{

src/KRB4_fmt_plug.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ john_register_one(&fmt_KRB4);
5454

5555
#define FORMAT_LABEL "krb4"
5656
#define FORMAT_NAME "Kerberos v4 TGT"
57+
#define FORMAT_TAG "$af$"
58+
#define FORMAT_TAG2 "$k4$"
59+
#define FORMAT_TAG_LEN (sizeof(FORMAT_TAG)-1)
60+
5761
#define ALGORITHM_NAME "DES 32/" ARCH_BITS_STR
5862
#define BENCHMARK_COMMENT ""
5963
#define BENCHMARK_LENGTH -1
@@ -114,10 +118,10 @@ static int valid(char *ciphertext, struct fmt_main *self)
114118
{
115119
char *tgt;
116120

117-
if (strncmp(ciphertext, "$k4$", 4) != 0 &&
118-
strncmp(ciphertext, "$af$", 4) != 0)
121+
if (strncmp(ciphertext, FORMAT_TAG, FORMAT_TAG_LEN) != 0 &&
122+
strncmp(ciphertext, FORMAT_TAG2, FORMAT_TAG_LEN) != 0)
119123
return 0;
120-
ciphertext += 4;
124+
ciphertext += FORMAT_TAG_LEN;
121125
tgt = strchr(ciphertext, '$');
122126

123127
if (!tgt)
@@ -163,8 +167,8 @@ static void *get_salt(char *ciphertext)
163167
char *p;
164168

165169
memset(&salt, 0, sizeof(salt));
166-
if (strncmp(ciphertext, "$af$", 4) == 0) {
167-
ciphertext += 4;
170+
if (strncmp(ciphertext, FORMAT_TAG, FORMAT_TAG_LEN) == 0) {
171+
ciphertext += FORMAT_TAG_LEN;
168172
p = strchr(ciphertext, '$');
169173
strnzcpy(salt.realm, ciphertext, (p - ciphertext) + 1);
170174
ciphertext = p + 1;
@@ -265,6 +269,7 @@ struct fmt_main fmt_KRB4 = {
265269
MAX_KEYS_PER_CRYPT,
266270
FMT_CASE | FMT_8_BIT,
267271
{ NULL },
272+
{ FORMAT_TAG, FORMAT_TAG2 },
268273
tests
269274
}, {
270275
fmt_default_init,

src/KRB5_fmt_plug.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ john_register_one(&fmt_KRB5);
5454

5555
// defines
5656
#define MAGIC_PREFIX "$krb5$"
57+
#define MAGIC_PREFIX_LEN (sizeof(MAGIC_PREFIX)-1)
5758
#define MAX_REALM_LEN 64
5859
#define TGT_SIZE 228
5960
#define MAX_USER_LEN 64
@@ -188,7 +189,7 @@ static void * get_salt(char *ciphertext) {
188189

189190
memset(&salt, 0, sizeof(salt));
190191
// advance past the $krb5$ string - it was checked for in valid()
191-
data += strlen(MAGIC_PREFIX);
192+
data += MAGIC_PREFIX_LEN;
192193

193194
// find and copy the user field
194195
p = strchr(data, '$');
@@ -224,7 +225,7 @@ static void * get_salt(char *ciphertext) {
224225
*/
225226
static int valid(char *ciphertext, struct fmt_main *self) {
226227

227-
if (strncmp(ciphertext, MAGIC_PREFIX, sizeof(MAGIC_PREFIX) - 1) != 0)
228+
if (strncmp(ciphertext, MAGIC_PREFIX, MAGIC_PREFIX_LEN) != 0)
228229
return 0;
229230

230231
return get_salt(ciphertext) ? 1 : 0;
@@ -337,6 +338,7 @@ struct fmt_main fmt_KRB5 = {
337338
MAX_KEYS_PER_CRYPT,
338339
FMT_CASE | FMT_8_BIT,
339340
{ NULL },
341+
{ MAGIC_PREFIX },
340342
fmt_tests
341343
}, {
342344
init,

0 commit comments

Comments
 (0)