2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * magnum <john.magnum@hushmail.com>
8 #define DEVICE_TYPE_CPU 2
9 #define DEVICE_TYPE_GPU 4
21 #define CONCAT(a, b) a##b
22 #define VTYPE(type, width) CONCAT(type, width)
30 typedef VTYPE(uchar
, VECT_SIZE
) u8x
;
31 typedef VTYPE(ushort
, VECT_SIZE
) u16x
;
32 typedef VTYPE(uint
, VECT_SIZE
) u32x
;
33 typedef VTYPE(ulong
, VECT_SIZE
) u64x
;
36 inline u32
l32_from_64_S (u64 a
)
38 const u32 r
= (u32
) (a
);
43 inline u32
h32_from_64_S (u64 a
)
47 const u32 r
= (u32
) (a
);
52 inline u64
hl32_to_64_S (const u32 a
, const u32 b
)
54 return as_ulong ((uint2
) (b
, a
));
57 inline u32x
l32_from_64 (u64x a
)
96 inline u32x
h32_from_64 (u64x a
)
137 inline u64x
hl32_to_64 (const u32x a
, const u32x b
)
142 r
= as_ulong ((uint2
) (b
, a
));
146 r
.s0
= as_ulong ((uint2
) (b
.s0
, a
.s0
));
147 r
.s1
= as_ulong ((uint2
) (b
.s1
, a
.s1
));
151 r
.s2
= as_ulong ((uint2
) (b
.s2
, a
.s2
));
152 r
.s3
= as_ulong ((uint2
) (b
.s3
, a
.s3
));
156 r
.s4
= as_ulong ((uint2
) (b
.s4
, a
.s4
));
157 r
.s5
= as_ulong ((uint2
) (b
.s5
, a
.s5
));
158 r
.s6
= as_ulong ((uint2
) (b
.s6
, a
.s6
));
159 r
.s7
= as_ulong ((uint2
) (b
.s7
, a
.s7
));
163 r
.s8
= as_ulong ((uint2
) (b
.s8
, a
.s8
));
164 r
.s9
= as_ulong ((uint2
) (b
.s9
, a
.s9
));
165 r
.sa
= as_ulong ((uint2
) (b
.sa
, a
.sa
));
166 r
.sb
= as_ulong ((uint2
) (b
.sb
, a
.sb
));
167 r
.sc
= as_ulong ((uint2
) (b
.sc
, a
.sc
));
168 r
.sd
= as_ulong ((uint2
) (b
.sd
, a
.sd
));
169 r
.se
= as_ulong ((uint2
) (b
.se
, a
.se
));
170 r
.sf
= as_ulong ((uint2
) (b
.sf
, a
.sf
));
177 inline u32
swap32_S (const u32 v
)
179 return (as_uint (as_uchar4 (v
).s3210
));
182 inline u64
swap64_S (const u64 v
)
184 return (as_ulong (as_uchar8 (v
).s76543210
));
187 inline u32
rotr32_S (const u32 a
, const u32 n
)
189 return rotate (a
, 32 - n
);
192 inline u32
rotl32_S (const u32 a
, const u32 n
)
194 return rotate (a
, n
);
197 inline u64
rotr64_S (const u64 a
, const u32 n
)
199 const u32 a0
= h32_from_64_S (a
);
200 const u32 a1
= l32_from_64_S (a
);
202 const u32 t0
= (n
>= 32) ? amd_bitalign (a0
, a1
, n
- 32) : amd_bitalign (a1
, a0
, n
);
203 const u32 t1
= (n
>= 32) ? amd_bitalign (a1
, a0
, n
- 32) : amd_bitalign (a0
, a1
, n
);
205 const u64 r
= hl32_to_64_S (t0
, t1
);
210 inline u64
rotl64_S (const u64 a
, const u32 n
)
212 return rotr64_S (a
, 64 - n
);
215 inline u32x
swap32 (const u32x v
)
217 return ((v
>> 24) & 0x000000ff)
218 | ((v
>> 8) & 0x0000ff00)
219 | ((v
<< 8) & 0x00ff0000)
220 | ((v
<< 24) & 0xff000000);
223 inline u64x
swap64 (const u64x v
)
225 return ((v
>> 56) & 0x00000000000000ff)
226 | ((v
>> 40) & 0x000000000000ff00)
227 | ((v
>> 24) & 0x0000000000ff0000)
228 | ((v
>> 8) & 0x00000000ff000000)
229 | ((v
<< 8) & 0x000000ff00000000)
230 | ((v
<< 24) & 0x0000ff0000000000)
231 | ((v
<< 40) & 0x00ff000000000000)
232 | ((v
<< 56) & 0xff00000000000000);
235 inline u32x
rotr32 (const u32x a
, const u32 n
)
237 return rotate (a
, 32 - n
);
240 inline u32x
rotl32 (const u32x a
, const u32 n
)
242 return rotate (a
, n
);
245 inline u64x
rotr64 (const u64x a
, const u32 n
)
247 const u32x a0
= h32_from_64 (a
);
248 const u32x a1
= l32_from_64 (a
);
250 const u32x t0
= (n
>= 32) ? amd_bitalign (a0
, a1
, n
- 32) : amd_bitalign (a1
, a0
, n
);
251 const u32x t1
= (n
>= 32) ? amd_bitalign (a1
, a0
, n
- 32) : amd_bitalign (a0
, a1
, n
);
253 const u64x r
= hl32_to_64 (t0
, t1
);
258 inline u64x
rotl64 (const u64x a
, const u32 n
)
260 return rotr64 (a
, 64 - n
);
263 inline u32
__bfe (const u32 a
, const u32 b
, const u32 c
)
265 return amd_bfe (a
, b
, c
);
268 inline u32
amd_bytealign_S (const u32 a
, const u32 b
, const u32 c
)
270 return amd_bytealign (a
, b
, c
);
275 inline u32
swap32_S (const u32 v
)
279 asm ("prmt.b32 %0, %1, 0, 0x0123;" : "=r"(r
) : "r"(v
));
284 inline u64
swap64_S (const u64 v
)
289 asm ("mov.b64 {%0, %1}, %2;" : "=r"(il
), "=r"(ir
) : "l"(v
));
294 asm ("prmt.b32 %0, %1, 0, 0x0123;" : "=r"(tl
) : "r"(il
));
295 asm ("prmt.b32 %0, %1, 0, 0x0123;" : "=r"(tr
) : "r"(ir
));
299 asm ("mov.b64 %0, {%1, %2};" : "=l"(r
) : "r"(tr
), "r"(tl
));
304 inline u32
rotr32_S (const u32 a
, const u32 n
)
306 return rotate (a
, 32 - n
);
309 inline u32
rotl32_S (const u32 a
, const u32 n
)
311 return rotate (a
, n
);
314 inline u64
rotr64_S (const u64 a
, const u32 n
)
316 return rotate (a
, (u64
) 64 - n
);
319 inline u64
rotl64_S (const u64 a
, const u32 n
)
321 return rotr64_S (a
, 64 - n
);
324 inline u32
__byte_perm_S (const u32 a
, const u32 b
, const u32 c
)
328 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
) : "r"(a
), "r"(b
), "r"(c
));
333 inline u32x
swap32 (const u32x v
)
335 return ((v
>> 24) & 0x000000ff)
336 | ((v
>> 8) & 0x0000ff00)
337 | ((v
<< 8) & 0x00ff0000)
338 | ((v
<< 24) & 0xff000000);
341 inline u64x
swap64 (const u64x v
)
343 return ((v
>> 56) & 0x00000000000000ff)
344 | ((v
>> 40) & 0x000000000000ff00)
345 | ((v
>> 24) & 0x0000000000ff0000)
346 | ((v
>> 8) & 0x00000000ff000000)
347 | ((v
<< 8) & 0x000000ff00000000)
348 | ((v
<< 24) & 0x0000ff0000000000)
349 | ((v
<< 40) & 0x00ff000000000000)
350 | ((v
<< 56) & 0xff00000000000000);
353 inline u32x
rotr32 (const u32x a
, const u32 n
)
355 return rotate (a
, 32 - n
);
358 inline u32x
rotl32 (const u32x a
, const u32 n
)
360 return rotate (a
, n
);
363 inline u64x
rotr64 (const u64x a
, const u32 n
)
365 return rotate (a
, (u64
) 64 - n
);
368 inline u64x
rotl64 (const u64x a
, const u32 n
)
370 return rotate (a
, (u64
) n
);
373 inline u32x
__byte_perm (const u32x a
, const u32x b
, const u32x c
)
378 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
) : "r"(a
), "r"(b
), "r"(c
) );
382 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s0
) : "r"(a
.s0
), "r"(b
.s0
), "r"(c
.s0
));
383 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s1
) : "r"(a
.s1
), "r"(b
.s1
), "r"(c
.s1
));
387 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s2
) : "r"(a
.s2
), "r"(b
.s2
), "r"(c
.s2
));
388 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s3
) : "r"(a
.s3
), "r"(b
.s3
), "r"(c
.s3
));
392 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s4
) : "r"(a
.s4
), "r"(b
.s4
), "r"(c
.s4
));
393 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s5
) : "r"(a
.s5
), "r"(b
.s5
), "r"(c
.s5
));
394 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s6
) : "r"(a
.s6
), "r"(b
.s6
), "r"(c
.s6
));
395 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s7
) : "r"(a
.s7
), "r"(b
.s7
), "r"(c
.s7
));
399 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s8
) : "r"(a
.s8
), "r"(b
.s8
), "r"(c
.s8
));
400 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s9
) : "r"(a
.s9
), "r"(b
.s9
), "r"(c
.s9
));
401 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sa
) : "r"(a
.sa
), "r"(b
.sa
), "r"(c
.sa
));
402 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sb
) : "r"(a
.sb
), "r"(b
.sb
), "r"(c
.sb
));
403 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sc
) : "r"(a
.sc
), "r"(b
.sc
), "r"(c
.sc
));
404 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sd
) : "r"(a
.sd
), "r"(b
.sd
), "r"(c
.sd
));
405 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.se
) : "r"(a
.se
), "r"(b
.se
), "r"(c
.se
));
406 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sf
) : "r"(a
.sf
), "r"(b
.sf
), "r"(c
.sf
));
412 inline u32
__bfe (const u32 a
, const u32 b
, const u32 c
)
416 asm ("bfe.u32 %0, %1, %2, %3;" : "=r"(r
) : "r"(a
), "r"(b
), "r"(c
));
421 inline u32
amd_bytealign (const u32 a
, const u32 b
, const u32 c
)
427 asm ("shf.r.wrap.b32 %0, %1, %2, %3;" : "=r"(r
) : "r"(b
), "r"(a
), "r"((c
& 3) * 8));
431 r
= __byte_perm_S (b
, a
, (0x76543210 >> ((c
& 3) * 4)) & 0xffff);
440 inline u32
swap32_S (const u32 v
)
442 return (as_uint (as_uchar4 (v
).s3210
));
445 inline u64
swap64_S (const u64 v
)
447 return (as_ulong (as_uchar8 (v
).s76543210
));
450 inline u32
rotr32_S (const u32 a
, const u32 n
)
452 return rotate (a
, 32 - n
);
455 inline u32
rotl32_S (const u32 a
, const u32 n
)
457 return rotate (a
, n
);
460 inline u64
rotr64_S (const u64 a
, const u32 n
)
462 return rotate (a
, (u64
) 64 - n
);
465 inline u64
rotl64_S (const u64 a
, const u32 n
)
467 return rotate (a
, (u64
) n
);
470 inline u32
amd_bytealign_S (const u32 a
, const u32 b
, const u32 c
)
472 const u64 tmp
= ((((u64
) a
) << 32) | ((u64
) b
)) >> ((c
& 3) * 8);
477 inline u32x
swap32 (const u32x v
)
479 return ((v
>> 24) & 0x000000ff)
480 | ((v
>> 8) & 0x0000ff00)
481 | ((v
<< 8) & 0x00ff0000)
482 | ((v
<< 24) & 0xff000000);
485 inline u64x
swap64 (const u64x v
)
487 return ((v
>> 56) & 0x00000000000000ff)
488 | ((v
>> 40) & 0x000000000000ff00)
489 | ((v
>> 24) & 0x0000000000ff0000)
490 | ((v
>> 8) & 0x00000000ff000000)
491 | ((v
<< 8) & 0x000000ff00000000)
492 | ((v
<< 24) & 0x0000ff0000000000)
493 | ((v
<< 40) & 0x00ff000000000000)
494 | ((v
<< 56) & 0xff00000000000000);
497 inline u32x
rotr32 (const u32x a
, const u32 n
)
499 return rotate (a
, 32 - n
);
502 inline u32x
rotl32 (const u32x a
, const u32 n
)
504 return rotate (a
, n
);
507 inline u64x
rotr64 (const u64x a
, const u32 n
)
509 return rotate (a
, (u64
) 64 - n
);
512 inline u64x
rotl64 (const u64x a
, const u32 n
)
514 return rotate (a
, (u64
) n
);
517 inline u32
__bfe (const u32 a
, const u32 b
, const u32 c
)
519 #define BIT(x) (1 << (x))
520 #define BIT_MASK(x) (BIT (x) - 1)
521 #define BFE(x,y,z) (((x) >> (y)) & BIT_MASK (z))
523 return BFE (a
, b
, c
);
526 inline u32x
amd_bytealign (const u32x a
, const u32x b
, const u32 c
)
529 const u64x tmp
= ((((u64x
) (a
)) << 32) | ((u64x
) (b
))) >> ((c
& 3) * 8);
535 const u64x tmp
= ((((u64x
) (a
.s0
, a
.s1
)) << 32) | ((u64x
) (b
.s0
, b
.s1
))) >> ((c
& 3) * 8);
537 return (u32x
) (tmp
.s0
, tmp
.s1
);
541 const u64x tmp
= ((((u64x
) (a
.s0
, a
.s1
, a
.s2
, a
.s3
)) << 32) | ((u64x
) (b
.s0
, b
.s1
, b
.s2
, b
.s3
))) >> ((c
& 3) * 8);
543 return (u32x
) (tmp
.s0
, tmp
.s1
, tmp
.s2
, tmp
.s3
);
547 const u64x tmp
= ((((u64x
) (a
.s0
, a
.s1
, a
.s2
, a
.s3
, a
.s4
, a
.s5
, a
.s6
, a
.s7
)) << 32) | ((u64x
) (b
.s0
, b
.s1
, b
.s2
, b
.s3
, b
.s4
, b
.s5
, b
.s6
, b
.s7
))) >> ((c
& 3) * 8);
549 return (u32x
) (tmp
.s0
, tmp
.s1
, tmp
.s2
, tmp
.s3
, tmp
.s4
, tmp
.s5
, tmp
.s6
, tmp
.s7
);
553 const u64x tmp
= ((((u64x
) (a
.s0
, a
.s1
, a
.s2
, a
.s3
, a
.s4
, a
.s5
, a
.s6
, a
.s7
, a
.s8
, a
.s9
, a
.sa
, a
.sb
, a
.sc
, a
.sd
, a
.se
, a
.sf
)) << 32) | ((u64x
) (b
.s0
, b
.s1
, b
.s2
, b
.s3
, b
.s4
, b
.s5
, b
.s6
, b
.s7
, b
.s8
, b
.s9
, b
.sa
, b
.sb
, b
.sc
, b
.sd
, b
.se
, b
.sf
))) >> ((c
& 3) * 8);
555 return (u32x
) (tmp
.s0
, tmp
.s1
, tmp
.s2
, tmp
.s3
, tmp
.s4
, tmp
.s5
, tmp
.s6
, tmp
.s7
, tmp
.s8
, tmp
.s9
, tmp
.sa
, tmp
.sb
, tmp
.sc
, tmp
.sd
, tmp
.se
, tmp
.sf
);
572 #elif defined _BCRYPT_
574 #elif defined _SHA256_
576 #elif defined _SHA384_
578 #elif defined _SHA512_
580 #elif defined _KECCAK_
582 #elif defined _RIPEMD160_
584 #elif defined _WHIRLPOOL_
588 #elif defined _GOST2012_256_
590 #elif defined _GOST2012_512_
596 #elif defined _MYSQL323_
598 #elif defined _LOTUS5_
600 #elif defined _LOTUS6_
602 #elif defined _SCRYPT_
604 #elif defined _LOTUS8_
606 #elif defined _OFFICE2007_
608 #elif defined _OFFICE2010_
610 #elif defined _OFFICE2013_
612 #elif defined _OLDOFFICE01_
614 #elif defined _OLDOFFICE34_
616 #elif defined _SIPHASH_
618 #elif defined _PBKDF2_MD5_
620 #elif defined _PBKDF2_SHA1_
622 #elif defined _PBKDF2_SHA256_
624 #elif defined _PBKDF2_SHA512_
626 #elif defined _PDF17L8_
628 #elif defined _CRC32_
630 #elif defined _SEVEN_ZIP_
632 #elif defined _ANDROIDFDE_
638 #elif defined _MD5_SHA1_
640 #elif defined _SHA1_MD5_
642 #elif defined _NETNTLMV2_
644 #elif defined _KRB5PA_
646 #elif defined _CLOUDKEY_
648 #elif defined _SCRYPT_
650 #elif defined _PSAFE2_
652 #elif defined _LOTUS8_
656 #elif defined _SHA256_SHA1_
658 #elif defined _MS_DRSR_
660 #elif defined _ANDROIDFDE_SAMSUNG_
664 #elif defined _KRB5TGS_
666 #elif defined _AXCRYPT_
668 #elif defined _KEEPASS_
735 u32 cry_master_buf
[64];
737 u32 public_key_buf
[64];
778 u32 userdomain_buf
[64];
795 u32 account_info
[512];
850 u32 encryptedVerifier
[4];
851 u32 encryptedVerifierHash
[5];
859 u32 encryptedVerifier
[4];
860 u32 encryptedVerifierHash
[8];
866 u32 encryptedVerifier
[4];
867 u32 encryptedVerifierHash
[8];
874 u32 encryptedVerifier
[4];
875 u32 encryptedVerifierHash
[4];
883 u32 encryptedVerifier
[4];
884 u32 encryptedVerifierHash
[5];
904 /* key-file handling */
908 u32 final_random_seed
[8];
909 u32 transf_random_seed
[8];
911 u32 contents_hash
[8];
913 /* specific to version 1 */
917 /* specific to version 2 */
918 u32 expected_bytes
[8];
986 } bitcoin_wallet_tmp_t
;
1084 } pbkdf2_sha1_tmp_t
;
1094 } pbkdf2_sha256_tmp_t
;
1104 } pbkdf2_sha512_tmp_t
;
1322 u32 alignment_placeholder_1
;
1323 u32 alignment_placeholder_2
;
1324 u32 alignment_placeholder_3
;