Added new hash-modes Mozilla key3.db and key4.db

pull/2762/head
Jens Steube 3 years ago
parent b9604b6f22
commit ee7d8ef0e7

@ -0,0 +1,720 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
//#define NEW_SIMD_CODE
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_rp.h"
#include "inc_rp.cl"
#include "inc_scalar.cl"
#include "inc_hash_sha1.cl"
#include "inc_cipher_des.cl"
#endif
typedef struct mozilla_3des
{
u32 ct_buf[4];
} mozilla_3des_t;
KERNEL_FQ void m26000_mxx (KERN_ATTR_RULES_ESALT (mozilla_3des_t))
{
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
const u64 lsz = get_local_size (0);
/**
* aes shared
*/
#ifdef REAL_SHM
LOCAL_VK u32 s_SPtrans[8][64];
LOCAL_VK u32 s_skb[8][64];
for (u32 i = lid; i < 64; i += lsz)
{
s_SPtrans[0][i] = c_SPtrans[0][i];
s_SPtrans[1][i] = c_SPtrans[1][i];
s_SPtrans[2][i] = c_SPtrans[2][i];
s_SPtrans[3][i] = c_SPtrans[3][i];
s_SPtrans[4][i] = c_SPtrans[4][i];
s_SPtrans[5][i] = c_SPtrans[5][i];
s_SPtrans[6][i] = c_SPtrans[6][i];
s_SPtrans[7][i] = c_SPtrans[7][i];
s_skb[0][i] = c_skb[0][i];
s_skb[1][i] = c_skb[1][i];
s_skb[2][i] = c_skb[2][i];
s_skb[3][i] = c_skb[3][i];
s_skb[4][i] = c_skb[4][i];
s_skb[5][i] = c_skb[5][i];
s_skb[6][i] = c_skb[6][i];
s_skb[7][i] = c_skb[7][i];
}
SYNC_THREADS ();
#else
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
#endif
if (gid >= gid_max) return;
/**
* base
*/
COPY_PW (pws[gid]);
u32 gs_buf[5];
gs_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 0]);
gs_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 1]);
gs_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 2]);
gs_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 3]);
gs_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 4]);
u32 es_buf[5];
es_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 8]);
es_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 9]);
es_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[10]);
es_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[11]);
es_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[12]);
u32 ct_buf0[2];
ct_buf0[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[0];
ct_buf0[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[1];
u32 ct_buf1[2];
ct_buf1[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[2];
ct_buf1[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[3];
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
pw_t tmp = PASTE_PW;
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
// my $hp = sha1 ($global_salt_bin . $word);
sha1_ctx_t ctx0;
sha1_init (&ctx0);
ctx0.w0[0] = gs_buf[0];
ctx0.w0[1] = gs_buf[1];
ctx0.w0[2] = gs_buf[2];
ctx0.w0[3] = gs_buf[3];
ctx0.w1[0] = gs_buf[4];
ctx0.len = 20;
sha1_update_swap (&ctx0, tmp.i, tmp.pw_len);
sha1_final (&ctx0);
u32 hp[5];
hp[0] = ctx0.h[0];
hp[1] = ctx0.h[1];
hp[2] = ctx0.h[2];
hp[3] = ctx0.h[3];
hp[4] = ctx0.h[4];
// my $chp = sha1 ($hp . $entry_salt_bin);
sha1_init (&ctx0);
ctx0.w0[0] = hp[0];
ctx0.w0[1] = hp[1];
ctx0.w0[2] = hp[2];
ctx0.w0[3] = hp[3];
ctx0.w1[0] = hp[4];
ctx0.w1[1] = es_buf[0];
ctx0.w1[2] = es_buf[1];
ctx0.w1[3] = es_buf[2];
ctx0.w2[0] = es_buf[3];
ctx0.w2[1] = es_buf[4];
ctx0.len = 40;
sha1_final (&ctx0);
u32 chp[5];
chp[0] = ctx0.h[0];
chp[1] = ctx0.h[1];
chp[2] = ctx0.h[2];
chp[3] = ctx0.h[3];
chp[4] = ctx0.h[4];
// my $k1 = hmac ($pes . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1;
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = chp[0];
w0[1] = chp[1];
w0[2] = chp[2];
w0[3] = chp[3];
w1[0] = chp[4];
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;
w3[3] = 0;
sha1_hmac_init_64 (&ctx1, w0, w1, w2, w3);
sha1_hmac_ctx_t ctx1a = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1a, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1a);
u32 k1[5];
k1[0] = ctx1a.opad.h[0];
k1[1] = ctx1a.opad.h[1];
k1[2] = ctx1a.opad.h[2];
k1[3] = ctx1a.opad.h[3];
k1[4] = ctx1a.opad.h[4];
// my $tk = hmac ($pes, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1b = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
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;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1b, w0, w1, w2, w3, 20);
sha1_hmac_final (&ctx1b);
u32 tk[5];
tk[0] = ctx1b.opad.h[0];
tk[1] = ctx1b.opad.h[1];
tk[2] = ctx1b.opad.h[2];
tk[3] = ctx1b.opad.h[3];
tk[4] = ctx1b.opad.h[4];
// my $k2 = hmac ($tk . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1c = ctx1;
w0[0] = tk[0];
w0[1] = tk[1];
w0[2] = tk[2];
w0[3] = tk[3];
w1[0] = tk[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1c, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1c);
u32 k2[5];
k2[0] = ctx1c.opad.h[0];
k2[1] = ctx1c.opad.h[1];
k2[2] = ctx1c.opad.h[2];
k2[3] = ctx1c.opad.h[3];
k2[4] = ctx1c.opad.h[4];
// 3DES
u32 ukey[6];
ukey[0] = hc_swap32_S (k1[0]);
ukey[1] = hc_swap32_S (k1[1]);
ukey[2] = hc_swap32_S (k1[2]);
ukey[3] = hc_swap32_S (k1[3]);
ukey[4] = hc_swap32_S (k1[4]);
ukey[5] = hc_swap32_S (k2[0]);
u32 iv[2];
iv[0] = hc_swap32_S (k2[3]);
iv[1] = hc_swap32_S (k2[4]);
u32 K0[16];
u32 K1[16];
u32 K2[16];
u32 K3[16];
u32 K4[16];
u32 K5[16];
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
u32 ct[2];
u32 pt[2];
u32 t1[2];
u32 t2[2];
ct[0] = ct_buf0[0];
ct[1] = ct_buf0[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// password
if (pt[0] != 0x73736170) continue;
if (pt[1] != 0x64726f77) continue;
iv[0] = ct_buf0[0];
iv[1] = ct_buf0[1];
ct[0] = ct_buf1[0];
ct[1] = ct_buf1[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// -check\x02\x02
if (pt[0] != 0x6568632d) continue;
if (pt[1] != 0x02026b63) continue;
const u32 r0 = ct_buf0[0];
const u32 r1 = ct_buf0[1];
const u32 r2 = ct_buf1[0];
const u32 r3 = ct_buf1[1];
COMPARE_M_SCALAR (r0, r1, r2, r3);
}
}
KERNEL_FQ void m26000_sxx (KERN_ATTR_RULES_ESALT (mozilla_3des_t))
{
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
const u64 lsz = get_local_size (0);
/**
* aes shared
*/
#ifdef REAL_SHM
LOCAL_VK u32 s_SPtrans[8][64];
LOCAL_VK u32 s_skb[8][64];
for (u32 i = lid; i < 64; i += lsz)
{
s_SPtrans[0][i] = c_SPtrans[0][i];
s_SPtrans[1][i] = c_SPtrans[1][i];
s_SPtrans[2][i] = c_SPtrans[2][i];
s_SPtrans[3][i] = c_SPtrans[3][i];
s_SPtrans[4][i] = c_SPtrans[4][i];
s_SPtrans[5][i] = c_SPtrans[5][i];
s_SPtrans[6][i] = c_SPtrans[6][i];
s_SPtrans[7][i] = c_SPtrans[7][i];
s_skb[0][i] = c_skb[0][i];
s_skb[1][i] = c_skb[1][i];
s_skb[2][i] = c_skb[2][i];
s_skb[3][i] = c_skb[3][i];
s_skb[4][i] = c_skb[4][i];
s_skb[5][i] = c_skb[5][i];
s_skb[6][i] = c_skb[6][i];
s_skb[7][i] = c_skb[7][i];
}
SYNC_THREADS ();
#else
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
#endif
if (gid >= gid_max) return;
/**
* digest
*/
const u32 search[4] =
{
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R0],
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R1],
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R2],
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R3]
};
/**
* base
*/
COPY_PW (pws[gid]);
u32 gs_buf[5];
gs_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 0]);
gs_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 1]);
gs_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 2]);
gs_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 3]);
gs_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 4]);
u32 es_buf[5];
es_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 8]);
es_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 9]);
es_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[10]);
es_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[11]);
es_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[12]);
u32 ct_buf0[2];
ct_buf0[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[0];
ct_buf0[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[1];
u32 ct_buf1[2];
ct_buf1[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[2];
ct_buf1[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[3];
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
pw_t tmp = PASTE_PW;
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
// my $hp = sha1 ($global_salt_bin . $word);
sha1_ctx_t ctx0;
sha1_init (&ctx0);
ctx0.w0[0] = gs_buf[0];
ctx0.w0[1] = gs_buf[1];
ctx0.w0[2] = gs_buf[2];
ctx0.w0[3] = gs_buf[3];
ctx0.w1[0] = gs_buf[4];
ctx0.len = 20;
sha1_update_swap (&ctx0, tmp.i, tmp.pw_len);
sha1_final (&ctx0);
u32 hp[5];
hp[0] = ctx0.h[0];
hp[1] = ctx0.h[1];
hp[2] = ctx0.h[2];
hp[3] = ctx0.h[3];
hp[4] = ctx0.h[4];
// my $chp = sha1 ($hp . $entry_salt_bin);
sha1_init (&ctx0);
ctx0.w0[0] = hp[0];
ctx0.w0[1] = hp[1];
ctx0.w0[2] = hp[2];
ctx0.w0[3] = hp[3];
ctx0.w1[0] = hp[4];
ctx0.w1[1] = es_buf[0];
ctx0.w1[2] = es_buf[1];
ctx0.w1[3] = es_buf[2];
ctx0.w2[0] = es_buf[3];
ctx0.w2[1] = es_buf[4];
ctx0.len = 40;
sha1_final (&ctx0);
u32 chp[5];
chp[0] = ctx0.h[0];
chp[1] = ctx0.h[1];
chp[2] = ctx0.h[2];
chp[3] = ctx0.h[3];
chp[4] = ctx0.h[4];
// my $k1 = hmac ($pes . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1;
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = chp[0];
w0[1] = chp[1];
w0[2] = chp[2];
w0[3] = chp[3];
w1[0] = chp[4];
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;
w3[3] = 0;
sha1_hmac_init_64 (&ctx1, w0, w1, w2, w3);
sha1_hmac_ctx_t ctx1a = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1a, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1a);
u32 k1[5];
k1[0] = ctx1a.opad.h[0];
k1[1] = ctx1a.opad.h[1];
k1[2] = ctx1a.opad.h[2];
k1[3] = ctx1a.opad.h[3];
k1[4] = ctx1a.opad.h[4];
// my $tk = hmac ($pes, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1b = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
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;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1b, w0, w1, w2, w3, 20);
sha1_hmac_final (&ctx1b);
u32 tk[5];
tk[0] = ctx1b.opad.h[0];
tk[1] = ctx1b.opad.h[1];
tk[2] = ctx1b.opad.h[2];
tk[3] = ctx1b.opad.h[3];
tk[4] = ctx1b.opad.h[4];
// my $k2 = hmac ($tk . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1c = ctx1;
w0[0] = tk[0];
w0[1] = tk[1];
w0[2] = tk[2];
w0[3] = tk[3];
w1[0] = tk[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1c, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1c);
u32 k2[5];
k2[0] = ctx1c.opad.h[0];
k2[1] = ctx1c.opad.h[1];
k2[2] = ctx1c.opad.h[2];
k2[3] = ctx1c.opad.h[3];
k2[4] = ctx1c.opad.h[4];
// 3DES
u32 ukey[6];
ukey[0] = hc_swap32_S (k1[0]);
ukey[1] = hc_swap32_S (k1[1]);
ukey[2] = hc_swap32_S (k1[2]);
ukey[3] = hc_swap32_S (k1[3]);
ukey[4] = hc_swap32_S (k1[4]);
ukey[5] = hc_swap32_S (k2[0]);
u32 iv[2];
iv[0] = hc_swap32_S (k2[3]);
iv[1] = hc_swap32_S (k2[4]);
u32 K0[16];
u32 K1[16];
u32 K2[16];
u32 K3[16];
u32 K4[16];
u32 K5[16];
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
u32 ct[2];
u32 pt[2];
u32 t1[2];
u32 t2[2];
ct[0] = ct_buf0[0];
ct[1] = ct_buf0[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// password
if (pt[0] != 0x73736170) continue;
if (pt[1] != 0x64726f77) continue;
iv[0] = ct_buf0[0];
iv[1] = ct_buf0[1];
ct[0] = ct_buf1[0];
ct[1] = ct_buf1[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// -check\x02\x02
if (pt[0] != 0x6568632d) continue;
if (pt[1] != 0x02026b63) continue;
const u32 r0 = ct_buf0[0];
const u32 r1 = ct_buf0[1];
const u32 r2 = ct_buf1[0];
const u32 r3 = ct_buf1[1];
COMPARE_S_SCALAR (r0, r1, r2, r3);
}
}

@ -0,0 +1,768 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
//#define NEW_SIMD_CODE
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_scalar.cl"
#include "inc_hash_sha1.cl"
#include "inc_cipher_des.cl"
#endif
typedef struct mozilla_3des
{
u32 ct_buf[4];
} mozilla_3des_t;
KERNEL_FQ void m26000_mxx (KERN_ATTR_ESALT (mozilla_3des_t))
{
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
const u64 lsz = get_local_size (0);
/**
* aes shared
*/
#ifdef REAL_SHM
LOCAL_VK u32 s_SPtrans[8][64];
LOCAL_VK u32 s_skb[8][64];
for (u32 i = lid; i < 64; i += lsz)
{
s_SPtrans[0][i] = c_SPtrans[0][i];
s_SPtrans[1][i] = c_SPtrans[1][i];
s_SPtrans[2][i] = c_SPtrans[2][i];
s_SPtrans[3][i] = c_SPtrans[3][i];
s_SPtrans[4][i] = c_SPtrans[4][i];
s_SPtrans[5][i] = c_SPtrans[5][i];
s_SPtrans[6][i] = c_SPtrans[6][i];
s_SPtrans[7][i] = c_SPtrans[7][i];
s_skb[0][i] = c_skb[0][i];
s_skb[1][i] = c_skb[1][i];
s_skb[2][i] = c_skb[2][i];
s_skb[3][i] = c_skb[3][i];
s_skb[4][i] = c_skb[4][i];
s_skb[5][i] = c_skb[5][i];
s_skb[6][i] = c_skb[6][i];
s_skb[7][i] = c_skb[7][i];
}
SYNC_THREADS ();
#else
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
#endif
if (gid >= gid_max) return;
/**
* base
*/
const u32 pw_len = pws[gid].pw_len;
u32 w[64] = { 0 };
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
u32 gs_buf[5];
gs_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 0]);
gs_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 1]);
gs_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 2]);
gs_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 3]);
gs_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 4]);
u32 es_buf[5];
es_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 8]);
es_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 9]);
es_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[10]);
es_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[11]);
es_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[12]);
u32 ct_buf0[2];
ct_buf0[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[0];
ct_buf0[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[1];
u32 ct_buf1[2];
ct_buf1[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[2];
ct_buf1[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[3];
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
const u32 comb_len = combs_buf[il_pos].pw_len;
u32 c[64];
#ifdef _unroll
#pragma unroll
#endif
for (int idx = 0; idx < 64; idx++)
{
c[idx] = combs_buf[il_pos].i[idx];
}
switch_buffer_by_offset_1x64_le_S (c, pw_len);
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 64; i++)
{
c[i] |= w[i];
}
// my $hp = sha1 ($global_salt_bin . $word);
sha1_ctx_t ctx0;
sha1_init (&ctx0);
ctx0.w0[0] = gs_buf[0];
ctx0.w0[1] = gs_buf[1];
ctx0.w0[2] = gs_buf[2];
ctx0.w0[3] = gs_buf[3];
ctx0.w1[0] = gs_buf[4];
ctx0.len = 20;
sha1_update_swap (&ctx0, c, pw_len + comb_len);
sha1_final (&ctx0);
u32 hp[5];
hp[0] = ctx0.h[0];
hp[1] = ctx0.h[1];
hp[2] = ctx0.h[2];
hp[3] = ctx0.h[3];
hp[4] = ctx0.h[4];
// my $chp = sha1 ($hp . $entry_salt_bin);
sha1_init (&ctx0);
ctx0.w0[0] = hp[0];
ctx0.w0[1] = hp[1];
ctx0.w0[2] = hp[2];
ctx0.w0[3] = hp[3];
ctx0.w1[0] = hp[4];
ctx0.w1[1] = es_buf[0];
ctx0.w1[2] = es_buf[1];
ctx0.w1[3] = es_buf[2];
ctx0.w2[0] = es_buf[3];
ctx0.w2[1] = es_buf[4];
ctx0.len = 40;
sha1_final (&ctx0);
u32 chp[5];
chp[0] = ctx0.h[0];
chp[1] = ctx0.h[1];
chp[2] = ctx0.h[2];
chp[3] = ctx0.h[3];
chp[4] = ctx0.h[4];
// my $k1 = hmac ($pes . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1;
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = chp[0];
w0[1] = chp[1];
w0[2] = chp[2];
w0[3] = chp[3];
w1[0] = chp[4];
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;
w3[3] = 0;
sha1_hmac_init_64 (&ctx1, w0, w1, w2, w3);
sha1_hmac_ctx_t ctx1a = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1a, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1a);
u32 k1[5];
k1[0] = ctx1a.opad.h[0];
k1[1] = ctx1a.opad.h[1];
k1[2] = ctx1a.opad.h[2];
k1[3] = ctx1a.opad.h[3];
k1[4] = ctx1a.opad.h[4];
// my $tk = hmac ($pes, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1b = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
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;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1b, w0, w1, w2, w3, 20);
sha1_hmac_final (&ctx1b);
u32 tk[5];
tk[0] = ctx1b.opad.h[0];
tk[1] = ctx1b.opad.h[1];
tk[2] = ctx1b.opad.h[2];
tk[3] = ctx1b.opad.h[3];
tk[4] = ctx1b.opad.h[4];
// my $k2 = hmac ($tk . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1c = ctx1;
w0[0] = tk[0];
w0[1] = tk[1];
w0[2] = tk[2];
w0[3] = tk[3];
w1[0] = tk[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1c, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1c);
u32 k2[5];
k2[0] = ctx1c.opad.h[0];
k2[1] = ctx1c.opad.h[1];
k2[2] = ctx1c.opad.h[2];
k2[3] = ctx1c.opad.h[3];
k2[4] = ctx1c.opad.h[4];
// 3DES
u32 ukey[6];
ukey[0] = hc_swap32_S (k1[0]);
ukey[1] = hc_swap32_S (k1[1]);
ukey[2] = hc_swap32_S (k1[2]);
ukey[3] = hc_swap32_S (k1[3]);
ukey[4] = hc_swap32_S (k1[4]);
ukey[5] = hc_swap32_S (k2[0]);
u32 iv[2];
iv[0] = hc_swap32_S (k2[3]);
iv[1] = hc_swap32_S (k2[4]);
u32 K0[16];
u32 K1[16];
u32 K2[16];
u32 K3[16];
u32 K4[16];
u32 K5[16];
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
u32 ct[2];
u32 pt[2];
u32 t1[2];
u32 t2[2];
ct[0] = ct_buf0[0];
ct[1] = ct_buf0[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// password
if (pt[0] != 0x73736170) continue;
if (pt[1] != 0x64726f77) continue;
iv[0] = ct_buf0[0];
iv[1] = ct_buf0[1];
ct[0] = ct_buf1[0];
ct[1] = ct_buf1[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// -check\x02\x02
if (pt[0] != 0x6568632d) continue;
if (pt[1] != 0x02026b63) continue;
const u32 r0 = ct_buf0[0];
const u32 r1 = ct_buf0[1];
const u32 r2 = ct_buf1[0];
const u32 r3 = ct_buf1[1];
COMPARE_M_SCALAR (r0, r1, r2, r3);
}
}
KERNEL_FQ void m26000_sxx (KERN_ATTR_ESALT (mozilla_3des_t))
{
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
const u64 lsz = get_local_size (0);
/**
* aes shared
*/
#ifdef REAL_SHM
LOCAL_VK u32 s_SPtrans[8][64];
LOCAL_VK u32 s_skb[8][64];
for (u32 i = lid; i < 64; i += lsz)
{
s_SPtrans[0][i] = c_SPtrans[0][i];
s_SPtrans[1][i] = c_SPtrans[1][i];
s_SPtrans[2][i] = c_SPtrans[2][i];
s_SPtrans[3][i] = c_SPtrans[3][i];
s_SPtrans[4][i] = c_SPtrans[4][i];
s_SPtrans[5][i] = c_SPtrans[5][i];
s_SPtrans[6][i] = c_SPtrans[6][i];
s_SPtrans[7][i] = c_SPtrans[7][i];
s_skb[0][i] = c_skb[0][i];
s_skb[1][i] = c_skb[1][i];
s_skb[2][i] = c_skb[2][i];
s_skb[3][i] = c_skb[3][i];
s_skb[4][i] = c_skb[4][i];
s_skb[5][i] = c_skb[5][i];
s_skb[6][i] = c_skb[6][i];
s_skb[7][i] = c_skb[7][i];
}
SYNC_THREADS ();
#else
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
#endif
if (gid >= gid_max) return;
/**
* digest
*/
const u32 search[4] =
{
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R0],
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R1],
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R2],
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R3]
};
/**
* base
*/
const u32 pw_len = pws[gid].pw_len;
u32 w[64] = { 0 };
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
u32 gs_buf[5];
gs_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 0]);
gs_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 1]);
gs_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 2]);
gs_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 3]);
gs_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 4]);
u32 es_buf[5];
es_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 8]);
es_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 9]);
es_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[10]);
es_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[11]);
es_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[12]);
u32 ct_buf0[2];
ct_buf0[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[0];
ct_buf0[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[1];
u32 ct_buf1[2];
ct_buf1[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[2];
ct_buf1[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[3];
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
const u32 comb_len = combs_buf[il_pos].pw_len;
u32 c[64];
#ifdef _unroll
#pragma unroll
#endif
for (int idx = 0; idx < 64; idx++)
{
c[idx] = combs_buf[il_pos].i[idx];
}
switch_buffer_by_offset_1x64_le_S (c, pw_len);
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 64; i++)
{
c[i] |= w[i];
}
// my $hp = sha1 ($global_salt_bin . $word);
sha1_ctx_t ctx0;
sha1_init (&ctx0);
ctx0.w0[0] = gs_buf[0];
ctx0.w0[1] = gs_buf[1];
ctx0.w0[2] = gs_buf[2];
ctx0.w0[3] = gs_buf[3];
ctx0.w1[0] = gs_buf[4];
ctx0.len = 20;
sha1_update_swap (&ctx0, c, pw_len + comb_len);
sha1_final (&ctx0);
u32 hp[5];
hp[0] = ctx0.h[0];
hp[1] = ctx0.h[1];
hp[2] = ctx0.h[2];
hp[3] = ctx0.h[3];
hp[4] = ctx0.h[4];
// my $chp = sha1 ($hp . $entry_salt_bin);
sha1_init (&ctx0);
ctx0.w0[0] = hp[0];
ctx0.w0[1] = hp[1];
ctx0.w0[2] = hp[2];
ctx0.w0[3] = hp[3];
ctx0.w1[0] = hp[4];
ctx0.w1[1] = es_buf[0];
ctx0.w1[2] = es_buf[1];
ctx0.w1[3] = es_buf[2];
ctx0.w2[0] = es_buf[3];
ctx0.w2[1] = es_buf[4];
ctx0.len = 40;
sha1_final (&ctx0);
u32 chp[5];
chp[0] = ctx0.h[0];
chp[1] = ctx0.h[1];
chp[2] = ctx0.h[2];
chp[3] = ctx0.h[3];
chp[4] = ctx0.h[4];
// my $k1 = hmac ($pes . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1;
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = chp[0];
w0[1] = chp[1];
w0[2] = chp[2];
w0[3] = chp[3];
w1[0] = chp[4];
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;
w3[3] = 0;
sha1_hmac_init_64 (&ctx1, w0, w1, w2, w3);
sha1_hmac_ctx_t ctx1a = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1a, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1a);
u32 k1[5];
k1[0] = ctx1a.opad.h[0];
k1[1] = ctx1a.opad.h[1];
k1[2] = ctx1a.opad.h[2];
k1[3] = ctx1a.opad.h[3];
k1[4] = ctx1a.opad.h[4];
// my $tk = hmac ($pes, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1b = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
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;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1b, w0, w1, w2, w3, 20);
sha1_hmac_final (&ctx1b);
u32 tk[5];
tk[0] = ctx1b.opad.h[0];
tk[1] = ctx1b.opad.h[1];
tk[2] = ctx1b.opad.h[2];
tk[3] = ctx1b.opad.h[3];
tk[4] = ctx1b.opad.h[4];
// my $k2 = hmac ($tk . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1c = ctx1;
w0[0] = tk[0];
w0[1] = tk[1];
w0[2] = tk[2];
w0[3] = tk[3];
w1[0] = tk[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1c, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1c);
u32 k2[5];
k2[0] = ctx1c.opad.h[0];
k2[1] = ctx1c.opad.h[1];
k2[2] = ctx1c.opad.h[2];
k2[3] = ctx1c.opad.h[3];
k2[4] = ctx1c.opad.h[4];
// 3DES
u32 ukey[6];
ukey[0] = hc_swap32_S (k1[0]);
ukey[1] = hc_swap32_S (k1[1]);
ukey[2] = hc_swap32_S (k1[2]);
ukey[3] = hc_swap32_S (k1[3]);
ukey[4] = hc_swap32_S (k1[4]);
ukey[5] = hc_swap32_S (k2[0]);
u32 iv[2];
iv[0] = hc_swap32_S (k2[3]);
iv[1] = hc_swap32_S (k2[4]);
u32 K0[16];
u32 K1[16];
u32 K2[16];
u32 K3[16];
u32 K4[16];
u32 K5[16];
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
u32 ct[2];
u32 pt[2];
u32 t1[2];
u32 t2[2];
ct[0] = ct_buf0[0];
ct[1] = ct_buf0[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// password
if (pt[0] != 0x73736170) continue;
if (pt[1] != 0x64726f77) continue;
iv[0] = ct_buf0[0];
iv[1] = ct_buf0[1];
ct[0] = ct_buf1[0];
ct[1] = ct_buf1[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// -check\x02\x02
if (pt[0] != 0x6568632d) continue;
if (pt[1] != 0x02026b63) continue;
const u32 r0 = ct_buf0[0];
const u32 r1 = ct_buf0[1];
const u32 r2 = ct_buf1[0];
const u32 r3 = ct_buf1[1];
COMPARE_S_SCALAR (r0, r1, r2, r3);
}
}

@ -0,0 +1,740 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
//#define NEW_SIMD_CODE
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_scalar.cl"
#include "inc_hash_sha1.cl"
#include "inc_cipher_des.cl"
#endif
typedef struct mozilla_3des
{
u32 ct_buf[4];
} mozilla_3des_t;
KERNEL_FQ void m26000_mxx (KERN_ATTR_VECTOR_ESALT (mozilla_3des_t))
{
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
const u64 lsz = get_local_size (0);
/**
* aes shared
*/
#ifdef REAL_SHM
LOCAL_VK u32 s_SPtrans[8][64];
LOCAL_VK u32 s_skb[8][64];
for (u32 i = lid; i < 64; i += lsz)
{
s_SPtrans[0][i] = c_SPtrans[0][i];
s_SPtrans[1][i] = c_SPtrans[1][i];
s_SPtrans[2][i] = c_SPtrans[2][i];
s_SPtrans[3][i] = c_SPtrans[3][i];
s_SPtrans[4][i] = c_SPtrans[4][i];
s_SPtrans[5][i] = c_SPtrans[5][i];
s_SPtrans[6][i] = c_SPtrans[6][i];
s_SPtrans[7][i] = c_SPtrans[7][i];
s_skb[0][i] = c_skb[0][i];
s_skb[1][i] = c_skb[1][i];
s_skb[2][i] = c_skb[2][i];
s_skb[3][i] = c_skb[3][i];
s_skb[4][i] = c_skb[4][i];
s_skb[5][i] = c_skb[5][i];
s_skb[6][i] = c_skb[6][i];
s_skb[7][i] = c_skb[7][i];
}
SYNC_THREADS ();
#else
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
#endif
if (gid >= gid_max) return;
/**
* base
*/
const u32 pw_len = pws[gid].pw_len;
u32 w[64] = { 0 };
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
u32 gs_buf[5];
gs_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 0]);
gs_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 1]);
gs_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 2]);
gs_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 3]);
gs_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 4]);
u32 es_buf[5];
es_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 8]);
es_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 9]);
es_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[10]);
es_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[11]);
es_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[12]);
u32 ct_buf0[2];
ct_buf0[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[0];
ct_buf0[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[1];
u32 ct_buf1[2];
ct_buf1[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[2];
ct_buf1[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[3];
/**
* loop
*/
u32 w0l = w[0];
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
{
const u32 w0r = words_buf_r[il_pos / VECT_SIZE];
const u32 w0lr = w0l | w0r;
w[0] = w0lr;
// my $hp = sha1 ($global_salt_bin . $word);
sha1_ctx_t ctx0;
sha1_init (&ctx0);
ctx0.w0[0] = gs_buf[0];
ctx0.w0[1] = gs_buf[1];
ctx0.w0[2] = gs_buf[2];
ctx0.w0[3] = gs_buf[3];
ctx0.w1[0] = gs_buf[4];
ctx0.len = 20;
sha1_update (&ctx0, w, pw_len);
sha1_final (&ctx0);
u32 hp[5];
hp[0] = ctx0.h[0];
hp[1] = ctx0.h[1];
hp[2] = ctx0.h[2];
hp[3] = ctx0.h[3];
hp[4] = ctx0.h[4];
// my $chp = sha1 ($hp . $entry_salt_bin);
sha1_init (&ctx0);
ctx0.w0[0] = hp[0];
ctx0.w0[1] = hp[1];
ctx0.w0[2] = hp[2];
ctx0.w0[3] = hp[3];
ctx0.w1[0] = hp[4];
ctx0.w1[1] = es_buf[0];
ctx0.w1[2] = es_buf[1];
ctx0.w1[3] = es_buf[2];
ctx0.w2[0] = es_buf[3];
ctx0.w2[1] = es_buf[4];
ctx0.len = 40;
sha1_final (&ctx0);
u32 chp[5];
chp[0] = ctx0.h[0];
chp[1] = ctx0.h[1];
chp[2] = ctx0.h[2];
chp[3] = ctx0.h[3];
chp[4] = ctx0.h[4];
// my $k1 = hmac ($pes . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1;
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = chp[0];
w0[1] = chp[1];
w0[2] = chp[2];
w0[3] = chp[3];
w1[0] = chp[4];
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;
w3[3] = 0;
sha1_hmac_init_64 (&ctx1, w0, w1, w2, w3);
sha1_hmac_ctx_t ctx1a = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1a, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1a);
u32 k1[5];
k1[0] = ctx1a.opad.h[0];
k1[1] = ctx1a.opad.h[1];
k1[2] = ctx1a.opad.h[2];
k1[3] = ctx1a.opad.h[3];
k1[4] = ctx1a.opad.h[4];
// my $tk = hmac ($pes, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1b = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
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;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1b, w0, w1, w2, w3, 20);
sha1_hmac_final (&ctx1b);
u32 tk[5];
tk[0] = ctx1b.opad.h[0];
tk[1] = ctx1b.opad.h[1];
tk[2] = ctx1b.opad.h[2];
tk[3] = ctx1b.opad.h[3];
tk[4] = ctx1b.opad.h[4];
// my $k2 = hmac ($tk . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1c = ctx1;
w0[0] = tk[0];
w0[1] = tk[1];
w0[2] = tk[2];
w0[3] = tk[3];
w1[0] = tk[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1c, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1c);
u32 k2[5];
k2[0] = ctx1c.opad.h[0];
k2[1] = ctx1c.opad.h[1];
k2[2] = ctx1c.opad.h[2];
k2[3] = ctx1c.opad.h[3];
k2[4] = ctx1c.opad.h[4];
// 3DES
u32 ukey[6];
ukey[0] = hc_swap32_S (k1[0]);
ukey[1] = hc_swap32_S (k1[1]);
ukey[2] = hc_swap32_S (k1[2]);
ukey[3] = hc_swap32_S (k1[3]);
ukey[4] = hc_swap32_S (k1[4]);
ukey[5] = hc_swap32_S (k2[0]);
u32 iv[2];
iv[0] = hc_swap32_S (k2[3]);
iv[1] = hc_swap32_S (k2[4]);
u32 K0[16];
u32 K1[16];
u32 K2[16];
u32 K3[16];
u32 K4[16];
u32 K5[16];
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
u32 ct[2];
u32 pt[2];
u32 t1[2];
u32 t2[2];
ct[0] = ct_buf0[0];
ct[1] = ct_buf0[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// password
if (pt[0] != 0x73736170) continue;
if (pt[1] != 0x64726f77) continue;
iv[0] = ct_buf0[0];
iv[1] = ct_buf0[1];
ct[0] = ct_buf1[0];
ct[1] = ct_buf1[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// -check\x02\x02
if (pt[0] != 0x6568632d) continue;
if (pt[1] != 0x02026b63) continue;
const u32 r0 = ct_buf0[0];
const u32 r1 = ct_buf0[1];
const u32 r2 = ct_buf1[0];
const u32 r3 = ct_buf1[1];
COMPARE_M_SCALAR (r0, r1, r2, r3);
}
}
KERNEL_FQ void m26000_sxx (KERN_ATTR_VECTOR_ESALT (mozilla_3des_t))
{
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
const u64 lsz = get_local_size (0);
/**
* aes shared
*/
#ifdef REAL_SHM
LOCAL_VK u32 s_SPtrans[8][64];
LOCAL_VK u32 s_skb[8][64];
for (u32 i = lid; i < 64; i += lsz)
{
s_SPtrans[0][i] = c_SPtrans[0][i];
s_SPtrans[1][i] = c_SPtrans[1][i];
s_SPtrans[2][i] = c_SPtrans[2][i];
s_SPtrans[3][i] = c_SPtrans[3][i];
s_SPtrans[4][i] = c_SPtrans[4][i];
s_SPtrans[5][i] = c_SPtrans[5][i];
s_SPtrans[6][i] = c_SPtrans[6][i];
s_SPtrans[7][i] = c_SPtrans[7][i];
s_skb[0][i] = c_skb[0][i];
s_skb[1][i] = c_skb[1][i];
s_skb[2][i] = c_skb[2][i];
s_skb[3][i] = c_skb[3][i];
s_skb[4][i] = c_skb[4][i];
s_skb[5][i] = c_skb[5][i];
s_skb[6][i] = c_skb[6][i];
s_skb[7][i] = c_skb[7][i];
}
SYNC_THREADS ();
#else
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
#endif
if (gid >= gid_max) return;
/**
* digest
*/
const u32 search[4] =
{
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R0],
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R1],
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R2],
digests_buf[DIGESTS_OFFSET].digest_buf[DGST_R3]
};
/**
* base
*/
const u32 pw_len = pws[gid].pw_len;
u32 w[64] = { 0 };
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
u32 gs_buf[5];
gs_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 0]);
gs_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 1]);
gs_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 2]);
gs_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 3]);
gs_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 4]);
u32 es_buf[5];
es_buf[0] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 8]);
es_buf[1] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[ 9]);
es_buf[2] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[10]);
es_buf[3] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[11]);
es_buf[4] = hc_swap32_S (salt_bufs[SALT_POS].salt_buf[12]);
u32 ct_buf0[2];
ct_buf0[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[0];
ct_buf0[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[1];
u32 ct_buf1[2];
ct_buf1[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[2];
ct_buf1[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[3];
/**
* loop
*/
u32 w0l = w[0];
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
{
const u32 w0r = words_buf_r[il_pos / VECT_SIZE];
const u32 w0lr = w0l | w0r;
w[0] = w0lr;
// my $hp = sha1 ($global_salt_bin . $word);
sha1_ctx_t ctx0;
sha1_init (&ctx0);
ctx0.w0[0] = gs_buf[0];
ctx0.w0[1] = gs_buf[1];
ctx0.w0[2] = gs_buf[2];
ctx0.w0[3] = gs_buf[3];
ctx0.w1[0] = gs_buf[4];
ctx0.len = 20;
sha1_update (&ctx0, w, pw_len);
sha1_final (&ctx0);
u32 hp[5];
hp[0] = ctx0.h[0];
hp[1] = ctx0.h[1];
hp[2] = ctx0.h[2];
hp[3] = ctx0.h[3];
hp[4] = ctx0.h[4];
// my $chp = sha1 ($hp . $entry_salt_bin);
sha1_init (&ctx0);
ctx0.w0[0] = hp[0];
ctx0.w0[1] = hp[1];
ctx0.w0[2] = hp[2];
ctx0.w0[3] = hp[3];
ctx0.w1[0] = hp[4];
ctx0.w1[1] = es_buf[0];
ctx0.w1[2] = es_buf[1];
ctx0.w1[3] = es_buf[2];
ctx0.w2[0] = es_buf[3];
ctx0.w2[1] = es_buf[4];
ctx0.len = 40;
sha1_final (&ctx0);
u32 chp[5];
chp[0] = ctx0.h[0];
chp[1] = ctx0.h[1];
chp[2] = ctx0.h[2];
chp[3] = ctx0.h[3];
chp[4] = ctx0.h[4];
// my $k1 = hmac ($pes . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1;
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = chp[0];
w0[1] = chp[1];
w0[2] = chp[2];
w0[3] = chp[3];
w1[0] = chp[4];
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;
w3[3] = 0;
sha1_hmac_init_64 (&ctx1, w0, w1, w2, w3);
sha1_hmac_ctx_t ctx1a = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1a, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1a);
u32 k1[5];
k1[0] = ctx1a.opad.h[0];
k1[1] = ctx1a.opad.h[1];
k1[2] = ctx1a.opad.h[2];
k1[3] = ctx1a.opad.h[3];
k1[4] = ctx1a.opad.h[4];
// my $tk = hmac ($pes, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1b = ctx1;
w0[0] = es_buf[0];
w0[1] = es_buf[1];
w0[2] = es_buf[2];
w0[3] = es_buf[3];
w1[0] = es_buf[4];
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;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1b, w0, w1, w2, w3, 20);
sha1_hmac_final (&ctx1b);
u32 tk[5];
tk[0] = ctx1b.opad.h[0];
tk[1] = ctx1b.opad.h[1];
tk[2] = ctx1b.opad.h[2];
tk[3] = ctx1b.opad.h[3];
tk[4] = ctx1b.opad.h[4];
// my $k2 = hmac ($tk . $entry_salt_bin, $chp, \&sha1, 64);
sha1_hmac_ctx_t ctx1c = ctx1;
w0[0] = tk[0];
w0[1] = tk[1];
w0[2] = tk[2];
w0[3] = tk[3];
w1[0] = tk[4];
w1[1] = es_buf[0];
w1[2] = es_buf[1];
w1[3] = es_buf[2];
w2[0] = es_buf[3];
w2[1] = es_buf[4];
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
sha1_hmac_update_64 (&ctx1c, w0, w1, w2, w3, 40);
sha1_hmac_final (&ctx1c);
u32 k2[5];
k2[0] = ctx1c.opad.h[0];
k2[1] = ctx1c.opad.h[1];
k2[2] = ctx1c.opad.h[2];
k2[3] = ctx1c.opad.h[3];
k2[4] = ctx1c.opad.h[4];
// 3DES
u32 ukey[6];
ukey[0] = hc_swap32_S (k1[0]);
ukey[1] = hc_swap32_S (k1[1]);
ukey[2] = hc_swap32_S (k1[2]);
ukey[3] = hc_swap32_S (k1[3]);
ukey[4] = hc_swap32_S (k1[4]);
ukey[5] = hc_swap32_S (k2[0]);
u32 iv[2];
iv[0] = hc_swap32_S (k2[3]);
iv[1] = hc_swap32_S (k2[4]);
u32 K0[16];
u32 K1[16];
u32 K2[16];
u32 K3[16];
u32 K4[16];
u32 K5[16];
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
u32 ct[2];
u32 pt[2];
u32 t1[2];
u32 t2[2];
ct[0] = ct_buf0[0];
ct[1] = ct_buf0[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// password
if (pt[0] != 0x73736170) continue;
if (pt[1] != 0x64726f77) continue;
iv[0] = ct_buf0[0];
iv[1] = ct_buf0[1];
ct[0] = ct_buf1[0];
ct[1] = ct_buf1[1];
_des_crypt_decrypt (t1, ct, K4, K5, s_SPtrans);
_des_crypt_encrypt (t2, t1, K2, K3, s_SPtrans);
_des_crypt_decrypt (pt, t2, K0, K1, s_SPtrans);
pt[0] ^= iv[0];
pt[1] ^= iv[1];
// -check\x02\x02
if (pt[0] != 0x6568632d) continue;
if (pt[1] != 0x02026b63) continue;
const u32 r0 = ct_buf0[0];
const u32 r1 = ct_buf0[1];
const u32 r2 = ct_buf1[0];
const u32 r3 = ct_buf1[1];
COMPARE_S_SCALAR (r0, r1, r2, r3);
}
}

@ -0,0 +1,428 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define NEW_SIMD_CODE
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_simd.cl"
#include "inc_hash_sha1.cl"
#include "inc_hash_sha256.cl"
#include "inc_cipher_aes.cl"
#endif
#define COMPARE_S "inc_comp_single.cl"
#define COMPARE_M "inc_comp_multi.cl"
typedef struct mozilla_aes_tmp
{
u32 ipad[8];
u32 opad[8];
u32 dgst[8];
u32 out[8];
} mozilla_aes_tmp_t;
typedef struct mozilla_aes
{
u32 iv_buf[4];
u32 ct_buf[4];
} mozilla_aes_t;
DECLSPEC void hmac_sha256_run_V (u32x *w0, u32x *w1, u32x *w2, u32x *w3, u32x *ipad, u32x *opad, u32x *digest)
{
digest[0] = ipad[0];
digest[1] = ipad[1];
digest[2] = ipad[2];
digest[3] = ipad[3];
digest[4] = ipad[4];
digest[5] = ipad[5];
digest[6] = ipad[6];
digest[7] = ipad[7];
sha256_transform_vector (w0, w1, w2, w3, digest);
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];
w2[0] = 0x80000000;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = (64 + 32) * 8;
digest[0] = opad[0];
digest[1] = opad[1];
digest[2] = opad[2];
digest[3] = opad[3];
digest[4] = opad[4];
digest[5] = opad[5];
digest[6] = opad[6];
digest[7] = opad[7];
sha256_transform_vector (w0, w1, w2, w3, digest);
}
KERNEL_FQ void m26100_init (KERN_ATTR_TMPS_ESALT (mozilla_aes_tmp_t, mozilla_aes_t))
{
/**
* base
*/
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
sha1_ctx_t ctx;
sha1_init (&ctx);
// there's some data in salt_buf[8] and onwards so we need to move this to local variable
u32 gs[16] = { 0 };
gs[0] = salt_bufs[DIGESTS_OFFSET].salt_buf[0];
gs[1] = salt_bufs[DIGESTS_OFFSET].salt_buf[1];
gs[2] = salt_bufs[DIGESTS_OFFSET].salt_buf[2];
gs[3] = salt_bufs[DIGESTS_OFFSET].salt_buf[3];
gs[4] = salt_bufs[DIGESTS_OFFSET].salt_buf[4];
sha1_update_swap (&ctx, gs, 20);
sha1_update_global_swap (&ctx, pws[gid].i, pws[gid].pw_len);
sha1_final (&ctx);
u32 ek[16] = { 0 };
ek[0] = ctx.h[0];
ek[1] = ctx.h[1];
ek[2] = ctx.h[2];
ek[3] = ctx.h[3];
ek[4] = ctx.h[4];
sha256_hmac_ctx_t sha256_hmac_ctx;
sha256_hmac_init (&sha256_hmac_ctx, ek, 20);
tmps[gid].ipad[0] = sha256_hmac_ctx.ipad.h[0];
tmps[gid].ipad[1] = sha256_hmac_ctx.ipad.h[1];
tmps[gid].ipad[2] = sha256_hmac_ctx.ipad.h[2];
tmps[gid].ipad[3] = sha256_hmac_ctx.ipad.h[3];
tmps[gid].ipad[4] = sha256_hmac_ctx.ipad.h[4];
tmps[gid].ipad[5] = sha256_hmac_ctx.ipad.h[5];
tmps[gid].ipad[6] = sha256_hmac_ctx.ipad.h[6];
tmps[gid].ipad[7] = sha256_hmac_ctx.ipad.h[7];
tmps[gid].opad[0] = sha256_hmac_ctx.opad.h[0];
tmps[gid].opad[1] = sha256_hmac_ctx.opad.h[1];
tmps[gid].opad[2] = sha256_hmac_ctx.opad.h[2];
tmps[gid].opad[3] = sha256_hmac_ctx.opad.h[3];
tmps[gid].opad[4] = sha256_hmac_ctx.opad.h[4];
tmps[gid].opad[5] = sha256_hmac_ctx.opad.h[5];
tmps[gid].opad[6] = sha256_hmac_ctx.opad.h[6];
tmps[gid].opad[7] = sha256_hmac_ctx.opad.h[7];
// accessing esalt from _init can lead to false negatives because,
// but we know the global salt is unique for each entry so its fine
u32 es[16] = { 0 };
es[0] = salt_bufs[DIGESTS_OFFSET].salt_buf[ 8];
es[1] = salt_bufs[DIGESTS_OFFSET].salt_buf[ 9];
es[2] = salt_bufs[DIGESTS_OFFSET].salt_buf[10];
es[3] = salt_bufs[DIGESTS_OFFSET].salt_buf[11];
es[4] = salt_bufs[DIGESTS_OFFSET].salt_buf[12];
es[5] = salt_bufs[DIGESTS_OFFSET].salt_buf[13];
es[6] = salt_bufs[DIGESTS_OFFSET].salt_buf[14];
es[7] = salt_bufs[DIGESTS_OFFSET].salt_buf[15];
sha256_hmac_update_swap (&sha256_hmac_ctx, es, 32);
for (u32 i = 0, j = 1; i < 8; i += 8, j += 1)
{
sha256_hmac_ctx_t sha256_hmac_ctx2 = sha256_hmac_ctx;
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = j;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
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;
w3[3] = 0;
sha256_hmac_update_64 (&sha256_hmac_ctx2, w0, w1, w2, w3, 4);
sha256_hmac_final (&sha256_hmac_ctx2);
tmps[gid].dgst[i + 0] = sha256_hmac_ctx2.opad.h[0];
tmps[gid].dgst[i + 1] = sha256_hmac_ctx2.opad.h[1];
tmps[gid].dgst[i + 2] = sha256_hmac_ctx2.opad.h[2];
tmps[gid].dgst[i + 3] = sha256_hmac_ctx2.opad.h[3];
tmps[gid].dgst[i + 4] = sha256_hmac_ctx2.opad.h[4];
tmps[gid].dgst[i + 5] = sha256_hmac_ctx2.opad.h[5];
tmps[gid].dgst[i + 6] = sha256_hmac_ctx2.opad.h[6];
tmps[gid].dgst[i + 7] = sha256_hmac_ctx2.opad.h[7];
tmps[gid].out[i + 0] = tmps[gid].dgst[i + 0];
tmps[gid].out[i + 1] = tmps[gid].dgst[i + 1];
tmps[gid].out[i + 2] = tmps[gid].dgst[i + 2];
tmps[gid].out[i + 3] = tmps[gid].dgst[i + 3];
tmps[gid].out[i + 4] = tmps[gid].dgst[i + 4];
tmps[gid].out[i + 5] = tmps[gid].dgst[i + 5];
tmps[gid].out[i + 6] = tmps[gid].dgst[i + 6];
tmps[gid].out[i + 7] = tmps[gid].dgst[i + 7];
}
}
KERNEL_FQ void m26100_loop (KERN_ATTR_TMPS_ESALT (mozilla_aes_tmp_t, mozilla_aes_t))
{
const u64 gid = get_global_id (0);
if ((gid * VECT_SIZE) >= gid_max) return;
u32x ipad[8];
u32x opad[8];
ipad[0] = packv (tmps, ipad, gid, 0);
ipad[1] = packv (tmps, ipad, gid, 1);
ipad[2] = packv (tmps, ipad, gid, 2);
ipad[3] = packv (tmps, ipad, gid, 3);
ipad[4] = packv (tmps, ipad, gid, 4);
ipad[5] = packv (tmps, ipad, gid, 5);
ipad[6] = packv (tmps, ipad, gid, 6);
ipad[7] = packv (tmps, ipad, gid, 7);
opad[0] = packv (tmps, opad, gid, 0);
opad[1] = packv (tmps, opad, gid, 1);
opad[2] = packv (tmps, opad, gid, 2);
opad[3] = packv (tmps, opad, gid, 3);
opad[4] = packv (tmps, opad, gid, 4);
opad[5] = packv (tmps, opad, gid, 5);
opad[6] = packv (tmps, opad, gid, 6);
opad[7] = packv (tmps, opad, gid, 7);
for (u32 i = 0; i < 8; i += 8)
{
u32x dgst[8];
u32x out[8];
dgst[0] = packv (tmps, dgst, gid, i + 0);
dgst[1] = packv (tmps, dgst, gid, i + 1);
dgst[2] = packv (tmps, dgst, gid, i + 2);
dgst[3] = packv (tmps, dgst, gid, i + 3);
dgst[4] = packv (tmps, dgst, gid, i + 4);
dgst[5] = packv (tmps, dgst, gid, i + 5);
dgst[6] = packv (tmps, dgst, gid, i + 6);
dgst[7] = packv (tmps, dgst, gid, i + 7);
out[0] = packv (tmps, out, gid, i + 0);
out[1] = packv (tmps, out, gid, i + 1);
out[2] = packv (tmps, out, gid, i + 2);
out[3] = packv (tmps, out, gid, i + 3);
out[4] = packv (tmps, out, gid, i + 4);
out[5] = packv (tmps, out, gid, i + 5);
out[6] = packv (tmps, out, gid, i + 6);
out[7] = packv (tmps, out, gid, i + 7);
for (u32 j = 0; j < loop_cnt; j++)
{
u32x w0[4];
u32x w1[4];
u32x w2[4];
u32x w3[4];
w0[0] = dgst[0];
w0[1] = dgst[1];
w0[2] = dgst[2];
w0[3] = dgst[3];
w1[0] = dgst[4];
w1[1] = dgst[5];
w1[2] = dgst[6];
w1[3] = dgst[7];
w2[0] = 0x80000000;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = (64 + 32) * 8;
hmac_sha256_run_V (w0, w1, w2, w3, ipad, opad, dgst);
out[0] ^= dgst[0];
out[1] ^= dgst[1];
out[2] ^= dgst[2];
out[3] ^= dgst[3];
out[4] ^= dgst[4];
out[5] ^= dgst[5];
out[6] ^= dgst[6];
out[7] ^= dgst[7];
}
unpackv (tmps, dgst, gid, i + 0, dgst[0]);
unpackv (tmps, dgst, gid, i + 1, dgst[1]);
unpackv (tmps, dgst, gid, i + 2, dgst[2]);
unpackv (tmps, dgst, gid, i + 3, dgst[3]);
unpackv (tmps, dgst, gid, i + 4, dgst[4]);
unpackv (tmps, dgst, gid, i + 5, dgst[5]);
unpackv (tmps, dgst, gid, i + 6, dgst[6]);
unpackv (tmps, dgst, gid, i + 7, dgst[7]);
unpackv (tmps, out, gid, i + 0, out[0]);
unpackv (tmps, out, gid, i + 1, out[1]);
unpackv (tmps, out, gid, i + 2, out[2]);
unpackv (tmps, out, gid, i + 3, out[3]);
unpackv (tmps, out, gid, i + 4, out[4]);
unpackv (tmps, out, gid, i + 5, out[5]);
unpackv (tmps, out, gid, i + 6, out[6]);
unpackv (tmps, out, gid, i + 7, out[7]);
}
}
KERNEL_FQ void m26100_comp (KERN_ATTR_TMPS_ESALT (mozilla_aes_tmp_t, mozilla_aes_t))
{
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
const u64 lsz = get_local_size (0);
/**
* aes shared
*/
#ifdef REAL_SHM
LOCAL_VK u32 s_td0[256];
LOCAL_VK u32 s_td1[256];
LOCAL_VK u32 s_td2[256];
LOCAL_VK u32 s_td3[256];
LOCAL_VK u32 s_td4[256];
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];
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];
}
SYNC_THREADS ();
#else
CONSTANT_AS u32a *s_td0 = td0;
CONSTANT_AS u32a *s_td1 = td1;
CONSTANT_AS u32a *s_td2 = td2;
CONSTANT_AS u32a *s_td3 = td3;
CONSTANT_AS u32a *s_td4 = td4;
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;
#endif
if (gid >= gid_max) return;
u32 ukey[8];
ukey[0] = tmps[gid].out[0];
ukey[1] = tmps[gid].out[1];
ukey[2] = tmps[gid].out[2];
ukey[3] = tmps[gid].out[3];
ukey[4] = tmps[gid].out[4];
ukey[5] = tmps[gid].out[5];
ukey[6] = tmps[gid].out[6];
ukey[7] = tmps[gid].out[7];
u32 ks[60];
AES256_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
// first check the padding
u32 iv_buf[4];
iv_buf[0] = esalt_bufs[DIGESTS_OFFSET].iv_buf[0];
iv_buf[1] = esalt_bufs[DIGESTS_OFFSET].iv_buf[1];
iv_buf[2] = esalt_bufs[DIGESTS_OFFSET].iv_buf[2];
iv_buf[3] = esalt_bufs[DIGESTS_OFFSET].iv_buf[3];
u32 ct_buf[4];
ct_buf[0] = esalt_bufs[DIGESTS_OFFSET].ct_buf[0];
ct_buf[1] = esalt_bufs[DIGESTS_OFFSET].ct_buf[1];
ct_buf[2] = esalt_bufs[DIGESTS_OFFSET].ct_buf[2];
ct_buf[3] = esalt_bufs[DIGESTS_OFFSET].ct_buf[3];
u32 pt_buf[4];
aes256_decrypt (ks, ct_buf, pt_buf, s_td0, s_td1, s_td2, s_td3, s_td4);
pt_buf[0] ^= iv_buf[0];
pt_buf[1] ^= iv_buf[1];
pt_buf[2] ^= iv_buf[2];
pt_buf[3] ^= iv_buf[3];
// password-check\x02\x02
if (pt_buf[0] != 0x73736170) return;
if (pt_buf[1] != 0x64726f77) return;
if (pt_buf[2] != 0x6568632d) return;
if (pt_buf[3] != 0x02026b63) return;
const u32 r0 = ct_buf[0];
const u32 r1 = ct_buf[1];
const u32 r2 = ct_buf[2];
const u32 r3 = ct_buf[3];
#define il_pos 0
#ifdef KERNEL_STATIC
#include COMPARE_M
#endif
}

@ -12,6 +12,8 @@
- Added hash-mode: Dahua Authentication MD5
- Added hash-mode: MongoDB ServerKey SCRAM-SHA-1
- Added hash-mode: MongoDB ServerKey SCRAM-SHA-256
- Added hash-mode: Mozilla key3.db
- Added hash-mode: Mozilla key4.db
- Added hash-mode: MS Office 2016 - SheetProtection
- Added hash-mode: PDF 1.4 - 1.6 (Acrobat 5 - 8) - edit password
- Added hash-mode: PKCS#8 Private Keys

@ -297,6 +297,8 @@ NVIDIA GPUs require "NVIDIA Driver" (440.64 or later) and "CUDA Toolkit" (9.0 or
- Blockchain, My Wallet
- Blockchain, My Wallet, V2
- Blockchain, My Wallet, Second Password (SHA256)
- Mozilla key3.db
- Mozilla key4.db
- Stargazer Stellar Wallet XLM
- Ethereum Pre-Sale Wallet, PBKDF2-HMAC-SHA256
- Ethereum Wallet, PBKDF2-HMAC-SHA256

@ -0,0 +1,263 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#include "common.h"
#include "types.h"
#include "modules.h"
#include "bitops.h"
#include "convert.h"
#include "shared.h"
static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL;
static const u32 DGST_POS0 = 0;
static const u32 DGST_POS1 = 1;
static const u32 DGST_POS2 = 2;
static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_4;
static const u32 HASH_CATEGORY = HASH_CATEGORY_PASSWORD_MANAGER;
static const char *HASH_NAME = "Mozilla key3.db";
static const u64 KERN_TYPE = 26000;
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_NOT_ITERATED;
static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_BE;
static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED;
static const char *ST_PASS = "hashcat";
static const char *ST_HASH = "$mozilla$*3DES*b735d19e6cadb5136376a98c2369f22819d08c79*2b36961682200a877f7d5550975b614acc9fefe3*f03f3575fd5bdbc9e32232316eab7623";
u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; }
u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; }
u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; }
u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; }
u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; }
u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; }
u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; }
const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; }
u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; }
u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; }
u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; }
u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; }
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
typedef struct mozilla_3des
{
u32 ct_buf[4];
} mozilla_3des_t;
static const char *SIGNATURE_MOZILLA = "$mozilla$";
static const char *SIGNATURE_MOZILLA_3DES = "3DES";
u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
{
const u64 esalt_size = (const u64) sizeof (mozilla_3des_t);
return esalt_size;
}
u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
{
// this overrides the reductions of PW_MAX in case optimized kernel is selected
// IOW, even in optimized kernel mode it support length 256
const u32 pw_max = PW_MAX;
return pw_max;
}
int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len)
{
u32 *digest = (u32 *) digest_buf;
mozilla_3des_t *mozilla_3des = (mozilla_3des_t *) esalt_buf;
token_t token;
token.token_cnt = 5;
token.signatures_cnt = 2;
token.signatures_buf[0] = SIGNATURE_MOZILLA;
token.signatures_buf[1] = SIGNATURE_MOZILLA_3DES;
token.sep[0] = '*';
token.len_min[0] = 9;
token.len_max[0] = 9;
token.attr[0] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_SIGNATURE;
token.sep[1] = '*';
token.len_min[1] = 4;
token.len_max[1] = 4;
token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_SIGNATURE;
token.sep[2] = '*';
token.len_min[2] = 40;
token.len_max[2] = 40;
token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
token.sep[3] = '*';
token.len_min[3] = 40;
token.len_max[3] = 40;
token.attr[3] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
token.sep[4] = '*';
token.len_min[4] = 32;
token.len_max[4] = 32;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);
if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);
// global salt buffer + entry salt buffer combined
// this also requires us to copy to local variables in kernel
const u8 *global_salt_pos = token.buf[2];
const u8 *entry_salt_pos = token.buf[3];
salt->salt_buf[ 0] = hex_to_u32 (global_salt_pos + 0);
salt->salt_buf[ 1] = hex_to_u32 (global_salt_pos + 8);
salt->salt_buf[ 2] = hex_to_u32 (global_salt_pos + 16);
salt->salt_buf[ 3] = hex_to_u32 (global_salt_pos + 24);
salt->salt_buf[ 4] = hex_to_u32 (global_salt_pos + 32);
salt->salt_buf[ 5] = 0;
salt->salt_buf[ 6] = 0;
salt->salt_buf[ 7] = 0;
salt->salt_buf[ 8] = hex_to_u32 (entry_salt_pos + 0);
salt->salt_buf[ 9] = hex_to_u32 (entry_salt_pos + 8);
salt->salt_buf[10] = hex_to_u32 (entry_salt_pos + 16);
salt->salt_buf[11] = hex_to_u32 (entry_salt_pos + 24);
salt->salt_buf[12] = hex_to_u32 (entry_salt_pos + 32);
salt->salt_buf[13] = 0;
salt->salt_buf[14] = 0;
salt->salt_buf[15] = 0;
salt->salt_len = 64;
// CT buffer
const u8 *ct_pos = token.buf[4];
mozilla_3des->ct_buf[0] = hex_to_u32 (ct_pos + 0);
mozilla_3des->ct_buf[1] = hex_to_u32 (ct_pos + 8);
mozilla_3des->ct_buf[2] = hex_to_u32 (ct_pos + 16);
mozilla_3des->ct_buf[3] = hex_to_u32 (ct_pos + 24);
// hash
digest[0] = mozilla_3des->ct_buf[0];
digest[1] = mozilla_3des->ct_buf[1];
digest[2] = mozilla_3des->ct_buf[2];
digest[3] = mozilla_3des->ct_buf[3];
return (PARSER_OK);
}
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
const mozilla_3des_t *mozilla_3des = (const mozilla_3des_t *) esalt_buf;
u8 *out_buf = (u8 *) line_buf;
const int out_len = snprintf ((char *) out_buf, line_size, "%s*%s*%08x%08x%08x%08x%08x*%08x%08x%08x%08x%08x*%08x%08x%08x%08x",
SIGNATURE_MOZILLA,
SIGNATURE_MOZILLA_3DES,
byte_swap_32 (salt->salt_buf[ 0]),
byte_swap_32 (salt->salt_buf[ 1]),
byte_swap_32 (salt->salt_buf[ 2]),
byte_swap_32 (salt->salt_buf[ 3]),
byte_swap_32 (salt->salt_buf[ 4]),
byte_swap_32 (salt->salt_buf[ 8]),
byte_swap_32 (salt->salt_buf[ 9]),
byte_swap_32 (salt->salt_buf[10]),
byte_swap_32 (salt->salt_buf[11]),
byte_swap_32 (salt->salt_buf[12]),
byte_swap_32 (mozilla_3des->ct_buf[0]),
byte_swap_32 (mozilla_3des->ct_buf[1]),
byte_swap_32 (mozilla_3des->ct_buf[2]),
byte_swap_32 (mozilla_3des->ct_buf[3]));
return out_len;
}
void module_init (module_ctx_t *module_ctx)
{
module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT;
module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT;
module_ctx->module_attack_exec = module_attack_exec;
module_ctx->module_benchmark_esalt = MODULE_DEFAULT;
module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT;
module_ctx->module_benchmark_mask = MODULE_DEFAULT;
module_ctx->module_benchmark_salt = MODULE_DEFAULT;
module_ctx->module_build_plain_postprocess = MODULE_DEFAULT;
module_ctx->module_deep_comp_kernel = MODULE_DEFAULT;
module_ctx->module_dgst_pos0 = module_dgst_pos0;
module_ctx->module_dgst_pos1 = module_dgst_pos1;
module_ctx->module_dgst_pos2 = module_dgst_pos2;
module_ctx->module_dgst_pos3 = module_dgst_pos3;
module_ctx->module_dgst_size = module_dgst_size;
module_ctx->module_dictstat_disable = MODULE_DEFAULT;
module_ctx->module_esalt_size = module_esalt_size;
module_ctx->module_extra_buffer_size = MODULE_DEFAULT;
module_ctx->module_extra_tmp_size = MODULE_DEFAULT;
module_ctx->module_forced_outfile_format = MODULE_DEFAULT;
module_ctx->module_hash_binary_count = MODULE_DEFAULT;
module_ctx->module_hash_binary_parse = MODULE_DEFAULT;
module_ctx->module_hash_binary_save = MODULE_DEFAULT;
module_ctx->module_hash_decode_potfile = MODULE_DEFAULT;
module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT;
module_ctx->module_hash_decode = module_hash_decode;
module_ctx->module_hash_encode_status = MODULE_DEFAULT;
module_ctx->module_hash_encode_potfile = MODULE_DEFAULT;
module_ctx->module_hash_encode = module_hash_encode;
module_ctx->module_hash_init_selftest = MODULE_DEFAULT;
module_ctx->module_hash_mode = MODULE_DEFAULT;
module_ctx->module_hash_category = module_hash_category;
module_ctx->module_hash_name = module_hash_name;
module_ctx->module_hashes_count_min = MODULE_DEFAULT;
module_ctx->module_hashes_count_max = MODULE_DEFAULT;
module_ctx->module_hlfmt_disable = MODULE_DEFAULT;
module_ctx->module_hook_extra_param_size = MODULE_DEFAULT;
module_ctx->module_hook_extra_param_init = MODULE_DEFAULT;
module_ctx->module_hook_extra_param_term = MODULE_DEFAULT;
module_ctx->module_hook12 = MODULE_DEFAULT;
module_ctx->module_hook23 = MODULE_DEFAULT;
module_ctx->module_hook_salt_size = MODULE_DEFAULT;
module_ctx->module_hook_size = MODULE_DEFAULT;
module_ctx->module_jit_build_options = MODULE_DEFAULT;
module_ctx->module_jit_cache_disable = MODULE_DEFAULT;
module_ctx->module_kernel_accel_max = MODULE_DEFAULT;
module_ctx->module_kernel_accel_min = MODULE_DEFAULT;
module_ctx->module_kernel_loops_max = MODULE_DEFAULT;
module_ctx->module_kernel_loops_min = MODULE_DEFAULT;
module_ctx->module_kernel_threads_max = MODULE_DEFAULT;
module_ctx->module_kernel_threads_min = MODULE_DEFAULT;
module_ctx->module_kern_type = module_kern_type;
module_ctx->module_kern_type_dynamic = MODULE_DEFAULT;
module_ctx->module_opti_type = module_opti_type;
module_ctx->module_opts_type = module_opts_type;
module_ctx->module_outfile_check_disable = MODULE_DEFAULT;
module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT;
module_ctx->module_potfile_custom_check = MODULE_DEFAULT;
module_ctx->module_potfile_disable = MODULE_DEFAULT;
module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT;
module_ctx->module_pwdump_column = MODULE_DEFAULT;
module_ctx->module_pw_max = module_pw_max;
module_ctx->module_pw_min = MODULE_DEFAULT;
module_ctx->module_salt_max = MODULE_DEFAULT;
module_ctx->module_salt_min = MODULE_DEFAULT;
module_ctx->module_salt_type = module_salt_type;
module_ctx->module_separator = MODULE_DEFAULT;
module_ctx->module_st_hash = module_st_hash;
module_ctx->module_st_pass = module_st_pass;
module_ctx->module_tmp_size = MODULE_DEFAULT;
module_ctx->module_unstable_warning = MODULE_DEFAULT;
module_ctx->module_warmup_disable = MODULE_DEFAULT;
}

@ -0,0 +1,319 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#include "common.h"
#include "types.h"
#include "modules.h"
#include "bitops.h"
#include "convert.h"
#include "shared.h"
static const u32 ATTACK_EXEC = ATTACK_EXEC_OUTSIDE_KERNEL;
static const u32 DGST_POS0 = 0;
static const u32 DGST_POS1 = 1;
static const u32 DGST_POS2 = 2;
static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_4;
static const u32 HASH_CATEGORY = HASH_CATEGORY_PASSWORD_MANAGER;
static const char *HASH_NAME = "Mozilla key4.db";
static const u64 KERN_TYPE = 26100;
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE;
static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED;
static const char *ST_PASS = "hashcat";
static const char *ST_HASH = "$mozilla$*AES*5add91733b9b13310ea79a4b38de5c3f797c3bf1*54c17e2a8a066cbdc55f2080c5e9f02ea3954d712cb34b4547f5186548f46512*10000*040e4b5a00f993e63f67a34f6cfc5704*eae9c6c003e6d1b2aa8aa21630838808";
u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; }
u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; }
u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; }
u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; }
u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; }
u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; }
u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; }
const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; }
u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; }
u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; }
u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; }
u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; }
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
typedef struct mozilla_aes_tmp
{
u32 ipad[8];
u32 opad[8];
u32 dgst[8];
u32 out[8];
} mozilla_aes_tmp_t;
typedef struct mozilla_aes
{
u32 iv_buf[4];
u32 ct_buf[4];
} mozilla_aes_t;
static const char *SIGNATURE_MOZILLA = "$mozilla$";
static const char *SIGNATURE_MOZILLA_AES = "AES";
u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
{
const u64 esalt_size = (const u64) sizeof (mozilla_aes_t);
return esalt_size;
}
u64 module_tmp_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
{
const u64 tmp_size = (const u64) sizeof (mozilla_aes_tmp_t);
return tmp_size;
}
u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
{
// this overrides the reductions of PW_MAX in case optimized kernel is selected
// IOW, even in optimized kernel mode it support length 256
const u32 pw_max = PW_MAX;
return pw_max;
}
int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len)
{
u32 *digest = (u32 *) digest_buf;
mozilla_aes_t *mozilla_aes = (mozilla_aes_t *) esalt_buf;
token_t token;
token.token_cnt = 7;
token.signatures_cnt = 2;
token.signatures_buf[0] = SIGNATURE_MOZILLA;
token.signatures_buf[1] = SIGNATURE_MOZILLA_AES;
token.sep[0] = '*';
token.len_min[0] = 9;
token.len_max[0] = 9;
token.attr[0] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_SIGNATURE;
token.sep[1] = '*';
token.len_min[1] = 3;
token.len_max[1] = 3;
token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_SIGNATURE;
token.sep[2] = '*';
token.len_min[2] = 40;
token.len_max[2] = 40;
token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
token.sep[3] = '*';
token.len_min[3] = 64;
token.len_max[3] = 64;
token.attr[3] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
token.sep[4] = '*';
token.len_min[4] = 1;
token.len_max[4] = 6;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_DIGIT;
token.sep[5] = '*';
token.len_min[5] = 32;
token.len_max[5] = 32;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
token.sep[6] = '*';
token.len_min[6] = 32;
token.len_max[6] = 32;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token);
if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);
// global salt buffer + entry salt buffer combined
// we do this because both buffer are accessed before the _loop kernel
// this also requires us to copy to local variables in _init kernel
const u8 *global_salt_pos = token.buf[2];
const u8 *entry_salt_pos = token.buf[3];
salt->salt_buf[ 0] = hex_to_u32 (global_salt_pos + 0);
salt->salt_buf[ 1] = hex_to_u32 (global_salt_pos + 8);
salt->salt_buf[ 2] = hex_to_u32 (global_salt_pos + 16);
salt->salt_buf[ 3] = hex_to_u32 (global_salt_pos + 24);
salt->salt_buf[ 4] = hex_to_u32 (global_salt_pos + 32);
salt->salt_buf[ 5] = 0;
salt->salt_buf[ 6] = 0;
salt->salt_buf[ 7] = 0;
salt->salt_buf[ 8] = hex_to_u32 (entry_salt_pos + 0);
salt->salt_buf[ 9] = hex_to_u32 (entry_salt_pos + 8);
salt->salt_buf[10] = hex_to_u32 (entry_salt_pos + 16);
salt->salt_buf[11] = hex_to_u32 (entry_salt_pos + 24);
salt->salt_buf[12] = hex_to_u32 (entry_salt_pos + 32);
salt->salt_buf[13] = hex_to_u32 (entry_salt_pos + 40);
salt->salt_buf[14] = hex_to_u32 (entry_salt_pos + 48);
salt->salt_buf[15] = hex_to_u32 (entry_salt_pos + 56);
salt->salt_len = 64;
// iter
const u8 *iter_pos = token.buf[4];
int iter = hc_strtoul ((const char *) iter_pos, NULL, 10);
salt->salt_iter = iter - 1;
// IV buffer
const u8 *iv_pos = token.buf[5];
mozilla_aes->iv_buf[0] = hex_to_u32 (iv_pos + 0);
mozilla_aes->iv_buf[1] = hex_to_u32 (iv_pos + 8);
mozilla_aes->iv_buf[2] = hex_to_u32 (iv_pos + 16);
mozilla_aes->iv_buf[3] = hex_to_u32 (iv_pos + 24);
// CT buffer
const u8 *ct_pos = token.buf[6];
mozilla_aes->ct_buf[0] = hex_to_u32 (ct_pos + 0);
mozilla_aes->ct_buf[1] = hex_to_u32 (ct_pos + 8);
mozilla_aes->ct_buf[2] = hex_to_u32 (ct_pos + 16);
mozilla_aes->ct_buf[3] = hex_to_u32 (ct_pos + 24);
// hash
digest[0] = mozilla_aes->ct_buf[0];
digest[1] = mozilla_aes->ct_buf[1];
digest[2] = mozilla_aes->ct_buf[2];
digest[3] = mozilla_aes->ct_buf[3];
return (PARSER_OK);
}
int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size)
{
const mozilla_aes_t *mozilla_aes = (const mozilla_aes_t *) esalt_buf;
u8 *out_buf = (u8 *) line_buf;
const int out_len = snprintf ((char *) out_buf, line_size, "%s*%s*%08x%08x%08x%08x%08x*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x*%08x%08x%08x%08x",
SIGNATURE_MOZILLA,
SIGNATURE_MOZILLA_AES,
byte_swap_32 (salt->salt_buf[ 0]),
byte_swap_32 (salt->salt_buf[ 1]),
byte_swap_32 (salt->salt_buf[ 2]),
byte_swap_32 (salt->salt_buf[ 3]),
byte_swap_32 (salt->salt_buf[ 4]),
byte_swap_32 (salt->salt_buf[ 8]),
byte_swap_32 (salt->salt_buf[ 9]),
byte_swap_32 (salt->salt_buf[10]),
byte_swap_32 (salt->salt_buf[11]),
byte_swap_32 (salt->salt_buf[12]),
byte_swap_32 (salt->salt_buf[13]),
byte_swap_32 (salt->salt_buf[14]),
byte_swap_32 (salt->salt_buf[15]),
salt->salt_iter + 1,
byte_swap_32 (mozilla_aes->iv_buf[0]),
byte_swap_32 (mozilla_aes->iv_buf[1]),
byte_swap_32 (mozilla_aes->iv_buf[2]),
byte_swap_32 (mozilla_aes->iv_buf[3]),
byte_swap_32 (mozilla_aes->ct_buf[0]),
byte_swap_32 (mozilla_aes->ct_buf[1]),
byte_swap_32 (mozilla_aes->ct_buf[2]),
byte_swap_32 (mozilla_aes->ct_buf[3]));
return out_len;
}
void module_init (module_ctx_t *module_ctx)
{
module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT;
module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT;
module_ctx->module_attack_exec = module_attack_exec;
module_ctx->module_benchmark_esalt = MODULE_DEFAULT;
module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT;
module_ctx->module_benchmark_mask = MODULE_DEFAULT;
module_ctx->module_benchmark_salt = MODULE_DEFAULT;
module_ctx->module_build_plain_postprocess = MODULE_DEFAULT;
module_ctx->module_deep_comp_kernel = MODULE_DEFAULT;
module_ctx->module_dgst_pos0 = module_dgst_pos0;
module_ctx->module_dgst_pos1 = module_dgst_pos1;
module_ctx->module_dgst_pos2 = module_dgst_pos2;
module_ctx->module_dgst_pos3 = module_dgst_pos3;
module_ctx->module_dgst_size = module_dgst_size;
module_ctx->module_dictstat_disable = MODULE_DEFAULT;
module_ctx->module_esalt_size = module_esalt_size;
module_ctx->module_extra_buffer_size = MODULE_DEFAULT;
module_ctx->module_extra_tmp_size = MODULE_DEFAULT;
module_ctx->module_forced_outfile_format = MODULE_DEFAULT;
module_ctx->module_hash_binary_count = MODULE_DEFAULT;
module_ctx->module_hash_binary_parse = MODULE_DEFAULT;
module_ctx->module_hash_binary_save = MODULE_DEFAULT;
module_ctx->module_hash_decode_potfile = MODULE_DEFAULT;
module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT;
module_ctx->module_hash_decode = module_hash_decode;
module_ctx->module_hash_encode_status = MODULE_DEFAULT;
module_ctx->module_hash_encode_potfile = MODULE_DEFAULT;
module_ctx->module_hash_encode = module_hash_encode;
module_ctx->module_hash_init_selftest = MODULE_DEFAULT;
module_ctx->module_hash_mode = MODULE_DEFAULT;
module_ctx->module_hash_category = module_hash_category;
module_ctx->module_hash_name = module_hash_name;
module_ctx->module_hashes_count_min = MODULE_DEFAULT;
module_ctx->module_hashes_count_max = MODULE_DEFAULT;
module_ctx->module_hlfmt_disable = MODULE_DEFAULT;
module_ctx->module_hook_extra_param_size = MODULE_DEFAULT;
module_ctx->module_hook_extra_param_init = MODULE_DEFAULT;
module_ctx->module_hook_extra_param_term = MODULE_DEFAULT;
module_ctx->module_hook12 = MODULE_DEFAULT;
module_ctx->module_hook23 = MODULE_DEFAULT;
module_ctx->module_hook_salt_size = MODULE_DEFAULT;
module_ctx->module_hook_size = MODULE_DEFAULT;
module_ctx->module_jit_build_options = MODULE_DEFAULT;
module_ctx->module_jit_cache_disable = MODULE_DEFAULT;
module_ctx->module_kernel_accel_max = MODULE_DEFAULT;
module_ctx->module_kernel_accel_min = MODULE_DEFAULT;
module_ctx->module_kernel_loops_max = MODULE_DEFAULT;
module_ctx->module_kernel_loops_min = MODULE_DEFAULT;
module_ctx->module_kernel_threads_max = MODULE_DEFAULT;
module_ctx->module_kernel_threads_min = MODULE_DEFAULT;
module_ctx->module_kern_type = module_kern_type;
module_ctx->module_kern_type_dynamic = MODULE_DEFAULT;
module_ctx->module_opti_type = module_opti_type;
module_ctx->module_opts_type = module_opts_type;
module_ctx->module_outfile_check_disable = MODULE_DEFAULT;
module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT;
module_ctx->module_potfile_custom_check = MODULE_DEFAULT;
module_ctx->module_potfile_disable = MODULE_DEFAULT;
module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT;
module_ctx->module_pwdump_column = MODULE_DEFAULT;
module_ctx->module_pw_max = module_pw_max;
module_ctx->module_pw_min = MODULE_DEFAULT;
module_ctx->module_salt_max = MODULE_DEFAULT;
module_ctx->module_salt_min = MODULE_DEFAULT;
module_ctx->module_salt_type = module_salt_type;
module_ctx->module_separator = MODULE_DEFAULT;
module_ctx->module_st_hash = module_st_hash;
module_ctx->module_st_pass = module_st_pass;
module_ctx->module_tmp_size = module_tmp_size;
module_ctx->module_unstable_warning = MODULE_DEFAULT;
module_ctx->module_warmup_disable = MODULE_DEFAULT;
}

@ -0,0 +1,148 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Crypt::DES;
use Crypt::DES_EDE3;
use Digest::SHA qw (sha1);
use Digest::HMAC qw (hmac);
sub module_constraints { [[0, 256], [40, 40], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $global_salt = shift;
my $entry_salt = shift // random_hex_string (40);
my $ct = shift;
my $global_salt_bin = pack ("H*", $global_salt);
my $entry_salt_bin = pack ("H*", $entry_salt);
my $hp = sha1 ($global_salt_bin . $word);
my $pes = substr ($entry_salt_bin . ("\x00" x 20), 0, 20);
my $chp = sha1 ($hp . $entry_salt_bin);
my $k1 = hmac ($pes . $entry_salt_bin, $chp, \&sha1, 64);
my $tk = hmac ($pes, $chp, \&sha1, 64);
my $k2 = hmac ($tk . $entry_salt_bin, $chp, \&sha1, 64);
my $k = $k1 . $k2;
my $key = substr ($k, 0, 24);
my $iv = substr ($k, 32, 8);
my $pt;
if (defined $ct)
{
my $ct_bin = pack ("H*", $ct);
my $ede3 = Crypt::DES_EDE3->new ($key);
my $ct1_bin = substr ($ct_bin, 0, 8);
my $ct2_bin = substr ($ct_bin, 8, 8);
my $pt1 = $ede3->decrypt ($ct1_bin);
$pt1 = exclusive_or ($pt1, $iv);
print unpack ("H*", $ct1_bin), "\n";
print unpack ("H*", $ct2_bin), "\n";
my $pt2 = $ede3->decrypt ($ct2_bin);
print unpack ("H*", $pt2), "\n";
$pt2 = exclusive_or ($pt2, $ct1_bin);
print unpack ("H*", $pt2), "\n";
$pt = $pt1 . $pt2;
if ($pt ne "password-check\x02\x02")
{
$pt = "\xff" x 16;
}
}
else
{
$pt = "password-check\x02\x02";
}
my $ede3 = Crypt::DES_EDE3->new ($key);
my $pt1 = substr ($pt, 0, 8);
my $pt2 = substr ($pt, 8, 8);
$pt1 = exclusive_or ($pt1, $iv);
my $ct1_bin = $ede3->encrypt ($pt1);
$pt2 = exclusive_or ($pt2, $ct1_bin);
my $ct2_bin = $ede3->encrypt ($pt2);
my $ct_bin = $ct1_bin . $ct2_bin;
my $hash = sprintf ('$mozilla$*3DES*%s*%s*%s', unpack ("H*", $global_salt_bin), unpack ("H*", $entry_salt_bin), unpack ("H*", $ct_bin));
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my $idx = index ($line, ':');
return unless $idx >= 0;
my $hash = substr ($line, 0, $idx);
my $word = substr ($line, $idx + 1);
return unless substr ($hash, 0, 9) eq '$mozilla$';
my ($signature, $type, $global_salt, $entry_salt, $ct) = split '\*', $hash;
return unless defined $signature;
return unless defined $type;
return unless defined $global_salt;
return unless defined $entry_salt;
return unless defined $ct;
return unless $type eq '3DES';
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $global_salt, $entry_salt, $ct);
return ($new_hash, $word);
}
sub exclusive_or
{
my $in1 = shift;
my $in2 = shift;
my $out = "";
for (my $i = 0; $i < length ($in1); $i++) # $i < $len
{
$out .= chr (ord (substr ($in1, $i, 1)) ^ ord (substr ($in2, $i, 1)));
}
return $out;
}
1;

@ -0,0 +1,120 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Crypt::PBKDF2;
use Crypt::CBC;
use Digest::SHA qw (sha1);
sub module_constraints { [[0, 256], [40, 40], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $global_salt = shift;
my $entry_salt = shift // random_hex_string (64);
my $iter = shift // 10000;
my $iv = shift // random_hex_string (32);
my $ct = shift;
my $kdf = Crypt::PBKDF2->new
(
hasher => Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA2', 256),
iterations => $iter,
output_len => 32
);
my $global_salt_bin = pack ("H*", $global_salt);
my $global_key = sha1 ($global_salt_bin . $word);
my $entry_salt_bin = pack ("H*", $entry_salt);
my $entry_key = $kdf->PBKDF2 ($entry_salt_bin, $global_key);
my $iv_bin = pack ("H*", $iv);
my $pt;
if (defined $ct)
{
my $aes_cbc = Crypt::CBC->new ({
cipher => "Crypt::Rijndael",
iv => $iv_bin,
key => $entry_key,
keysize => 32,
literal_key => 1,
header => "none",
padding => "none"
});
my $ct_bin = pack ("H*", $ct);
$pt = $aes_cbc->decrypt ($ct_bin);
if ($pt ne "password-check\x02\x02")
{
$pt = "\xff" x 16;
}
}
else
{
$pt = "password-check\x02\x02";
}
my $aes_cbc = Crypt::CBC->new ({
cipher => "Crypt::Rijndael",
iv => $iv_bin,
key => $entry_key,
keysize => 32,
literal_key => 1,
header => "none",
padding => "none"
});
my $ct_bin = $aes_cbc->encrypt ($pt);
my $hash = sprintf ('$mozilla$*AES*%s*%s*%d*%s*%s', unpack ("H*", $global_salt_bin), unpack ("H*", $entry_salt_bin), $iter, unpack ("H*", $iv_bin), unpack ("H*", $ct_bin));
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my $idx = index ($line, ':');
return unless $idx >= 0;
my $hash = substr ($line, 0, $idx);
my $word = substr ($line, $idx + 1);
return unless substr ($hash, 0, 9) eq '$mozilla$';
my ($signature, $type, $global_salt, $entry_salt, $iter, $iv, $ct) = split '\*', $hash;
return unless defined $signature;
return unless defined $type;
return unless defined $global_salt;
return unless defined $entry_salt;
return unless defined $iter;
return unless defined $iv;
return unless defined $ct;
return unless $type eq 'AES';
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $global_salt, $entry_salt, $iter, $iv, $ct);
return ($new_hash, $word);
}
1;
Loading…
Cancel
Save