Upgrade kernel to support dynamic local work sizes
[hashcat.git] / OpenCL / m10700.cl
index abdead1..1a409d1 100644 (file)
 #define DGST_R3 3
 
 #include "include/kernel_functions.c"
-#include "types_ocl.c"
-#include "common.c"
+#include "OpenCL/types_ocl.c"
+#include "OpenCL/common.c"
 
-#define COMPARE_S "check_single_comp4.c"
-#define COMPARE_M "check_multi_comp4.c"
+#define COMPARE_S "OpenCL/check_single_comp4.c"
+#define COMPARE_M "OpenCL/check_multi_comp4.c"
 
 typedef struct
 {
@@ -181,22 +181,22 @@ static void sha384_transform (const u64 w0[4], const u64 w1[4], const u64 w2[4],
   u64 g = digest[6];
   u64 h = digest[7];
 
-  u64 w0_t = swap32 (w0[0]);
-  u64 w1_t = swap32 (w0[1]);
-  u64 w2_t = swap32 (w0[2]);
-  u64 w3_t = swap32 (w0[3]);
-  u64 w4_t = swap32 (w1[0]);
-  u64 w5_t = swap32 (w1[1]);
-  u64 w6_t = swap32 (w1[2]);
-  u64 w7_t = swap32 (w1[3]);
-  u64 w8_t = swap32 (w2[0]);
-  u64 w9_t = swap32 (w2[1]);
-  u64 wa_t = swap32 (w2[2]);
-  u64 wb_t = swap32 (w2[3]);
-  u64 wc_t = swap32 (w3[0]);
-  u64 wd_t = swap32 (w3[1]);
-  u64 we_t = swap32 (w3[2]);
-  u64 wf_t = swap32 (w3[3]);
+  u64 w0_t = swap64 (w0[0]);
+  u64 w1_t = swap64 (w0[1]);
+  u64 w2_t = swap64 (w0[2]);
+  u64 w3_t = swap64 (w0[3]);
+  u64 w4_t = swap64 (w1[0]);
+  u64 w5_t = swap64 (w1[1]);
+  u64 w6_t = swap64 (w1[2]);
+  u64 w7_t = swap64 (w1[3]);
+  u64 w8_t = swap64 (w2[0]);
+  u64 w9_t = swap64 (w2[1]);
+  u64 wa_t = swap64 (w2[2]);
+  u64 wb_t = swap64 (w2[3]);
+  u64 wc_t = swap64 (w3[0]);
+  u64 wd_t = swap64 (w3[1]);
+  u64 we_t = swap64 (w3[2]);
+  u64 wf_t = swap64 (w3[3]);
 
   #define ROUND384_EXPAND()                         \
   {                                                 \
@@ -291,22 +291,22 @@ static void sha512_transform (const u64 w0[4], const u64 w1[4], const u64 w2[4],
   u64 g = digest[6];
   u64 h = digest[7];
 
-  u64 w0_t = swap32 (w0[0]);
-  u64 w1_t = swap32 (w0[1]);
-  u64 w2_t = swap32 (w0[2]);
-  u64 w3_t = swap32 (w0[3]);
-  u64 w4_t = swap32 (w1[0]);
-  u64 w5_t = swap32 (w1[1]);
-  u64 w6_t = swap32 (w1[2]);
-  u64 w7_t = swap32 (w1[3]);
-  u64 w8_t = swap32 (w2[0]);
-  u64 w9_t = swap32 (w2[1]);
-  u64 wa_t = swap32 (w2[2]);
-  u64 wb_t = swap32 (w2[3]);
-  u64 wc_t = swap32 (w3[0]);
-  u64 wd_t = swap32 (w3[1]);
-  u64 we_t = swap32 (w3[2]);
-  u64 wf_t = swap32 (w3[3]);
+  u64 w0_t = swap64 (w0[0]);
+  u64 w1_t = swap64 (w0[1]);
+  u64 w2_t = swap64 (w0[2]);
+  u64 w3_t = swap64 (w0[3]);
+  u64 w4_t = swap64 (w1[0]);
+  u64 w5_t = swap64 (w1[1]);
+  u64 w6_t = swap64 (w1[2]);
+  u64 w7_t = swap64 (w1[3]);
+  u64 w8_t = swap64 (w2[0]);
+  u64 w9_t = swap64 (w2[1]);
+  u64 wa_t = swap64 (w2[2]);
+  u64 wb_t = swap64 (w2[3]);
+  u64 wc_t = swap64 (w3[0]);
+  u64 wd_t = swap64 (w3[1]);
+  u64 we_t = swap64 (w3[2]);
+  u64 wf_t = swap64 (w3[3]);
 
   #define ROUND512_EXPAND()                         \
   {                                                 \
@@ -1198,7 +1198,7 @@ static void make_sc (u32 *sc, const u32 *pw, const u32 pw_len, const u32 *bl, co
 
     u32 i;
 
-    #ifdef IS_AMD
+    #if defined IS_AMD || defined IS_GENERIC
     for (i = 0; i < pd; i++) sc[idx++] = pw[i];
                              sc[idx++] = pw[i]
                                        | amd_bytealign (bl[0],         0, pm4);
@@ -1229,7 +1229,7 @@ static void make_pt_with_offset (u32 *pt, const u32 offset, const u32 *sc, const
   const u32 om = m % 4;
   const u32 od = m / 4;
 
-  #ifdef IS_AMD
+  #if defined IS_AMD || defined IS_GENERIC
   pt[0] = amd_bytealign (sc[od + 1], sc[od + 0], om);
   pt[1] = amd_bytealign (sc[od + 2], sc[od + 1], om);
   pt[2] = amd_bytealign (sc[od + 3], sc[od + 2], om);
@@ -1394,7 +1394,7 @@ static u32 do_round (const u32 *pw, const u32 pw_len, ctx_t *ctx, __local u32 s_
                     ctx->W64[12] = 0;
                     ctx->W64[13] = 0;
                     ctx->W64[14] = 0;
-                    ctx->W64[15] = swap32 ((u64) (final_len * 8));
+                    ctx->W64[15] = swap64 ((u64) (final_len * 8));
                     ex = ctx->W64[7] >> 56;
                     break;
       case BLSZ512: make_w_with_offset (ctx, 64, offset, sc, pwbl_len, iv, rek, s_te0, s_te1, s_te2, s_te3, s_te4);
@@ -1405,7 +1405,7 @@ static u32 do_round (const u32 *pw, const u32 pw_len, ctx_t *ctx, __local u32 s_
                     ctx->W64[12] = 0;
                     ctx->W64[13] = 0;
                     ctx->W64[14] = 0;
-                    ctx->W64[15] = swap32 ((u64) (final_len * 8));
+                    ctx->W64[15] = swap64 ((u64) (final_len * 8));
                     ex = ctx->W64[7] >> 56;
                     break;
     }
@@ -1448,7 +1448,7 @@ static u32 do_round (const u32 *pw, const u32 pw_len, ctx_t *ctx, __local u32 s_
                     ctx->W64[12] = 0;
                     ctx->W64[13] = 0;
                     ctx->W64[14] = 0;
-                    ctx->W64[15] = swap32 ((u64) (final_len * 8));
+                    ctx->W64[15] = swap64 ((u64) (final_len * 8));
                     break;
       case BLSZ512: ex = ctx->W64[15] >> 56;
                     ctx->W64[ 0] = 0x80;
@@ -1466,7 +1466,7 @@ static u32 do_round (const u32 *pw, const u32 pw_len, ctx_t *ctx, __local u32 s_
                     ctx->W64[12] = 0;
                     ctx->W64[13] = 0;
                     ctx->W64[14] = 0;
-                    ctx->W64[15] = swap32 ((u64) (final_len * 8));
+                    ctx->W64[15] = swap64 ((u64) (final_len * 8));
                     break;
     }
   }
@@ -1492,31 +1492,31 @@ static u32 do_round (const u32 *pw, const u32 pw_len, ctx_t *ctx, __local u32 s_
                   ctx->dgst32[15] = 0;
                   break;
     case BLSZ384: sha384_transform (&ctx->W64[ 0], &ctx->W64[ 4], &ctx->W64[ 8], &ctx->W64[12], ctx->dgst64);
-                  ctx->dgst64[0] = swap32 (ctx->dgst64[0]);
-                  ctx->dgst64[1] = swap32 (ctx->dgst64[1]);
-                  ctx->dgst64[2] = swap32 (ctx->dgst64[2]);
-                  ctx->dgst64[3] = swap32 (ctx->dgst64[3]);
-                  ctx->dgst64[4] = swap32 (ctx->dgst64[4]);
-                  ctx->dgst64[5] = swap32 (ctx->dgst64[5]);
+                  ctx->dgst64[0] = swap64 (ctx->dgst64[0]);
+                  ctx->dgst64[1] = swap64 (ctx->dgst64[1]);
+                  ctx->dgst64[2] = swap64 (ctx->dgst64[2]);
+                  ctx->dgst64[3] = swap64 (ctx->dgst64[3]);
+                  ctx->dgst64[4] = swap64 (ctx->dgst64[4]);
+                  ctx->dgst64[5] = swap64 (ctx->dgst64[5]);
                   ctx->dgst64[6] = 0;
                   ctx->dgst64[7] = 0;
                   break;
     case BLSZ512: sha512_transform (&ctx->W64[ 0], &ctx->W64[ 4], &ctx->W64[ 8], &ctx->W64[12], ctx->dgst64);
-                  ctx->dgst64[0] = swap32 (ctx->dgst64[0]);
-                  ctx->dgst64[1] = swap32 (ctx->dgst64[1]);
-                  ctx->dgst64[2] = swap32 (ctx->dgst64[2]);
-                  ctx->dgst64[3] = swap32 (ctx->dgst64[3]);
-                  ctx->dgst64[4] = swap32 (ctx->dgst64[4]);
-                  ctx->dgst64[5] = swap32 (ctx->dgst64[5]);
-                  ctx->dgst64[6] = swap32 (ctx->dgst64[6]);
-                  ctx->dgst64[7] = swap32 (ctx->dgst64[7]);
+                  ctx->dgst64[0] = swap64 (ctx->dgst64[0]);
+                  ctx->dgst64[1] = swap64 (ctx->dgst64[1]);
+                  ctx->dgst64[2] = swap64 (ctx->dgst64[2]);
+                  ctx->dgst64[3] = swap64 (ctx->dgst64[3]);
+                  ctx->dgst64[4] = swap64 (ctx->dgst64[4]);
+                  ctx->dgst64[5] = swap64 (ctx->dgst64[5]);
+                  ctx->dgst64[6] = swap64 (ctx->dgst64[6]);
+                  ctx->dgst64[7] = swap64 (ctx->dgst64[7]);
                   break;
   }
 
   return ex;
 }
 
-__kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10700_init (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pdf17l8_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
+__kernel void m10700_init (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pdf17l8_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
 {
   /**
    * base
@@ -1622,47 +1622,34 @@ __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10700_init (__gl
   tmps[gid].W_len     = WORDSZ256;
 }
 
-__kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10700_loop (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pdf17l8_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
+__kernel void m10700_loop (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pdf17l8_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
 {
+  /**
+   * base
+   */
+
   const u32 gid = get_global_id (0);
   const u32 lid = get_local_id (0);
+  const u32 lsz = get_local_size (0);
 
   /**
    * aes shared
    */
 
-  const u32 lid4 = lid * 4;
-
   __local u32 s_te0[256];
   __local u32 s_te1[256];
   __local u32 s_te2[256];
   __local u32 s_te3[256];
   __local u32 s_te4[256];
 
-  s_te0[lid4 + 0] = te0[lid4 + 0];
-  s_te0[lid4 + 1] = te0[lid4 + 1];
-  s_te0[lid4 + 2] = te0[lid4 + 2];
-  s_te0[lid4 + 3] = te0[lid4 + 3];
-
-  s_te1[lid4 + 0] = te1[lid4 + 0];
-  s_te1[lid4 + 1] = te1[lid4 + 1];
-  s_te1[lid4 + 2] = te1[lid4 + 2];
-  s_te1[lid4 + 3] = te1[lid4 + 3];
-
-  s_te2[lid4 + 0] = te2[lid4 + 0];
-  s_te2[lid4 + 1] = te2[lid4 + 1];
-  s_te2[lid4 + 2] = te2[lid4 + 2];
-  s_te2[lid4 + 3] = te2[lid4 + 3];
-
-  s_te3[lid4 + 0] = te3[lid4 + 0];
-  s_te3[lid4 + 1] = te3[lid4 + 1];
-  s_te3[lid4 + 2] = te3[lid4 + 2];
-  s_te3[lid4 + 3] = te3[lid4 + 3];
-
-  s_te4[lid4 + 0] = te4[lid4 + 0];
-  s_te4[lid4 + 1] = te4[lid4 + 1];
-  s_te4[lid4 + 2] = te4[lid4 + 2];
-  s_te4[lid4 + 3] = te4[lid4 + 3];
+  for (u32 i = lid; i < 256; i += lsz)
+  {
+    s_te0[i] = te0[i];
+    s_te1[i] = te1[i];
+    s_te2[i] = te2[i];
+    s_te3[i] = te3[i];
+    s_te4[i] = te4[i];
+  }
 
   barrier (CLK_LOCAL_MEM_FENCE);
 
@@ -1725,7 +1712,7 @@ __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10700_loop (__gl
   tmps[gid].W_len     = ctx.W_len;
 }
 
-__kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10700_comp (__global pw_t *pws, __global gpu_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pdf17l8_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
+__kernel void m10700_comp (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global pdf17l8_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global pdf_t *pdf_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
 {
   /**
    * modifier