forked from hashcat/hashcat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinc_diskcryptor_xts.cl
380 lines (258 loc) · 12.7 KB
/
inc_diskcryptor_xts.cl
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.h"
#include "inc_common.h"
#include "inc_cipher_aes.h"
#include "inc_cipher_serpent.h"
#include "inc_cipher_twofish.h"
#include "inc_diskcryptor_xts.h"
DECLSPEC void dcrp_xts_mul2 (PRIVATE_AS u32 *in, PRIVATE_AS u32 *out)
{
const u32 c = in[3] >> 31;
out[3] = (in[3] << 1) | (in[2] >> 31);
out[2] = (in[2] << 1) | (in[1] >> 31);
out[1] = (in[1] << 1) | (in[0] >> 31);
out[0] = (in[0] << 1);
out[0] ^= c * 0x87;
}
DECLSPEC void dcrp_aes256_decrypt_xts (PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2, PRIVATE_AS const u32 *in, PRIVATE_AS u32 *out, PRIVATE_AS u32 *S, PRIVATE_AS u32 *T, PRIVATE_AS u32 *ks, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4, SHM_TYPE u32 *s_td0, SHM_TYPE u32 *s_td1, SHM_TYPE u32 *s_td2, SHM_TYPE u32 *s_td3, SHM_TYPE u32 *s_td4)
{
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
out[3] = in[3];
aes256_set_encrypt_key (ks, ukey2, s_te0, s_te1, s_te2, s_te3);
aes256_encrypt (ks, S, T, s_te0, s_te1, s_te2, s_te3, s_te4);
// skip four blocks (the starting position + 64 raw salt bytes that were replaced after encryption):
dcrp_xts_mul2 (T, T);
dcrp_xts_mul2 (T, T);
dcrp_xts_mul2 (T, T);
dcrp_xts_mul2 (T, T);
out[0] ^= T[0];
out[1] ^= T[1];
out[2] ^= T[2];
out[3] ^= T[3];
aes256_set_decrypt_key (ks, ukey1, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
aes256_decrypt (ks, out, out, s_td0, s_td1, s_td2, s_td3, s_td4);
out[0] ^= T[0];
out[1] ^= T[1];
out[2] ^= T[2];
out[3] ^= T[3];
}
DECLSPEC void dcrp_serpent256_decrypt_xts (PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2, PRIVATE_AS const u32 *in, PRIVATE_AS u32 *out, PRIVATE_AS u32 *S, PRIVATE_AS u32 *T, PRIVATE_AS u32 *ks)
{
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
out[3] = in[3];
serpent256_set_key (ks, ukey2);
serpent256_encrypt (ks, S, T);
// skip four blocks (the starting position + 64 raw salt bytes that were replaced after encryption):
dcrp_xts_mul2 (T, T);
dcrp_xts_mul2 (T, T);
dcrp_xts_mul2 (T, T);
dcrp_xts_mul2 (T, T);
out[0] ^= T[0];
out[1] ^= T[1];
out[2] ^= T[2];
out[3] ^= T[3];
serpent256_set_key (ks, ukey1);
serpent256_decrypt (ks, out, out);
out[0] ^= T[0];
out[1] ^= T[1];
out[2] ^= T[2];
out[3] ^= T[3];
}
DECLSPEC void dcrp_twofish256_decrypt_xts (PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2, PRIVATE_AS const u32 *in, PRIVATE_AS u32 *out, PRIVATE_AS u32 *S, PRIVATE_AS u32 *T, PRIVATE_AS u32 *sk, PRIVATE_AS u32 *lk)
{
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
out[3] = in[3];
twofish256_set_key (sk, lk, ukey2);
twofish256_encrypt (sk, lk, S, T);
// skip four blocks (the starting position + 64 raw salt bytes that were replaced after encryption):
dcrp_xts_mul2 (T, T);
dcrp_xts_mul2 (T, T);
dcrp_xts_mul2 (T, T);
dcrp_xts_mul2 (T, T);
out[0] ^= T[0];
out[1] ^= T[1];
out[2] ^= T[2];
out[3] ^= T[3];
twofish256_set_key (sk, lk, ukey1);
twofish256_decrypt (sk, lk, out, out);
out[0] ^= T[0];
out[1] ^= T[1];
out[2] ^= T[2];
out[3] ^= T[3];
}
// 512 bit
DECLSPEC int dcrp_verify_header_aes (GLOBAL_AS const u32 *data_buf, PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4, SHM_TYPE u32 *s_td0, SHM_TYPE u32 *s_td1, SHM_TYPE u32 *s_td2, SHM_TYPE u32 *s_td3, SHM_TYPE u32 *s_td4)
{
u32 ks_aes[60];
u32 S[4] = { 1, 0, 0, 0 }; // this weird offset / sector ID
u32 T_aes[4] = { 0 };
u32 data[4];
data[0] = data_buf[0];
data[1] = data_buf[1];
data[2] = data_buf[2];
data[3] = data_buf[3];
u32 tmp[4];
dcrp_aes256_decrypt_xts (ukey1, ukey2, data, tmp, S, T_aes, ks_aes, s_te0, s_te1, s_te2, s_te3, s_te4, s_td0, s_td1, s_td2, s_td3, s_td4);
if (tmp[0] != 0x50524344) return 0; // signature / magic: "DCRP"
if ((tmp[2] != 0x00040002) && (tmp[2] != 0x00050002) && (tmp[2] != 0x00080002)) return 0; // header version 0x0002 and flags either 0x04, 0x05 or 0x08
if ((tmp[3] & 0xffff) != 0) return 0; // remaining 2 bytes of 0x00000004 / 0x00000005 / 0x00000008 => must be 0x0000
return 1;
}
DECLSPEC int dcrp_verify_header_serpent (GLOBAL_AS const u32 *data_buf, PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2)
{
u32 ks_serpent[140];
u32 S[4] = { 1, 0, 0, 0 }; // this weird offset / sector ID. found by lot of research by philsmd
u32 T_serpent[4] = { 0 };
u32 data[4];
data[0] = data_buf[0];
data[1] = data_buf[1];
data[2] = data_buf[2];
data[3] = data_buf[3];
u32 tmp[4];
dcrp_serpent256_decrypt_xts (ukey1, ukey2, data, tmp, S, T_serpent, ks_serpent);
if (tmp[0] != 0x50524344) return 0; // signature / magic: "DCRP"
if ((tmp[2] != 0x00040002) && (tmp[2] != 0x00050002) && (tmp[2] != 0x00080002)) return 0; // header version 0x0002 and flags either 0x04, 0x05 or 0x08
if ((tmp[3] & 0xffff) != 0) return 0; // remaining 2 bytes of 0x00000004 / 0x00000005 / 0x00000008 => must be 0x0000
return 1;
}
DECLSPEC int dcrp_verify_header_twofish (GLOBAL_AS const u32 *data_buf, PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2)
{
u32 sk_twofish[4];
u32 lk_twofish[40];
u32 S[4] = { 1, 0, 0, 0 }; // this weird offset / sector ID. found by lot of research by philsmd
u32 T_twofish[4] = { 0 };
u32 data[4];
data[0] = data_buf[0];
data[1] = data_buf[1];
data[2] = data_buf[2];
data[3] = data_buf[3];
u32 tmp[4];
dcrp_twofish256_decrypt_xts (ukey1, ukey2, data, tmp, S, T_twofish, sk_twofish, lk_twofish);
if (tmp[0] != 0x50524344) return 0; // signature / magic: "DCRP"
if ((tmp[2] != 0x00040002) && (tmp[2] != 0x00050002) && (tmp[2] != 0x00080002)) return 0; // header version 0x0002 and flags either 0x04, 0x05 or 0x08
if ((tmp[3] & 0xffff) != 0) return 0; // remaining 2 bytes of 0x00000004 / 0x00000005 / 0x00000008 => must be 0x0000
return 1;
}
// 1024 bit
DECLSPEC int dcrp_verify_header_aes_twofish (GLOBAL_AS const u32 *data_buf, PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2, PRIVATE_AS const u32 *ukey3, PRIVATE_AS const u32 *ukey4, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4, SHM_TYPE u32 *s_td0, SHM_TYPE u32 *s_td1, SHM_TYPE u32 *s_td2, SHM_TYPE u32 *s_td3, SHM_TYPE u32 *s_td4)
{
u32 ks_aes[60];
u32 sk_twofish[4];
u32 lk_twofish[40];
u32 S[4] = { 1, 0, 0, 0 }; // this weird offset / sector ID. found by lot of research by philsmd
u32 T_aes[4] = { 0 };
u32 T_twofish[4] = { 0 };
u32 data[4];
data[0] = data_buf[0];
data[1] = data_buf[1];
data[2] = data_buf[2];
data[3] = data_buf[3];
u32 tmp[4];
dcrp_aes256_decrypt_xts (ukey2, ukey4, data, tmp, S, T_aes, ks_aes, s_te0, s_te1, s_te2, s_te3, s_te4, s_td0, s_td1, s_td2, s_td3, s_td4);
dcrp_twofish256_decrypt_xts (ukey1, ukey3, tmp, tmp, S, T_twofish, sk_twofish, lk_twofish);
if (tmp[0] != 0x50524344) return 0; // signature / magic: "DCRP"
if ((tmp[2] != 0x00040002) && (tmp[2] != 0x00050002) && (tmp[2] != 0x00080002)) return 0; // header version 0x0002 and flags either 0x04, 0x05 or 0x08
if ((tmp[3] & 0xffff) != 0) return 0; // remaining 2 bytes of 0x00000004 / 0x00000005 / 0x00000008 => must be 0x0000
return 1;
}
DECLSPEC int dcrp_verify_header_serpent_aes (GLOBAL_AS const u32 *data_buf, PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2, PRIVATE_AS const u32 *ukey3, PRIVATE_AS const u32 *ukey4, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4, SHM_TYPE u32 *s_td0, SHM_TYPE u32 *s_td1, SHM_TYPE u32 *s_td2, SHM_TYPE u32 *s_td3, SHM_TYPE u32 *s_td4)
{
u32 ks_serpent[140];
u32 ks_aes[60];
u32 S[4] = { 1, 0, 0, 0 }; // this weird offset / sector ID. found by lot of research by philsmd
u32 T_serpent[4] = { 0 };
u32 T_aes[4] = { 0 };
u32 data[4];
data[0] = data_buf[0];
data[1] = data_buf[1];
data[2] = data_buf[2];
data[3] = data_buf[3];
u32 tmp[4];
dcrp_serpent256_decrypt_xts (ukey2, ukey4, data, tmp, S, T_serpent, ks_serpent);
dcrp_aes256_decrypt_xts (ukey1, ukey3, tmp, tmp, S, T_aes, ks_aes, s_te0, s_te1, s_te2, s_te3, s_te4, s_td0, s_td1, s_td2, s_td3, s_td4);
if (tmp[0] != 0x50524344) return 0; // signature / magic: "DCRP"
if ((tmp[2] != 0x00040002) && (tmp[2] != 0x00050002) && (tmp[2] != 0x00080002)) return 0; // header version 0x0002 and flags either 0x04, 0x05 or 0x08
if ((tmp[3] & 0xffff) != 0) return 0; // remaining 2 bytes of 0x00000004 / 0x00000005 / 0x00000008 => must be 0x0000
return 1;
}
DECLSPEC int dcrp_verify_header_twofish_serpent (GLOBAL_AS const u32 *data_buf, PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2, PRIVATE_AS const u32 *ukey3, PRIVATE_AS const u32 *ukey4)
{
u32 sk_twofish[4];
u32 lk_twofish[40];
u32 ks_serpent[140];
u32 S[4] = { 1, 0, 0, 0 }; // this weird offset / sector ID. found by lot of research by philsmd
u32 T_twofish[4] = { 0 };
u32 T_serpent[4] = { 0 };
u32 data[4];
data[0] = data_buf[0];
data[1] = data_buf[1];
data[2] = data_buf[2];
data[3] = data_buf[3];
u32 tmp[4];
dcrp_twofish256_decrypt_xts (ukey2, ukey4, data, tmp, S, T_twofish, sk_twofish, lk_twofish);
dcrp_serpent256_decrypt_xts (ukey1, ukey3, tmp, tmp, S, T_serpent, ks_serpent);
if (tmp[0] != 0x50524344) return 0; // signature / magic: "DCRP"
if ((tmp[2] != 0x00040002) && (tmp[2] != 0x00050002) && (tmp[2] != 0x00080002)) return 0; // header version 0x0002 and flags either 0x04, 0x05 or 0x08
if ((tmp[3] & 0xffff) != 0) return 0; // remaining 2 bytes of 0x00000004 / 0x00000005 / 0x00000008 => must be 0x0000
return 1;
}
// 1536 bit
DECLSPEC int dcrp_verify_header_aes_twofish_serpent (GLOBAL_AS const u32 *data_buf, PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2, PRIVATE_AS const u32 *ukey3, PRIVATE_AS const u32 *ukey4, PRIVATE_AS const u32 *ukey5, PRIVATE_AS const u32 *ukey6, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4, SHM_TYPE u32 *s_td0, SHM_TYPE u32 *s_td1, SHM_TYPE u32 *s_td2, SHM_TYPE u32 *s_td3, SHM_TYPE u32 *s_td4)
{
u32 ks_aes[60];
u32 sk_twofish[4];
u32 lk_twofish[40];
u32 ks_serpent[140];
u32 S[4] = { 1, 0, 0, 0 }; // this weird offset / sector ID. found by lot of research by philsmd
u32 T_aes[4] = { 0 };
u32 T_twofish[4] = { 0 };
u32 T_serpent[4] = { 0 };
u32 data[4];
data[0] = data_buf[0];
data[1] = data_buf[1];
data[2] = data_buf[2];
data[3] = data_buf[3];
u32 tmp[4];
dcrp_aes256_decrypt_xts (ukey3, ukey6, data, tmp, S, T_aes, ks_aes, s_te0, s_te1, s_te2, s_te3, s_te4, s_td0, s_td1, s_td2, s_td3, s_td4);
dcrp_twofish256_decrypt_xts (ukey2, ukey5, tmp, tmp, S, T_twofish, sk_twofish, lk_twofish);
dcrp_serpent256_decrypt_xts (ukey1, ukey4, tmp, tmp, S, T_serpent, ks_serpent);
if (tmp[0] != 0x50524344) return 0; // signature / magic: "DCRP"
if ((tmp[2] != 0x00040002) && (tmp[2] != 0x00050002) && (tmp[2] != 0x00080002)) return 0; // header version 0x0002 and flags either 0x04, 0x05 or 0x08
if ((tmp[3] & 0xffff) != 0) return 0; // remaining 2 bytes of 0x00000004 / 0x00000005 / 0x00000008 => must be 0x0000
return 1;
}
DECLSPEC int dcrp_verify_header_serpent_twofish_aes (GLOBAL_AS const u32 *data_buf, PRIVATE_AS const u32 *ukey1, PRIVATE_AS const u32 *ukey2, PRIVATE_AS const u32 *ukey3, PRIVATE_AS const u32 *ukey4, PRIVATE_AS const u32 *ukey5, PRIVATE_AS const u32 *ukey6, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4, SHM_TYPE u32 *s_td0, SHM_TYPE u32 *s_td1, SHM_TYPE u32 *s_td2, SHM_TYPE u32 *s_td3, SHM_TYPE u32 *s_td4)
{
u32 ks_serpent[140];
u32 sk_twofish[4];
u32 lk_twofish[40];
u32 ks_aes[60];
u32 S[4] = { 1, 0, 0, 0 }; // this weird offset / sector ID. found by lot of research by philsmd
u32 T_serpent[4] = { 0 };
u32 T_twofish[4] = { 0 };
u32 T_aes[4] = { 0 };
u32 data[4];
data[0] = data_buf[0];
data[1] = data_buf[1];
data[2] = data_buf[2];
data[3] = data_buf[3];
u32 tmp[4];
dcrp_serpent256_decrypt_xts (ukey3, ukey6, data, tmp, S, T_serpent, ks_serpent);
dcrp_twofish256_decrypt_xts (ukey2, ukey5, tmp, tmp, S, T_twofish, sk_twofish, lk_twofish);
dcrp_aes256_decrypt_xts (ukey1, ukey4, tmp, tmp, S, T_aes, ks_aes, s_te0, s_te1, s_te2, s_te3, s_te4, s_td0, s_td1, s_td2, s_td3, s_td4);
if (tmp[0] != 0x50524344) return 0; // signature / magic: "DCRP"
if ((tmp[2] != 0x00040002) && (tmp[2] != 0x00050002) && (tmp[2] != 0x00080002)) return 0; // header version 0x0002 and flags either 0x04, 0x05 or 0x08
if ((tmp[3] & 0xffff) != 0) return 0; // remaining 2 bytes of 0x00000004 / 0x00000005 / 0x00000008 => must be 0x0000
return 1;
}