2015-12-04 15:47:52 +01:00
|
|
|
/**
|
2016-09-11 22:20:15 +02:00
|
|
|
* Author......: See docs/credits.txt
|
2015-12-04 15:47:52 +01:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
//#define NEW_SIMD_CODE
|
|
|
|
|
2019-03-22 15:16:25 +01:00
|
|
|
#ifdef KERNEL_STATIC
|
2022-02-07 09:57:08 +01:00
|
|
|
#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.cl)
|
|
|
|
#include M2S(INCLUDE_PATH/inc_hash_md5.cl)
|
2019-03-22 15:16:25 +01:00
|
|
|
#endif
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2022-02-07 13:31:22 +01:00
|
|
|
#define COMPARE_S M2S(INCLUDE_PATH/inc_comp_single.cl)
|
|
|
|
#define COMPARE_M M2S(INCLUDE_PATH/inc_comp_multi.cl)
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2019-03-08 10:18:20 +01:00
|
|
|
typedef struct md5crypt_tmp
|
|
|
|
{
|
|
|
|
u32 digest_buf[4];
|
|
|
|
|
|
|
|
} md5crypt_tmp_t;
|
|
|
|
|
2016-01-22 12:35:27 +01:00
|
|
|
#define md5apr1_magic0 0x72706124u
|
|
|
|
#define md5apr1_magic1 0x00002431u
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2019-03-22 22:27:58 +01:00
|
|
|
KERNEL_FQ void m01600_init (KERN_ATTR_TMPS (md5crypt_tmp_t))
|
2015-12-04 15:47:52 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* base
|
|
|
|
*/
|
|
|
|
|
2017-08-19 16:39:22 +02:00
|
|
|
const u64 gid = get_global_id (0);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2022-01-04 22:57:26 +01:00
|
|
|
if (gid >= GID_CNT) return;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* init
|
|
|
|
*/
|
|
|
|
|
2019-02-26 21:20:07 +01:00
|
|
|
const u32 pw_len = pws[gid].pw_len;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
u32 w[64] = { 0 };
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2019-04-10 12:23:39 +02:00
|
|
|
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
2017-07-18 13:23:42 +02:00
|
|
|
{
|
|
|
|
w[idx] = pws[gid].i[idx];
|
|
|
|
}
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2022-01-04 18:07:18 +01:00
|
|
|
const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
u32 s[64] = { 0 };
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2019-04-10 12:23:39 +02:00
|
|
|
for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1)
|
2017-07-18 13:23:42 +02:00
|
|
|
{
|
2022-01-04 18:07:18 +01:00
|
|
|
s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx];
|
2017-07-18 13:23:42 +02:00
|
|
|
}
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
/**
|
|
|
|
* prepare
|
|
|
|
*/
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_ctx_t md5_ctx1;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_init (&md5_ctx1);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_update (&md5_ctx1, w, pw_len);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_update (&md5_ctx1, s, salt_len);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_update (&md5_ctx1, w, pw_len);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_final (&md5_ctx1);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
u32 final[16] = { 0 };
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02: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 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_ctx_t md5_ctx;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_init (&md5_ctx);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_update (&md5_ctx, w, pw_len);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
u32 m[16] = { 0 };
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
m[0] = md5apr1_magic0;
|
|
|
|
m[1] = md5apr1_magic1;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_update (&md5_ctx, m, 6);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_update (&md5_ctx, s, salt_len);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
int pl;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-08-16 13:46:40 +02:00
|
|
|
for (pl = pw_len; pl > 16; pl -= 16)
|
2017-07-18 13:23:42 +02:00
|
|
|
{
|
|
|
|
md5_update (&md5_ctx, final, 16);
|
|
|
|
}
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-08-24 20:07:43 +02:00
|
|
|
truncate_block_4x4_le_S (final, pl);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_update (&md5_ctx, final, pl);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
|
|
|
/* Then something really weird... */
|
|
|
|
|
2017-08-16 13:46:40 +02:00
|
|
|
for (int i = pw_len; i != 0; i >>= 1)
|
2015-12-04 15:47:52 +01:00
|
|
|
{
|
2017-07-18 13:23:42 +02:00
|
|
|
u32 t[16] = { 0 };
|
|
|
|
|
2017-08-16 13:46:40 +02:00
|
|
|
if (i & 1)
|
2017-07-18 13:23:42 +02:00
|
|
|
{
|
|
|
|
t[0] = 0;
|
|
|
|
}
|
|
|
|
else
|
2015-12-04 15:47:52 +01:00
|
|
|
{
|
2017-07-18 13:23:42 +02:00
|
|
|
t[0] = w[0] & 0xff;
|
2015-12-04 15:47:52 +01:00
|
|
|
}
|
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_update (&md5_ctx, t, 1);
|
2015-12-04 15:47:52 +01:00
|
|
|
}
|
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_final (&md5_ctx);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02: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 15:47:52 +01:00
|
|
|
}
|
|
|
|
|
2019-03-22 22:27:58 +01:00
|
|
|
KERNEL_FQ void m01600_loop (KERN_ATTR_TMPS (md5crypt_tmp_t))
|
2015-12-04 15:47:52 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* base
|
|
|
|
*/
|
|
|
|
|
2017-08-19 16:39:22 +02:00
|
|
|
const u64 gid = get_global_id (0);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2022-01-04 22:57:26 +01:00
|
|
|
if (gid >= GID_CNT) return;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
/**
|
|
|
|
* init
|
|
|
|
*/
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2019-02-26 21:20:07 +01:00
|
|
|
const u32 pw_len = pws[gid].pw_len;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
u32 w[64] = { 0 };
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2019-04-10 12:23:39 +02:00
|
|
|
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
2017-07-18 13:23:42 +02:00
|
|
|
{
|
|
|
|
w[idx] = pws[gid].i[idx];
|
|
|
|
}
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2022-01-04 18:07:18 +01:00
|
|
|
const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
u32 s[64] = { 0 };
|
|
|
|
|
2019-04-10 12:23:39 +02:00
|
|
|
for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1)
|
2017-07-18 13:23:42 +02:00
|
|
|
{
|
2022-01-04 18:07:18 +01:00
|
|
|
s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx];
|
2017-07-18 13:23:42 +02:00
|
|
|
}
|
2015-12-04 15:47:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* digest
|
|
|
|
*/
|
|
|
|
|
2019-04-04 21:02:26 +02:00
|
|
|
u32 digest[16] = { 0 };
|
2015-12-04 15:47:52 +01: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];
|
|
|
|
|
2019-04-04 21:02:26 +02:00
|
|
|
/**
|
|
|
|
* loop
|
|
|
|
*/
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2022-01-04 18:07:18 +01:00
|
|
|
for (u32 i = 0, j = LOOP_POS; i < LOOP_CNT; i++, j++)
|
2018-02-15 12:31:59 +01:00
|
|
|
{
|
2019-04-04 21:02:26 +02:00
|
|
|
md5_ctx_t md5_ctx;
|
2018-02-14 19:13:23 +01:00
|
|
|
|
2019-04-04 21:02:26 +02:00
|
|
|
md5_init (&md5_ctx);
|
|
|
|
|
|
|
|
if (j & 1)
|
2015-12-04 15:47:52 +01:00
|
|
|
{
|
2019-04-04 21:02:26 +02:00
|
|
|
md5_update (&md5_ctx, w, pw_len);
|
2017-07-18 13:23:42 +02:00
|
|
|
}
|
2018-02-15 12:31:59 +01:00
|
|
|
else
|
2017-07-18 13:23:42 +02:00
|
|
|
{
|
2019-04-04 21:02:26 +02:00
|
|
|
md5_update (&md5_ctx, digest, 16);
|
2017-07-18 13:23:42 +02:00
|
|
|
}
|
2018-02-15 12:31:59 +01:00
|
|
|
|
2019-04-04 21:02:26 +02:00
|
|
|
if (j % 3)
|
2017-07-18 13:23:42 +02:00
|
|
|
{
|
2019-04-04 21:02:26 +02:00
|
|
|
md5_update (&md5_ctx, s, salt_len);
|
2015-12-04 15:47:52 +01:00
|
|
|
}
|
|
|
|
|
2019-04-04 21:02:26 +02:00
|
|
|
if (j % 7)
|
2018-02-15 12:31:59 +01:00
|
|
|
{
|
2019-04-04 21:02:26 +02:00
|
|
|
md5_update (&md5_ctx, w, pw_len);
|
2018-02-14 19:13:23 +01:00
|
|
|
}
|
2018-02-15 12:31:59 +01:00
|
|
|
|
2019-04-04 21:02:26 +02:00
|
|
|
if (j & 1)
|
2017-07-18 13:23:42 +02:00
|
|
|
{
|
2019-04-04 21:02:26 +02:00
|
|
|
md5_update (&md5_ctx, digest, 16);
|
2017-07-18 13:23:42 +02:00
|
|
|
}
|
2018-02-15 12:31:59 +01:00
|
|
|
else
|
2017-07-18 13:23:42 +02:00
|
|
|
{
|
2019-04-04 21:02:26 +02:00
|
|
|
md5_update (&md5_ctx, w, pw_len);
|
2018-02-15 12:31:59 +01:00
|
|
|
}
|
|
|
|
|
2017-07-18 13:23:42 +02:00
|
|
|
md5_final (&md5_ctx);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-07-18 13:23:42 +02: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 15:47:52 +01: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 22:27:58 +01:00
|
|
|
KERNEL_FQ void m01600_comp (KERN_ATTR_TMPS (md5crypt_tmp_t))
|
2015-12-04 15:47:52 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* modifier
|
|
|
|
*/
|
|
|
|
|
2017-08-19 16:39:22 +02:00
|
|
|
const u64 gid = get_global_id (0);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2022-01-04 22:57:26 +01:00
|
|
|
if (gid >= GID_CNT) return;
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2017-08-19 16:39:22 +02:00
|
|
|
const u64 lid = get_local_id (0);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* digest
|
|
|
|
*/
|
|
|
|
|
2015-12-15 12:04:22 +01: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 15:47:52 +01:00
|
|
|
|
|
|
|
#define il_pos 0
|
|
|
|
|
2019-03-22 15:16:25 +01:00
|
|
|
#ifdef KERNEL_STATIC
|
2015-12-15 12:04:22 +01:00
|
|
|
#include COMPARE_M
|
2019-03-22 15:16:25 +01:00
|
|
|
#endif
|
2015-12-04 15:47:52 +01:00
|
|
|
}
|