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
)
362 asm ("shr.b32 %4, %2, %6;"
363 "shr.b32 %5, %3, %6;"
364 "mad.lo.u32 %0, %2, %7, %4;"
365 "mad.lo.u32 %1, %3, %7, %5;"
377 asm ("shr.b32 %8, %4, %12;\n"
378 "shr.b32 %9, %5, %12;\n"
379 "shr.b32 %10, %6, %12;\n"
380 "shr.b32 %11, %7, %12;\n"
381 "mad.lo.u32 %0, %4, %13, %8;\n"
382 "mad.lo.u32 %1, %5, %13, %9;\n"
383 "mad.lo.u32 %2, %6, %13, %10;\n"
384 "mad.lo.u32 %3, %7, %13, %11;\n"
410 return rotate (a
, n
);
415 inline u32x
rotl32 (const u32x a
, const u32 n
)
417 return rotr32 (a
, 32 - n
);
420 inline u64x
rotr64 (const u64x a
, const u32 n
)
422 return rotate (a
, (u64
) 64 - n
);
425 inline u64x
rotl64 (const u64x a
, const u32 n
)
427 return rotate (a
, (u64
) n
);
430 inline u32x
__byte_perm (const u32x a
, const u32x b
, const u32x c
)
435 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
) : "r"(a
), "r"(b
), "r"(c
) );
439 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s0
) : "r"(a
.s0
), "r"(b
.s0
), "r"(c
.s0
));
440 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s1
) : "r"(a
.s1
), "r"(b
.s1
), "r"(c
.s1
));
444 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s2
) : "r"(a
.s2
), "r"(b
.s2
), "r"(c
.s2
));
445 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s3
) : "r"(a
.s3
), "r"(b
.s3
), "r"(c
.s3
));
449 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s4
) : "r"(a
.s4
), "r"(b
.s4
), "r"(c
.s4
));
450 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s5
) : "r"(a
.s5
), "r"(b
.s5
), "r"(c
.s5
));
451 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s6
) : "r"(a
.s6
), "r"(b
.s6
), "r"(c
.s6
));
452 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s7
) : "r"(a
.s7
), "r"(b
.s7
), "r"(c
.s7
));
456 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s8
) : "r"(a
.s8
), "r"(b
.s8
), "r"(c
.s8
));
457 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s9
) : "r"(a
.s9
), "r"(b
.s9
), "r"(c
.s9
));
458 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sa
) : "r"(a
.sa
), "r"(b
.sa
), "r"(c
.sa
));
459 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sb
) : "r"(a
.sb
), "r"(b
.sb
), "r"(c
.sb
));
460 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sc
) : "r"(a
.sc
), "r"(b
.sc
), "r"(c
.sc
));
461 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sd
) : "r"(a
.sd
), "r"(b
.sd
), "r"(c
.sd
));
462 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.se
) : "r"(a
.se
), "r"(b
.se
), "r"(c
.se
));
463 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sf
) : "r"(a
.sf
), "r"(b
.sf
), "r"(c
.sf
));
469 inline u32
__bfe (const u32 a
, const u32 b
, const u32 c
)
473 asm ("bfe.u32 %0, %1, %2, %3;" : "=r"(r
) : "r"(a
), "r"(b
), "r"(c
));
479 inline u32
amd_bytealign (const u32 a
, const u32 b
, const u32 c
)
483 asm ("shf.r.wrap.b32 %0, %1, %2, %3;" : "=r"(r
) : "r"(b
), "r"(a
), "r"((c
& 3) * 8));
488 inline u32
amd_bytealign (const u32 a
, const u32 b
, const u32 c
)
490 return __byte_perm_S (b
, a
, (0x76543210 >> ((c
& 3) * 4)) & 0xffff);
497 inline u32
swap32_S (const u32 v
)
499 return (as_uint (as_uchar4 (v
).s3210
));
502 inline u64
swap64_S (const u64 v
)
504 return (as_ulong (as_uchar8 (v
).s76543210
));
507 inline u32
rotr32_S (const u32 a
, const u32 n
)
509 return rotate (a
, 32 - n
);
512 inline u32
rotl32_S (const u32 a
, const u32 n
)
514 return rotate (a
, n
);
517 inline u64
rotr64_S (const u64 a
, const u32 n
)
519 return rotate (a
, (u64
) 64 - n
);
522 inline u64
rotl64_S (const u64 a
, const u32 n
)
524 return rotate (a
, (u64
) n
);
527 inline u32
amd_bytealign_S (const u32 a
, const u32 b
, const u32 c
)
529 const u64 tmp
= ((((u64
) a
) << 32) | ((u64
) b
)) >> ((c
& 3) * 8);
534 inline u32x
swap32 (const u32x v
)
536 return ((v
>> 24) & 0x000000ff)
537 | ((v
>> 8) & 0x0000ff00)
538 | ((v
<< 8) & 0x00ff0000)
539 | ((v
<< 24) & 0xff000000);
542 inline u64x
swap64 (const u64x v
)
544 return ((v
>> 56) & 0x00000000000000ff)
545 | ((v
>> 40) & 0x000000000000ff00)
546 | ((v
>> 24) & 0x0000000000ff0000)
547 | ((v
>> 8) & 0x00000000ff000000)
548 | ((v
<< 8) & 0x000000ff00000000)
549 | ((v
<< 24) & 0x0000ff0000000000)
550 | ((v
<< 40) & 0x00ff000000000000)
551 | ((v
<< 56) & 0xff00000000000000);
554 inline u32x
rotr32 (const u32x a
, const u32 n
)
556 return rotate (a
, 32 - n
);
559 inline u32x
rotl32 (const u32x a
, const u32 n
)
561 return rotate (a
, n
);
564 inline u64x
rotr64 (const u64x a
, const u32 n
)
566 return rotate (a
, (u64
) 64 - n
);
569 inline u64x
rotl64 (const u64x a
, const u32 n
)
571 return rotate (a
, (u64
) n
);
574 inline u32
__bfe (const u32 a
, const u32 b
, const u32 c
)
576 #define BIT(x) (1 << (x))
577 #define BIT_MASK(x) (BIT (x) - 1)
578 #define BFE(x,y,z) (((x) >> (y)) & BIT_MASK (z))
580 return BFE (a
, b
, c
);
583 inline u32x
amd_bytealign (const u32x a
, const u32x b
, const u32 c
)
586 const u64x tmp
= ((((u64x
) (a
)) << 32) | ((u64x
) (b
))) >> ((c
& 3) * 8);
592 const u64x tmp
= ((((u64x
) (a
.s0
, a
.s1
)) << 32) | ((u64x
) (b
.s0
, b
.s1
))) >> ((c
& 3) * 8);
594 return (u32x
) (tmp
.s0
, tmp
.s1
);
598 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);
600 return (u32x
) (tmp
.s0
, tmp
.s1
, tmp
.s2
, tmp
.s3
);
604 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);
606 return (u32x
) (tmp
.s0
, tmp
.s1
, tmp
.s2
, tmp
.s3
, tmp
.s4
, tmp
.s5
, tmp
.s6
, tmp
.s7
);
610 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);
612 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
);
629 #elif defined _BCRYPT_
631 #elif defined _SHA256_
633 #elif defined _SHA384_
635 #elif defined _SHA512_
637 #elif defined _KECCAK_
639 #elif defined _RIPEMD160_
641 #elif defined _WHIRLPOOL_
645 #elif defined _GOST2012_256_
647 #elif defined _GOST2012_512_
653 #elif defined _MYSQL323_
655 #elif defined _LOTUS5_
657 #elif defined _LOTUS6_
659 #elif defined _SCRYPT_
661 #elif defined _LOTUS8_
663 #elif defined _OFFICE2007_
665 #elif defined _OFFICE2010_
667 #elif defined _OFFICE2013_
669 #elif defined _OLDOFFICE01_
671 #elif defined _OLDOFFICE34_
673 #elif defined _SIPHASH_
675 #elif defined _PBKDF2_MD5_
677 #elif defined _PBKDF2_SHA1_
679 #elif defined _PBKDF2_SHA256_
681 #elif defined _PBKDF2_SHA512_
683 #elif defined _PDF17L8_
685 #elif defined _CRC32_
687 #elif defined _SEVEN_ZIP_
689 #elif defined _ANDROIDFDE_
695 #elif defined _MD5_SHA1_
697 #elif defined _SHA1_MD5_
699 #elif defined _NETNTLMV2_
701 #elif defined _KRB5PA_
703 #elif defined _CLOUDKEY_
705 #elif defined _SCRYPT_
707 #elif defined _PSAFE2_
709 #elif defined _LOTUS8_
713 #elif defined _SHA256_SHA1_
715 #elif defined _MS_DRSR_
717 #elif defined _ANDROIDFDE_SAMSUNG_
721 #elif defined _KRB5TGS_
723 #elif defined _AXCRYPT_
725 #elif defined _KEEPASS_
792 u32 cry_master_buf
[64];
794 u32 public_key_buf
[64];
835 u32 userdomain_buf
[64];
852 u32 account_info
[512];
907 u32 encryptedVerifier
[4];
908 u32 encryptedVerifierHash
[5];
916 u32 encryptedVerifier
[4];
917 u32 encryptedVerifierHash
[8];
923 u32 encryptedVerifier
[4];
924 u32 encryptedVerifierHash
[8];
931 u32 encryptedVerifier
[4];
932 u32 encryptedVerifierHash
[4];
940 u32 encryptedVerifier
[4];
941 u32 encryptedVerifierHash
[5];
961 /* key-file handling */
965 u32 final_random_seed
[8];
966 u32 transf_random_seed
[8];
968 u32 contents_hash
[8];
970 /* specific to version 1 */
974 /* specific to version 2 */
975 u32 expected_bytes
[8];
1018 } sha256crypt_tmp_t
;
1022 u64 l_alt_result
[8];
1027 } sha512crypt_tmp_t
;
1043 } bitcoin_wallet_tmp_t
;
1141 } pbkdf2_sha1_tmp_t
;
1151 } pbkdf2_sha256_tmp_t
;
1161 } pbkdf2_sha512_tmp_t
;
1379 u32 alignment_placeholder_1
;
1380 u32 alignment_placeholder_2
;
1381 u32 alignment_placeholder_3
;