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