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