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