-
Notifications
You must be signed in to change notification settings - Fork 2
/
format_john_sha256.py
203 lines (170 loc) · 6.92 KB
/
format_john_sha256.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# -*- coding: utf-8 -*-
# sha256 with output to john's format
# Copyright © 2015 Aleksey Cherepanov <lyosha@openwall.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted.
import util_ui as U
import bytecode_main as B
import output_c as O
# import output_c_sse as O
# args = U.parse_args()
c_template = 'raw'
algo_file = 'sha256'
c_code = U.load_code_template(c_template)
size = 4
endianity = 'be'
args = {}
args['args'] = { 'size': size }
# O.apply_size(size)
# O.apply_endianity(endianity)
bs_size = 64
O.apply_bs_size(bs_size)
# Format setup
tests = '''
#define HEX_TAG "$SHA256$"
/* No cisco hashes in this version */
{"71c3f65d17745f05235570f1799d75e69795d469d9fcb83e326f82f1afa80dea", "epixoip"},
{HEX_TAG "71c3f65d17745f05235570f1799d75e69795d469d9fcb83e326f82f1afa80dea", "epixoip"},
{"25b64f637b373d33a8aa2b7579784e99a20e6b7dfea99a71af124394b8958f27", "doesthiswork"},
{"5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", "password"},
{"27c6794c8aa2f70f5f6dc93d3bfb25ca6de9b0752c8318614cbd4ad203bea24c", "ALLCAPS"},
{"04cdd6c523673bf448efe055711a9b184817d7843b0a76c2046f5398b5854152", "TestTESTt3st"},
{HEX_TAG "ef797c8118f02dfb649607dd5d3f8c7623048c9c063d532cc95c5ed7a898a64f", "12345678"},
{HEX_TAG "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
{HEX_TAG "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", ""},
{"a49c2c9d0c006c8cb55a9a7a38822b83e0cd442614cb416af952fa50156761dc", "openwall"},
{"9e7d3e56996c5a06a6a378567e62f5aa7138ebb0f55c0bdaf73666bf77f73380", "mot\xf6rhead"},
{"1b4f0e9851971998e732078544c96b36c3d01cedf7caa332359d6f1d83567014", "test1"},
{"fd61a03af4f77d870fc21e05e7e80678095c92d808cfb3b5c279ee04c74aca13", "test3"},
{"d150eb0383c8ef7478248d7e6cf18db333e8753d05e15a8a83714b7cf63922b3", "thatsworking"},
{"c775e7b757ede630cd0aa1113bd102661ab38829ca52a6422ab782862f268646", "1234567890"},
#if PLAINTEXT_LENGTH > 19 //Has to be inside a header, it check againt a #define.
{"6ed645ef0e1abea1bf1e4e935ff04f9e18d39812387f63cda3415b46240f0405", "12345678901234567890"},
{"f54e5c8f810648e7638d25eb7ed6d24b7e5999d588e88826f2aa837d2ee52ecd", "123456789012345678901234567890"},
{"a4ebdd541454b84cc670c9f1f5508baf67ffd3fe59b883267808781f992a0b1d", "1234567890123456789012345678901234567890"},
{"f58fffba129aa67ec63bf12571a42977c0b785d3b2a93cc0538557c91da2115d", "12345678901234567890123456789012345678901234567890"},
{"3874d5c9cc5ab726e6bbebadee22c680ce530004d4f0bb32f765d42a0a6c6dc1", "123456789012345678901234567890123456789012345678901"},
{"03c3a70e99ed5eeccd80f73771fcf1ece643d939d9ecc76f25544b0233f708e9", "1234567890123456789012345678901234567890123456789012345"},
{"0f46e4b0802fee6fed599682a16287d0397699cfd742025482c086a70979e56a", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, // 31
{"c62e4615bd39e222572f3a1bf7c2132ea1e65b17ec805047bd6b2842c593493f", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, // 32
{"d5e285683cd4efc02d021a5c62014694958901005d6f71e89e0989fac77e4072", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, // 55
#endif
'''
vs = {
'fmt_struct_name': 'raw1_sha256',
'format_name': 'Raw-SHA256',
'algo_name': 'SHA256',
'tag': '$SHA256$',
'plaintext_length': '55',
'binary_form_size': '32',
'tests': tests
}
U.setup_vars(vs)
# Optimizations and code generation
# http://en.wikipedia.org/wiki/SHA256
# sha224 is sha256 with other initial values and one output dropped
interleave = 1
# B.global_vars['batch_size'] = 20
# B.global_vars['batch_size'] = 16
B.global_vars['batch_size'] = 1
reverse_num = 7
B.global_vars['interleave'] = interleave
B.global_vars['reverse_num'] = reverse_num
B.global_vars['vectorize'] = 1
# d = B.thread_code( B.get_code_full(algo_file, **args),
# B.replace_state_with_const,
# [ B.unroll_cycle_const_range, 'setupW' ],
# [ B.unroll_cycle_const_range, 'main' ],
# [ B.unpack_const_subscripts, 'k' ],
# B.remove_assignments,
# # [ B.dump, 'before.bytecode' ],
# [ B.compute_const_expressions, size ],
# B.drop_arrays,
# B.drop_print,
# [ B.compute_const_expressions, size ],
# B.bitslice,
# [ B.dump, 'test.bytecode' ],
# [ B.interpret,
# [ 0x65706978, 0x6f697080, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000038 ],
# [ 0x71c3f65d, 0x17745f05, 0x235570f1, 0x799d75e6, 0x9795d469, 0xd9fcb83e, 0x326f82f1, 0xafa80dea ]],
# B.my_exit,
# )
# # Print bitslice and exit.
# d = B.thread_code( B.get_code_full(algo_file, **args),
# B.replace_state_with_const,
# [ B.unroll_cycle_const_range, 'setupW' ],
# [ B.unroll_cycle_const_range, 'main' ],
# [ B.unpack_const_subscripts, 'k' ],
# B.remove_assignments,
# # [ B.dump, 'before.bytecode' ],
# [ B.compute_const_expressions, size ],
# B.drop_arrays,
# B.drop_print,
# [ B.compute_const_expressions, size ],
# [ B.bitslice, size ],
# B.drop_unused,
# [ B.dump, 'sha256bs.bytecode' ]
# )
# exit(1)
d = B.thread_code( B.get_code_full(algo_file, **args),
B.replace_state_with_const,
[ B.dump, 'pure.bytecode' ],
# [ B.bitslice, 64, size ],
# [ B.unroll_cycle_const_range, 'setupW' ],
# [ B.unroll_cycle_const_range_partly, 'setupW', 16 ],
# [ B.unroll_cycle_const_range_partly, 'main', 40 ],
[ B.unroll_cycle_const_range, 'main' ],
[ B.unpack_const_subscripts, 'k' ],
B.remove_assignments,
[ B.compute_const_expressions, size ],
# B.drop_print,
# [ B.reduce_assignments, 'main', 'main_end' ],
[ B.dump, 'all.bytecode' ],
# B.research_reverse,
# [ B.reverse_ops, reverse_num ],
[ B.no_reverse, reverse_num ],
)
# # asm
# d = B.thread_code( B.get_code_full('sha256_registers3', **args),
# [ B.dump, 'all.bytecode' ],
# [ B.no_reverse, reverse_num ],
# )
reverse = d['reverse']
code = d['code']
scalar = B.deep_copy(code)
reverse_str = B.thread_code( reverse,
[ B.dump, 'reverse.bytecode' ],
[ O.gen_to_str, '$code', args ]
)
B.global_vars['reverse'] = reverse_str
scalar_str = B.thread_code( scalar,
[ B.dump, 'scalar.bytecode' ],
[ O.gen_to_str, '$code', args ]
)
B.global_vars['scalar'] = scalar_str
# # asm
# b.thread_code( code,
# # B.reuse_variables,
# B.vectorize,
# [ B.dump, 'vector.bytecode' ],
# # B.to_asm,
# # B.put_asm_borders,
# [ B.dump, 'asm.bytecode' ],
# # [ B.unroll_cycle_const_range, 'setupW' ],
# # [ B.unroll_cycle_const_range_partly, 'main', 2 ],
# [ B.interleave, interleave ],
# [ B.dump, 'code.bytecode' ],
# [ O.gen, c_code, args, B.global_vars ]
# )
B.thread_code( code,
# B.reuse_variables,
B.vectorize,
[ B.unroll_cycle_const_range_partly, 'setupW', 16 ],
# [ B.unroll_cycle_const_range, 'setupW' ],
# [ B.unroll_cycle_const_range_partly, 'main', 2 ],
B.use_define_for_some,
[ B.interleave, interleave ],
[ B.dump, 'code.bytecode' ],
[ O.gen, c_code, args, B.global_vars ]
)