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
)
363 "shl.b32 %4, %2, %6;\n"
364 "shl.b32 %5, %3, %6;\n"
365 "shr.b32 %0, %2, %7;\n"
366 "shr.b32 %1, %3, %7;\n"
367 "add.u32 %0, %0, %4;\n"
368 "add.u32 %1, %1, %5;\n"
381 "shl.b32 %8, %4, %12;\n"
382 "shl.b32 %9, %5, %12;\n"
383 "shl.b32 %10, %6, %12;\n"
384 "shl.b32 %11, %7, %12;\n"
385 "shr.b32 %0, %4, %13;\n"
386 "shr.b32 %1, %5, %13;\n"
387 "shr.b32 %2, %6, %13;\n"
388 "shr.b32 %3, %7, %13;\n"
389 "add.u32 %0, %0, %8;\n"
390 "add.u32 %1, %1, %9;\n"
391 "add.u32 %2, %2, %10;\n"
392 "add.u32 %3, %3, %11;\n"
418 return rotate (a
, n
);
423 inline u32x
rotl32 (const u32x a
, const u32 n
)
425 return rotr32 (a
, 32 - n
);
428 inline u64x
rotr64 (const u64x a
, const u32 n
)
430 return rotate (a
, (u64
) 64 - n
);
433 inline u64x
rotl64 (const u64x a
, const u32 n
)
435 return rotate (a
, (u64
) n
);
438 inline u32x
__byte_perm (const u32x a
, const u32x b
, const u32x c
)
443 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
) : "r"(a
), "r"(b
), "r"(c
) );
447 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s0
) : "r"(a
.s0
), "r"(b
.s0
), "r"(c
.s0
));
448 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s1
) : "r"(a
.s1
), "r"(b
.s1
), "r"(c
.s1
));
452 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s2
) : "r"(a
.s2
), "r"(b
.s2
), "r"(c
.s2
));
453 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s3
) : "r"(a
.s3
), "r"(b
.s3
), "r"(c
.s3
));
457 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s4
) : "r"(a
.s4
), "r"(b
.s4
), "r"(c
.s4
));
458 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s5
) : "r"(a
.s5
), "r"(b
.s5
), "r"(c
.s5
));
459 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s6
) : "r"(a
.s6
), "r"(b
.s6
), "r"(c
.s6
));
460 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s7
) : "r"(a
.s7
), "r"(b
.s7
), "r"(c
.s7
));
464 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s8
) : "r"(a
.s8
), "r"(b
.s8
), "r"(c
.s8
));
465 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s9
) : "r"(a
.s9
), "r"(b
.s9
), "r"(c
.s9
));
466 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sa
) : "r"(a
.sa
), "r"(b
.sa
), "r"(c
.sa
));
467 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sb
) : "r"(a
.sb
), "r"(b
.sb
), "r"(c
.sb
));
468 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sc
) : "r"(a
.sc
), "r"(b
.sc
), "r"(c
.sc
));
469 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sd
) : "r"(a
.sd
), "r"(b
.sd
), "r"(c
.sd
));
470 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.se
) : "r"(a
.se
), "r"(b
.se
), "r"(c
.se
));
471 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sf
) : "r"(a
.sf
), "r"(b
.sf
), "r"(c
.sf
));
477 inline u32
__bfe (const u32 a
, const u32 b
, const u32 c
)
481 asm ("bfe.u32 %0, %1, %2, %3;" : "=r"(r
) : "r"(a
), "r"(b
), "r"(c
));
487 inline u32
amd_bytealign (const u32 a
, const u32 b
, const u32 c
)
491 asm ("shf.r.wrap.b32 %0, %1, %2, %3;" : "=r"(r
) : "r"(b
), "r"(a
), "r"((c
& 3) * 8));
496 inline u32
amd_bytealign (const u32 a
, const u32 b
, const u32 c
)
498 return __byte_perm_S (b
, a
, (0x76543210 >> ((c
& 3) * 4)) & 0xffff);
505 inline u32
swap32_S (const u32 v
)
507 return (as_uint (as_uchar4 (v
).s3210
));
510 inline u64
swap64_S (const u64 v
)
512 return (as_ulong (as_uchar8 (v
).s76543210
));
515 inline u32
rotr32_S (const u32 a
, const u32 n
)
517 return rotate (a
, 32 - n
);
520 inline u32
rotl32_S (const u32 a
, const u32 n
)
522 return rotate (a
, n
);
525 inline u64
rotr64_S (const u64 a
, const u32 n
)
527 return rotate (a
, (u64
) 64 - n
);
530 inline u64
rotl64_S (const u64 a
, const u32 n
)
532 return rotate (a
, (u64
) n
);
535 inline u32
amd_bytealign_S (const u32 a
, const u32 b
, const u32 c
)
537 const u64 tmp
= ((((u64
) a
) << 32) | ((u64
) b
)) >> ((c
& 3) * 8);
542 inline u32x
swap32 (const u32x v
)
544 return ((v
>> 24) & 0x000000ff)
545 | ((v
>> 8) & 0x0000ff00)
546 | ((v
<< 8) & 0x00ff0000)
547 | ((v
<< 24) & 0xff000000);
550 inline u64x
swap64 (const u64x v
)
552 return ((v
>> 56) & 0x00000000000000ff)
553 | ((v
>> 40) & 0x000000000000ff00)
554 | ((v
>> 24) & 0x0000000000ff0000)
555 | ((v
>> 8) & 0x00000000ff000000)
556 | ((v
<< 8) & 0x000000ff00000000)
557 | ((v
<< 24) & 0x0000ff0000000000)
558 | ((v
<< 40) & 0x00ff000000000000)
559 | ((v
<< 56) & 0xff00000000000000);
562 inline u32x
rotr32 (const u32x a
, const u32 n
)
564 return rotate (a
, 32 - n
);
567 inline u32x
rotl32 (const u32x a
, const u32 n
)
569 return rotate (a
, n
);
572 inline u64x
rotr64 (const u64x a
, const u32 n
)
574 return rotate (a
, (u64
) 64 - n
);
577 inline u64x
rotl64 (const u64x a
, const u32 n
)
579 return rotate (a
, (u64
) n
);
582 inline u32
__bfe (const u32 a
, const u32 b
, const u32 c
)
584 #define BIT(x) (1 << (x))
585 #define BIT_MASK(x) (BIT (x) - 1)
586 #define BFE(x,y,z) (((x) >> (y)) & BIT_MASK (z))
588 return BFE (a
, b
, c
);
591 inline u32x
amd_bytealign (const u32x a
, const u32x b
, const u32 c
)
594 const u64x tmp
= ((((u64x
) (a
)) << 32) | ((u64x
) (b
))) >> ((c
& 3) * 8);
600 const u64x tmp
= ((((u64x
) (a
.s0
, a
.s1
)) << 32) | ((u64x
) (b
.s0
, b
.s1
))) >> ((c
& 3) * 8);
602 return (u32x
) (tmp
.s0
, tmp
.s1
);
606 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);
608 return (u32x
) (tmp
.s0
, tmp
.s1
, tmp
.s2
, tmp
.s3
);
612 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);
614 return (u32x
) (tmp
.s0
, tmp
.s1
, tmp
.s2
, tmp
.s3
, tmp
.s4
, tmp
.s5
, tmp
.s6
, tmp
.s7
);
618 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);
620 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
);
637 #elif defined _BCRYPT_
639 #elif defined _SHA256_
641 #elif defined _SHA384_
643 #elif defined _SHA512_
645 #elif defined _KECCAK_
647 #elif defined _RIPEMD160_
649 #elif defined _WHIRLPOOL_
653 #elif defined _GOST2012_256_
655 #elif defined _GOST2012_512_
661 #elif defined _MYSQL323_
663 #elif defined _LOTUS5_
665 #elif defined _LOTUS6_
667 #elif defined _SCRYPT_
669 #elif defined _LOTUS8_
671 #elif defined _OFFICE2007_
673 #elif defined _OFFICE2010_
675 #elif defined _OFFICE2013_
677 #elif defined _OLDOFFICE01_
679 #elif defined _OLDOFFICE34_
681 #elif defined _SIPHASH_
683 #elif defined _PBKDF2_MD5_
685 #elif defined _PBKDF2_SHA1_
687 #elif defined _PBKDF2_SHA256_
689 #elif defined _PBKDF2_SHA512_
691 #elif defined _PDF17L8_
693 #elif defined _CRC32_
695 #elif defined _SEVEN_ZIP_
697 #elif defined _ANDROIDFDE_
703 #elif defined _MD5_SHA1_
705 #elif defined _SHA1_MD5_
707 #elif defined _NETNTLMV2_
709 #elif defined _KRB5PA_
711 #elif defined _CLOUDKEY_
713 #elif defined _SCRYPT_
715 #elif defined _PSAFE2_
717 #elif defined _LOTUS8_
721 #elif defined _SHA256_SHA1_
723 #elif defined _MS_DRSR_
725 #elif defined _ANDROIDFDE_SAMSUNG_
729 #elif defined _KRB5TGS_
731 #elif defined _AXCRYPT_
733 #elif defined _KEEPASS_
800 u32 cry_master_buf
[64];
802 u32 public_key_buf
[64];
843 u32 userdomain_buf
[64];
860 u32 account_info
[512];
915 u32 encryptedVerifier
[4];
916 u32 encryptedVerifierHash
[5];
924 u32 encryptedVerifier
[4];
925 u32 encryptedVerifierHash
[8];
931 u32 encryptedVerifier
[4];
932 u32 encryptedVerifierHash
[8];
939 u32 encryptedVerifier
[4];
940 u32 encryptedVerifierHash
[4];
948 u32 encryptedVerifier
[4];
949 u32 encryptedVerifierHash
[5];
969 /* key-file handling */
973 u32 final_random_seed
[8];
974 u32 transf_random_seed
[8];
976 u32 contents_hash
[8];
978 /* specific to version 1 */
982 /* specific to version 2 */
983 u32 expected_bytes
[8];
1026 } sha256crypt_tmp_t
;
1030 u64 l_alt_result
[8];
1035 } sha512crypt_tmp_t
;
1051 } bitcoin_wallet_tmp_t
;
1149 } pbkdf2_sha1_tmp_t
;
1159 } pbkdf2_sha256_tmp_t
;
1169 } pbkdf2_sha512_tmp_t
;
1387 u32 alignment_placeholder_1
;
1388 u32 alignment_placeholder_2
;
1389 u32 alignment_placeholder_3
;