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-18 11:23:42 +00:00
|
|
|
//#define NEW_SIMD_CODE
|
|
|
|
|
2019-03-22 14:16:25 +00:00
|
|
|
#ifdef KERNEL_STATIC
|
2019-03-21 22:00:38 +00:00
|
|
|
#include "inc_vendor.h"
|
|
|
|
#include "inc_types.h"
|
2016-05-25 21:04:26 +00:00
|
|
|
#include "inc_common.cl"
|
2017-07-18 11:23:42 +00:00
|
|
|
#include "inc_hash_md5.cl"
|
2019-03-22 14:16:25 +00:00
|
|
|
#endif
|
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
|
|
|
|
2018-02-15 14:35:22 +00:00
|
|
|
#define PUTCHAR_LE(a,p,c) ((u8 *)(a))[(p)] = (u8) (c)
|
|
|
|
#define GETCHAR_LE(a,p) ((u8 *)(a))[(p)]
|
|
|
|
|
2019-03-08 09:18:20 +00:00
|
|
|
typedef struct md5crypt_tmp
|
|
|
|
{
|
|
|
|
u32 digest_buf[4];
|
|
|
|
|
|
|
|
} md5crypt_tmp_t;
|
|
|
|
|
2016-01-22 11:35:27 +00:00
|
|
|
#define md5apr1_magic0 0x72706124u
|
|
|
|
#define md5apr1_magic1 0x00002431u
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2019-03-22 21:27:58 +00:00
|
|
|
KERNEL_FQ void m01600_init (KERN_ATTR_TMPS (md5crypt_tmp_t))
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* init
|
|
|
|
*/
|
|
|
|
|
2019-02-26 20:20:07 +00:00
|
|
|
const u32 pw_len = pws[gid].pw_len;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
u32 w[64] = { 0 };
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-08-17 11:43:35 +00:00
|
|
|
for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
2017-07-18 11:23:42 +00:00
|
|
|
{
|
|
|
|
w[idx] = pws[gid].i[idx];
|
|
|
|
}
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
const u32 salt_len = salt_bufs[salt_pos].salt_len;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
u32 s[64] = { 0 };
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-08-17 11:43:35 +00:00
|
|
|
for (int i = 0, idx = 0; i < salt_len; i += 4, idx += 1)
|
2017-07-18 11:23:42 +00:00
|
|
|
{
|
|
|
|
s[idx] = salt_bufs[salt_pos].salt_buf[idx];
|
|
|
|
}
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
/**
|
|
|
|
* prepare
|
|
|
|
*/
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_ctx_t md5_ctx1;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_init (&md5_ctx1);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_update (&md5_ctx1, w, pw_len);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_update (&md5_ctx1, s, salt_len);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_update (&md5_ctx1, w, pw_len);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_final (&md5_ctx1);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
u32 final[16] = { 0 };
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
final[0] = md5_ctx1.h[0];
|
|
|
|
final[1] = md5_ctx1.h[1];
|
|
|
|
final[2] = md5_ctx1.h[2];
|
|
|
|
final[3] = md5_ctx1.h[3];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_ctx_t md5_ctx;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_init (&md5_ctx);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_update (&md5_ctx, w, pw_len);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
u32 m[16] = { 0 };
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
m[0] = md5apr1_magic0;
|
|
|
|
m[1] = md5apr1_magic1;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_update (&md5_ctx, m, 6);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_update (&md5_ctx, s, salt_len);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
int pl;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-08-16 11:46:40 +00:00
|
|
|
for (pl = pw_len; pl > 16; pl -= 16)
|
2017-07-18 11:23:42 +00:00
|
|
|
{
|
|
|
|
md5_update (&md5_ctx, final, 16);
|
|
|
|
}
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-08-24 18:07:43 +00:00
|
|
|
truncate_block_4x4_le_S (final, pl);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_update (&md5_ctx, final, pl);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
/* Then something really weird... */
|
|
|
|
|
2017-08-16 11:46:40 +00:00
|
|
|
for (int i = pw_len; i != 0; i >>= 1)
|
2015-12-04 14:47:52 +00:00
|
|
|
{
|
2017-07-18 11:23:42 +00:00
|
|
|
u32 t[16] = { 0 };
|
|
|
|
|
2017-08-16 11:46:40 +00:00
|
|
|
if (i & 1)
|
2017-07-18 11:23:42 +00:00
|
|
|
{
|
|
|
|
t[0] = 0;
|
|
|
|
}
|
|
|
|
else
|
2015-12-04 14:47:52 +00:00
|
|
|
{
|
2017-07-18 11:23:42 +00:00
|
|
|
t[0] = w[0] & 0xff;
|
2015-12-04 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_update (&md5_ctx, t, 1);
|
2015-12-04 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_final (&md5_ctx);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
tmps[gid].digest_buf[0] = md5_ctx.h[0];
|
|
|
|
tmps[gid].digest_buf[1] = md5_ctx.h[1];
|
|
|
|
tmps[gid].digest_buf[2] = md5_ctx.h[2];
|
|
|
|
tmps[gid].digest_buf[3] = md5_ctx.h[3];
|
2015-12-04 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 21:27:58 +00:00
|
|
|
KERNEL_FQ void m01600_loop (KERN_ATTR_TMPS (md5crypt_tmp_t))
|
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-18 11:23:42 +00:00
|
|
|
/**
|
|
|
|
* init
|
|
|
|
*/
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2019-02-26 20:20:07 +00:00
|
|
|
const u32 pw_len = pws[gid].pw_len;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
u32 w[64] = { 0 };
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-08-17 11:43:35 +00:00
|
|
|
for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
2017-07-18 11:23:42 +00:00
|
|
|
{
|
|
|
|
w[idx] = pws[gid].i[idx];
|
|
|
|
}
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
const u32 salt_len = salt_bufs[salt_pos].salt_len;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
u32 s[64] = { 0 };
|
|
|
|
|
2017-08-17 11:43:35 +00:00
|
|
|
for (int i = 0, idx = 0; i < salt_len; i += 4, idx += 1)
|
2017-07-18 11:23:42 +00:00
|
|
|
{
|
|
|
|
s[idx] = salt_bufs[salt_pos].salt_buf[idx];
|
|
|
|
}
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* digest
|
|
|
|
*/
|
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
u32 digest[4];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
digest[0] = tmps[gid].digest_buf[0];
|
|
|
|
digest[1] = tmps[gid].digest_buf[1];
|
|
|
|
digest[2] = tmps[gid].digest_buf[2];
|
|
|
|
digest[3] = tmps[gid].digest_buf[3];
|
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
u32 wpc_len[8];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
wpc_len[0] = 16 + 0 + 0 + pw_len;
|
|
|
|
wpc_len[1] = pw_len + 0 + 0 + 16;
|
|
|
|
wpc_len[2] = 16 + salt_len + 0 + pw_len;
|
|
|
|
wpc_len[3] = pw_len + salt_len + 0 + 16;
|
|
|
|
wpc_len[4] = 16 + 0 + pw_len + pw_len;
|
|
|
|
wpc_len[5] = pw_len + 0 + pw_len + 16;
|
|
|
|
wpc_len[6] = 16 + salt_len + pw_len + pw_len;
|
|
|
|
wpc_len[7] = pw_len + salt_len + pw_len + 16;
|
2018-02-14 18:13:23 +00:00
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
// largest possible wpc_len[7] is not enough because of zero buffer loop
|
2018-02-14 18:13:23 +00:00
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
u32 wpc[8][64 + 64 + 64 + 64];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
#ifdef _unroll
|
|
|
|
#pragma unroll
|
|
|
|
#endif
|
|
|
|
for (u32 i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
u32 block_len = 0;
|
2018-02-14 18:13:23 +00:00
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
if (i & 1)
|
2015-12-04 14:47:52 +00:00
|
|
|
{
|
2018-02-15 11:31:59 +00:00
|
|
|
for (u32 j = 0; j < pw_len; j++)
|
|
|
|
{
|
|
|
|
PUTCHAR_LE (wpc[i], block_len++, GETCHAR_LE (w, j));
|
|
|
|
}
|
2017-07-18 11:23:42 +00:00
|
|
|
}
|
2018-02-15 11:31:59 +00:00
|
|
|
else
|
2017-07-18 11:23:42 +00:00
|
|
|
{
|
2018-02-15 11:31:59 +00:00
|
|
|
block_len += 16;
|
2017-07-18 11:23:42 +00:00
|
|
|
}
|
2018-02-15 11:31:59 +00:00
|
|
|
|
|
|
|
if (i & 2)
|
2017-07-18 11:23:42 +00:00
|
|
|
{
|
2018-02-15 11:31:59 +00:00
|
|
|
for (u32 j = 0; j < salt_len; j++)
|
|
|
|
{
|
|
|
|
PUTCHAR_LE (wpc[i], block_len++, GETCHAR_LE (s, j));
|
|
|
|
}
|
2015-12-04 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
if (i & 4)
|
|
|
|
{
|
|
|
|
for (u32 j = 0; j < pw_len; j++)
|
|
|
|
{
|
|
|
|
PUTCHAR_LE (wpc[i], block_len++, GETCHAR_LE (w, j));
|
|
|
|
}
|
2018-02-14 18:13:23 +00:00
|
|
|
}
|
2018-02-15 11:31:59 +00:00
|
|
|
|
|
|
|
if (i & 1)
|
2017-07-18 11:23:42 +00:00
|
|
|
{
|
2018-02-15 11:31:59 +00:00
|
|
|
block_len += 16;
|
2017-07-18 11:23:42 +00:00
|
|
|
}
|
2018-02-15 11:31:59 +00:00
|
|
|
else
|
2017-07-18 11:23:42 +00:00
|
|
|
{
|
2018-02-15 11:31:59 +00:00
|
|
|
for (u32 j = 0; j < pw_len; j++)
|
|
|
|
{
|
|
|
|
PUTCHAR_LE (wpc[i], block_len++, GETCHAR_LE (w, j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _unroll
|
|
|
|
#pragma unroll
|
|
|
|
#endif
|
|
|
|
for (u32 i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
u32 *z = wpc[i] + ((wpc_len[i] / 64) * 16);
|
|
|
|
|
|
|
|
truncate_block_16x4_le_S (z + 0, z + 4, z + 8, z + 12, wpc_len[i] & 63);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* loop
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (u32 i = 0, j = loop_pos; i < loop_cnt; i++, j++)
|
|
|
|
{
|
|
|
|
const u32 j1 = (j & 1) ? 1 : 0;
|
|
|
|
const u32 j3 = (j % 3) ? 2 : 0;
|
|
|
|
const u32 j7 = (j % 7) ? 4 : 0;
|
2018-02-14 18:13:23 +00:00
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
const u32 pc = j1 + j3 + j7;
|
2018-02-14 18:13:23 +00:00
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
if (j1)
|
|
|
|
{
|
2019-03-03 18:18:56 +00:00
|
|
|
const u32 off = wpc_len[pc] / 4;
|
|
|
|
const u32 mod = wpc_len[pc] % 4;
|
2018-02-15 14:35:22 +00:00
|
|
|
|
|
|
|
u32 *ptr = wpc[pc] + off - 4;
|
|
|
|
|
|
|
|
switch (mod)
|
2018-02-15 11:31:59 +00:00
|
|
|
{
|
2018-02-15 14:35:22 +00:00
|
|
|
case 0:
|
|
|
|
ptr[0] = digest[0];
|
|
|
|
ptr[1] = digest[1];
|
|
|
|
ptr[2] = digest[2];
|
|
|
|
ptr[3] = digest[3];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
ptr[0] = (ptr[0] & 0xff) | (digest[0] << 8);
|
|
|
|
ptr[1] = (digest[0] >> 24) | (digest[1] << 8);
|
|
|
|
ptr[2] = (digest[1] >> 24) | (digest[2] << 8);
|
|
|
|
ptr[3] = (digest[2] >> 24) | (digest[3] << 8);
|
|
|
|
ptr[4] = (digest[3] >> 24);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
ptr[0] = (ptr[0] & 0xffff) | (digest[0] << 16);
|
|
|
|
ptr[1] = (digest[0] >> 16) | (digest[1] << 16);
|
|
|
|
ptr[2] = (digest[1] >> 16) | (digest[2] << 16);
|
|
|
|
ptr[3] = (digest[2] >> 16) | (digest[3] << 16);
|
|
|
|
ptr[4] = (digest[3] >> 16);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
ptr[0] = (ptr[0] & 0xffffff) | (digest[0] << 24);
|
|
|
|
ptr[1] = (digest[0] >> 8) | (digest[1] << 24);
|
|
|
|
ptr[2] = (digest[1] >> 8) | (digest[2] << 24);
|
|
|
|
ptr[3] = (digest[2] >> 8) | (digest[3] << 24);
|
|
|
|
ptr[4] = (digest[3] >> 8);
|
|
|
|
break;
|
2018-02-15 11:31:59 +00:00
|
|
|
}
|
2018-02-14 18:13:23 +00:00
|
|
|
}
|
2018-02-15 11:31:59 +00:00
|
|
|
else
|
2018-02-14 18:13:23 +00:00
|
|
|
{
|
2018-02-15 11:31:59 +00:00
|
|
|
wpc[pc][0] = digest[0];
|
|
|
|
wpc[pc][1] = digest[1];
|
|
|
|
wpc[pc][2] = digest[2];
|
|
|
|
wpc[pc][3] = digest[3];
|
2017-07-18 11:23:42 +00:00
|
|
|
}
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2018-02-15 11:31:59 +00:00
|
|
|
md5_ctx_t md5_ctx;
|
|
|
|
|
|
|
|
md5_init (&md5_ctx);
|
|
|
|
|
|
|
|
md5_update (&md5_ctx, wpc[pc], wpc_len[pc]);
|
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
md5_final (&md5_ctx);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
digest[0] = md5_ctx.h[0];
|
|
|
|
digest[1] = md5_ctx.h[1];
|
|
|
|
digest[2] = md5_ctx.h[2];
|
|
|
|
digest[3] = md5_ctx.h[3];
|
2015-12-04 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tmps[gid].digest_buf[0] = digest[0];
|
|
|
|
tmps[gid].digest_buf[1] = digest[1];
|
|
|
|
tmps[gid].digest_buf[2] = digest[2];
|
|
|
|
tmps[gid].digest_buf[3] = digest[3];
|
|
|
|
}
|
|
|
|
|
2019-03-22 21:27:58 +00:00
|
|
|
KERNEL_FQ void m01600_comp (KERN_ATTR_TMPS (md5crypt_tmp_t))
|
2015-12-04 14:47:52 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* modifier
|
|
|
|
*/
|
|
|
|
|
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-08-19 14:39:22 +00:00
|
|
|
const u64 lid = get_local_id (0);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* digest
|
|
|
|
*/
|
|
|
|
|
2015-12-15 11:04:22 +00:00
|
|
|
const u32 r0 = tmps[gid].digest_buf[DGST_R0];
|
|
|
|
const u32 r1 = tmps[gid].digest_buf[DGST_R1];
|
|
|
|
const u32 r2 = tmps[gid].digest_buf[DGST_R2];
|
|
|
|
const u32 r3 = tmps[gid].digest_buf[DGST_R3];
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
#define il_pos 0
|
|
|
|
|
2019-03-22 14:16:25 +00:00
|
|
|
#ifdef KERNEL_STATIC
|
2015-12-15 11:04:22 +00:00
|
|
|
#include COMPARE_M
|
2019-03-22 14:16:25 +00:00
|
|
|
#endif
|
2015-12-04 14:47:52 +00:00
|
|
|
}
|