diff --git a/OpenCL/inc_hash_functions.cl b/OpenCL/inc_hash_functions.cl index fd133b8bd..f87012162 100644 --- a/OpenCL/inc_hash_functions.cl +++ b/OpenCL/inc_hash_functions.cl @@ -267,6 +267,19 @@ #define SHA384_F1o(x,y,z) (SHA384_F1 ((x), (y), (z))) #endif +#define SHA384_STEP_S(F0,F1,a,b,c,d,e,f,g,h,x,K) \ +{ \ + h += K; \ + h += x; \ + h += SHA384_S1_S (e); \ + h += F0 (e, f, g); \ + d += h; \ + h += SHA384_S0_S (a); \ + h += F1 (a, b, c); \ +} + +#define SHA384_EXPAND_S(x,y,z,w) (SHA384_S3_S (x) + y + SHA384_S2_S (z) + w) + #define SHA384_STEP(F0,F1,a,b,c,d,e,f,g,h,x,K) \ { \ h += K; \ diff --git a/OpenCL/inc_hash_sha384.cl b/OpenCL/inc_hash_sha384.cl new file mode 100644 index 000000000..1b2f88acd --- /dev/null +++ b/OpenCL/inc_hash_sha384.cl @@ -0,0 +1,1643 @@ + +// important notes on this: +// input buf unused bytes needs to be set to zero +// input buf needs to be in algorithm native byte order (md5 = LE, sha1 = BE, etc) +// input buf needs to be 128 byte aligned when using sha512_update() + +__constant u64a k_sha384[80] = +{ + SHA512C00, SHA512C01, SHA512C02, SHA512C03, + SHA512C04, SHA512C05, SHA512C06, SHA512C07, + SHA512C08, SHA512C09, SHA512C0a, SHA512C0b, + SHA512C0c, SHA512C0d, SHA512C0e, SHA512C0f, + SHA512C10, SHA512C11, SHA512C12, SHA512C13, + SHA512C14, SHA512C15, SHA512C16, SHA512C17, + SHA512C18, SHA512C19, SHA512C1a, SHA512C1b, + SHA512C1c, SHA512C1d, SHA512C1e, SHA512C1f, + SHA512C20, SHA512C21, SHA512C22, SHA512C23, + SHA512C24, SHA512C25, SHA512C26, SHA512C27, + SHA512C28, SHA512C29, SHA512C2a, SHA512C2b, + SHA512C2c, SHA512C2d, SHA512C2e, SHA512C2f, + SHA512C30, SHA512C31, SHA512C32, SHA512C33, + SHA512C34, SHA512C35, SHA512C36, SHA512C37, + SHA512C38, SHA512C39, SHA512C3a, SHA512C3b, + SHA512C3c, SHA512C3d, SHA512C3e, SHA512C3f, + SHA512C40, SHA512C41, SHA512C42, SHA512C43, + SHA512C44, SHA512C45, SHA512C46, SHA512C47, + SHA512C48, SHA512C49, SHA512C4a, SHA512C4b, + SHA512C4c, SHA512C4d, SHA512C4e, SHA512C4f, +}; + +typedef struct sha384_ctx +{ + u64 h[8]; + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + u32 w4[4]; + u32 w5[4]; + u32 w6[4]; + u32 w7[4]; + + int len; + +} sha384_ctx_t; + +void sha384_transform (const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4], const u32 w4[4], const u32 w5[4], const u32 w6[4], const u32 w7[4], u64 digest[8]) +{ + u64 a = digest[0]; + u64 b = digest[1]; + u64 c = digest[2]; + u64 d = digest[3]; + u64 e = digest[4]; + u64 f = digest[5]; + u64 g = digest[6]; + u64 h = digest[7]; + + u64 w0_t = hl32_to_64_S (w0[0], w0[1]); + u64 w1_t = hl32_to_64_S (w0[2], w0[3]); + u64 w2_t = hl32_to_64_S (w1[0], w1[1]); + u64 w3_t = hl32_to_64_S (w1[2], w1[3]); + u64 w4_t = hl32_to_64_S (w2[0], w2[1]); + u64 w5_t = hl32_to_64_S (w2[2], w2[3]); + u64 w6_t = hl32_to_64_S (w3[0], w3[1]); + u64 w7_t = hl32_to_64_S (w3[2], w3[3]); + u64 w8_t = hl32_to_64_S (w4[0], w4[1]); + u64 w9_t = hl32_to_64_S (w4[2], w4[3]); + u64 wa_t = hl32_to_64_S (w5[0], w5[1]); + u64 wb_t = hl32_to_64_S (w5[2], w5[3]); + u64 wc_t = hl32_to_64_S (w6[0], w6[1]); + u64 wd_t = hl32_to_64_S (w6[2], w6[3]); + u64 we_t = hl32_to_64_S (w7[0], w7[1]); + u64 wf_t = hl32_to_64_S (w7[2], w7[3]); + + #define ROUND_EXPAND_S() \ + { \ + w0_t = SHA384_EXPAND_S (we_t, w9_t, w1_t, w0_t); \ + w1_t = SHA384_EXPAND_S (wf_t, wa_t, w2_t, w1_t); \ + w2_t = SHA384_EXPAND_S (w0_t, wb_t, w3_t, w2_t); \ + w3_t = SHA384_EXPAND_S (w1_t, wc_t, w4_t, w3_t); \ + w4_t = SHA384_EXPAND_S (w2_t, wd_t, w5_t, w4_t); \ + w5_t = SHA384_EXPAND_S (w3_t, we_t, w6_t, w5_t); \ + w6_t = SHA384_EXPAND_S (w4_t, wf_t, w7_t, w6_t); \ + w7_t = SHA384_EXPAND_S (w5_t, w0_t, w8_t, w7_t); \ + w8_t = SHA384_EXPAND_S (w6_t, w1_t, w9_t, w8_t); \ + w9_t = SHA384_EXPAND_S (w7_t, w2_t, wa_t, w9_t); \ + wa_t = SHA384_EXPAND_S (w8_t, w3_t, wb_t, wa_t); \ + wb_t = SHA384_EXPAND_S (w9_t, w4_t, wc_t, wb_t); \ + wc_t = SHA384_EXPAND_S (wa_t, w5_t, wd_t, wc_t); \ + wd_t = SHA384_EXPAND_S (wb_t, w6_t, we_t, wd_t); \ + we_t = SHA384_EXPAND_S (wc_t, w7_t, wf_t, we_t); \ + wf_t = SHA384_EXPAND_S (wd_t, w8_t, w0_t, wf_t); \ + } + + #define ROUND_STEP_S(i) \ + { \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha384[i + 0]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha384[i + 1]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha384[i + 2]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha384[i + 3]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha384[i + 4]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha384[i + 5]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha384[i + 6]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha384[i + 7]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha384[i + 8]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha384[i + 9]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha384[i + 10]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha384[i + 11]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha384[i + 12]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha384[i + 13]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, c, d, e, f, g, h, a, b, we_t, k_sha384[i + 14]); \ + SHA384_STEP_S (SHA384_F0o, SHA384_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha384[i + 15]); \ + } + + ROUND_STEP_S (0); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 16; i < 80; i += 16) + { + ROUND_EXPAND_S (); ROUND_STEP_S (i); + } + + #undef ROUND_EXPAND_S + #undef ROUND_STEP_S + + digest[0] += a; + digest[1] += b; + digest[2] += c; + digest[3] += d; + digest[4] += e; + digest[5] += f; + digest[6] += g; + digest[7] += h; +} + +void sha384_init (sha384_ctx_t *ctx) +{ + ctx->h[0] = SHA384M_A; + ctx->h[1] = SHA384M_B; + ctx->h[2] = SHA384M_C; + ctx->h[3] = SHA384M_D; + ctx->h[4] = SHA384M_E; + ctx->h[5] = SHA384M_F; + ctx->h[6] = SHA384M_G; + ctx->h[7] = SHA384M_H; + + ctx->w0[0] = 0; + ctx->w0[1] = 0; + ctx->w0[2] = 0; + ctx->w0[3] = 0; + ctx->w1[0] = 0; + ctx->w1[1] = 0; + ctx->w1[2] = 0; + ctx->w1[3] = 0; + ctx->w2[0] = 0; + ctx->w2[1] = 0; + ctx->w2[2] = 0; + ctx->w2[3] = 0; + ctx->w3[0] = 0; + ctx->w3[1] = 0; + ctx->w3[2] = 0; + ctx->w3[3] = 0; + ctx->w4[0] = 0; + ctx->w4[1] = 0; + ctx->w4[2] = 0; + ctx->w4[3] = 0; + ctx->w5[0] = 0; + ctx->w5[1] = 0; + ctx->w5[2] = 0; + ctx->w5[3] = 0; + ctx->w6[0] = 0; + ctx->w6[1] = 0; + ctx->w6[2] = 0; + ctx->w6[3] = 0; + ctx->w7[0] = 0; + ctx->w7[1] = 0; + ctx->w7[2] = 0; + ctx->w7[3] = 0; + + ctx->len = 0; +} + +void sha384_update_128 (sha384_ctx_t *ctx, u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u32 w4[4], u32 w5[4], u32 w6[4], u32 w7[4], const int len) +{ + const int pos = ctx->len & 127; + + ctx->len += len; + + if ((pos + len) < 128) + { + switch_buffer_by_offset_8x4_be_S (w0, w1, w2, w3, w4, w5, w6, w7, pos); + + ctx->w0[0] |= w0[0]; + ctx->w0[1] |= w0[1]; + ctx->w0[2] |= w0[2]; + ctx->w0[3] |= w0[3]; + ctx->w1[0] |= w1[0]; + ctx->w1[1] |= w1[1]; + ctx->w1[2] |= w1[2]; + ctx->w1[3] |= w1[3]; + ctx->w2[0] |= w2[0]; + ctx->w2[1] |= w2[1]; + ctx->w2[2] |= w2[2]; + ctx->w2[3] |= w2[3]; + ctx->w3[0] |= w3[0]; + ctx->w3[1] |= w3[1]; + ctx->w3[2] |= w3[2]; + ctx->w3[3] |= w3[3]; + ctx->w4[0] |= w4[0]; + ctx->w4[1] |= w4[1]; + ctx->w4[2] |= w4[2]; + ctx->w4[3] |= w4[3]; + ctx->w5[0] |= w5[0]; + ctx->w5[1] |= w5[1]; + ctx->w5[2] |= w5[2]; + ctx->w5[3] |= w5[3]; + ctx->w6[0] |= w6[0]; + ctx->w6[1] |= w6[1]; + ctx->w6[2] |= w6[2]; + ctx->w6[3] |= w6[3]; + ctx->w7[0] |= w7[0]; + ctx->w7[1] |= w7[1]; + ctx->w7[2] |= w7[2]; + ctx->w7[3] |= w7[3]; + } + else + { + u32 c0[4] = { 0 }; + u32 c1[4] = { 0 }; + u32 c2[4] = { 0 }; + u32 c3[4] = { 0 }; + u32 c4[4] = { 0 }; + u32 c5[4] = { 0 }; + u32 c6[4] = { 0 }; + u32 c7[4] = { 0 }; + + switch_buffer_by_offset_8x4_carry_be_S (w0, w1, w2, w3, w4, w5, w6, w7, c0, c1, c2, c3, c4, c5, c6, c7, pos); + + ctx->w0[0] |= w0[0]; + ctx->w0[1] |= w0[1]; + ctx->w0[2] |= w0[2]; + ctx->w0[3] |= w0[3]; + ctx->w1[0] |= w1[0]; + ctx->w1[1] |= w1[1]; + ctx->w1[2] |= w1[2]; + ctx->w1[3] |= w1[3]; + ctx->w2[0] |= w2[0]; + ctx->w2[1] |= w2[1]; + ctx->w2[2] |= w2[2]; + ctx->w2[3] |= w2[3]; + ctx->w3[0] |= w3[0]; + ctx->w3[1] |= w3[1]; + ctx->w3[2] |= w3[2]; + ctx->w3[3] |= w3[3]; + ctx->w4[0] |= w4[0]; + ctx->w4[1] |= w4[1]; + ctx->w4[2] |= w4[2]; + ctx->w4[3] |= w4[3]; + ctx->w5[0] |= w5[0]; + ctx->w5[1] |= w5[1]; + ctx->w5[2] |= w5[2]; + ctx->w5[3] |= w5[3]; + ctx->w6[0] |= w6[0]; + ctx->w6[1] |= w6[1]; + ctx->w6[2] |= w6[2]; + ctx->w6[3] |= w6[3]; + ctx->w7[0] |= w7[0]; + ctx->w7[1] |= w7[1]; + ctx->w7[2] |= w7[2]; + ctx->w7[3] |= w7[3]; + + sha384_transform (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->w4, ctx->w5, ctx->w6, ctx->w7, ctx->h); + + ctx->w0[0] = c0[0]; + ctx->w0[1] = c0[1]; + ctx->w0[2] = c0[2]; + ctx->w0[3] = c0[3]; + ctx->w1[0] = c1[0]; + ctx->w1[1] = c1[1]; + ctx->w1[2] = c1[2]; + ctx->w1[3] = c1[3]; + ctx->w2[0] = c2[0]; + ctx->w2[1] = c2[1]; + ctx->w2[2] = c2[2]; + ctx->w2[3] = c2[3]; + ctx->w3[0] = c3[0]; + ctx->w3[1] = c3[1]; + ctx->w3[2] = c3[2]; + ctx->w3[3] = c3[3]; + ctx->w4[0] = c4[0]; + ctx->w4[1] = c4[1]; + ctx->w4[2] = c4[2]; + ctx->w4[3] = c4[3]; + ctx->w5[0] = c5[0]; + ctx->w5[1] = c5[1]; + ctx->w5[2] = c5[2]; + ctx->w5[3] = c5[3]; + ctx->w6[0] = c6[0]; + ctx->w6[1] = c6[1]; + ctx->w6[2] = c6[2]; + ctx->w6[3] = c6[3]; + ctx->w7[0] = c7[0]; + ctx->w7[1] = c7[1]; + ctx->w7[2] = c7[2]; + ctx->w7[3] = c7[3]; + } +} + +void sha384_update (sha384_ctx_t *ctx, const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + u32 w4[4]; + u32 w5[4]; + u32 w6[4]; + u32 w7[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 128; pos1 += 128, pos4 += 32) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + w4[0] = w[pos4 + 16]; + w4[1] = w[pos4 + 17]; + w4[2] = w[pos4 + 18]; + w4[3] = w[pos4 + 19]; + w5[0] = w[pos4 + 20]; + w5[1] = w[pos4 + 21]; + w5[2] = w[pos4 + 22]; + w5[3] = w[pos4 + 23]; + w6[0] = w[pos4 + 24]; + w6[1] = w[pos4 + 25]; + w6[2] = w[pos4 + 26]; + w6[3] = w[pos4 + 27]; + w7[0] = w[pos4 + 28]; + w7[1] = w[pos4 + 29]; + w7[2] = w[pos4 + 30]; + w7[3] = w[pos4 + 31]; + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, 128); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + w4[0] = w[pos4 + 16]; + w4[1] = w[pos4 + 17]; + w4[2] = w[pos4 + 18]; + w4[3] = w[pos4 + 19]; + w5[0] = w[pos4 + 20]; + w5[1] = w[pos4 + 21]; + w5[2] = w[pos4 + 22]; + w5[3] = w[pos4 + 23]; + w6[0] = w[pos4 + 24]; + w6[1] = w[pos4 + 25]; + w6[2] = w[pos4 + 26]; + w6[3] = w[pos4 + 27]; + w7[0] = w[pos4 + 28]; + w7[1] = w[pos4 + 29]; + w7[2] = w[pos4 + 30]; + w7[3] = w[pos4 + 31]; + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, len - pos1); +} + +void sha384_update_swap (sha384_ctx_t *ctx, const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + u32 w4[4]; + u32 w5[4]; + u32 w6[4]; + u32 w7[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 128; pos1 += 128, pos4 += 32) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + w4[0] = w[pos4 + 16]; + w4[1] = w[pos4 + 17]; + w4[2] = w[pos4 + 18]; + w4[3] = w[pos4 + 19]; + w5[0] = w[pos4 + 20]; + w5[1] = w[pos4 + 21]; + w5[2] = w[pos4 + 22]; + w5[3] = w[pos4 + 23]; + w6[0] = w[pos4 + 24]; + w6[1] = w[pos4 + 25]; + w6[2] = w[pos4 + 26]; + w6[3] = w[pos4 + 27]; + w7[0] = w[pos4 + 28]; + w7[1] = w[pos4 + 29]; + w7[2] = w[pos4 + 30]; + w7[3] = w[pos4 + 31]; + + w0[0] = swap32_S (w0[0]); + w0[1] = swap32_S (w0[1]); + w0[2] = swap32_S (w0[2]); + w0[3] = swap32_S (w0[3]); + w1[0] = swap32_S (w1[0]); + w1[1] = swap32_S (w1[1]); + w1[2] = swap32_S (w1[2]); + w1[3] = swap32_S (w1[3]); + w2[0] = swap32_S (w2[0]); + w2[1] = swap32_S (w2[1]); + w2[2] = swap32_S (w2[2]); + w2[3] = swap32_S (w2[3]); + w3[0] = swap32_S (w3[0]); + w3[1] = swap32_S (w3[1]); + w3[2] = swap32_S (w3[2]); + w3[3] = swap32_S (w3[3]); + w4[0] = swap32_S (w4[0]); + w4[1] = swap32_S (w4[1]); + w4[2] = swap32_S (w4[2]); + w4[3] = swap32_S (w4[3]); + w5[0] = swap32_S (w5[0]); + w5[1] = swap32_S (w5[1]); + w5[2] = swap32_S (w5[2]); + w5[3] = swap32_S (w5[3]); + w6[0] = swap32_S (w6[0]); + w6[1] = swap32_S (w6[1]); + w6[2] = swap32_S (w6[2]); + w6[3] = swap32_S (w6[3]); + w7[0] = swap32_S (w7[0]); + w7[1] = swap32_S (w7[1]); + w7[2] = swap32_S (w7[2]); + w7[3] = swap32_S (w7[3]); + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, 128); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + w4[0] = w[pos4 + 16]; + w4[1] = w[pos4 + 17]; + w4[2] = w[pos4 + 18]; + w4[3] = w[pos4 + 19]; + w5[0] = w[pos4 + 20]; + w5[1] = w[pos4 + 21]; + w5[2] = w[pos4 + 22]; + w5[3] = w[pos4 + 23]; + w6[0] = w[pos4 + 24]; + w6[1] = w[pos4 + 25]; + w6[2] = w[pos4 + 26]; + w6[3] = w[pos4 + 27]; + w7[0] = w[pos4 + 28]; + w7[1] = w[pos4 + 29]; + w7[2] = w[pos4 + 30]; + w7[3] = w[pos4 + 31]; + + w0[0] = swap32_S (w0[0]); + w0[1] = swap32_S (w0[1]); + w0[2] = swap32_S (w0[2]); + w0[3] = swap32_S (w0[3]); + w1[0] = swap32_S (w1[0]); + w1[1] = swap32_S (w1[1]); + w1[2] = swap32_S (w1[2]); + w1[3] = swap32_S (w1[3]); + w2[0] = swap32_S (w2[0]); + w2[1] = swap32_S (w2[1]); + w2[2] = swap32_S (w2[2]); + w2[3] = swap32_S (w2[3]); + w3[0] = swap32_S (w3[0]); + w3[1] = swap32_S (w3[1]); + w3[2] = swap32_S (w3[2]); + w3[3] = swap32_S (w3[3]); + w4[0] = swap32_S (w4[0]); + w4[1] = swap32_S (w4[1]); + w4[2] = swap32_S (w4[2]); + w4[3] = swap32_S (w4[3]); + w5[0] = swap32_S (w5[0]); + w5[1] = swap32_S (w5[1]); + w5[2] = swap32_S (w5[2]); + w5[3] = swap32_S (w5[3]); + w6[0] = swap32_S (w6[0]); + w6[1] = swap32_S (w6[1]); + w6[2] = swap32_S (w6[2]); + w6[3] = swap32_S (w6[3]); + w7[0] = swap32_S (w7[0]); + w7[1] = swap32_S (w7[1]); + w7[2] = swap32_S (w7[2]); + w7[3] = swap32_S (w7[3]); + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, len - pos1); +} + +void sha384_update_global (sha384_ctx_t *ctx, const __global u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + u32 w4[4]; + u32 w5[4]; + u32 w6[4]; + u32 w7[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 128; pos1 += 128, pos4 += 32) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + w4[0] = w[pos4 + 16]; + w4[1] = w[pos4 + 17]; + w4[2] = w[pos4 + 18]; + w4[3] = w[pos4 + 19]; + w5[0] = w[pos4 + 20]; + w5[1] = w[pos4 + 21]; + w5[2] = w[pos4 + 22]; + w5[3] = w[pos4 + 23]; + w6[0] = w[pos4 + 24]; + w6[1] = w[pos4 + 25]; + w6[2] = w[pos4 + 26]; + w6[3] = w[pos4 + 27]; + w7[0] = w[pos4 + 28]; + w7[1] = w[pos4 + 29]; + w7[2] = w[pos4 + 30]; + w7[3] = w[pos4 + 31]; + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, 128); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + w4[0] = w[pos4 + 16]; + w4[1] = w[pos4 + 17]; + w4[2] = w[pos4 + 18]; + w4[3] = w[pos4 + 19]; + w5[0] = w[pos4 + 20]; + w5[1] = w[pos4 + 21]; + w5[2] = w[pos4 + 22]; + w5[3] = w[pos4 + 23]; + w6[0] = w[pos4 + 24]; + w6[1] = w[pos4 + 25]; + w6[2] = w[pos4 + 26]; + w6[3] = w[pos4 + 27]; + w7[0] = w[pos4 + 28]; + w7[1] = w[pos4 + 29]; + w7[2] = w[pos4 + 30]; + w7[3] = w[pos4 + 31]; + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, len - pos1); +} + +void sha384_update_global_swap (sha384_ctx_t *ctx, const __global u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + u32 w4[4]; + u32 w5[4]; + u32 w6[4]; + u32 w7[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 128; pos1 += 128, pos4 += 32) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + w4[0] = w[pos4 + 16]; + w4[1] = w[pos4 + 17]; + w4[2] = w[pos4 + 18]; + w4[3] = w[pos4 + 19]; + w5[0] = w[pos4 + 20]; + w5[1] = w[pos4 + 21]; + w5[2] = w[pos4 + 22]; + w5[3] = w[pos4 + 23]; + w6[0] = w[pos4 + 24]; + w6[1] = w[pos4 + 25]; + w6[2] = w[pos4 + 26]; + w6[3] = w[pos4 + 27]; + w7[0] = w[pos4 + 28]; + w7[1] = w[pos4 + 29]; + w7[2] = w[pos4 + 30]; + w7[3] = w[pos4 + 31]; + + w0[0] = swap32_S (w0[0]); + w0[1] = swap32_S (w0[1]); + w0[2] = swap32_S (w0[2]); + w0[3] = swap32_S (w0[3]); + w1[0] = swap32_S (w1[0]); + w1[1] = swap32_S (w1[1]); + w1[2] = swap32_S (w1[2]); + w1[3] = swap32_S (w1[3]); + w2[0] = swap32_S (w2[0]); + w2[1] = swap32_S (w2[1]); + w2[2] = swap32_S (w2[2]); + w2[3] = swap32_S (w2[3]); + w3[0] = swap32_S (w3[0]); + w3[1] = swap32_S (w3[1]); + w3[2] = swap32_S (w3[2]); + w3[3] = swap32_S (w3[3]); + w4[0] = swap32_S (w4[0]); + w4[1] = swap32_S (w4[1]); + w4[2] = swap32_S (w4[2]); + w4[3] = swap32_S (w4[3]); + w5[0] = swap32_S (w5[0]); + w5[1] = swap32_S (w5[1]); + w5[2] = swap32_S (w5[2]); + w5[3] = swap32_S (w5[3]); + w6[0] = swap32_S (w6[0]); + w6[1] = swap32_S (w6[1]); + w6[2] = swap32_S (w6[2]); + w6[3] = swap32_S (w6[3]); + w7[0] = swap32_S (w7[0]); + w7[1] = swap32_S (w7[1]); + w7[2] = swap32_S (w7[2]); + w7[3] = swap32_S (w7[3]); + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, 128); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + w4[0] = w[pos4 + 16]; + w4[1] = w[pos4 + 17]; + w4[2] = w[pos4 + 18]; + w4[3] = w[pos4 + 19]; + w5[0] = w[pos4 + 20]; + w5[1] = w[pos4 + 21]; + w5[2] = w[pos4 + 22]; + w5[3] = w[pos4 + 23]; + w6[0] = w[pos4 + 24]; + w6[1] = w[pos4 + 25]; + w6[2] = w[pos4 + 26]; + w6[3] = w[pos4 + 27]; + w7[0] = w[pos4 + 28]; + w7[1] = w[pos4 + 29]; + w7[2] = w[pos4 + 30]; + w7[3] = w[pos4 + 31]; + + w0[0] = swap32_S (w0[0]); + w0[1] = swap32_S (w0[1]); + w0[2] = swap32_S (w0[2]); + w0[3] = swap32_S (w0[3]); + w1[0] = swap32_S (w1[0]); + w1[1] = swap32_S (w1[1]); + w1[2] = swap32_S (w1[2]); + w1[3] = swap32_S (w1[3]); + w2[0] = swap32_S (w2[0]); + w2[1] = swap32_S (w2[1]); + w2[2] = swap32_S (w2[2]); + w2[3] = swap32_S (w2[3]); + w3[0] = swap32_S (w3[0]); + w3[1] = swap32_S (w3[1]); + w3[2] = swap32_S (w3[2]); + w3[3] = swap32_S (w3[3]); + w4[0] = swap32_S (w4[0]); + w4[1] = swap32_S (w4[1]); + w4[2] = swap32_S (w4[2]); + w4[3] = swap32_S (w4[3]); + w5[0] = swap32_S (w5[0]); + w5[1] = swap32_S (w5[1]); + w5[2] = swap32_S (w5[2]); + w5[3] = swap32_S (w5[3]); + w6[0] = swap32_S (w6[0]); + w6[1] = swap32_S (w6[1]); + w6[2] = swap32_S (w6[2]); + w6[3] = swap32_S (w6[3]); + w7[0] = swap32_S (w7[0]); + w7[1] = swap32_S (w7[1]); + w7[2] = swap32_S (w7[2]); + w7[3] = swap32_S (w7[3]); + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, len - pos1); +} + +void sha384_update_global_utf16le (sha384_ctx_t *ctx, const __global u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + u32 w4[4]; + u32 w5[4]; + u32 w6[4]; + u32 w7[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + make_utf16le_S (w3, w6, w7); + make_utf16le_S (w2, w4, w5); + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, 64 * 2); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + make_utf16le_S (w3, w6, w7); + make_utf16le_S (w2, w4, w5); + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, (len - pos1) * 2); +} + +void sha384_update_global_utf16le_swap (sha384_ctx_t *ctx, const __global u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + u32 w4[4]; + u32 w5[4]; + u32 w6[4]; + u32 w7[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + make_utf16le_S (w3, w6, w7); + make_utf16le_S (w2, w4, w5); + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + w0[0] = swap32_S (w0[0]); + w0[1] = swap32_S (w0[1]); + w0[2] = swap32_S (w0[2]); + w0[3] = swap32_S (w0[3]); + w1[0] = swap32_S (w1[0]); + w1[1] = swap32_S (w1[1]); + w1[2] = swap32_S (w1[2]); + w1[3] = swap32_S (w1[3]); + w2[0] = swap32_S (w2[0]); + w2[1] = swap32_S (w2[1]); + w2[2] = swap32_S (w2[2]); + w2[3] = swap32_S (w2[3]); + w3[0] = swap32_S (w3[0]); + w3[1] = swap32_S (w3[1]); + w3[2] = swap32_S (w3[2]); + w3[3] = swap32_S (w3[3]); + w4[0] = swap32_S (w4[0]); + w4[1] = swap32_S (w4[1]); + w4[2] = swap32_S (w4[2]); + w4[3] = swap32_S (w4[3]); + w5[0] = swap32_S (w5[0]); + w5[1] = swap32_S (w5[1]); + w5[2] = swap32_S (w5[2]); + w5[3] = swap32_S (w5[3]); + w6[0] = swap32_S (w6[0]); + w6[1] = swap32_S (w6[1]); + w6[2] = swap32_S (w6[2]); + w6[3] = swap32_S (w6[3]); + w7[0] = swap32_S (w7[0]); + w7[1] = swap32_S (w7[1]); + w7[2] = swap32_S (w7[2]); + w7[3] = swap32_S (w7[3]); + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, 64 * 2); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + make_utf16le_S (w3, w6, w7); + make_utf16le_S (w2, w4, w5); + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + w0[0] = swap32_S (w0[0]); + w0[1] = swap32_S (w0[1]); + w0[2] = swap32_S (w0[2]); + w0[3] = swap32_S (w0[3]); + w1[0] = swap32_S (w1[0]); + w1[1] = swap32_S (w1[1]); + w1[2] = swap32_S (w1[2]); + w1[3] = swap32_S (w1[3]); + w2[0] = swap32_S (w2[0]); + w2[1] = swap32_S (w2[1]); + w2[2] = swap32_S (w2[2]); + w2[3] = swap32_S (w2[3]); + w3[0] = swap32_S (w3[0]); + w3[1] = swap32_S (w3[1]); + w3[2] = swap32_S (w3[2]); + w3[3] = swap32_S (w3[3]); + w4[0] = swap32_S (w4[0]); + w4[1] = swap32_S (w4[1]); + w4[2] = swap32_S (w4[2]); + w4[3] = swap32_S (w4[3]); + w5[0] = swap32_S (w5[0]); + w5[1] = swap32_S (w5[1]); + w5[2] = swap32_S (w5[2]); + w5[3] = swap32_S (w5[3]); + w6[0] = swap32_S (w6[0]); + w6[1] = swap32_S (w6[1]); + w6[2] = swap32_S (w6[2]); + w6[3] = swap32_S (w6[3]); + w7[0] = swap32_S (w7[0]); + w7[1] = swap32_S (w7[1]); + w7[2] = swap32_S (w7[2]); + w7[3] = swap32_S (w7[3]); + + sha384_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, (len - pos1) * 2); +} + +void sha384_final (sha384_ctx_t *ctx) +{ + int pos = ctx->len & 127; + + append_0x80_8x4_S (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->w4, ctx->w5, ctx->w6, ctx->w7, pos ^ 3); + + if (pos >= 112) + { + sha384_transform (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->w4, ctx->w5, ctx->w6, ctx->w7, ctx->h); + + ctx->w0[0] = 0; + ctx->w0[1] = 0; + ctx->w0[2] = 0; + ctx->w0[3] = 0; + ctx->w1[0] = 0; + ctx->w1[1] = 0; + ctx->w1[2] = 0; + ctx->w1[3] = 0; + ctx->w2[0] = 0; + ctx->w2[1] = 0; + ctx->w2[2] = 0; + ctx->w2[3] = 0; + ctx->w3[0] = 0; + ctx->w3[1] = 0; + ctx->w3[2] = 0; + ctx->w3[3] = 0; + ctx->w4[0] = 0; + ctx->w4[1] = 0; + ctx->w4[2] = 0; + ctx->w4[3] = 0; + ctx->w5[0] = 0; + ctx->w5[1] = 0; + ctx->w5[2] = 0; + ctx->w5[3] = 0; + ctx->w6[0] = 0; + ctx->w6[1] = 0; + ctx->w6[2] = 0; + ctx->w6[3] = 0; + ctx->w7[0] = 0; + ctx->w7[1] = 0; + ctx->w7[2] = 0; + ctx->w7[3] = 0; + } + + ctx->w7[2] = 0; + ctx->w7[3] = ctx->len * 8; + + sha384_transform (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->w4, ctx->w5, ctx->w6, ctx->w7, ctx->h); +} + +// sha384_hmac + +typedef struct sha384_hmac_ctx +{ + sha384_ctx_t ipad; + sha384_ctx_t opad; + +} sha384_hmac_ctx_t; + +void sha384_hmac_init (sha384_hmac_ctx_t *ctx, const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4], const u32 w4[4], const u32 w5[4], const u32 w6[4], const u32 w7[4]) +{ + u32 t0[4]; + u32 t1[4]; + u32 t2[4]; + u32 t3[4]; + u32 t4[4]; + u32 t5[4]; + u32 t6[4]; + u32 t7[4]; + + // ipad + + t0[0] = w0[0] ^ 0x36363636; + t0[1] = w0[1] ^ 0x36363636; + t0[2] = w0[2] ^ 0x36363636; + t0[3] = w0[3] ^ 0x36363636; + t1[0] = w1[0] ^ 0x36363636; + t1[1] = w1[1] ^ 0x36363636; + t1[2] = w1[2] ^ 0x36363636; + t1[3] = w1[3] ^ 0x36363636; + t2[0] = w2[0] ^ 0x36363636; + t2[1] = w2[1] ^ 0x36363636; + t2[2] = w2[2] ^ 0x36363636; + t2[3] = w2[3] ^ 0x36363636; + t3[0] = w3[0] ^ 0x36363636; + t3[1] = w3[1] ^ 0x36363636; + t3[2] = w3[2] ^ 0x36363636; + t3[3] = w3[3] ^ 0x36363636; + t4[0] = w4[0] ^ 0x36363636; + t4[1] = w4[1] ^ 0x36363636; + t4[2] = w4[2] ^ 0x36363636; + t4[3] = w4[3] ^ 0x36363636; + t5[0] = w5[0] ^ 0x36363636; + t5[1] = w5[1] ^ 0x36363636; + t5[2] = w5[2] ^ 0x36363636; + t5[3] = w5[3] ^ 0x36363636; + t6[0] = w6[0] ^ 0x36363636; + t6[1] = w6[1] ^ 0x36363636; + t6[2] = w6[2] ^ 0x36363636; + t6[3] = w6[3] ^ 0x36363636; + t7[0] = w7[0] ^ 0x36363636; + t7[1] = w7[1] ^ 0x36363636; + t7[2] = w7[2] ^ 0x36363636; + t7[3] = w7[3] ^ 0x36363636; + + sha384_init (&ctx->ipad); + + sha384_update_128 (&ctx->ipad, t0, t1, t2, t3, t4, t5, t6, t7, 128); + + // opad + + t0[0] = w0[0] ^ 0x5c5c5c5c; + t0[1] = w0[1] ^ 0x5c5c5c5c; + t0[2] = w0[2] ^ 0x5c5c5c5c; + t0[3] = w0[3] ^ 0x5c5c5c5c; + t1[0] = w1[0] ^ 0x5c5c5c5c; + t1[1] = w1[1] ^ 0x5c5c5c5c; + t1[2] = w1[2] ^ 0x5c5c5c5c; + t1[3] = w1[3] ^ 0x5c5c5c5c; + t2[0] = w2[0] ^ 0x5c5c5c5c; + t2[1] = w2[1] ^ 0x5c5c5c5c; + t2[2] = w2[2] ^ 0x5c5c5c5c; + t2[3] = w2[3] ^ 0x5c5c5c5c; + t3[0] = w3[0] ^ 0x5c5c5c5c; + t3[1] = w3[1] ^ 0x5c5c5c5c; + t3[2] = w3[2] ^ 0x5c5c5c5c; + t3[3] = w3[3] ^ 0x5c5c5c5c; + t4[0] = w4[0] ^ 0x5c5c5c5c; + t4[1] = w4[1] ^ 0x5c5c5c5c; + t4[2] = w4[2] ^ 0x5c5c5c5c; + t4[3] = w4[3] ^ 0x5c5c5c5c; + t5[0] = w5[0] ^ 0x5c5c5c5c; + t5[1] = w5[1] ^ 0x5c5c5c5c; + t5[2] = w5[2] ^ 0x5c5c5c5c; + t5[3] = w5[3] ^ 0x5c5c5c5c; + t6[0] = w6[0] ^ 0x5c5c5c5c; + t6[1] = w6[1] ^ 0x5c5c5c5c; + t6[2] = w6[2] ^ 0x5c5c5c5c; + t6[3] = w6[3] ^ 0x5c5c5c5c; + t7[0] = w7[0] ^ 0x5c5c5c5c; + t7[1] = w7[1] ^ 0x5c5c5c5c; + t7[2] = w7[2] ^ 0x5c5c5c5c; + t7[3] = w7[3] ^ 0x5c5c5c5c; + + sha384_init (&ctx->opad); + + sha384_update_128 (&ctx->opad, t0, t1, t2, t3, t4, t5, t6, t7, 128); +} + +void sha384_hmac_update_128 (sha384_hmac_ctx_t *ctx, u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u32 w4[4], u32 w5[4], u32 w6[4], u32 w7[4], const int len) +{ + sha384_update_128 (&ctx->ipad, w0, w1, w2, w3, w4, w5, w6, w7, len); +} + +void sha384_hmac_update (sha384_hmac_ctx_t *ctx, const u32 *w, const int len) +{ + sha384_update (&ctx->ipad, w, len); +} + +void sha384_hmac_update_global (sha384_hmac_ctx_t *ctx, const __global u32 *w, const int len) +{ + sha384_update_global (&ctx->ipad, w, len); +} + +void sha384_hmac_update_global_swap (sha384_hmac_ctx_t *ctx, const __global u32 *w, const int len) +{ + sha384_update_global_swap (&ctx->ipad, w, len); +} + +void sha384_hmac_update_global_utf16le (sha384_hmac_ctx_t *ctx, const __global u32 *w, const int len) +{ + sha384_update_global_utf16le (&ctx->ipad, w, len); +} + +void sha384_hmac_update_global_utf16le_swap (sha384_hmac_ctx_t *ctx, const __global u32 *w, const int len) +{ + sha384_update_global_utf16le_swap (&ctx->ipad, w, len); +} + +void sha384_hmac_final (sha384_hmac_ctx_t *ctx) +{ + sha384_final (&ctx->ipad); + + u32 t0[4]; + u32 t1[4]; + u32 t2[4]; + u32 t3[4]; + u32 t4[4]; + u32 t5[4]; + u32 t6[4]; + u32 t7[4]; + + t0[0] = h32_from_64_S (ctx->ipad.h[0]); + t0[1] = l32_from_64_S (ctx->ipad.h[0]); + t0[2] = h32_from_64_S (ctx->ipad.h[1]); + t0[3] = l32_from_64_S (ctx->ipad.h[1]); + t1[0] = h32_from_64_S (ctx->ipad.h[2]); + t1[1] = l32_from_64_S (ctx->ipad.h[2]); + t1[2] = h32_from_64_S (ctx->ipad.h[3]); + t1[3] = l32_from_64_S (ctx->ipad.h[3]); + t2[0] = h32_from_64_S (ctx->ipad.h[4]); + t2[1] = l32_from_64_S (ctx->ipad.h[4]); + t2[2] = h32_from_64_S (ctx->ipad.h[5]); + t2[3] = l32_from_64_S (ctx->ipad.h[5]); + t3[0] = h32_from_64_S (ctx->ipad.h[6]); + t3[1] = l32_from_64_S (ctx->ipad.h[6]); + t3[2] = h32_from_64_S (ctx->ipad.h[7]); + t3[3] = l32_from_64_S (ctx->ipad.h[7]); + t4[0] = 0; + t4[1] = 0; + t4[2] = 0; + t4[3] = 0; + t5[0] = 0; + t5[1] = 0; + t5[2] = 0; + t5[3] = 0; + t6[0] = 0; + t6[1] = 0; + t6[2] = 0; + t6[3] = 0; + t7[0] = 0; + t7[1] = 0; + t7[2] = 0; + t7[3] = 0; + + sha384_update_128 (&ctx->opad, t0, t1, t2, t3, t4, t5, t6, t7, 64); + + sha384_final (&ctx->opad); +} + +// while input buf can be a vector datatype, the length of the different elements can not + +typedef struct sha384_ctx_vector +{ + u64x h[8]; + + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + u32x w4[4]; + u32x w5[4]; + u32x w6[4]; + u32x w7[4]; + + int len; + +} sha384_ctx_vector_t; + +void sha384_transform_vector (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], const u32x w4[4], const u32x w5[4], const u32x w6[4], const u32x w7[4], u64x digest[8]) +{ + u64x a = digest[0]; + u64x b = digest[1]; + u64x c = digest[2]; + u64x d = digest[3]; + u64x e = digest[4]; + u64x f = digest[5]; + u64x g = digest[6]; + u64x h = digest[7]; + + u64x w0_t = hl32_to_64 (w0[0], w0[1]); + u64x w1_t = hl32_to_64 (w0[2], w0[3]); + u64x w2_t = hl32_to_64 (w1[0], w1[1]); + u64x w3_t = hl32_to_64 (w1[2], w1[3]); + u64x w4_t = hl32_to_64 (w2[0], w2[1]); + u64x w5_t = hl32_to_64 (w2[2], w2[3]); + u64x w6_t = hl32_to_64 (w3[0], w3[1]); + u64x w7_t = hl32_to_64 (w3[2], w3[3]); + u64x w8_t = hl32_to_64 (w4[0], w4[1]); + u64x w9_t = hl32_to_64 (w4[2], w4[3]); + u64x wa_t = hl32_to_64 (w5[0], w5[1]); + u64x wb_t = hl32_to_64 (w5[2], w5[3]); + u64x wc_t = hl32_to_64 (w6[0], w6[1]); + u64x wd_t = hl32_to_64 (w6[2], w6[3]); + u64x we_t = hl32_to_64 (w7[0], w7[1]); + u64x wf_t = hl32_to_64 (w7[2], w7[3]); + + #define ROUND_EXPAND() \ + { \ + w0_t = SHA384_EXPAND (we_t, w9_t, w1_t, w0_t); \ + w1_t = SHA384_EXPAND (wf_t, wa_t, w2_t, w1_t); \ + w2_t = SHA384_EXPAND (w0_t, wb_t, w3_t, w2_t); \ + w3_t = SHA384_EXPAND (w1_t, wc_t, w4_t, w3_t); \ + w4_t = SHA384_EXPAND (w2_t, wd_t, w5_t, w4_t); \ + w5_t = SHA384_EXPAND (w3_t, we_t, w6_t, w5_t); \ + w6_t = SHA384_EXPAND (w4_t, wf_t, w7_t, w6_t); \ + w7_t = SHA384_EXPAND (w5_t, w0_t, w8_t, w7_t); \ + w8_t = SHA384_EXPAND (w6_t, w1_t, w9_t, w8_t); \ + w9_t = SHA384_EXPAND (w7_t, w2_t, wa_t, w9_t); \ + wa_t = SHA384_EXPAND (w8_t, w3_t, wb_t, wa_t); \ + wb_t = SHA384_EXPAND (w9_t, w4_t, wc_t, wb_t); \ + wc_t = SHA384_EXPAND (wa_t, w5_t, wd_t, wc_t); \ + wd_t = SHA384_EXPAND (wb_t, w6_t, we_t, wd_t); \ + we_t = SHA384_EXPAND (wc_t, w7_t, wf_t, we_t); \ + wf_t = SHA384_EXPAND (wd_t, w8_t, w0_t, wf_t); \ + } + + #define ROUND_STEP(i) \ + { \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha384[i + 0]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha384[i + 1]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha384[i + 2]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha384[i + 3]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha384[i + 4]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha384[i + 5]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha384[i + 6]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha384[i + 7]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha384[i + 8]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha384[i + 9]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha384[i + 10]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha384[i + 11]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha384[i + 12]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha384[i + 13]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, c, d, e, f, g, h, a, b, we_t, k_sha384[i + 14]); \ + SHA384_STEP (SHA384_F0o, SHA384_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha384[i + 15]); \ + } + + ROUND_STEP (0); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 16; i < 80; i += 16) + { + ROUND_EXPAND (); ROUND_STEP (i); + } + + #undef ROUND_EXPAND + #undef ROUND_STEP + + digest[0] += a; + digest[1] += b; + digest[2] += c; + digest[3] += d; + digest[4] += e; + digest[5] += f; + digest[6] += g; + digest[7] += h; +} + +void sha384_init_vector (sha384_ctx_vector_t *ctx) +{ + ctx->h[0] = SHA384M_A; + ctx->h[1] = SHA384M_B; + ctx->h[2] = SHA384M_C; + ctx->h[3] = SHA384M_D; + ctx->h[4] = SHA384M_E; + ctx->h[5] = SHA384M_F; + ctx->h[6] = SHA384M_G; + ctx->h[7] = SHA384M_H; + + ctx->w0[0] = 0; + ctx->w0[1] = 0; + ctx->w0[2] = 0; + ctx->w0[3] = 0; + ctx->w1[0] = 0; + ctx->w1[1] = 0; + ctx->w1[2] = 0; + ctx->w1[3] = 0; + ctx->w2[0] = 0; + ctx->w2[1] = 0; + ctx->w2[2] = 0; + ctx->w2[3] = 0; + ctx->w3[0] = 0; + ctx->w3[1] = 0; + ctx->w3[2] = 0; + ctx->w3[3] = 0; + ctx->w4[0] = 0; + ctx->w4[1] = 0; + ctx->w4[2] = 0; + ctx->w4[3] = 0; + ctx->w5[0] = 0; + ctx->w5[1] = 0; + ctx->w5[2] = 0; + ctx->w5[3] = 0; + ctx->w6[0] = 0; + ctx->w6[1] = 0; + ctx->w6[2] = 0; + ctx->w6[3] = 0; + ctx->w7[0] = 0; + ctx->w7[1] = 0; + ctx->w7[2] = 0; + ctx->w7[3] = 0; + + ctx->len = 0; +} + +void sha384_update_vector_128 (sha384_ctx_vector_t *ctx, u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x w4[4], u32x w5[4], u32x w6[4], u32x w7[4], const int len) +{ + const int pos = ctx->len & 127; + + ctx->len += len; + + if ((pos + len) < 128) + { + switch_buffer_by_offset_8x4_be (w0, w1, w2, w3, w4, w5, w6, w7, pos); + + ctx->w0[0] |= w0[0]; + ctx->w0[1] |= w0[1]; + ctx->w0[2] |= w0[2]; + ctx->w0[3] |= w0[3]; + ctx->w1[0] |= w1[0]; + ctx->w1[1] |= w1[1]; + ctx->w1[2] |= w1[2]; + ctx->w1[3] |= w1[3]; + ctx->w2[0] |= w2[0]; + ctx->w2[1] |= w2[1]; + ctx->w2[2] |= w2[2]; + ctx->w2[3] |= w2[3]; + ctx->w3[0] |= w3[0]; + ctx->w3[1] |= w3[1]; + ctx->w3[2] |= w3[2]; + ctx->w3[3] |= w3[3]; + ctx->w4[0] |= w4[0]; + ctx->w4[1] |= w4[1]; + ctx->w4[2] |= w4[2]; + ctx->w4[3] |= w4[3]; + ctx->w5[0] |= w5[0]; + ctx->w5[1] |= w5[1]; + ctx->w5[2] |= w5[2]; + ctx->w5[3] |= w5[3]; + ctx->w6[0] |= w6[0]; + ctx->w6[1] |= w6[1]; + ctx->w6[2] |= w6[2]; + ctx->w6[3] |= w6[3]; + ctx->w7[0] |= w7[0]; + ctx->w7[1] |= w7[1]; + ctx->w7[2] |= w7[2]; + ctx->w7[3] |= w7[3]; + } + else + { + u32x c0[4] = { 0 }; + u32x c1[4] = { 0 }; + u32x c2[4] = { 0 }; + u32x c3[4] = { 0 }; + u32x c4[4] = { 0 }; + u32x c5[4] = { 0 }; + u32x c6[4] = { 0 }; + u32x c7[4] = { 0 }; + + switch_buffer_by_offset_8x4_carry_be (w0, w1, w2, w3, w4, w5, w6, w7, c0, c1, c2, c3, c4, c5, c6, c7, pos); + + ctx->w0[0] |= w0[0]; + ctx->w0[1] |= w0[1]; + ctx->w0[2] |= w0[2]; + ctx->w0[3] |= w0[3]; + ctx->w1[0] |= w1[0]; + ctx->w1[1] |= w1[1]; + ctx->w1[2] |= w1[2]; + ctx->w1[3] |= w1[3]; + ctx->w2[0] |= w2[0]; + ctx->w2[1] |= w2[1]; + ctx->w2[2] |= w2[2]; + ctx->w2[3] |= w2[3]; + ctx->w3[0] |= w3[0]; + ctx->w3[1] |= w3[1]; + ctx->w3[2] |= w3[2]; + ctx->w3[3] |= w3[3]; + ctx->w4[0] |= w4[0]; + ctx->w4[1] |= w4[1]; + ctx->w4[2] |= w4[2]; + ctx->w4[3] |= w4[3]; + ctx->w5[0] |= w5[0]; + ctx->w5[1] |= w5[1]; + ctx->w5[2] |= w5[2]; + ctx->w5[3] |= w5[3]; + ctx->w6[0] |= w6[0]; + ctx->w6[1] |= w6[1]; + ctx->w6[2] |= w6[2]; + ctx->w6[3] |= w6[3]; + ctx->w7[0] |= w7[0]; + ctx->w7[1] |= w7[1]; + ctx->w7[2] |= w7[2]; + ctx->w7[3] |= w7[3]; + + sha384_transform_vector (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->w4, ctx->w5, ctx->w6, ctx->w7, ctx->h); + + ctx->w0[0] = c0[0]; + ctx->w0[1] = c0[1]; + ctx->w0[2] = c0[2]; + ctx->w0[3] = c0[3]; + ctx->w1[0] = c1[0]; + ctx->w1[1] = c1[1]; + ctx->w1[2] = c1[2]; + ctx->w1[3] = c1[3]; + ctx->w2[0] = c2[0]; + ctx->w2[1] = c2[1]; + ctx->w2[2] = c2[2]; + ctx->w2[3] = c2[3]; + ctx->w3[0] = c3[0]; + ctx->w3[1] = c3[1]; + ctx->w3[2] = c3[2]; + ctx->w3[3] = c3[3]; + ctx->w4[0] = c4[0]; + ctx->w4[1] = c4[1]; + ctx->w4[2] = c4[2]; + ctx->w4[3] = c4[3]; + ctx->w5[0] = c5[0]; + ctx->w5[1] = c5[1]; + ctx->w5[2] = c5[2]; + ctx->w5[3] = c5[3]; + ctx->w6[0] = c6[0]; + ctx->w6[1] = c6[1]; + ctx->w6[2] = c6[2]; + ctx->w6[3] = c6[3]; + ctx->w7[0] = c7[0]; + ctx->w7[1] = c7[1]; + ctx->w7[2] = c7[2]; + ctx->w7[3] = c7[3]; + } +} + +void sha384_update_vector (sha384_ctx_vector_t *ctx, const u32x *w, const int len) +{ + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + u32x w4[4]; + u32x w5[4]; + u32x w6[4]; + u32x w7[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 128; pos1 += 128, pos4 += 32) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + w4[0] = w[pos4 + 16]; + w4[1] = w[pos4 + 17]; + w4[2] = w[pos4 + 18]; + w4[3] = w[pos4 + 19]; + w5[0] = w[pos4 + 20]; + w5[1] = w[pos4 + 21]; + w5[2] = w[pos4 + 22]; + w5[3] = w[pos4 + 23]; + w6[0] = w[pos4 + 24]; + w6[1] = w[pos4 + 25]; + w6[2] = w[pos4 + 26]; + w6[3] = w[pos4 + 27]; + w7[0] = w[pos4 + 28]; + w7[1] = w[pos4 + 29]; + w7[2] = w[pos4 + 30]; + w7[3] = w[pos4 + 31]; + + sha384_update_vector_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, 128); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + w4[0] = w[pos4 + 16]; + w4[1] = w[pos4 + 17]; + w4[2] = w[pos4 + 18]; + w4[3] = w[pos4 + 19]; + w5[0] = w[pos4 + 20]; + w5[1] = w[pos4 + 21]; + w5[2] = w[pos4 + 22]; + w5[3] = w[pos4 + 23]; + w6[0] = w[pos4 + 24]; + w6[1] = w[pos4 + 25]; + w6[2] = w[pos4 + 26]; + w6[3] = w[pos4 + 27]; + w7[0] = w[pos4 + 28]; + w7[1] = w[pos4 + 29]; + w7[2] = w[pos4 + 30]; + w7[3] = w[pos4 + 31]; + + sha384_update_vector_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, len - pos1); +} + +void sha384_final_vector (sha384_ctx_vector_t *ctx) +{ + int pos = ctx->len & 127; + + append_0x80_8x4 (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->w4, ctx->w5, ctx->w6, ctx->w7, pos ^ 3); + + if (pos >= 112) + { + sha384_transform_vector (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->w4, ctx->w5, ctx->w6, ctx->w7, ctx->h); + + ctx->w0[0] = 0; + ctx->w0[1] = 0; + ctx->w0[2] = 0; + ctx->w0[3] = 0; + ctx->w1[0] = 0; + ctx->w1[1] = 0; + ctx->w1[2] = 0; + ctx->w1[3] = 0; + ctx->w2[0] = 0; + ctx->w2[1] = 0; + ctx->w2[2] = 0; + ctx->w2[3] = 0; + ctx->w3[0] = 0; + ctx->w3[1] = 0; + ctx->w3[2] = 0; + ctx->w3[3] = 0; + ctx->w4[0] = 0; + ctx->w4[1] = 0; + ctx->w4[2] = 0; + ctx->w4[3] = 0; + ctx->w5[0] = 0; + ctx->w5[1] = 0; + ctx->w5[2] = 0; + ctx->w5[3] = 0; + ctx->w6[0] = 0; + ctx->w6[1] = 0; + ctx->w6[2] = 0; + ctx->w6[3] = 0; + ctx->w7[0] = 0; + ctx->w7[1] = 0; + ctx->w7[2] = 0; + ctx->w7[3] = 0; + } + + ctx->w7[2] = 0; + ctx->w7[3] = ctx->len * 8; + + sha384_transform_vector (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->w4, ctx->w5, ctx->w6, ctx->w7, ctx->h); +} diff --git a/OpenCL/m10800_a3-pure.cl b/OpenCL/m10800_a3-pure.cl new file mode 100644 index 000000000..ea2143d52 --- /dev/null +++ b/OpenCL/m10800_a3-pure.cl @@ -0,0 +1,144 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#include "inc_vendor.cl" +#include "inc_hash_constants.h" +#include "inc_hash_functions.cl" +#include "inc_types.cl" +#include "inc_common.cl" +#include "inc_simd.cl" +#include "inc_hash_sha384.cl" + +__kernel void m10800_mxx (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const u32x *words_buf_r, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global const void *esalt_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max) +{ + /** + * modifier + */ + + const u32 lid = get_local_id (0); + const u32 gid = get_global_id (0); + + if (gid >= gid_max) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + const u32 pw_lenv = ceil ((float) pw_len / 4); + + u32x w[64] = { 0 }; + + for (int idx = 0; idx < pw_lenv; idx++) + { + w[idx] = pws[gid].i[idx]; + + barrier (CLK_GLOBAL_MEM_FENCE); + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + sha384_ctx_vector_t ctx; + + sha384_init_vector (&ctx); + + sha384_update_vector (&ctx, w, pw_len); + + sha384_final_vector (&ctx); + + const u32x r0 = l32_from_64 (ctx.h[3]); + const u32x r1 = h32_from_64 (ctx.h[3]); + const u32x r2 = l32_from_64 (ctx.h[2]); + const u32x r3 = h32_from_64 (ctx.h[2]); + + COMPARE_M_SIMD (r0, r1, r2, r3); + } +} + +__kernel void m10800_sxx (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const u32x *words_buf_r, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global const void *esalt_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max) +{ + /** + * modifier + */ + + const u32 lid = get_local_id (0); + const u32 gid = get_global_id (0); + + if (gid >= gid_max) return; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[digests_offset].digest_buf[DGST_R0], + digests_buf[digests_offset].digest_buf[DGST_R1], + digests_buf[digests_offset].digest_buf[DGST_R2], + digests_buf[digests_offset].digest_buf[DGST_R3] + }; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + const u32 pw_lenv = ceil ((float) pw_len / 4); + + u32x w[64] = { 0 }; + + for (int idx = 0; idx < pw_lenv; idx++) + { + w[idx] = pws[gid].i[idx]; + + barrier (CLK_GLOBAL_MEM_FENCE); + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + sha384_ctx_vector_t ctx; + + sha384_init_vector (&ctx); + + sha384_update_vector (&ctx, w, pw_len); + + sha384_final_vector (&ctx); + + const u32x r0 = l32_from_64 (ctx.h[3]); + const u32x r1 = h32_from_64 (ctx.h[3]); + const u32x r2 = l32_from_64 (ctx.h[2]); + const u32x r3 = h32_from_64 (ctx.h[2]); + + COMPARE_S_SIMD (r0, r1, r2, r3); + } +}