2016-04-02 12:36:02 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-04-02 12:36:02 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
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-09 13:12:11 +00:00
|
|
|
#include "inc_hash_sha256.cl"
|
2017-01-30 12:03:56 +00:00
|
|
|
#include "inc_cipher_aes.cl"
|
2017-01-27 19:59:15 +00:00
|
|
|
#include "inc_cipher_twofish.cl"
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
#define COMPARE_S "inc_comp_single.cl"
|
|
|
|
#define COMPARE_M "inc_comp_multi.cl"
|
|
|
|
|
2019-03-08 10:14:33 +00:00
|
|
|
typedef struct keepass_tmp
|
|
|
|
{
|
|
|
|
u32 tmp_digest[8];
|
|
|
|
|
|
|
|
} keepass_tmp_t;
|
|
|
|
|
|
|
|
typedef struct keepass
|
|
|
|
{
|
|
|
|
u32 version;
|
|
|
|
u32 algorithm;
|
|
|
|
|
|
|
|
/* key-file handling */
|
|
|
|
u32 keyfile_len;
|
|
|
|
u32 keyfile[8];
|
|
|
|
|
|
|
|
u32 final_random_seed[8];
|
|
|
|
u32 transf_random_seed[8];
|
|
|
|
u32 enc_iv[4];
|
|
|
|
u32 contents_hash[8];
|
|
|
|
|
|
|
|
/* specific to version 1 */
|
|
|
|
u32 contents_len;
|
|
|
|
u32 contents[75000];
|
|
|
|
|
|
|
|
/* specific to version 2 */
|
|
|
|
u32 expected_bytes[8];
|
|
|
|
|
|
|
|
} keepass_t;
|
|
|
|
|
2018-11-16 09:38:22 +00:00
|
|
|
__kernel void m13400_init (KERN_ATTR_TMPS_ESALT (keepass_tmp_t, keepass_t))
|
2016-04-02 12:36:02 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* base
|
|
|
|
*/
|
|
|
|
|
2017-08-19 14:39:22 +00:00
|
|
|
const u64 gid = get_global_id (0);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
if (gid >= gid_max) return;
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_ctx_t ctx;
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_init (&ctx);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2019-02-26 20:20:07 +00:00
|
|
|
sha256_update_global_swap (&ctx, pws[gid].i, pws[gid].pw_len);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_final (&ctx);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
u32 digest[8];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
digest[0] = ctx.h[0];
|
|
|
|
digest[1] = ctx.h[1];
|
|
|
|
digest[2] = ctx.h[2];
|
|
|
|
digest[3] = ctx.h[3];
|
|
|
|
digest[4] = ctx.h[4];
|
|
|
|
digest[5] = ctx.h[5];
|
|
|
|
digest[6] = ctx.h[6];
|
|
|
|
digest[7] = ctx.h[7];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-03-07 08:44:58 +00:00
|
|
|
if (esalt_bufs[digests_offset].version == 2 && esalt_bufs[digests_offset].keyfile_len == 0)
|
2016-04-02 12:36:02 +00:00
|
|
|
{
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 w0[4];
|
|
|
|
u32 w1[4];
|
|
|
|
u32 w2[4];
|
|
|
|
u32 w3[4];
|
|
|
|
|
2016-04-02 12:36:02 +00:00
|
|
|
w0[0] = digest[0];
|
|
|
|
w0[1] = digest[1];
|
|
|
|
w0[2] = digest[2];
|
|
|
|
w0[3] = digest[3];
|
|
|
|
w1[0] = digest[4];
|
|
|
|
w1[1] = digest[5];
|
|
|
|
w1[2] = digest[6];
|
|
|
|
w1[3] = digest[7];
|
2017-07-09 13:12:11 +00:00
|
|
|
w2[0] = 0;
|
2016-04-02 12:36:02 +00:00
|
|
|
w2[1] = 0;
|
|
|
|
w2[2] = 0;
|
|
|
|
w2[3] = 0;
|
|
|
|
w3[0] = 0;
|
|
|
|
w3[1] = 0;
|
|
|
|
w3[2] = 0;
|
2017-07-09 13:12:11 +00:00
|
|
|
w3[3] = 0;
|
|
|
|
|
|
|
|
sha256_init (&ctx);
|
|
|
|
|
|
|
|
sha256_update_64 (&ctx, w0, w1, w2, w3, 32);
|
|
|
|
|
|
|
|
sha256_final (&ctx);
|
|
|
|
|
|
|
|
digest[0] = ctx.h[0];
|
|
|
|
digest[1] = ctx.h[1];
|
|
|
|
digest[2] = ctx.h[2];
|
|
|
|
digest[3] = ctx.h[3];
|
|
|
|
digest[4] = ctx.h[4];
|
|
|
|
digest[5] = ctx.h[5];
|
|
|
|
digest[6] = ctx.h[6];
|
|
|
|
digest[7] = ctx.h[7];
|
2016-04-02 12:36:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 08:44:58 +00:00
|
|
|
if (esalt_bufs[digests_offset].keyfile_len != 0)
|
2016-04-06 12:59:00 +00:00
|
|
|
{
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 w0[4];
|
|
|
|
u32 w1[4];
|
|
|
|
u32 w2[4];
|
|
|
|
u32 w3[4];
|
|
|
|
|
2016-04-06 12:59:00 +00:00
|
|
|
w0[0] = digest[0];
|
|
|
|
w0[1] = digest[1];
|
|
|
|
w0[2] = digest[2];
|
|
|
|
w0[3] = digest[3];
|
|
|
|
w1[0] = digest[4];
|
|
|
|
w1[1] = digest[5];
|
|
|
|
w1[2] = digest[6];
|
|
|
|
w1[3] = digest[7];
|
2017-03-07 08:44:58 +00:00
|
|
|
w2[0] = esalt_bufs[digests_offset].keyfile[0];
|
|
|
|
w2[1] = esalt_bufs[digests_offset].keyfile[1];
|
|
|
|
w2[2] = esalt_bufs[digests_offset].keyfile[2];
|
|
|
|
w2[3] = esalt_bufs[digests_offset].keyfile[3];
|
|
|
|
w3[0] = esalt_bufs[digests_offset].keyfile[4];
|
|
|
|
w3[1] = esalt_bufs[digests_offset].keyfile[5];
|
|
|
|
w3[2] = esalt_bufs[digests_offset].keyfile[6];
|
2017-07-09 13:12:11 +00:00
|
|
|
w3[3] = esalt_bufs[digests_offset].keyfile[7];
|
2016-04-06 12:59:00 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_init (&ctx);
|
2016-04-06 12:59:00 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_update_64 (&ctx, w0, w1, w2, w3, 64);
|
2016-04-06 12:59:00 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_final (&ctx);
|
2016-04-06 12:59:00 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
digest[0] = ctx.h[0];
|
|
|
|
digest[1] = ctx.h[1];
|
|
|
|
digest[2] = ctx.h[2];
|
|
|
|
digest[3] = ctx.h[3];
|
|
|
|
digest[4] = ctx.h[4];
|
|
|
|
digest[5] = ctx.h[5];
|
|
|
|
digest[6] = ctx.h[6];
|
|
|
|
digest[7] = ctx.h[7];
|
2016-04-06 12:59:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-02 12:36:02 +00:00
|
|
|
tmps[gid].tmp_digest[0] = digest[0];
|
|
|
|
tmps[gid].tmp_digest[1] = digest[1];
|
|
|
|
tmps[gid].tmp_digest[2] = digest[2];
|
|
|
|
tmps[gid].tmp_digest[3] = digest[3];
|
|
|
|
tmps[gid].tmp_digest[4] = digest[4];
|
|
|
|
tmps[gid].tmp_digest[5] = digest[5];
|
|
|
|
tmps[gid].tmp_digest[6] = digest[6];
|
|
|
|
tmps[gid].tmp_digest[7] = digest[7];
|
|
|
|
}
|
|
|
|
|
2018-11-16 09:38:22 +00:00
|
|
|
__kernel void m13400_loop (KERN_ATTR_TMPS_ESALT (keepass_tmp_t, keepass_t))
|
2016-04-02 12:36:02 +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);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* aes shared
|
|
|
|
*/
|
|
|
|
|
2017-01-30 12:03:56 +00:00
|
|
|
#ifdef REAL_SHM
|
|
|
|
|
2016-04-02 12:36:02 +00:00
|
|
|
__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];
|
|
|
|
|
2019-03-03 18:18:56 +00:00
|
|
|
for (u32 i = lid; i < 256; i += lsz)
|
2016-04-02 12:36:02 +00:00
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
barrier (CLK_LOCAL_MEM_FENCE);
|
|
|
|
|
2017-01-30 12:03:56 +00:00
|
|
|
#else
|
|
|
|
|
2017-02-26 14:04:53 +00:00
|
|
|
__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;
|
2017-01-30 12:03:56 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-04-02 12:36:02 +00:00
|
|
|
if (gid >= gid_max) return;
|
|
|
|
|
|
|
|
/* Construct AES key */
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 ukey[8];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
ukey[0] = esalt_bufs[digests_offset].transf_random_seed[0];
|
|
|
|
ukey[1] = esalt_bufs[digests_offset].transf_random_seed[1];
|
|
|
|
ukey[2] = esalt_bufs[digests_offset].transf_random_seed[2];
|
|
|
|
ukey[3] = esalt_bufs[digests_offset].transf_random_seed[3];
|
|
|
|
ukey[4] = esalt_bufs[digests_offset].transf_random_seed[4];
|
|
|
|
ukey[5] = esalt_bufs[digests_offset].transf_random_seed[5];
|
|
|
|
ukey[6] = esalt_bufs[digests_offset].transf_random_seed[6];
|
|
|
|
ukey[7] = esalt_bufs[digests_offset].transf_random_seed[7];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
#define KEYLEN 60
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 ks[KEYLEN];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
AES256_set_encrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_te4);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
u32 data0[4];
|
|
|
|
u32 data1[4];
|
|
|
|
|
|
|
|
data0[0] = tmps[gid].tmp_digest[0];
|
|
|
|
data0[1] = tmps[gid].tmp_digest[1];
|
|
|
|
data0[2] = tmps[gid].tmp_digest[2];
|
|
|
|
data0[3] = tmps[gid].tmp_digest[3];
|
|
|
|
data1[0] = tmps[gid].tmp_digest[4];
|
|
|
|
data1[1] = tmps[gid].tmp_digest[5];
|
|
|
|
data1[2] = tmps[gid].tmp_digest[6];
|
|
|
|
data1[3] = tmps[gid].tmp_digest[7];
|
|
|
|
|
|
|
|
for (u32 i = 0; i < loop_cnt; i++)
|
|
|
|
{
|
2017-07-09 13:12:11 +00:00
|
|
|
AES256_encrypt (ks, data0, data0, s_te0, s_te1, s_te2, s_te3, s_te4);
|
|
|
|
AES256_encrypt (ks, data1, data1, s_te0, s_te1, s_te2, s_te3, s_te4);
|
2016-04-02 12:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tmps[gid].tmp_digest[0] = data0[0];
|
|
|
|
tmps[gid].tmp_digest[1] = data0[1];
|
|
|
|
tmps[gid].tmp_digest[2] = data0[2];
|
|
|
|
tmps[gid].tmp_digest[3] = data0[3];
|
|
|
|
tmps[gid].tmp_digest[4] = data1[0];
|
|
|
|
tmps[gid].tmp_digest[5] = data1[1];
|
|
|
|
tmps[gid].tmp_digest[6] = data1[2];
|
|
|
|
tmps[gid].tmp_digest[7] = data1[3];
|
|
|
|
}
|
|
|
|
|
2018-11-16 09:38:22 +00:00
|
|
|
__kernel void m13400_comp (KERN_ATTR_TMPS_ESALT (keepass_tmp_t, keepass_t))
|
2016-04-02 12:36:02 +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);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* aes shared
|
|
|
|
*/
|
|
|
|
|
2017-01-30 12:03:56 +00:00
|
|
|
#ifdef REAL_SHM
|
|
|
|
|
2016-04-03 09:00:02 +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-04-02 12:36:02 +00:00
|
|
|
|
2019-03-03 18:18:56 +00:00
|
|
|
for (u32 i = lid; i < 256; i += lsz)
|
2016-04-02 12:36:02 +00:00
|
|
|
{
|
2016-04-03 09:00:02 +00:00
|
|
|
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];
|
2016-04-02 12:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
barrier (CLK_LOCAL_MEM_FENCE);
|
|
|
|
|
2017-01-30 12:03:56 +00:00
|
|
|
#else
|
|
|
|
|
2017-02-26 14:04:53 +00:00
|
|
|
__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;
|
2017-01-30 12:03:56 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-04-02 12:36:02 +00:00
|
|
|
if (gid >= gid_max) return;
|
|
|
|
|
|
|
|
/* hash output... */
|
2017-07-09 13:12:11 +00:00
|
|
|
|
2016-04-02 12:36:02 +00:00
|
|
|
u32 w0[4];
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 w1[4];
|
|
|
|
u32 w2[4];
|
|
|
|
u32 w3[4];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
w0[0] = tmps[gid].tmp_digest[0];
|
|
|
|
w0[1] = tmps[gid].tmp_digest[1];
|
|
|
|
w0[2] = tmps[gid].tmp_digest[2];
|
|
|
|
w0[3] = tmps[gid].tmp_digest[3];
|
|
|
|
w1[0] = tmps[gid].tmp_digest[4];
|
|
|
|
w1[1] = tmps[gid].tmp_digest[5];
|
|
|
|
w1[2] = tmps[gid].tmp_digest[6];
|
|
|
|
w1[3] = tmps[gid].tmp_digest[7];
|
2017-07-09 13:12:11 +00:00
|
|
|
w2[0] = 0;
|
2016-04-02 12:36:02 +00:00
|
|
|
w2[1] = 0;
|
|
|
|
w2[2] = 0;
|
|
|
|
w2[3] = 0;
|
|
|
|
w3[0] = 0;
|
|
|
|
w3[1] = 0;
|
|
|
|
w3[2] = 0;
|
2017-07-09 13:12:11 +00:00
|
|
|
w3[3] = 0;
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_ctx_t ctx;
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_init (&ctx);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_update_64 (&ctx, w0, w1, w2, w3, 32);
|
|
|
|
|
|
|
|
sha256_final (&ctx);
|
|
|
|
|
|
|
|
u32 digest[8];
|
|
|
|
|
|
|
|
digest[0] = ctx.h[0];
|
|
|
|
digest[1] = ctx.h[1];
|
|
|
|
digest[2] = ctx.h[2];
|
|
|
|
digest[3] = ctx.h[3];
|
|
|
|
digest[4] = ctx.h[4];
|
|
|
|
digest[5] = ctx.h[5];
|
|
|
|
digest[6] = ctx.h[6];
|
|
|
|
digest[7] = ctx.h[7];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
/* ...then hash final_random_seed | output */
|
2017-07-09 13:12:11 +00:00
|
|
|
|
2017-03-07 08:44:58 +00:00
|
|
|
if (esalt_bufs[digests_offset].version == 1)
|
2016-04-02 12:36:02 +00:00
|
|
|
{
|
2017-07-09 13:12:11 +00:00
|
|
|
w0[0] = esalt_bufs[digests_offset].final_random_seed[0];
|
|
|
|
w0[1] = esalt_bufs[digests_offset].final_random_seed[1];
|
|
|
|
w0[2] = esalt_bufs[digests_offset].final_random_seed[2];
|
|
|
|
w0[3] = esalt_bufs[digests_offset].final_random_seed[3];
|
2016-04-02 12:36:02 +00:00
|
|
|
w1[0] = digest[0];
|
|
|
|
w1[1] = digest[1];
|
|
|
|
w1[2] = digest[2];
|
|
|
|
w1[3] = digest[3];
|
|
|
|
w2[0] = digest[4];
|
|
|
|
w2[1] = digest[5];
|
|
|
|
w2[2] = digest[6];
|
|
|
|
w2[3] = digest[7];
|
2017-07-09 13:12:11 +00:00
|
|
|
w3[0] = 0;
|
2016-04-02 12:36:02 +00:00
|
|
|
w3[1] = 0;
|
|
|
|
w3[2] = 0;
|
2017-07-09 13:12:11 +00:00
|
|
|
w3[3] = 0;
|
|
|
|
|
|
|
|
sha256_init (&ctx);
|
|
|
|
|
|
|
|
sha256_update_64 (&ctx, w0, w1, w2, w3, 48);
|
|
|
|
|
|
|
|
sha256_final (&ctx);
|
|
|
|
|
|
|
|
digest[0] = ctx.h[0];
|
|
|
|
digest[1] = ctx.h[1];
|
|
|
|
digest[2] = ctx.h[2];
|
|
|
|
digest[3] = ctx.h[3];
|
|
|
|
digest[4] = ctx.h[4];
|
|
|
|
digest[5] = ctx.h[5];
|
|
|
|
digest[6] = ctx.h[6];
|
|
|
|
digest[7] = ctx.h[7];
|
2016-04-02 12:36:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-09 13:12:11 +00:00
|
|
|
w0[0] = esalt_bufs[digests_offset].final_random_seed[0];
|
|
|
|
w0[1] = esalt_bufs[digests_offset].final_random_seed[1];
|
|
|
|
w0[2] = esalt_bufs[digests_offset].final_random_seed[2];
|
|
|
|
w0[3] = esalt_bufs[digests_offset].final_random_seed[3];
|
|
|
|
w1[0] = esalt_bufs[digests_offset].final_random_seed[4];
|
|
|
|
w1[1] = esalt_bufs[digests_offset].final_random_seed[5];
|
|
|
|
w1[2] = esalt_bufs[digests_offset].final_random_seed[6];
|
|
|
|
w1[3] = esalt_bufs[digests_offset].final_random_seed[7];
|
2016-04-02 12:36:02 +00:00
|
|
|
w2[0] = digest[0];
|
|
|
|
w2[1] = digest[1];
|
|
|
|
w2[2] = digest[2];
|
|
|
|
w2[3] = digest[3];
|
|
|
|
w3[0] = digest[4];
|
|
|
|
w3[1] = digest[5];
|
|
|
|
w3[2] = digest[6];
|
|
|
|
w3[3] = digest[7];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_init (&ctx);
|
|
|
|
|
|
|
|
sha256_update_64 (&ctx, w0, w1, w2, w3, 64);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_final (&ctx);
|
|
|
|
|
|
|
|
digest[0] = ctx.h[0];
|
|
|
|
digest[1] = ctx.h[1];
|
|
|
|
digest[2] = ctx.h[2];
|
|
|
|
digest[3] = ctx.h[3];
|
|
|
|
digest[4] = ctx.h[4];
|
|
|
|
digest[5] = ctx.h[5];
|
|
|
|
digest[6] = ctx.h[6];
|
|
|
|
digest[7] = ctx.h[7];
|
2016-04-02 12:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// at this point we have to distinguish between the different keypass versions
|
|
|
|
|
|
|
|
u32 iv[4];
|
|
|
|
|
2017-03-07 08:44:58 +00:00
|
|
|
iv[0] = esalt_bufs[digests_offset].enc_iv[0];
|
|
|
|
iv[1] = esalt_bufs[digests_offset].enc_iv[1];
|
|
|
|
iv[2] = esalt_bufs[digests_offset].enc_iv[2];
|
|
|
|
iv[3] = esalt_bufs[digests_offset].enc_iv[3];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 r0 = 0;
|
|
|
|
u32 r1 = 0;
|
|
|
|
u32 r2 = 0;
|
|
|
|
u32 r3 = 0;
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-03-07 08:44:58 +00:00
|
|
|
if (esalt_bufs[digests_offset].version == 1)
|
2016-04-02 12:36:02 +00:00
|
|
|
{
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_ctx_t ctx;
|
|
|
|
|
|
|
|
sha256_init (&ctx);
|
|
|
|
|
2017-03-07 08:44:58 +00:00
|
|
|
if (esalt_bufs[digests_offset].algorithm == 1)
|
2016-04-02 12:36:02 +00:00
|
|
|
{
|
|
|
|
/* Construct final Twofish key */
|
|
|
|
u32 sk[4];
|
|
|
|
u32 lk[40];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
digest[0] = swap32_S (digest[0]);
|
|
|
|
digest[1] = swap32_S (digest[1]);
|
|
|
|
digest[2] = swap32_S (digest[2]);
|
|
|
|
digest[3] = swap32_S (digest[3]);
|
|
|
|
digest[4] = swap32_S (digest[4]);
|
|
|
|
digest[5] = swap32_S (digest[5]);
|
|
|
|
digest[6] = swap32_S (digest[6]);
|
|
|
|
digest[7] = swap32_S (digest[7]);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
twofish256_set_key (sk, lk, digest);
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
iv[0] = swap32_S (iv[0]);
|
|
|
|
iv[1] = swap32_S (iv[1]);
|
|
|
|
iv[2] = swap32_S (iv[2]);
|
|
|
|
iv[3] = swap32_S (iv[3]);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-03-07 08:44:58 +00:00
|
|
|
u32 contents_len = esalt_bufs[digests_offset].contents_len;
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
u32 contents_pos;
|
|
|
|
u32 contents_off;
|
|
|
|
|
|
|
|
// process (decrypt and hash) the buffer with the biggest steps possible.
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
for (contents_pos = 0, contents_off = 0; contents_pos < contents_len - 16; contents_pos += 16, contents_off += 4)
|
2016-04-02 12:36:02 +00:00
|
|
|
{
|
|
|
|
u32 data[4];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
data[0] = esalt_bufs[digests_offset].contents[contents_off + 0];
|
|
|
|
data[1] = esalt_bufs[digests_offset].contents[contents_off + 1];
|
|
|
|
data[2] = esalt_bufs[digests_offset].contents[contents_off + 2];
|
|
|
|
data[3] = esalt_bufs[digests_offset].contents[contents_off + 3];
|
|
|
|
|
|
|
|
data[0] = swap32_S (data[0]);
|
|
|
|
data[1] = swap32_S (data[1]);
|
|
|
|
data[2] = swap32_S (data[2]);
|
|
|
|
data[3] = swap32_S (data[3]);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
u32 out[4];
|
|
|
|
|
|
|
|
twofish256_decrypt (sk, lk, data, out);
|
|
|
|
|
|
|
|
out[0] ^= iv[0];
|
|
|
|
out[1] ^= iv[1];
|
|
|
|
out[2] ^= iv[2];
|
|
|
|
out[3] ^= iv[3];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
out[0] = swap32_S (out[0]);
|
|
|
|
out[1] = swap32_S (out[1]);
|
|
|
|
out[2] = swap32_S (out[2]);
|
|
|
|
out[3] = swap32_S (out[3]);
|
|
|
|
|
|
|
|
u32 w0[4] = { 0 };
|
|
|
|
u32 w1[4] = { 0 };
|
|
|
|
u32 w2[4] = { 0 };
|
|
|
|
u32 w3[4] = { 0 };
|
|
|
|
|
|
|
|
w0[0] = out[0];
|
|
|
|
w0[1] = out[1];
|
|
|
|
w0[2] = out[2];
|
|
|
|
w0[3] = out[3];
|
|
|
|
|
|
|
|
sha256_update_64 (&ctx, w0, w1, w2, w3, 16);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
iv[0] = data[0];
|
|
|
|
iv[1] = data[1];
|
|
|
|
iv[2] = data[2];
|
|
|
|
iv[3] = data[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
// we've reached the final block for decrypt, it will contain the padding bytes we're looking for
|
|
|
|
|
|
|
|
u32 data[4];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
data[0] = esalt_bufs[digests_offset].contents[contents_off + 0];
|
|
|
|
data[1] = esalt_bufs[digests_offset].contents[contents_off + 1];
|
|
|
|
data[2] = esalt_bufs[digests_offset].contents[contents_off + 2];
|
|
|
|
data[3] = esalt_bufs[digests_offset].contents[contents_off + 3];
|
|
|
|
|
|
|
|
data[0] = swap32_S (data[0]);
|
|
|
|
data[1] = swap32_S (data[1]);
|
|
|
|
data[2] = swap32_S (data[2]);
|
|
|
|
data[3] = swap32_S (data[3]);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
u32 out[4];
|
|
|
|
|
|
|
|
twofish256_decrypt (sk, lk, data, out);
|
|
|
|
|
|
|
|
out[0] ^= iv[0];
|
|
|
|
out[1] ^= iv[1];
|
|
|
|
out[2] ^= iv[2];
|
|
|
|
out[3] ^= iv[3];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
out[0] = swap32_S (out[0]);
|
|
|
|
out[1] = swap32_S (out[1]);
|
|
|
|
out[2] = swap32_S (out[2]);
|
|
|
|
out[3] = swap32_S (out[3]);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
// now we can access the pad byte
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
const u32 pad_byte = out[3] & 0xff;
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
// we need to clear the buffer of the padding data
|
|
|
|
|
2017-08-24 18:07:43 +00:00
|
|
|
truncate_block_4x4_be_S (out, 16 - pad_byte);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 w0[4] = { 0 };
|
|
|
|
u32 w1[4] = { 0 };
|
|
|
|
u32 w2[4] = { 0 };
|
|
|
|
u32 w3[4] = { 0 };
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
w0[0] = out[0];
|
|
|
|
w0[1] = out[1];
|
|
|
|
w0[2] = out[2];
|
|
|
|
w0[3] = out[3];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_update_64 (&ctx, w0, w1, w2, w3, 16 - pad_byte);
|
2016-04-02 12:36:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Construct final AES key */
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
#define KEYLEN 60
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 ks[KEYLEN];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
AES256_set_decrypt_key (ks, digest, s_te0, s_te1, s_te2, s_te3, s_te4, s_td0, s_td1, s_td2, s_td3, s_td4);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-03-07 08:44:58 +00:00
|
|
|
u32 contents_len = esalt_bufs[digests_offset].contents_len;
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
u32 contents_pos;
|
|
|
|
u32 contents_off;
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
for (contents_pos = 0, contents_off = 0; contents_pos < contents_len - 16; contents_pos += 16, contents_off += 4)
|
2016-04-02 12:36:02 +00:00
|
|
|
{
|
|
|
|
u32 data[4];
|
|
|
|
|
2017-03-07 08:44:58 +00:00
|
|
|
data[0] = esalt_bufs[digests_offset].contents[contents_off + 0];
|
|
|
|
data[1] = esalt_bufs[digests_offset].contents[contents_off + 1];
|
|
|
|
data[2] = esalt_bufs[digests_offset].contents[contents_off + 2];
|
|
|
|
data[3] = esalt_bufs[digests_offset].contents[contents_off + 3];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
u32 out[4];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
AES256_decrypt (ks, data, out, s_td0, s_td1, s_td2, s_td3, s_td4);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
out[0] ^= iv[0];
|
|
|
|
out[1] ^= iv[1];
|
|
|
|
out[2] ^= iv[2];
|
|
|
|
out[3] ^= iv[3];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 w0[4] = { 0 };
|
|
|
|
u32 w1[4] = { 0 };
|
|
|
|
u32 w2[4] = { 0 };
|
|
|
|
u32 w3[4] = { 0 };
|
|
|
|
|
|
|
|
w0[0] = out[0];
|
|
|
|
w0[1] = out[1];
|
|
|
|
w0[2] = out[2];
|
|
|
|
w0[3] = out[3];
|
|
|
|
|
|
|
|
sha256_update_64 (&ctx, w0, w1, w2, w3, 16);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
iv[0] = data[0];
|
|
|
|
iv[1] = data[1];
|
|
|
|
iv[2] = data[2];
|
|
|
|
iv[3] = data[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
// we've reached the final block for decrypt, it will contain the padding bytes we're looking for
|
|
|
|
|
|
|
|
u32 data[4];
|
|
|
|
|
2017-03-07 08:44:58 +00:00
|
|
|
data[0] = esalt_bufs[digests_offset].contents[contents_off + 0];
|
|
|
|
data[1] = esalt_bufs[digests_offset].contents[contents_off + 1];
|
|
|
|
data[2] = esalt_bufs[digests_offset].contents[contents_off + 2];
|
|
|
|
data[3] = esalt_bufs[digests_offset].contents[contents_off + 3];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
u32 out[4];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
AES256_decrypt (ks, data, out, s_td0, s_td1, s_td2, s_td3, s_td4);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
out[0] ^= iv[0];
|
|
|
|
out[1] ^= iv[1];
|
|
|
|
out[2] ^= iv[2];
|
|
|
|
out[3] ^= iv[3];
|
|
|
|
|
|
|
|
// now we can access the pad byte
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
const u32 pad_byte = out[3] & 0xff;
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
// we need to clear the buffer of the padding data
|
|
|
|
|
2017-08-24 18:07:43 +00:00
|
|
|
truncate_block_4x4_be_S (out, 16 - pad_byte);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 w0[4] = { 0 };
|
|
|
|
u32 w1[4] = { 0 };
|
|
|
|
u32 w2[4] = { 0 };
|
|
|
|
u32 w3[4] = { 0 };
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
w0[0] = out[0];
|
|
|
|
w0[1] = out[1];
|
|
|
|
w0[2] = out[2];
|
|
|
|
w0[3] = out[3];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_update_64 (&ctx, w0, w1, w2, w3, 16 - pad_byte);
|
|
|
|
}
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
sha256_final (&ctx);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
r0 = ctx.h[0];
|
|
|
|
r1 = ctx.h[1];
|
|
|
|
r2 = ctx.h[2];
|
|
|
|
r3 = ctx.h[3];
|
2016-04-02 12:36:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Construct final AES key */
|
2017-07-09 13:12:11 +00:00
|
|
|
|
2016-04-02 12:36:02 +00:00
|
|
|
#define KEYLEN 60
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 ks[KEYLEN];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
AES256_set_decrypt_key (ks, digest, s_te0, s_te1, s_te2, s_te3, s_te4, s_td0, s_td1, s_td2, s_td3, s_td4);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 data[4];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
data[0] = esalt_bufs[digests_offset].contents_hash[0];
|
|
|
|
data[1] = esalt_bufs[digests_offset].contents_hash[1];
|
|
|
|
data[2] = esalt_bufs[digests_offset].contents_hash[2];
|
|
|
|
data[3] = esalt_bufs[digests_offset].contents_hash[3];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
u32 out[4];
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
AES256_decrypt (ks, data, out, s_td0, s_td1, s_td2, s_td3, s_td4);
|
2016-04-02 12:36:02 +00:00
|
|
|
|
|
|
|
out[0] ^= iv[0];
|
|
|
|
out[1] ^= iv[1];
|
|
|
|
out[2] ^= iv[2];
|
|
|
|
out[3] ^= iv[3];
|
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
r0 = out[0];
|
|
|
|
r1 = out[1];
|
|
|
|
r2 = out[2];
|
|
|
|
r3 = out[3];
|
|
|
|
}
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
#define il_pos 0
|
2016-04-02 12:36:02 +00:00
|
|
|
|
2017-07-09 13:12:11 +00:00
|
|
|
#include COMPARE_M
|
2016-04-02 12:36:02 +00:00
|
|
|
}
|