1 /*
2 * This software is Copyright (c) 2004 bartavelle, <simon at banquise.net>, and it is hereby released to the general public under the following terms:
3 * Redistribution and use in source and binary forms, with or without modification, are permitted.
4 *
5 * Converted to thin format, into $dynamic_19$ format.
6 */
7
8 #if AC_BUILT
9 #include "autoconfig.h"
10 #endif
11 #ifndef DYNAMIC_DISABLED
12
13 #if FMT_EXTERNS_H
14 extern struct fmt_main fmt_pixMD5;
15 #elif FMT_REGISTERS_H
16 john_register_one(&fmt_pixMD5);
17 #else
18
19 #include <string.h>
20
21 #include "common.h"
22 #include "formats.h"
23 #include "dynamic.h"
24
25 #define FORMAT_LABEL "pix-md5"
26 #define FORMAT_NAME "Cisco PIX"
27 #define ALGORITHM_NAME "?" /* filled in by md5-gen */
28 #define BENCHMARK_COMMENT ""
29 #define BENCHMARK_LENGTH 0x107
30
31 // set PLAINTEXT_LENGTH to 0, so dyna will set this (note, 16 was right, but just let dyna set it)
32 #define PLAINTEXT_LENGTH 0
33 #define CIPHERTEXT_LENGTH 16
34 #define BINARY_SIZE 16
35 #define BINARY_ALIGN MEM_ALIGN_WORD
36 #define SALT_ALIGN MEM_ALIGN_WORD
37
38 #define SALT_SIZE 0
39
40 static struct fmt_tests pixmd5_tests[] = {
41 {"2KFQnbNIdI.2KYOU", "cisco"},
42 {"TRPEas6f/aa6JSPL", "test1"},
43 {"OMT6mXmAvGyzrCtp", "test2"},
44 {"gTC7RIy1XJzagmLm", "test3"},
45 {"oWC1WRwqlBlbpf/O", "test4"},
46 {"NuLKvvWGg.x9HEKO", "password"},
47 {"8Ry2YjIyt7RRXU24", ""},
48 {".7nfVBEIEu4KbF/1","0123456789abcdef"}, // added a exact 16 byte password, to make sure it works properly
49 // repeat first hash in exactly the same format that is used in john.pot
50 {"$dynamic_19$2KFQnbNIdI.2KYOU", "cisco"},
51 {NULL}
52 };
53
54 static char Conv_Buf[80];
55 static struct fmt_main *pDynamic_19;
56 static void pixmd5_init(struct fmt_main *self);
57 static void get_ptr();
58
59 /* this function converts a 'native' pixmd5 signature string into a Dynamic_19 syntax string */
Convert(char * Buf,char * ciphertext)60 static char *Convert(char *Buf, char *ciphertext) {
61 // 2KFQnbNIdI.2KYOU -> $dynamic_19$2KFQnbNIdI.2KYOU
62 if (text_in_dynamic_format_already(pDynamic_19, ciphertext))
63 return ciphertext;
64
65 if (strnlen(ciphertext, CIPHERTEXT_LENGTH + 1) == CIPHERTEXT_LENGTH) {
66 sprintf(Buf, "$dynamic_19$%s", ciphertext);
67 return Buf;
68 }
69 return ciphertext;
70 }
71
our_split(char * ciphertext,int index,struct fmt_main * self)72 static char *our_split(char *ciphertext, int index, struct fmt_main *self)
73 {
74 get_ptr();
75 return pDynamic_19->methods.split(Convert(Conv_Buf, ciphertext), index, self);
76 }
our_salt(char * ciphertext)77 static void * our_salt(char *ciphertext) {
78 get_ptr();
79 return pDynamic_19->methods.salt(Convert(Conv_Buf, ciphertext));
80 }
81
valid(char * ciphertext,struct fmt_main * self)82 static int valid(char *ciphertext, struct fmt_main *self) {
83 int i;
84
85 if (!ciphertext)
86 return 0;
87 get_ptr();
88
89 i = strnlen(ciphertext, CIPHERTEXT_LENGTH + 1);
90 if (i > CIPHERTEXT_LENGTH)
91 return pDynamic_19->methods.valid(ciphertext, pDynamic_19);
92 if (i == CIPHERTEXT_LENGTH)
93 return pDynamic_19->methods.valid(Convert(Conv_Buf, ciphertext), pDynamic_19);
94 return 0;
95 }
96
our_binary(char * ciphertext)97 static void * our_binary(char *ciphertext) {
98 get_ptr();
99 return pDynamic_19->methods.binary(Convert(Conv_Buf, ciphertext));
100 }
101
102 struct fmt_main fmt_pixMD5 = {
103 {
104 // setup the labeling and stuff. NOTE the max and min crypts are set to 1
105 // here, but will be reset within our init() function.
106 FORMAT_LABEL, FORMAT_NAME, ALGORITHM_NAME, BENCHMARK_COMMENT, BENCHMARK_LENGTH,
107 0, PLAINTEXT_LENGTH, BINARY_SIZE, BINARY_ALIGN, SALT_SIZE, SALT_ALIGN, 1, 1, FMT_CASE | FMT_8_BIT | FMT_DYNAMIC,
108 { NULL },
109 { NULL },
110 pixmd5_tests
111 },
112 {
113 /* All we setup here, is the pointer to valid, and the pointer to init */
114 /* within the call to init, we will properly set this full object */
115 pixmd5_init,
116 fmt_default_done,
117 fmt_default_reset,
118 fmt_default_prepare,
119 valid,
120 our_split
121 }
122 };
123
link_funcs()124 static void link_funcs() {
125 fmt_pixMD5.methods.salt = our_salt;
126 fmt_pixMD5.methods.binary = our_binary;
127 fmt_pixMD5.methods.split = our_split;
128 }
129
pixmd5_init(struct fmt_main * self)130 static void pixmd5_init(struct fmt_main *self)
131 {
132 if (self->private.initialized == 0) {
133 get_ptr();
134 pDynamic_19->methods.init(pDynamic_19);
135 self->private.initialized = 1;
136 }
137 }
138
get_ptr()139 static void get_ptr() {
140 if (!pDynamic_19) {
141 pDynamic_19 = dynamic_THIN_FORMAT_LINK(&fmt_pixMD5, Convert(Conv_Buf, pixmd5_tests[0].ciphertext), "pix-md5", 0);
142 link_funcs();
143 }
144 }
145
146 #endif /* plugin stanza */
147
148 #endif /* DYNAMIC_DISABLED */
149