2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * magnum <john.magnum@hushmail.com>
18 #define CONCAT(a, b) a##b
19 #define VTYPE(type, width) CONCAT(type, width)
27 typedef VTYPE(uchar
, VECT_SIZE
) u8x
;
28 typedef VTYPE(ushort
, VECT_SIZE
) u16x
;
29 typedef VTYPE(uint
, VECT_SIZE
) u32x
;
30 typedef VTYPE(ulong
, VECT_SIZE
) u64x
;
33 inline u32
l32_from_64_S (u64 a
)
35 const u32 r
= (u32
) (a
);
40 inline u32
h32_from_64_S (u64 a
)
44 const u32 r
= (u32
) (a
);
49 inline u64
hl32_to_64_S (const u32 a
, const u32 b
)
51 return as_ulong ((uint2
) (b
, a
));
54 inline u32x
l32_from_64 (u64x a
)
93 inline u32x
h32_from_64 (u64x a
)
134 inline u64x
hl32_to_64 (const u32x a
, const u32x b
)
139 r
= as_ulong ((uint2
) (b
, a
));
143 r
.s0
= as_ulong ((uint2
) (b
.s0
, a
.s0
));
144 r
.s1
= as_ulong ((uint2
) (b
.s1
, a
.s1
));
148 r
.s2
= as_ulong ((uint2
) (b
.s2
, a
.s2
));
149 r
.s3
= as_ulong ((uint2
) (b
.s3
, a
.s3
));
153 r
.s4
= as_ulong ((uint2
) (b
.s4
, a
.s4
));
154 r
.s5
= as_ulong ((uint2
) (b
.s5
, a
.s5
));
155 r
.s6
= as_ulong ((uint2
) (b
.s6
, a
.s6
));
156 r
.s7
= as_ulong ((uint2
) (b
.s7
, a
.s7
));
160 r
.s8
= as_ulong ((uint2
) (b
.s8
, a
.s8
));
161 r
.s9
= as_ulong ((uint2
) (b
.s9
, a
.s9
));
162 r
.sa
= as_ulong ((uint2
) (b
.sa
, a
.sa
));
163 r
.sb
= as_ulong ((uint2
) (b
.sb
, a
.sb
));
164 r
.sc
= as_ulong ((uint2
) (b
.sc
, a
.sc
));
165 r
.sd
= as_ulong ((uint2
) (b
.sd
, a
.sd
));
166 r
.se
= as_ulong ((uint2
) (b
.se
, a
.se
));
167 r
.sf
= as_ulong ((uint2
) (b
.sf
, a
.sf
));
174 inline u32
swap32_S (const u32 v
)
176 return (as_uint (as_uchar4 (v
).s3210
));
179 inline u64
swap64_S (const u64 v
)
181 return (as_ulong (as_uchar8 (v
).s76543210
));
184 inline u32
rotr32_S (const u32 a
, const u32 n
)
186 return rotate (a
, 32 - n
);
189 inline u32
rotl32_S (const u32 a
, const u32 n
)
191 return rotate (a
, n
);
194 inline u64
rotr64_S (const u64 a
, const u32 n
)
196 const u32 a0
= h32_from_64_S (a
);
197 const u32 a1
= l32_from_64_S (a
);
199 const u32 t0
= (n
>= 32) ? amd_bitalign (a0
, a1
, n
- 32) : amd_bitalign (a1
, a0
, n
);
200 const u32 t1
= (n
>= 32) ? amd_bitalign (a1
, a0
, n
- 32) : amd_bitalign (a0
, a1
, n
);
202 const u64 r
= hl32_to_64_S (t0
, t1
);
207 inline u64
rotl64_S (const u64 a
, const u32 n
)
209 return rotr64_S (a
, 64 - n
);
212 inline u32x
swap32 (const u32x v
)
214 return ((v
>> 24) & 0x000000ff)
215 | ((v
>> 8) & 0x0000ff00)
216 | ((v
<< 8) & 0x00ff0000)
217 | ((v
<< 24) & 0xff000000);
220 inline u64x
swap64 (const u64x v
)
222 return ((v
>> 56) & 0x00000000000000ff)
223 | ((v
>> 40) & 0x000000000000ff00)
224 | ((v
>> 24) & 0x0000000000ff0000)
225 | ((v
>> 8) & 0x00000000ff000000)
226 | ((v
<< 8) & 0x000000ff00000000)
227 | ((v
<< 24) & 0x0000ff0000000000)
228 | ((v
<< 40) & 0x00ff000000000000)
229 | ((v
<< 56) & 0xff00000000000000);
232 inline u32x
rotr32 (const u32x a
, const u32 n
)
234 return rotate (a
, 32 - n
);
237 inline u32x
rotl32 (const u32x a
, const u32 n
)
239 return rotate (a
, n
);
242 inline u64x
rotr64 (const u64x a
, const u32 n
)
244 const u32x a0
= h32_from_64 (a
);
245 const u32x a1
= l32_from_64 (a
);
247 const u32x t0
= (n
>= 32) ? amd_bitalign (a0
, a1
, n
- 32) : amd_bitalign (a1
, a0
, n
);
248 const u32x t1
= (n
>= 32) ? amd_bitalign (a1
, a0
, n
- 32) : amd_bitalign (a0
, a1
, n
);
250 const u64x r
= hl32_to_64 (t0
, t1
);
255 inline u64x
rotl64 (const u64x a
, const u32 n
)
257 return rotr64 (a
, 64 - n
);
260 inline u32
__bfe (const u32 a
, const u32 b
, const u32 c
)
262 return amd_bfe (a
, b
, c
);
265 inline u32
amd_bytealign_S (const u32 a
, const u32 b
, const u32 c
)
267 return amd_bytealign (a
, b
, c
);
272 inline u32
swap32_S (const u32 v
)
276 asm ("prmt.b32 %0, %1, 0, 0x0123;" : "=r"(r
) : "r"(v
));
281 inline u64
swap64_S (const u64 v
)
286 asm ("mov.b64 {%0, %1}, %2;" : "=r"(il
), "=r"(ir
) : "l"(v
));
291 asm ("prmt.b32 %0, %1, 0, 0x0123;" : "=r"(tl
) : "r"(il
));
292 asm ("prmt.b32 %0, %1, 0, 0x0123;" : "=r"(tr
) : "r"(ir
));
296 asm ("mov.b64 %0, {%1, %2};" : "=l"(r
) : "r"(tr
), "r"(tl
));
301 inline u32
rotr32_S (const u32 a
, const u32 n
)
303 return rotate (a
, 32 - n
);
306 inline u32
rotl32_S (const u32 a
, const u32 n
)
308 return rotate (a
, n
);
311 inline u64
rotr64_S (const u64 a
, const u32 n
)
313 return rotate (a
, (u64
) 64 - n
);
316 inline u64
rotl64_S (const u64 a
, const u32 n
)
318 return rotr64_S (a
, 64 - n
);
321 inline u32
__byte_perm_S (const u32 a
, const u32 b
, const u32 c
)
325 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
) : "r"(a
), "r"(b
), "r"(c
));
330 inline u32x
swap32 (const u32x v
)
332 return ((v
>> 24) & 0x000000ff)
333 | ((v
>> 8) & 0x0000ff00)
334 | ((v
<< 8) & 0x00ff0000)
335 | ((v
<< 24) & 0xff000000);
338 inline u64x
swap64 (const u64x v
)
340 return ((v
>> 56) & 0x00000000000000ff)
341 | ((v
>> 40) & 0x000000000000ff00)
342 | ((v
>> 24) & 0x0000000000ff0000)
343 | ((v
>> 8) & 0x00000000ff000000)
344 | ((v
<< 8) & 0x000000ff00000000)
345 | ((v
<< 24) & 0x0000ff0000000000)
346 | ((v
<< 40) & 0x00ff000000000000)
347 | ((v
<< 56) & 0xff00000000000000);
350 inline u32x
rotr32 (const u32x a
, const u32 n
)
352 return rotate (a
, 32 - n
);
355 inline u32x
rotl32 (const u32x a
, const u32 n
)
357 return rotate (a
, n
);
360 inline u64x
rotr64 (const u64x a
, const u32 n
)
362 return rotate (a
, (u64
) 64 - n
);
365 inline u64x
rotl64 (const u64x a
, const u32 n
)
367 return rotate (a
, (u64
) n
);
370 inline u32x
__byte_perm (const u32x a
, const u32x b
, const u32x c
)
375 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
) : "r"(a
), "r"(b
), "r"(c
) );
379 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s0
) : "r"(a
.s0
), "r"(b
.s0
), "r"(c
.s0
));
380 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s1
) : "r"(a
.s1
), "r"(b
.s1
), "r"(c
.s1
));
384 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s2
) : "r"(a
.s2
), "r"(b
.s2
), "r"(c
.s2
));
385 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s3
) : "r"(a
.s3
), "r"(b
.s3
), "r"(c
.s3
));
389 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s4
) : "r"(a
.s4
), "r"(b
.s4
), "r"(c
.s4
));
390 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s5
) : "r"(a
.s5
), "r"(b
.s5
), "r"(c
.s5
));
391 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s6
) : "r"(a
.s6
), "r"(b
.s6
), "r"(c
.s6
));
392 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s7
) : "r"(a
.s7
), "r"(b
.s7
), "r"(c
.s7
));
396 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s8
) : "r"(a
.s8
), "r"(b
.s8
), "r"(c
.s8
));
397 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.s9
) : "r"(a
.s9
), "r"(b
.s9
), "r"(c
.s9
));
398 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sa
) : "r"(a
.sa
), "r"(b
.sa
), "r"(c
.sa
));
399 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sb
) : "r"(a
.sb
), "r"(b
.sb
), "r"(c
.sb
));
400 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sc
) : "r"(a
.sc
), "r"(b
.sc
), "r"(c
.sc
));
401 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sd
) : "r"(a
.sd
), "r"(b
.sd
), "r"(c
.sd
));
402 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.se
) : "r"(a
.se
), "r"(b
.se
), "r"(c
.se
));
403 asm ("prmt.b32 %0, %1, %2, %3;" : "=r"(r
.sf
) : "r"(a
.sf
), "r"(b
.sf
), "r"(c
.sf
));
409 inline u32
__bfe (const u32 a
, const u32 b
, const u32 c
)
413 asm ("bfe.u32 %0, %1, %2, %3;" : "=r"(r
) : "r"(a
), "r"(b
), "r"(c
));
418 inline u32
amd_bytealign (const u32 a
, const u32 b
, const u32 c
)
424 asm ("shf.r.wrap.b32 %0, %1, %2, %3;" : "=r"(r
) : "r"(b
), "r"(a
), "r"((c
& 3) * 8));
428 r
= __byte_perm_S (b
, a
, (0x76543210 >> ((c
& 3) * 4)) & 0xffff);
437 inline u32
swap32_S (const u32 v
)
439 return (as_uint (as_uchar4 (v
).s3210
));
442 inline u64
swap64_S (const u64 v
)
444 return (as_ulong (as_uchar8 (v
).s76543210
));
447 inline u32
rotr32_S (const u32 a
, const u32 n
)
449 return rotate (a
, 32 - n
);
452 inline u32
rotl32_S (const u32 a
, const u32 n
)
454 return rotate (a
, n
);
457 inline u64
rotr64_S (const u64 a
, const u32 n
)
459 return rotate (a
, (u64
) 64 - n
);
462 inline u64
rotl64_S (const u64 a
, const u32 n
)
464 return rotate (a
, (u64
) n
);
467 inline u32
amd_bytealign_S (const u32 a
, const u32 b
, const u32 c
)
469 const u64 tmp
= ((((u64
) a
) << 32) | ((u64
) b
)) >> ((c
& 3) * 8);
474 inline u32x
swap32 (const u32x v
)
476 return ((v
>> 24) & 0x000000ff)
477 | ((v
>> 8) & 0x0000ff00)
478 | ((v
<< 8) & 0x00ff0000)
479 | ((v
<< 24) & 0xff000000);
482 inline u64x
swap64 (const u64x v
)
484 return ((v
>> 56) & 0x00000000000000ff)
485 | ((v
>> 40) & 0x000000000000ff00)
486 | ((v
>> 24) & 0x0000000000ff0000)
487 | ((v
>> 8) & 0x00000000ff000000)
488 | ((v
<< 8) & 0x000000ff00000000)
489 | ((v
<< 24) & 0x0000ff0000000000)
490 | ((v
<< 40) & 0x00ff000000000000)
491 | ((v
<< 56) & 0xff00000000000000);
494 inline u32x
rotr32 (const u32x a
, const u32 n
)
496 return rotate (a
, 32 - n
);
499 inline u32x
rotl32 (const u32x a
, const u32 n
)
501 return rotate (a
, n
);
504 inline u64x
rotr64 (const u64x a
, const u32 n
)
506 return rotate (a
, (u64
) 64 - n
);
509 inline u64x
rotl64 (const u64x a
, const u32 n
)
511 return rotate (a
, (u64
) n
);
514 inline u32
__bfe (const u32 a
, const u32 b
, const u32 c
)
516 #define BIT(x) (1 << (x))
517 #define BIT_MASK(x) (BIT (x) - 1)
518 #define BFE(x,y,z) (((x) >> (y)) & BIT_MASK (z))
520 return BFE (a
, b
, c
);
523 inline u32x
amd_bytealign (const u32x a
, const u32x b
, const u32 c
)
526 const u64x tmp
= ((((u64x
) (a
)) << 32) | ((u64x
) (b
))) >> ((c
& 3) * 8);
532 const u64x tmp
= ((((u64x
) (a
.s0
, a
.s1
)) << 32) | ((u64x
) (b
.s0
, b
.s1
))) >> ((c
& 3) * 8);
534 return (u32x
) (tmp
.s0
, tmp
.s1
);
538 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);
540 return (u32x
) (tmp
.s0
, tmp
.s1
, tmp
.s2
, tmp
.s3
);
544 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);
546 return (u32x
) (tmp
.s0
, tmp
.s1
, tmp
.s2
, tmp
.s3
, tmp
.s4
, tmp
.s5
, tmp
.s6
, tmp
.s7
);
550 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);
552 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
);
569 #elif defined _BCRYPT_
571 #elif defined _SHA256_
573 #elif defined _SHA384_
575 #elif defined _SHA512_
577 #elif defined _KECCAK_
579 #elif defined _RIPEMD160_
581 #elif defined _WHIRLPOOL_
585 #elif defined _GOST2012_256_
587 #elif defined _GOST2012_512_
593 #elif defined _MYSQL323_
595 #elif defined _LOTUS5_
597 #elif defined _LOTUS6_
599 #elif defined _SCRYPT_
601 #elif defined _LOTUS8_
603 #elif defined _OFFICE2007_
605 #elif defined _OFFICE2010_
607 #elif defined _OFFICE2013_
609 #elif defined _OLDOFFICE01_
611 #elif defined _OLDOFFICE34_
613 #elif defined _SIPHASH_
615 #elif defined _PBKDF2_MD5_
617 #elif defined _PBKDF2_SHA1_
619 #elif defined _PBKDF2_SHA256_
621 #elif defined _PBKDF2_SHA512_
623 #elif defined _PDF17L8_
625 #elif defined _CRC32_
627 #elif defined _SEVEN_ZIP_
629 #elif defined _ANDROIDFDE_
635 #elif defined _MD5_SHA1_
637 #elif defined _SHA1_MD5_
639 #elif defined _NETNTLMV2_
641 #elif defined _KRB5PA_
643 #elif defined _CLOUDKEY_
645 #elif defined _SCRYPT_
647 #elif defined _PSAFE2_
649 #elif defined _LOTUS8_
653 #elif defined _SHA256_SHA1_
655 #elif defined _MS_DRSR_
657 #elif defined _ANDROIDFDE_SAMSUNG_
661 #elif defined _KRB5TGS_
663 #elif defined _AXCRYPT_
665 #elif defined _KEEPASS_
732 u32 cry_master_buf
[64];
734 u32 public_key_buf
[64];
775 u32 userdomain_buf
[64];
792 u32 account_info
[512];
847 u32 encryptedVerifier
[4];
848 u32 encryptedVerifierHash
[5];
856 u32 encryptedVerifier
[4];
857 u32 encryptedVerifierHash
[8];
863 u32 encryptedVerifier
[4];
864 u32 encryptedVerifierHash
[8];
871 u32 encryptedVerifier
[4];
872 u32 encryptedVerifierHash
[4];
880 u32 encryptedVerifier
[4];
881 u32 encryptedVerifierHash
[5];
901 /* key-file handling */
905 u32 final_random_seed
[8];
906 u32 transf_random_seed
[8];
908 u32 contents_hash
[8];
910 /* specific to version 1 */
914 /* specific to version 2 */
915 u32 expected_bytes
[8];
983 } bitcoin_wallet_tmp_t
;
1081 } pbkdf2_sha1_tmp_t
;
1091 } pbkdf2_sha256_tmp_t
;
1101 } pbkdf2_sha512_tmp_t
;
1319 u32 alignment_placeholder_1
;
1320 u32 alignment_placeholder_2
;
1321 u32 alignment_placeholder_3
;