Initial commit
[hashcat.git] / amd / types_amd.c
1 /**
2 * Author......: Jens Steube <jens.steube@gmail.com>
3 * License.....: MIT
4 */
5
6 typedef uchar u8;
7 typedef ushort u16;
8 typedef uint u32;
9 typedef ulong u64;
10
11 #ifdef VECT_SIZE1
12 #define VECT_SHIFT 0
13 #define VECT_DIV 1
14 typedef uchar u8x;
15 typedef uint u32x;
16 typedef ulong u64x;
17 #endif
18
19 #ifdef VECT_SIZE2
20 #define VECT_SHIFT 1
21 #define VECT_DIV 2
22 typedef uchar2 u8x;
23 typedef uint2 u32x;
24 typedef ulong2 u64x;
25
26 #define u8x(a,b) (u8x) (a,b)
27 #define u16x(a,b) (u16x) (a,b)
28 #define u32x(a,b) (u32x) (a,b)
29 #define u64x(a,b) (u64x) (a,b)
30 #endif
31
32 #ifdef VECT_SIZE4
33 #define VECT_SHIFT 2
34 #define VECT_DIV 4
35 typedef uchar4 u8x;
36 typedef uint4 u32x;
37 typedef ulong4 u64x;
38
39 #define u8x(a,b,c,d) (u8x) (a,b,c,d)
40 #define u16x(a,b,c,d) (u16x) (a,b,c,d)
41 #define u32x(a,b,c,d) (u32x) (a,b,c,d)
42 #define u64x(a,b,c,d) (u64x) (a,b,c,d)
43 #endif
44
45 static inline bool allx (const u32 r)
46 {
47 return r;
48 }
49
50 static inline u32 rotr32 (const u32 a, const u32 n)
51 {
52 return amd_bitalign (a, a, n);
53 }
54
55 static inline u32 rotl32 (const u32 a, const u32 n)
56 {
57 return rotate (a, n);
58 }
59
60 static inline u32 l32_from_64 (u64 a)
61 {
62 const u32 r = (uint) (a);
63
64 return r;
65 }
66
67 static inline u32 h32_from_64 (u64 a)
68 {
69 a >>= 32;
70
71 const u32 r = (uint) (a);
72
73 return r;
74 }
75
76 static inline u64 hl32_to_64 (const u32 a, const u32 b)
77 {
78 return as_ulong ((uint2) (b, a));
79 }
80
81 static inline u64 rotr64 (const u64 a, const u32 n)
82 {
83 uint2 a2 = as_uint2 (a);
84
85 uint2 t;
86
87 t.s0 = (n >= 32) ? amd_bitalign (a2.s0, a2.s1, n - 32)
88 : amd_bitalign (a2.s1, a2.s0, n);
89 t.s1 = (n >= 32) ? amd_bitalign (a2.s1, a2.s0, n - 32)
90 : amd_bitalign (a2.s0, a2.s1, n);
91
92 return as_ulong (t);
93 }
94
95 static inline u64 rotl64 (const u64 a, const u32 n)
96 {
97 return rotr64 (a, 64 - n);
98 }
99
100 #ifdef VECT_SIZE2
101 static inline bool allx (const int2 r)
102 {
103 return all (r);
104 }
105
106 static inline u32x rotl32 (const u32x a, const u32 n)
107 {
108 return (u32x) (rotl32 (a.s0, n),
109 rotl32 (a.s1, n));
110 }
111
112 static inline u32x rotr32 (const u32x a, const u32 n)
113 {
114 return (u32x) (rotr32 (a.s0, n),
115 rotr32 (a.s1, n));
116 }
117
118 static inline u64x rotl64 (const u64x a, const u32 n)
119 {
120 return (u64x) (rotl64 (a.s0, n),
121 rotl64 (a.s1, n));
122 }
123
124 static inline u64x rotr64 (const u64x a, const u32 n)
125 {
126 return (u64x) (rotr64 (a.s0, n),
127 rotr64 (a.s1, n));
128 }
129
130 static inline u32x l32_from_64 (const u64x a)
131 {
132 return (u32x) (l32_from_64 (a.s0),
133 l32_from_64 (a.s1));
134 }
135
136 static inline u32x h32_from_64 (const u64x a)
137 {
138 return (u32x) (h32_from_64 (a.s0),
139 h32_from_64 (a.s1));
140 }
141
142 static inline u64x hl32_to_64 (const u32x a, const u32x b)
143 {
144 return (u64x) (hl32_to_64 (a.s0, b.s0),
145 hl32_to_64 (a.s1, b.s1));
146 }
147
148
149 #endif
150
151 #ifdef VECT_SIZE4
152 static inline bool allx (const int4 r)
153 {
154 return all (r);
155 }
156
157 static inline u32x rotl32 (const u32x a, const u32 n)
158 {
159 return (u32x) (rotl32 (a.s0, n),
160 rotl32 (a.s1, n),
161 rotl32 (a.s2, n),
162 rotl32 (a.s3, n));
163 }
164
165 static inline u32x rotr32 (const u32x a, const u32 n)
166 {
167 return (u32x) (rotr32 (a.s0, n),
168 rotr32 (a.s1, n),
169 rotr32 (a.s2, n),
170 rotr32 (a.s3, n));
171 }
172
173 static inline u64x rotl64 (const u64x a, const u32 n)
174 {
175 return (u64x) (rotl64 (a.s0, n),
176 rotl64 (a.s1, n),
177 rotl64 (a.s2, n),
178 rotl64 (a.s3, n));
179 }
180
181 static inline u64x rotr64 (const u64x a, const u32 n)
182 {
183 return (u64x) (rotr64 (a.s0, n),
184 rotr64 (a.s1, n),
185 rotr64 (a.s2, n),
186 rotr64 (a.s3, n));
187 }
188
189 static inline u32x l32_from_64 (const u64x a)
190 {
191 return (u32x) (l32_from_64 (a.s0),
192 l32_from_64 (a.s1),
193 l32_from_64 (a.s2),
194 l32_from_64 (a.s3));
195 }
196
197 static inline u32x h32_from_64 (const u64x a)
198 {
199 return (u32x) (h32_from_64 (a.s0),
200 h32_from_64 (a.s1),
201 h32_from_64 (a.s2),
202 h32_from_64 (a.s3));
203 }
204
205 static inline u64x hl32_to_64 (const u32x a, const u32x b)
206 {
207 return (u64x) (hl32_to_64 (a.s0, b.s0),
208 hl32_to_64 (a.s1, b.s1),
209 hl32_to_64 (a.s2, b.s2),
210 hl32_to_64 (a.s3, b.s3));
211 }
212 #endif
213
214 typedef struct
215 {
216 #if defined _DES_
217 u32 digest_buf[4];
218 #elif defined _MD4_
219 u32 digest_buf[4];
220 #elif defined _MD5_
221 u32 digest_buf[4];
222 #elif defined _MD5H_
223 u32 digest_buf[4];
224 #elif defined _SHA1_
225 u32 digest_buf[5];
226 #elif defined _BCRYPT_
227 u32 digest_buf[6];
228 #elif defined _SHA256_
229 u32 digest_buf[8];
230 #elif defined _SHA384_
231 u32 digest_buf[16];
232 #elif defined _SHA512_
233 u32 digest_buf[16];
234 #elif defined _KECCAK_
235 u32 digest_buf[50];
236 #elif defined _RIPEMD160_
237 u32 digest_buf[5];
238 #elif defined _WHIRLPOOL_
239 u32 digest_buf[16];
240 #elif defined _GOST_
241 u32 digest_buf[8];
242 #elif defined _GOST2012_256_
243 u32 digest_buf[8];
244 #elif defined _GOST2012_512_
245 u32 digest_buf[16];
246 #elif defined _SAPB_
247 u32 digest_buf[4];
248 #elif defined _SAPG_
249 u32 digest_buf[5];
250 #elif defined _MYSQL323_
251 u32 digest_buf[4];
252 #elif defined _LOTUS5_
253 u32 digest_buf[4];
254 #elif defined _LOTUS6_
255 u32 digest_buf[4];
256 #elif defined _SCRYPT_
257 u32 digest_buf[8];
258 #elif defined _LOTUS8_
259 u32 digest_buf[4];
260 #elif defined _OFFICE2007_
261 u32 digest_buf[4];
262 #elif defined _OFFICE2010_
263 u32 digest_buf[4];
264 #elif defined _OFFICE2013_
265 u32 digest_buf[4];
266 #elif defined _OLDOFFICE01_
267 u32 digest_buf[4];
268 #elif defined _OLDOFFICE34_
269 u32 digest_buf[4];
270 #elif defined _SIPHASH_
271 u32 digest_buf[4];
272 #elif defined _PBKDF2_MD5_
273 u32 digest_buf[32];
274 #elif defined _PBKDF2_SHA1_
275 u32 digest_buf[32];
276 #elif defined _PBKDF2_SHA256_
277 u32 digest_buf[32];
278 #elif defined _PBKDF2_SHA512_
279 u32 digest_buf[32];
280 #elif defined _PDF17L8_
281 u32 digest_buf[8];
282 #elif defined _CRC32_
283 u32 digest_buf[4];
284 #elif defined _SEVEN_ZIP_
285 u32 digest_buf[4];
286 #elif defined _ANDROIDFDE_
287 u32 digest_buf[4];
288 #elif defined _DCC2_
289 u32 digest_buf[4];
290 #elif defined _WPA_
291 u32 digest_buf[4];
292 #elif defined _MD5_SHA1_
293 u32 digest_buf[4];
294 #elif defined _SHA1_MD5_
295 u32 digest_buf[5];
296 #elif defined _NETNTLMV2_
297 u32 digest_buf[4];
298 #elif defined _KRB5PA_
299 u32 digest_buf[4];
300 #elif defined _CLOUDKEY_
301 u32 digest_buf[8];
302 #elif defined _SCRYPT_
303 u32 digest_buf[4];
304 #elif defined _PSAFE2_
305 u32 digest_buf[5];
306 #elif defined _LOTUS8_
307 u32 digest_buf[4];
308 #elif defined _RAR3_
309 u32 digest_buf[4];
310 #elif defined _SHA256_SHA1_
311 u32 digest_buf[8];
312 #elif defined _MS_DRSR_
313 u32 digest_buf[8];
314 #endif
315
316 } digest_t;
317
318 typedef struct
319 {
320 u32 salt_buf[16];
321 u32 salt_buf_pc[8];
322
323 u32 salt_len;
324 u32 salt_iter;
325 u32 salt_sign[2];
326
327 u32 keccak_mdlen;
328 u32 truecrypt_mdlen;
329
330 u32 digests_cnt;
331 u32 digests_done;
332
333 u32 digests_offset;
334
335 u32 scrypt_N;
336 u32 scrypt_r;
337 u32 scrypt_p;
338 u32 scrypt_tmto;
339 u32 scrypt_phy;
340
341 } salt_t;
342
343 typedef struct
344 {
345 int V;
346 int R;
347 int P;
348
349 int enc_md;
350
351 u32 id_buf[8];
352 u32 u_buf[32];
353 u32 o_buf[32];
354
355 int id_len;
356 int o_len;
357 int u_len;
358
359 u32 rc4key[2];
360 u32 rc4data[2];
361
362 } pdf_t;
363
364 typedef struct
365 {
366 u32 pke[25];
367 u32 eapol[64];
368 int eapol_size;
369 int keyver;
370
371 } wpa_t;
372
373 typedef struct
374 {
375 u32 cry_master_buf[64];
376 u32 ckey_buf[64];
377 u32 public_key_buf[64];
378
379 u32 cry_master_len;
380 u32 ckey_len;
381 u32 public_key_len;
382
383 } bitcoin_wallet_t;
384
385 typedef struct
386 {
387 u32 salt_buf[30];
388 u32 salt_len;
389
390 u32 esalt_buf[38];
391 u32 esalt_len;
392
393 } sip_t;
394
395 typedef struct
396 {
397 u32 data[384];
398
399 } androidfde_t;
400
401 typedef struct
402 {
403 u32 nr_buf[16];
404 u32 nr_len;
405
406 u32 msg_buf[128];
407 u32 msg_len;
408
409 } ikepsk_t;
410
411 typedef struct
412 {
413 u32 user_len;
414 u32 domain_len;
415 u32 srvchall_len;
416 u32 clichall_len;
417
418 u32 userdomain_buf[64];
419 u32 chall_buf[256];
420
421 } netntlm_t;
422
423 typedef struct
424 {
425 u32 user[16];
426 u32 realm[16];
427 u32 salt[32];
428 u32 timestamp[16];
429 u32 checksum[4];
430
431 } krb5pa_t;
432
433 typedef struct
434 {
435 u32 salt_buf[16];
436 u32 data_buf[112];
437 u32 keyfile_buf[16];
438
439 } tc_t;
440
441 typedef struct
442 {
443 u32 salt_buf[16];
444
445 } pbkdf2_md5_t;
446
447 typedef struct
448 {
449 u32 salt_buf[16];
450
451 } pbkdf2_sha1_t;
452
453 typedef struct
454 {
455 u32 salt_buf[16];
456
457 } pbkdf2_sha256_t;
458
459 typedef struct
460 {
461 u32 salt_buf[32];
462
463 } pbkdf2_sha512_t;
464
465 typedef struct
466 {
467 u32 salt_buf[128];
468 u32 salt_len;
469
470 } rakp_t;
471
472 typedef struct
473 {
474 u32 data_len;
475 u32 data_buf[512];
476
477 } cloudkey_t;
478
479 typedef struct
480 {
481 u32 encryptedVerifier[4];
482 u32 encryptedVerifierHash[5];
483
484 u32 keySize;
485
486 } office2007_t;
487
488 typedef struct
489 {
490 u32 encryptedVerifier[4];
491 u32 encryptedVerifierHash[8];
492
493 } office2010_t;
494
495 typedef struct
496 {
497 u32 encryptedVerifier[4];
498 u32 encryptedVerifierHash[8];
499
500 } office2013_t;
501
502 typedef struct
503 {
504 u32 version;
505 u32 encryptedVerifier[4];
506 u32 encryptedVerifierHash[4];
507 u32 rc4key[2];
508
509 } oldoffice01_t;
510
511 typedef struct
512 {
513 u32 version;
514 u32 encryptedVerifier[4];
515 u32 encryptedVerifierHash[5];
516 u32 rc4key[2];
517
518 } oldoffice34_t;
519
520 typedef struct
521 {
522 u32x digest[4];
523 u32x out[4];
524
525 } pdf14_tmp_t;
526
527 typedef struct
528 {
529 union
530 {
531 u32 dgst32[16];
532 u64 dgst64[8];
533 };
534
535 u32 dgst_len;
536 u32 W_len;
537
538 } pdf17l8_tmp_t;
539
540 typedef struct
541 {
542 u32x digest_buf[4];
543
544 } phpass_tmp_t;
545
546 typedef struct
547 {
548 u32x digest_buf[4];
549
550 } md5crypt_tmp_t;
551
552 typedef struct
553 {
554 u32x alt_result[8];
555
556 u32x p_bytes[4];
557 u32x s_bytes[4];
558
559 } sha256crypt_tmp_t;
560
561 typedef struct
562 {
563 u64x l_alt_result[8];
564
565 u64x l_p_bytes[2];
566 u64x l_s_bytes[2];
567
568 } sha512crypt_tmp_t;
569
570 typedef struct
571 {
572 u32x ipad[5];
573 u32x opad[5];
574
575 u32x dgst[10];
576 u32x out[10];
577
578 } wpa_tmp_t;
579
580 typedef struct
581 {
582 u64x dgst[8];
583
584 } bitcoin_wallet_tmp_t;
585
586 typedef struct
587 {
588 u32x ipad[5];
589 u32x opad[5];
590
591 u32x dgst[5];
592 u32x out[4];
593
594 } dcc2_tmp_t;
595
596 typedef struct
597 {
598 u32x P[18];
599
600 u32x S0[256];
601 u32x S1[256];
602 u32x S2[256];
603 u32x S3[256];
604
605 } bcrypt_tmp_t;
606
607 typedef struct
608 {
609 u32x digest[2];
610
611 u32x P[18];
612
613 u32x S0[256];
614 u32x S1[256];
615 u32x S2[256];
616 u32x S3[256];
617
618 } pwsafe2_tmp_t;
619
620 typedef struct
621 {
622 u32x digest_buf[8];
623
624 } pwsafe3_tmp_t;
625
626 typedef struct
627 {
628 u32x digest_buf[5];
629
630 } androidpin_tmp_t;
631
632 typedef struct
633 {
634 u32x ipad[5];
635 u32x opad[5];
636
637 u32x dgst[10];
638 u32x out[10];
639
640 } androidfde_tmp_t;
641
642 typedef struct
643 {
644 u32x ipad[16];
645 u32x opad[16];
646
647 u32x dgst[64];
648 u32x out[64];
649
650 } tc_tmp_t;
651
652 typedef struct
653 {
654 u64x ipad[8];
655 u64x opad[8];
656
657 u64x dgst[32];
658 u64x out[32];
659
660 } tc64_tmp_t;
661
662 typedef struct
663 {
664 u32x ipad[4];
665 u32x opad[4];
666
667 u32x dgst[32];
668 u32x out[32];
669
670 } pbkdf2_md5_tmp_t;
671
672 typedef struct
673 {
674 u32x ipad[5];
675 u32x opad[5];
676
677 u32x dgst[32];
678 u32x out[32];
679
680 } pbkdf2_sha1_tmp_t;
681
682 typedef struct
683 {
684 u32x ipad[8];
685 u32x opad[8];
686
687 u32x dgst[32];
688 u32x out[32];
689
690 } pbkdf2_sha256_tmp_t;
691
692 typedef struct
693 {
694 u64x ipad[8];
695 u64x opad[8];
696
697 u64x dgst[16];
698 u64x out[16];
699
700 } pbkdf2_sha512_tmp_t;
701
702 typedef struct
703 {
704 u64x out[8];
705
706 } ecryptfs_tmp_t;
707
708 typedef struct
709 {
710 u64x ipad[8];
711 u64x opad[8];
712
713 u64x dgst[16];
714 u64x out[16];
715
716 } oraclet_tmp_t;
717
718 typedef struct
719 {
720 u32x ipad[5];
721 u32x opad[5];
722
723 u32x dgst[5];
724 u32x out[5];
725
726 } agilekey_tmp_t;
727
728 typedef struct
729 {
730 u32 ipad[5];
731 u32 opad[5];
732
733 u32 dgst1[5];
734 u32 out1[5];
735
736 u32 dgst2[5];
737 u32 out2[5];
738
739 } mywallet_tmp_t;
740
741 typedef struct
742 {
743 u32x ipad[5];
744 u32x opad[5];
745
746 u32x dgst[5];
747 u32x out[5];
748
749 } sha1aix_tmp_t;
750
751 typedef struct
752 {
753 u32x ipad[8];
754 u32x opad[8];
755
756 u32x dgst[8];
757 u32x out[8];
758
759 } sha256aix_tmp_t;
760
761 typedef struct
762 {
763 u64x ipad[8];
764 u64x opad[8];
765
766 u64x dgst[8];
767 u64x out[8];
768
769 } sha512aix_tmp_t;
770
771 typedef struct
772 {
773 u32x ipad[8];
774 u32x opad[8];
775
776 u32x dgst[8];
777 u32x out[8];
778
779 } lastpass_tmp_t;
780
781 typedef struct
782 {
783 u64x digest_buf[8];
784
785 } drupal7_tmp_t;
786
787 typedef struct
788 {
789 u32x ipad[5];
790 u32x opad[5];
791
792 u32x dgst[5];
793 u32x out[5];
794
795 } lotus8_tmp_t;
796
797 typedef struct
798 {
799 u32x out[5];
800
801 } office2007_tmp_t;
802
803 typedef struct
804 {
805 u32x out[5];
806
807 } office2010_tmp_t;
808
809 typedef struct
810 {
811 u64x out[8];
812
813 } office2013_tmp_t;
814
815 typedef struct
816 {
817 u32x digest_buf[5];
818
819 } saph_sha1_tmp_t;
820
821 typedef struct
822 {
823 u32x block[16];
824
825 u32x dgst[8];
826
827 u32x block_len;
828 u32x final_len;
829
830 } seven_zip_tmp_t;
831
832 typedef struct
833 {
834 u32x Kc[16];
835 u32x Kd[16];
836
837 u32x iv[2];
838
839 } bsdicrypt_tmp_t;
840
841 typedef struct
842 {
843 u32 dgst[17][5];
844
845 } rar3_tmp_t;
846
847 typedef struct
848 {
849 u32 user[16];
850
851 } cram_md5_t;
852
853 typedef struct
854 {
855 u32 iv_buf[4];
856 u32 iv_len;
857
858 u32 salt_buf[4];
859 u32 salt_len;
860
861 u32 crc;
862
863 u32 data_buf[96];
864 u32 data_len;
865
866 u32 unpack_size;
867
868 } seven_zip_t;
869
870 typedef struct
871 {
872 u32 key;
873 u64 val;
874
875 } hcstat_table_t;
876
877 typedef struct
878 {
879 u32 cs_buf[0x100];
880 u32 cs_len;
881
882 } cs_t;
883
884 typedef struct
885 {
886 u32 cmds[15];
887
888 } gpu_rule_t;
889
890 /*
891 typedef struct
892 {
893 u32 plain_buf[16];
894 u32 plailen;
895
896 } plain_t;
897 */
898
899 typedef struct
900 {
901 u32 gidvid;
902 u32 il_pos;
903
904 } plain_t;
905
906 typedef struct
907 {
908 #ifdef _SCALAR_
909 u32 i[64];
910 #else
911 #ifdef VECT_SIZE4
912 u32x i[16];
913 #endif
914
915 #ifdef VECT_SIZE2
916 u32x i[32];
917 #endif
918
919 #ifdef VECT_SIZE1
920 u32x i[64];
921 #endif
922 #endif
923
924 u32 pw_len;
925 u32 alignment_placeholder_1;
926 u32 alignment_placeholder_2;
927 u32 alignment_placeholder_3;
928
929 } pw_t;
930
931 typedef struct
932 {
933 u32 i;
934
935 } bf_t;
936
937 typedef struct
938 {
939 u32 i[8];
940
941 u32 pw_len;
942
943 } comb_t;
944
945 typedef struct
946 {
947 u32 b[32];
948
949 } bs_word_t;
950
951 typedef struct
952 {
953 uint4 P[64];
954
955 } scrypt_tmp_t;