/
m13200-pure.cl
235 lines (175 loc) · 4.76 KB
/
m13200-pure.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
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_hash_sha1.cl"
#include "inc_cipher_aes.cl"
#endif
typedef struct axcrypt_tmp
{
u32 KEK[4];
u32 lsb[4];
u32 cipher[4];
} axcrypt_tmp_t;
KERNEL_FQ void m13200_init (KERN_ATTR_TMPS (axcrypt_tmp_t))
{
/**
* base
*/
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
/**
* KEK
*/
sha1_ctx_t ctx;
sha1_init (&ctx);
sha1_update_global_swap (&ctx, pws[gid].i, pws[gid].pw_len);
sha1_final (&ctx);
u32 KEK[5];
KEK[0] = ctx.h[0];
KEK[1] = ctx.h[1];
KEK[2] = ctx.h[2];
KEK[3] = ctx.h[3];
KEK[4] = ctx.h[4];
/* hash XOR salt is KEK, used as key for AES wrapping routine */
tmps[gid].KEK[0] = KEK[0] ^ salt_bufs[salt_pos].salt_buf[0];
tmps[gid].KEK[1] = KEK[1] ^ salt_bufs[salt_pos].salt_buf[1];
tmps[gid].KEK[2] = KEK[2] ^ salt_bufs[salt_pos].salt_buf[2];
tmps[gid].KEK[3] = KEK[3] ^ salt_bufs[salt_pos].salt_buf[3];
/**
* salt_buf[0..3] is salt
* salt_buf[4..9] is wrapped_key
*/
/* set lsb */
tmps[gid].lsb[0] = salt_bufs[salt_pos].salt_buf[6];
tmps[gid].lsb[1] = salt_bufs[salt_pos].salt_buf[7];
tmps[gid].lsb[2] = salt_bufs[salt_pos].salt_buf[8];
tmps[gid].lsb[3] = salt_bufs[salt_pos].salt_buf[9];
/* set msb */
tmps[gid].cipher[0] = salt_bufs[salt_pos].salt_buf[4];
tmps[gid].cipher[1] = salt_bufs[salt_pos].salt_buf[5];
tmps[gid].cipher[2] = 0;
tmps[gid].cipher[3] = 0;
}
KERNEL_FQ void m13200_loop (KERN_ATTR_TMPS (axcrypt_tmp_t))
{
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
const u64 lsz = get_local_size (0);
/**
* aes shared
*/
#ifdef REAL_SHM
LOCAL_VK u32 s_td0[256];
LOCAL_VK u32 s_td1[256];
LOCAL_VK u32 s_td2[256];
LOCAL_VK u32 s_td3[256];
LOCAL_VK u32 s_td4[256];
LOCAL_VK u32 s_te0[256];
LOCAL_VK u32 s_te1[256];
LOCAL_VK u32 s_te2[256];
LOCAL_VK u32 s_te3[256];
LOCAL_VK u32 s_te4[256];
for (u32 i = lid; i < 256; i += lsz)
{
s_td0[i] = td0[i];
s_td1[i] = td1[i];
s_td2[i] = td2[i];
s_td3[i] = td3[i];
s_td4[i] = td4[i];
s_te0[i] = te0[i];
s_te1[i] = te1[i];
s_te2[i] = te2[i];
s_te3[i] = te3[i];
s_te4[i] = te4[i];
}
SYNC_THREADS ();
#else
CONSTANT_AS u32a *s_td0 = td0;
CONSTANT_AS u32a *s_td1 = td1;
CONSTANT_AS u32a *s_td2 = td2;
CONSTANT_AS u32a *s_td3 = td3;
CONSTANT_AS u32a *s_td4 = td4;
CONSTANT_AS u32a *s_te0 = te0;
CONSTANT_AS u32a *s_te1 = te1;
CONSTANT_AS u32a *s_te2 = te2;
CONSTANT_AS u32a *s_te3 = te3;
CONSTANT_AS u32a *s_te4 = te4;
#endif
if (gid >= gid_max) return;
u32 ukey[4];
ukey[0] = tmps[gid].KEK[0];
ukey[1] = tmps[gid].KEK[1];
ukey[2] = tmps[gid].KEK[2];
ukey[3] = tmps[gid].KEK[3];
u32 lsb[4];
lsb[0] = tmps[gid].lsb[0];
lsb[1] = tmps[gid].lsb[1];
lsb[2] = tmps[gid].lsb[2];
lsb[3] = tmps[gid].lsb[3];
u32 cipher[4];
cipher[0] = tmps[gid].cipher[0];
cipher[1] = tmps[gid].cipher[1];
cipher[2] = tmps[gid].cipher[2];
cipher[3] = tmps[gid].cipher[3];
/**
* aes init
*/
#define KEYLEN 44
u32 ks[KEYLEN];
/**
* aes decrypt key
*/
AES128_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
const u32 wrapping_rounds = salt_bufs[salt_pos].salt_iter - 1;
/* custom AES un-wrapping loop */
for (u32 i = 0, j = wrapping_rounds - loop_pos; i < loop_cnt; i++, j--)
{
const u32 j2 = j * 2;
cipher[0] ^= hc_swap32_S (j2 + 2);
/* R[i] */
cipher[2] = lsb[2];
cipher[3] = lsb[3];
/* AES_ECB(KEK, (MSB XOR (NUMBER_AES_BLOCKS * j + i)) | R[i]) */
AES128_decrypt (ks, cipher, cipher, s_td0, s_td1, s_td2, s_td3, s_td4);
lsb[2] = cipher[2];
lsb[3] = cipher[3];
/* 2nd block treatment */
cipher[0] ^= hc_swap32_S (j2 + 1);
cipher[2] = lsb[0];
cipher[3] = lsb[1];
AES128_decrypt (ks, cipher, cipher, s_td0, s_td1, s_td2, s_td3, s_td4);
lsb[0] = cipher[2];
lsb[1] = cipher[3];
}
tmps[gid].lsb[0] = lsb[0];
tmps[gid].lsb[1] = lsb[1];
tmps[gid].lsb[2] = lsb[2];
tmps[gid].lsb[3] = lsb[3];
tmps[gid].cipher[0] = cipher[0];
tmps[gid].cipher[1] = cipher[1];
tmps[gid].cipher[2] = cipher[2];
tmps[gid].cipher[3] = cipher[3];
}
KERNEL_FQ void m13200_comp (KERN_ATTR_TMPS (axcrypt_tmp_t))
{
/**
* base
*/
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
const u64 lid = get_local_id (0);
#define il_pos 0
if (tmps[gid].cipher[0] == 0xa6a6a6a6 && tmps[gid].cipher[1] == 0xa6a6a6a6)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0);
}
}
}