1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-23 07:08:19 +00:00
hashcat/OpenCL/m31400_a3-pure.cl

509 lines
12 KiB
Common Lisp
Raw Normal View History

2023-03-15 20:22:10 +00:00
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
2023-03-15 20:22:10 +00:00
#define NEW_SIMD_CODE
#ifdef KERNEL_STATIC
#include M2S(INCLUDE_PATH/inc_vendor.h)
#include M2S(INCLUDE_PATH/inc_types.h)
#include M2S(INCLUDE_PATH/inc_platform.cl)
#include M2S(INCLUDE_PATH/inc_common.h)
#include M2S(INCLUDE_PATH/inc_common.cl)
#include M2S(INCLUDE_PATH/inc_rp.h)
#include M2S(INCLUDE_PATH/inc_rp.cl)
#include M2S(INCLUDE_PATH/inc_simd.cl)
#include M2S(INCLUDE_PATH/inc_scalar.cl)
#include M2S(INCLUDE_PATH/inc_hash_sha256.cl)
#include M2S(INCLUDE_PATH/inc_cipher_aes.h)
#include M2S(INCLUDE_PATH/inc_cipher_aes.cl)
#endif
typedef struct scrtv2
{
u32 ct_buf[64];
int ct_len;
} scrtv2_t;
DECLSPEC void shift_buffer_by_offset (PRIVATE_AS u32 *w0, const u32 offset)
2023-03-15 20:22:10 +00:00
{
const int offset_switch = offset / 4;
2023-03-15 20:22:10 +00:00
#if ((defined IS_AMD || defined IS_HIP) && HAS_VPERM == 0) || defined IS_GENERIC
switch (offset_switch)
{
2023-03-15 20:22:10 +00:00
case 0:
w0[3] = hc_bytealign_be_S (w0[2], w0[3], offset);
w0[2] = hc_bytealign_be_S (w0[1], w0[2], offset);
w0[1] = hc_bytealign_be_S (w0[0], w0[1], offset);
w0[0] = hc_bytealign_be_S ( 0, w0[0], offset);
break;
2023-03-15 20:22:10 +00:00
case 1:
w0[3] = hc_bytealign_be_S (w0[1], w0[2], offset);
w0[2] = hc_bytealign_be_S (w0[0], w0[1], offset);
w0[1] = hc_bytealign_be_S ( 0, w0[0], offset);
w0[0] = 0;
break;
2023-03-15 20:22:10 +00:00
case 2:
w0[3] = hc_bytealign_be_S (w0[0], w0[1], offset);
w0[2] = hc_bytealign_be_S ( 0, w0[0], offset);
w0[1] = 0;
w0[0] = 0;
break;
2023-03-15 20:22:10 +00:00
case 3:
w0[3] = hc_bytealign_be_S ( 0, w0[0], offset);
w0[2] = 0;
w0[1] = 0;
w0[0] = 0;
break;
2023-03-15 20:22:10 +00:00
default:
w0[3] = 0;
w0[2] = 0;
w0[1] = 0;
w0[0] = 0;
break;
}
#endif
#if ((defined IS_AMD || defined IS_HIP) && HAS_VPERM == 1) || defined IS_NV
#if defined IS_NV
const int selector = (0x76543210 >> ((offset & 3) * 4)) & 0xffff;
#endif
#if (defined IS_AMD || defined IS_HIP)
const int selector = l32_from_64_S(0x0706050403020100UL >> ((offset & 3) * 8));
#endif
switch (offset_switch)
{
2023-03-15 20:22:10 +00:00
case 0:
w0[3] = hc_byte_perm_S (w0[3], w0[2], selector);
w0[2] = hc_byte_perm_S (w0[2], w0[1], selector);
w0[1] = hc_byte_perm_S (w0[1], w0[0], selector);
w0[0] = hc_byte_perm_S (w0[0], 0, selector);
break;
2023-03-15 20:22:10 +00:00
case 1:
w0[3] = hc_byte_perm_S (w0[2], w0[1], selector);
w0[2] = hc_byte_perm_S (w0[1], w0[0], selector);
w0[1] = hc_byte_perm_S (w0[0], 0, selector);
w0[0] = 0;
break;
2023-03-15 20:22:10 +00:00
case 2:
w0[3] = hc_byte_perm_S (w0[1], w0[0], selector);
w0[2] = hc_byte_perm_S (w0[0], 0, selector);
w0[1] = 0;
w0[0] = 0;
break;
2023-03-15 20:22:10 +00:00
case 3:
w0[3] = hc_byte_perm_S (w0[0], 0, selector);
w0[2] = 0;
w0[1] = 0;
w0[0] = 0;
break;
2023-03-15 20:22:10 +00:00
default:
w0[3] = 0;
w0[2] = 0;
w0[1] = 0;
w0[0] = 0;
break;
}
#endif
2023-03-15 20:22:10 +00:00
}
2023-03-17 15:37:51 +00:00
DECLSPEC void aes256_scrt_format (PRIVATE_AS u32 *aes_ks, PRIVATE_AS u32 *pw, const u32 pw_len, PRIVATE_AS u32 *hash, PRIVATE_AS u32 *out, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4)
2023-03-15 20:22:10 +00:00
{
AES256_set_encrypt_key (aes_ks, hash, s_te0, s_te1, s_te2, s_te3);
shift_buffer_by_offset (hash, pw_len + 4);
2023-03-15 20:22:10 +00:00
hash[0] = hc_swap32_S (pw_len);
hash[1] |= hc_swap32_S (pw[0]);
hash[2] |= hc_swap32_S (pw[1]);
hash[3] |= hc_swap32_S (pw[2]);
2023-03-15 20:22:10 +00:00
AES256_encrypt (aes_ks, hash, out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-15 20:22:10 +00:00
}
2023-03-17 15:38:48 +00:00
DECLSPEC void aes256_scrt_format_VV (PRIVATE_AS u32 *aes_ks, PRIVATE_AS u32x *w, const u32 pw_len, PRIVATE_AS u32x *h, PRIVATE_AS u32x *out, SHM_TYPE u32 *s_te0, SHM_TYPE u32 *s_te1, SHM_TYPE u32 *s_te2, SHM_TYPE u32 *s_te3, SHM_TYPE u32 *s_te4)
2023-03-15 20:22:10 +00:00
{
#if VECT_SIZE == 1
aes256_scrt_format (aes_ks, w, pw_len, h, out, s_te0, s_te1, s_te2, s_te3, s_te4);
#endif
2023-03-15 20:22:10 +00:00
#if VECT_SIZE >= 2
u32 tmp_w[4];
u32 tmp_h[8];
u32 tmp_out[4];
2023-03-16 18:08:57 +00:00
//s0
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].s0;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].s0;
2023-03-16 18:08:57 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-17 03:04:10 +00:00
for (u32 i = 0; i < 4; i++) out[i].s0 = tmp_out[i];
2023-03-16 18:08:57 +00:00
//s1
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].s1;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].s1;
2023-03-16 18:08:57 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) out[i].s1 = tmp_out[i];
2023-03-17 03:04:10 +00:00
#endif
2023-03-16 18:08:57 +00:00
#if VECT_SIZE >= 4
2023-03-16 18:08:57 +00:00
//s2
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].s2;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].s2;
2023-03-15 20:22:10 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) out[i].s2 = tmp_out[i];
2023-03-17 03:04:10 +00:00
//s3
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].s3;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].s3;
2023-03-16 18:08:57 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) out[i].s3 = tmp_out[i];
2023-03-16 18:08:57 +00:00
#endif
2023-03-16 18:08:57 +00:00
#if VECT_SIZE >= 8
2023-03-16 18:08:57 +00:00
//s4
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].s4;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].s4;
2023-03-15 20:22:10 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) out[i].s4 = tmp_out[i];
2023-03-17 03:04:10 +00:00
//s5
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].s5;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].s5;
2023-03-16 18:08:57 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-17 03:04:10 +00:00
for (u32 i = 0; i < 4; i++) out[i].s5 = tmp_out[i];
2023-03-16 18:08:57 +00:00
//s6
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].s6;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].s6;
2023-03-16 18:08:57 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) out[i].s6 = tmp_out[i];
2023-03-16 18:08:57 +00:00
//s7
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].s7;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].s7;
2023-03-16 18:08:57 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) out[i].s7 = tmp_out[i];
2023-03-17 03:04:10 +00:00
#endif
2023-03-16 18:08:57 +00:00
#if VECT_SIZE >= 16
2023-03-16 18:08:57 +00:00
//s8
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].s8;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].s8;
2023-03-16 18:08:57 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-17 03:04:10 +00:00
for (u32 i = 0; i < 4; i++) out[i].s8 = tmp_out[i];
2023-03-16 18:08:57 +00:00
//s9
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].s9;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].s9;
2023-03-16 18:08:57 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) out[i].s9 = tmp_out[i];
2023-03-17 03:04:10 +00:00
//sa
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].sa;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].sa;
2023-03-16 18:08:57 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) out[i].sa = tmp_out[i];
2023-03-16 18:08:57 +00:00
//sb
2023-03-17 03:04:10 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].sb;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].sb;
2023-03-16 18:08:57 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) out[i].sb = tmp_out[i];
2023-03-17 03:04:10 +00:00
//sc
2023-03-17 03:04:10 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].sc;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].sc;
2023-03-17 03:04:10 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-17 03:04:10 +00:00
for (u32 i = 0; i < 4; i++) out[i].sc = tmp_out[i];
2023-03-16 18:08:57 +00:00
//sd
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].sd;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].sd;
2023-03-17 03:04:10 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) out[i].sd = tmp_out[i];
2023-03-16 18:08:57 +00:00
//se
2023-03-16 18:08:57 +00:00
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].se;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].se;
2023-03-17 03:04:10 +00:00
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
for (u32 i = 0; i < 4; i++) out[i].se = tmp_out[i];
//sf
for (u32 i = 0; i < 4; i++) tmp_w[i] = w[i].sf;
for (u32 i = 0; i < 8; i++) tmp_h[i] = h[i].sf;
aes256_scrt_format (aes_ks, tmp_w, pw_len, tmp_h, tmp_out, s_te0, s_te1, s_te2, s_te3, s_te4);
for (u32 i = 0; i < 4; i++) out[i].sf = tmp_out[i];
#endif
2023-03-15 20:22:10 +00:00
}
KERNEL_FQ void m31400_mxx (KERN_ATTR_VECTOR_ESALT (scrtv2_t))
2023-03-15 20:22:10 +00:00
{
/**
* modifier
*/
2023-03-15 20:22:10 +00:00
const u64 lid = get_local_id (0);
const u64 gid = get_global_id (0);
const u64 lsz = get_local_size (0);
2023-03-15 20:22:10 +00:00
/**
* aes shared
*/
2023-03-15 20:22:10 +00:00
#ifdef REAL_SHM
2023-03-15 20:22:10 +00:00
LOCAL_VK u32 s_te0[256];
LOCAL_VK u32 s_te1[256];
LOCAL_VK u32 s_te2[256];
LOCAL_VK u32 s_te3[256];
LOCAL_VK u32 s_te4[256];
2023-03-15 20:22:10 +00:00
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];
}
2023-03-15 20:22:10 +00:00
SYNC_THREADS();
2023-03-15 20:22:10 +00:00
#else
2023-03-15 20:22:10 +00:00
CONSTANT_AS u32a *s_te0 = te0;
CONSTANT_AS u32a *s_te1 = te1;
CONSTANT_AS u32a *s_te2 = te2;
CONSTANT_AS u32a *s_te3 = te3;
CONSTANT_AS u32a *s_te4 = te4;
2023-03-15 20:22:10 +00:00
#endif
2023-03-15 20:22:10 +00:00
if (gid >= GID_CNT) return;
2023-03-15 20:22:10 +00:00
/**
* base
*/
2023-03-15 20:22:10 +00:00
u32 ks[60];
2023-03-15 20:22:10 +00:00
u32x w[64] = {0};
2023-03-15 20:22:10 +00:00
const u32 pw_len = pws[gid].pw_len;
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
2023-03-15 20:22:10 +00:00
/**
* loop
*/
2023-03-15 20:22:10 +00:00
u32x w0l = w[0];
2023-03-15 20:22:10 +00:00
for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE)
{
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
2023-03-15 20:22:10 +00:00
const u32x w0 = w0l | w0r;
2023-03-15 20:22:10 +00:00
w[0] = w0;
2023-03-15 20:22:10 +00:00
sha256_ctx_vector_t ctx;
2023-03-15 20:22:10 +00:00
sha256_init_vector (&ctx);
2023-03-15 20:22:10 +00:00
sha256_update_vector_swap (&ctx, w, pw_len);
2023-03-15 20:22:10 +00:00
sha256_final_vector (&ctx);
2023-03-15 20:22:10 +00:00
u32x out[4] = { 0 };
2023-03-15 20:22:10 +00:00
aes256_scrt_format_VV (ks, w, pw_len, ctx.h, out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-15 20:22:10 +00:00
const u32x r0 = out[DGST_R0];
const u32x r1 = out[DGST_R1];
const u32x r2 = out[DGST_R2];
const u32x r3 = out[DGST_R3];
2023-03-15 20:22:10 +00:00
COMPARE_M_SIMD (r0, r1, r2, r3);
}
2023-03-15 20:22:10 +00:00
}
KERNEL_FQ void m31400_sxx (KERN_ATTR_VECTOR_ESALT (scrtv2_t))
2023-03-15 20:22:10 +00:00
{
/**
* modifier
*/
2023-03-15 20:22:10 +00:00
const u64 lid = get_local_id (0);
const u64 gid = get_global_id (0);
const u64 lsz = get_local_size (0);
2023-03-15 20:22:10 +00:00
/**
* aes shared
*/
2023-03-15 20:22:10 +00:00
#ifdef REAL_SHM
2023-03-15 20:22:10 +00:00
LOCAL_VK u32 s_te0[256];
LOCAL_VK u32 s_te1[256];
LOCAL_VK u32 s_te2[256];
LOCAL_VK u32 s_te3[256];
LOCAL_VK u32 s_te4[256];
2023-03-15 20:22:10 +00:00
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];
}
2023-03-15 20:22:10 +00:00
SYNC_THREADS();
2023-03-15 20:22:10 +00:00
#else
2023-03-15 20:22:10 +00:00
CONSTANT_AS u32a *s_te0 = te0;
CONSTANT_AS u32a *s_te1 = te1;
CONSTANT_AS u32a *s_te2 = te2;
CONSTANT_AS u32a *s_te3 = te3;
CONSTANT_AS u32a *s_te4 = te4;
2023-03-15 20:22:10 +00:00
#endif
2023-03-15 20:22:10 +00:00
if (gid >= GID_CNT) return;
2023-03-15 20:22:10 +00:00
/**
* digest
*/
2023-03-15 20:22:10 +00:00
const u32 search[4] =
{
digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0],
digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1],
digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2],
digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3]
};
2023-03-15 20:22:10 +00:00
/**
* base
*/
2023-03-15 20:22:10 +00:00
u32 ks[60];
2023-03-15 20:22:10 +00:00
u32x w[64] = { 0 };
const u32 pw_len = pws[gid].pw_len;
2023-03-15 20:22:10 +00:00
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
2023-03-15 20:22:10 +00:00
/**
* loop
*/
2023-03-15 20:22:10 +00:00
u32x w0l = w[0];
2023-03-15 20:22:10 +00:00
for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE)
{
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
2023-03-15 20:22:10 +00:00
const u32x w0 = w0l | w0r;
2023-03-15 20:22:10 +00:00
w[0] = w0;
2023-03-15 20:22:10 +00:00
sha256_ctx_vector_t ctx;
2023-03-15 20:22:10 +00:00
sha256_init_vector (&ctx);
2023-03-15 20:22:10 +00:00
sha256_update_vector_swap (&ctx, w, pw_len);
2023-03-15 20:22:10 +00:00
sha256_final_vector (&ctx);
u32x out[4] = { 0 };
2023-03-15 20:22:10 +00:00
aes256_scrt_format_VV (ks, w, pw_len, ctx.h, out, s_te0, s_te1, s_te2, s_te3, s_te4);
2023-03-15 20:22:10 +00:00
const u32x r0 = out[DGST_R0];
const u32x r1 = out[DGST_R1];
const u32x r2 = out[DGST_R2];
const u32x r3 = out[DGST_R3];
2023-03-15 20:22:10 +00:00
COMPARE_S_SIMD (r0, r1, r2, r3);
}
2023-03-15 20:22:10 +00:00
}