2015-12-04 14:47:52 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2015-12-04 14:47:52 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
#define NEW_SIMD_CODE
|
|
|
|
|
2016-05-25 21:04:26 +00:00
|
|
|
#include "inc_vendor.cl"
|
2016-06-26 21:39:42 +00:00
|
|
|
#include "inc_hash_constants.h"
|
2016-05-25 21:04:26 +00:00
|
|
|
#include "inc_hash_functions.cl"
|
|
|
|
#include "inc_types.cl"
|
|
|
|
#include "inc_common.cl"
|
2017-07-07 08:03:59 +00:00
|
|
|
#include "inc_simd.cl"
|
|
|
|
#include "inc_hash_sha1.cl"
|
2017-07-07 09:35:47 +00:00
|
|
|
#include "inc_cipher_aes.cl"
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-05-25 21:04:26 +00:00
|
|
|
#define COMPARE_S "inc_comp_single.cl"
|
|
|
|
#define COMPARE_M "inc_comp_multi.cl"
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-08-19 14:39:22 +00:00
|
|
|
__kernel void m09500_init (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global office2010_tmp_t *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 office2010_t *office2010_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 u64 gid_max)
|
2015-12-04 14:47:52 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* base
|
|
|
|
*/
|
|
|
|
|
2017-08-19 14:39:22 +00:00
|
|
|
const u64 gid = get_global_id (0);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
if (gid >= gid_max) return;
|
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_ctx_t ctx;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_init (&ctx);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_update_global (&ctx, salt_bufs[salt_pos].salt_buf, salt_bufs[salt_pos].salt_len);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_update_global_utf16le_swap (&ctx, pws[gid].i, pws[gid].pw_len);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_final (&ctx);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
tmps[gid].out[0] = ctx.h[0];
|
|
|
|
tmps[gid].out[1] = ctx.h[1];
|
|
|
|
tmps[gid].out[2] = ctx.h[2];
|
|
|
|
tmps[gid].out[3] = ctx.h[3];
|
|
|
|
tmps[gid].out[4] = ctx.h[4];
|
2015-12-04 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 14:39:22 +00:00
|
|
|
__kernel void m09500_loop (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global office2010_tmp_t *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 office2010_t *office2010_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 u64 gid_max)
|
2015-12-04 14:47:52 +00:00
|
|
|
{
|
2017-08-19 14:39:22 +00:00
|
|
|
const u64 gid = get_global_id (0);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
if ((gid * VECT_SIZE) >= gid_max) return;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:42:39 +00:00
|
|
|
u32x t0 = packv (tmps, out, gid, 0);
|
|
|
|
u32x t1 = packv (tmps, out, gid, 1);
|
|
|
|
u32x t2 = packv (tmps, out, gid, 2);
|
|
|
|
u32x t3 = packv (tmps, out, gid, 3);
|
|
|
|
u32x t4 = packv (tmps, out, gid, 4);
|
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
u32x w0[4];
|
|
|
|
u32x w1[4];
|
|
|
|
u32x w2[4];
|
|
|
|
u32x w3[4];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
w0[0] = 0;
|
2017-07-07 08:42:39 +00:00
|
|
|
w0[1] = 0;
|
|
|
|
w0[2] = 0;
|
|
|
|
w0[3] = 0;
|
|
|
|
w1[0] = 0;
|
|
|
|
w1[1] = 0;
|
2015-12-04 14:47:52 +00:00
|
|
|
w1[2] = 0x80000000;
|
|
|
|
w1[3] = 0;
|
|
|
|
w2[0] = 0;
|
|
|
|
w2[1] = 0;
|
|
|
|
w2[2] = 0;
|
|
|
|
w2[3] = 0;
|
|
|
|
w3[0] = 0;
|
|
|
|
w3[1] = 0;
|
|
|
|
w3[2] = 0;
|
|
|
|
w3[3] = (4 + 20) * 8;
|
|
|
|
|
|
|
|
for (u32 i = 0, j = loop_pos; i < loop_cnt; i++, j++)
|
|
|
|
{
|
2015-12-15 15:50:21 +00:00
|
|
|
w0[0] = swap32 (j);
|
2017-07-07 08:42:39 +00:00
|
|
|
w0[1] = t0;
|
|
|
|
w0[2] = t1;
|
|
|
|
w0[3] = t2;
|
|
|
|
w1[0] = t3;
|
|
|
|
w1[1] = t4;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
u32x digest[5];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
digest[0] = SHA1M_A;
|
|
|
|
digest[1] = SHA1M_B;
|
|
|
|
digest[2] = SHA1M_C;
|
|
|
|
digest[3] = SHA1M_D;
|
|
|
|
digest[4] = SHA1M_E;
|
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_transform_vector (w0, w1, w2, w3, digest);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:42:39 +00:00
|
|
|
t0 = digest[0];
|
|
|
|
t1 = digest[1];
|
|
|
|
t2 = digest[2];
|
|
|
|
t3 = digest[3];
|
|
|
|
t4 = digest[4];
|
2015-12-04 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 08:42:39 +00:00
|
|
|
unpackv (tmps, out, gid, 0, t0);
|
|
|
|
unpackv (tmps, out, gid, 1, t1);
|
|
|
|
unpackv (tmps, out, gid, 2, t2);
|
|
|
|
unpackv (tmps, out, gid, 3, t3);
|
|
|
|
unpackv (tmps, out, gid, 4, t4);
|
2015-12-04 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 14:39:22 +00:00
|
|
|
__kernel void m09500_comp (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global office2010_tmp_t *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 office2010_t *office2010_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 u64 gid_max)
|
2015-12-04 14:47:52 +00:00
|
|
|
{
|
2017-08-19 14:39:22 +00:00
|
|
|
const u64 gid = get_global_id (0);
|
|
|
|
const u64 lid = get_local_id (0);
|
|
|
|
const u64 lsz = get_local_size (0);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* aes shared
|
|
|
|
*/
|
|
|
|
|
2017-07-07 09:35:47 +00:00
|
|
|
#ifdef REAL_SHM
|
|
|
|
|
2015-12-04 14:47:52 +00:00
|
|
|
__local u32 s_td0[256];
|
|
|
|
__local u32 s_td1[256];
|
|
|
|
__local u32 s_td2[256];
|
|
|
|
__local u32 s_td3[256];
|
|
|
|
__local u32 s_td4[256];
|
|
|
|
|
|
|
|
__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];
|
|
|
|
|
2016-01-19 15:06:03 +00:00
|
|
|
for (u32 i = lid; i < 256; i += lsz)
|
|
|
|
{
|
|
|
|
s_td0[i] = td0[i];
|
|
|
|
s_td1[i] = td1[i];
|
|
|
|
s_td2[i] = td2[i];
|
|
|
|
s_td3[i] = td3[i];
|
|
|
|
s_td4[i] = td4[i];
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
barrier (CLK_LOCAL_MEM_FENCE);
|
|
|
|
|
2017-07-07 09:35:47 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
__constant u32a *s_td0 = td0;
|
|
|
|
__constant u32a *s_td1 = td1;
|
|
|
|
__constant u32a *s_td2 = td2;
|
|
|
|
__constant u32a *s_td3 = td3;
|
|
|
|
__constant u32a *s_td4 = td4;
|
|
|
|
|
|
|
|
__constant u32a *s_te0 = te0;
|
|
|
|
__constant u32a *s_te1 = te1;
|
|
|
|
__constant u32a *s_te2 = te2;
|
|
|
|
__constant u32a *s_te3 = te3;
|
|
|
|
__constant u32a *s_te4 = te4;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-12-04 14:47:52 +00:00
|
|
|
if (gid >= gid_max) return;
|
|
|
|
|
2016-01-19 15:06:03 +00:00
|
|
|
/**
|
|
|
|
* base
|
|
|
|
*/
|
|
|
|
|
2015-12-15 11:04:22 +00:00
|
|
|
u32 encryptedVerifierHashInputBlockKey[2] = { 0xfea7d276, 0x3b4b9e79 };
|
|
|
|
u32 encryptedVerifierHashValueBlockKey[2] = { 0xd7aa0f6d, 0x3061344e };
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2015-12-15 11:04:22 +00:00
|
|
|
u32 w0[4];
|
|
|
|
u32 w1[4];
|
|
|
|
u32 w2[4];
|
|
|
|
u32 w3[4];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
w0[0] = tmps[gid].out[0];
|
|
|
|
w0[1] = tmps[gid].out[1];
|
|
|
|
w0[2] = tmps[gid].out[2];
|
|
|
|
w0[3] = tmps[gid].out[3];
|
|
|
|
w1[0] = tmps[gid].out[4];
|
|
|
|
w1[1] = encryptedVerifierHashInputBlockKey[0];
|
|
|
|
w1[2] = encryptedVerifierHashInputBlockKey[1];
|
2017-07-07 08:03:59 +00:00
|
|
|
w1[3] = 0;
|
2015-12-04 14:47:52 +00:00
|
|
|
w2[0] = 0;
|
|
|
|
w2[1] = 0;
|
|
|
|
w2[2] = 0;
|
|
|
|
w2[3] = 0;
|
|
|
|
w3[0] = 0;
|
|
|
|
w3[1] = 0;
|
|
|
|
w3[2] = 0;
|
2017-07-07 08:03:59 +00:00
|
|
|
w3[3] = 0;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_ctx_t ctx;
|
|
|
|
|
|
|
|
sha1_init (&ctx);
|
|
|
|
|
|
|
|
sha1_update_64 (&ctx, w0, w1, w2, w3, 20 + 8);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_final (&ctx);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 09:35:47 +00:00
|
|
|
u32 digest0[4];
|
2017-07-07 08:03:59 +00:00
|
|
|
|
|
|
|
digest0[0] = ctx.h[0];
|
|
|
|
digest0[1] = ctx.h[1];
|
|
|
|
digest0[2] = ctx.h[2];
|
|
|
|
digest0[3] = ctx.h[3];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
w0[0] = tmps[gid].out[0];
|
|
|
|
w0[1] = tmps[gid].out[1];
|
|
|
|
w0[2] = tmps[gid].out[2];
|
|
|
|
w0[3] = tmps[gid].out[3];
|
|
|
|
w1[0] = tmps[gid].out[4];
|
|
|
|
w1[1] = encryptedVerifierHashValueBlockKey[0];
|
|
|
|
w1[2] = encryptedVerifierHashValueBlockKey[1];
|
2017-07-07 08:03:59 +00:00
|
|
|
w1[3] = 0;
|
2015-12-04 14:47:52 +00:00
|
|
|
w2[0] = 0;
|
|
|
|
w2[1] = 0;
|
|
|
|
w2[2] = 0;
|
|
|
|
w2[3] = 0;
|
|
|
|
w3[0] = 0;
|
|
|
|
w3[1] = 0;
|
|
|
|
w3[2] = 0;
|
2017-07-07 08:03:59 +00:00
|
|
|
w3[3] = 0;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_init (&ctx);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_update_64 (&ctx, w0, w1, w2, w3, 20 + 8);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_final (&ctx);
|
|
|
|
|
2017-07-07 09:35:47 +00:00
|
|
|
u32 digest1[4];
|
2017-07-07 08:03:59 +00:00
|
|
|
|
|
|
|
digest1[0] = ctx.h[0];
|
|
|
|
digest1[1] = ctx.h[1];
|
|
|
|
digest1[2] = ctx.h[2];
|
|
|
|
digest1[3] = ctx.h[3];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
// now we got the AES key, decrypt the verifier
|
|
|
|
|
2017-07-09 15:39:38 +00:00
|
|
|
u32 ukey[4];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-09 15:39:38 +00:00
|
|
|
ukey[0] = digest0[0];
|
|
|
|
ukey[1] = digest0[1];
|
|
|
|
ukey[2] = digest0[2];
|
|
|
|
ukey[3] = digest0[3];
|
2017-07-07 09:35:47 +00:00
|
|
|
|
|
|
|
u32 ks[44];
|
|
|
|
|
2017-07-09 15:39:38 +00:00
|
|
|
AES128_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_te4, s_td0, s_td1, s_td2, s_td3, s_td4);
|
2017-07-07 09:35:47 +00:00
|
|
|
|
|
|
|
u32 data[4];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 09:35:47 +00:00
|
|
|
data[0] = office2010_bufs[digests_offset].encryptedVerifier[0];
|
|
|
|
data[1] = office2010_bufs[digests_offset].encryptedVerifier[1];
|
|
|
|
data[2] = office2010_bufs[digests_offset].encryptedVerifier[2];
|
|
|
|
data[3] = office2010_bufs[digests_offset].encryptedVerifier[3];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
u32 out[4];
|
|
|
|
|
2017-07-09 15:39:38 +00:00
|
|
|
AES128_decrypt (ks, data, out, s_td0, s_td1, s_td2, s_td3, s_td4);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
out[0] ^= salt_bufs[salt_pos].salt_buf[0];
|
|
|
|
out[1] ^= salt_bufs[salt_pos].salt_buf[1];
|
|
|
|
out[2] ^= salt_bufs[salt_pos].salt_buf[2];
|
|
|
|
out[3] ^= salt_bufs[salt_pos].salt_buf[3];
|
|
|
|
|
|
|
|
// do a sha1 of the result
|
|
|
|
|
|
|
|
w0[0] = out[0];
|
|
|
|
w0[1] = out[1];
|
|
|
|
w0[2] = out[2];
|
|
|
|
w0[3] = out[3];
|
2017-07-07 08:03:59 +00:00
|
|
|
w1[0] = 0;
|
2015-12-04 14:47:52 +00:00
|
|
|
w1[1] = 0;
|
|
|
|
w1[2] = 0;
|
|
|
|
w1[3] = 0;
|
|
|
|
w2[0] = 0;
|
|
|
|
w2[1] = 0;
|
|
|
|
w2[2] = 0;
|
|
|
|
w2[3] = 0;
|
|
|
|
w3[0] = 0;
|
|
|
|
w3[1] = 0;
|
|
|
|
w3[2] = 0;
|
2017-07-07 08:03:59 +00:00
|
|
|
w3[3] = 0;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_init (&ctx);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
sha1_update_64 (&ctx, w0, w1, w2, w3, 16);
|
|
|
|
|
|
|
|
sha1_final (&ctx);
|
|
|
|
|
2017-07-07 09:35:47 +00:00
|
|
|
u32 digest[4];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-07 08:03:59 +00:00
|
|
|
digest[0] = ctx.h[0];
|
|
|
|
digest[1] = ctx.h[1];
|
|
|
|
digest[2] = ctx.h[2];
|
|
|
|
digest[3] = ctx.h[3];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
// encrypt it again for verify
|
|
|
|
|
2017-07-09 15:39:38 +00:00
|
|
|
ukey[0] = digest1[0];
|
|
|
|
ukey[1] = digest1[1];
|
|
|
|
ukey[2] = digest1[2];
|
|
|
|
ukey[3] = digest1[3];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-09 15:39:38 +00:00
|
|
|
AES128_set_encrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_te4);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
data[0] = digest[0] ^ salt_bufs[salt_pos].salt_buf[0];
|
|
|
|
data[1] = digest[1] ^ salt_bufs[salt_pos].salt_buf[1];
|
|
|
|
data[2] = digest[2] ^ salt_bufs[salt_pos].salt_buf[2];
|
|
|
|
data[3] = digest[3] ^ salt_bufs[salt_pos].salt_buf[3];
|
|
|
|
|
2017-07-09 15:39:38 +00:00
|
|
|
AES128_encrypt (ks, data, out, s_te0, s_te1, s_te2, s_te3, s_te4);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2015-12-15 11:04:22 +00:00
|
|
|
const u32 r0 = out[0];
|
|
|
|
const u32 r1 = out[1];
|
|
|
|
const u32 r2 = out[2];
|
|
|
|
const u32 r3 = out[3];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
#define il_pos 0
|
|
|
|
|
2015-12-15 11:04:22 +00:00
|
|
|
#include COMPARE_M
|
2015-12-04 14:47:52 +00:00
|
|
|
}
|