Skip to content

Commit

Permalink
Add support for zero-length salts in Electrum $4 and $5
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteube committed Apr 20, 2024
1 parent fafb277 commit 6716447
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
14 changes: 9 additions & 5 deletions OpenCL/m21700-pure.cl
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ KERNEL_FQ void m21700_comp (KERN_ATTR_TMPS_ESALT (electrum_tmp_t, electrum_t))

if (gid >= GID_CNT) return;

const u32 digest_pos = LOOP_POS;

const u32 digest_cur = DIGESTS_OFFSET_HOST + digest_pos;

GLOBAL_AS const electrum_t *electrum = &esalt_bufs[digest_cur];

u64 out[8];

out[0] = tmps[gid].out[0];
Expand Down Expand Up @@ -379,13 +385,12 @@ KERNEL_FQ void m21700_comp (KERN_ATTR_TMPS_ESALT (electrum_tmp_t, electrum_t))
* the main secp256k1 point multiplication by a scalar/tweak:
*/

GLOBAL_AS secp256k1_t *coords = (GLOBAL_AS secp256k1_t *) &esalt_bufs[DIGESTS_OFFSET_HOST].coords;
GLOBAL_AS const secp256k1_t *coords = (GLOBAL_AS const secp256k1_t *) &electrum->coords;

u32 pubkey[64] = { 0 }; // for point_mul () we need: 1 + 32 bytes (for sha512 () we need more)

point_mul (pubkey, tweak, coords);


/*
* sha512 () of the pubkey:
*/
Expand All @@ -396,14 +401,13 @@ KERNEL_FQ void m21700_comp (KERN_ATTR_TMPS_ESALT (electrum_tmp_t, electrum_t))
sha512_update (&sha512_ctx, pubkey, 33); // 33 because of 32 byte curve point + sign
sha512_final (&sha512_ctx);


/*
* sha256-hmac () of the data_buf
*/

GLOBAL_AS u32 *data_buf = (GLOBAL_AS u32 *) esalt_bufs[DIGESTS_OFFSET_HOST].data_buf;
GLOBAL_AS const u32 *data_buf = (GLOBAL_AS const u32 *) electrum->data_buf;

u32 data_len = esalt_bufs[DIGESTS_OFFSET_HOST].data_len;
u32 data_len = electrum->data_len;

u32 key[16] = { 0 };

Expand Down
9 changes: 7 additions & 2 deletions OpenCL/m21800-pure.cl
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ KERNEL_FQ void m21800_comp (KERN_ATTR_TMPS_ESALT (electrum_tmp_t, electrum_t))

if (gid >= GID_CNT) return;

const u32 digest_pos = LOOP_POS;

const u32 digest_cur = DIGESTS_OFFSET_HOST + digest_pos;

GLOBAL_AS const electrum_t *electrum = &esalt_bufs[digest_cur];

/*
* Start by copying/aligning the data
Expand Down Expand Up @@ -434,7 +439,7 @@ KERNEL_FQ void m21800_comp (KERN_ATTR_TMPS_ESALT (electrum_tmp_t, electrum_t))
* the main secp256k1 point multiplication by a scalar/tweak:
*/

GLOBAL_AS secp256k1_t *coords = (GLOBAL_AS secp256k1_t *) &esalt_bufs[DIGESTS_OFFSET_HOST].coords;
GLOBAL_AS const secp256k1_t *coords = (GLOBAL_AS const secp256k1_t *) &electrum->coords;

u32 pubkey[64] = { 0 }; // for point_mul () we need: 1 + 32 bytes (for sha512 () we need more)

Expand Down Expand Up @@ -499,7 +504,7 @@ KERNEL_FQ void m21800_comp (KERN_ATTR_TMPS_ESALT (electrum_tmp_t, electrum_t))

// we need to run it at least once:

GLOBAL_AS u32 *data_buf = (GLOBAL_AS u32 *) esalt_bufs[DIGESTS_OFFSET_HOST].data_buf;
GLOBAL_AS const u32 *data_buf = (GLOBAL_AS const u32 *) electrum->data_buf;

u32 data[4];

Expand Down
17 changes: 9 additions & 8 deletions src/modules/module_21700.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_USES_BITS_64
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
| OPTS_TYPE_DEEP_COMP_KERNEL
| OPTS_TYPE_PT_GENERATE_LE;
static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED;
static const char *ST_PASS = "hashcat";
Expand Down Expand Up @@ -66,6 +67,11 @@ typedef struct electrum_tmp

static const char *SIGNATURE_ELECTRUM = "$electrum$4*";

u32 module_deep_comp_kernel (MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED const u32 salt_pos, MAYBE_UNUSED const u32 digest_pos)
{
return KERN_RUN_3;
}

bool module_unstable_warning (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hc_device_param_t *device_param)
{
if (device_param->opencl_device_vendor_id == VENDOR_ID_INTEL_SDK)
Expand Down Expand Up @@ -214,13 +220,8 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE

// fake salt

salt->salt_buf[0] = esalt->data_buf[0];
salt->salt_buf[1] = esalt->data_buf[1];
salt->salt_buf[2] = esalt->data_buf[2];
salt->salt_buf[3] = esalt->data_buf[3];

salt->salt_len = 16;

salt->salt_buf[0] = 0;
salt->salt_len = 0;
salt->salt_iter = 1024 - 1;

return (PARSER_OK);
Expand Down Expand Up @@ -294,7 +295,7 @@ void module_init (module_ctx_t *module_ctx)
module_ctx->module_benchmark_charset = 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_deep_comp_kernel = module_deep_comp_kernel;
module_ctx->module_deprecated_notice = MODULE_DEFAULT;
module_ctx->module_dgst_pos0 = module_dgst_pos0;
module_ctx->module_dgst_pos1 = module_dgst_pos1;
Expand Down
17 changes: 9 additions & 8 deletions src/modules/module_21800.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
| OPTS_TYPE_PT_GENERATE_LE
| OPTS_TYPE_DEEP_COMP_KERNEL
| OPTS_TYPE_NATIVE_THREADS;
static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED;
static const char *ST_PASS = "hashcat";
Expand Down Expand Up @@ -66,6 +67,11 @@ typedef struct electrum_tmp

static const char *SIGNATURE_ELECTRUM = "$electrum$5*";

u32 module_deep_comp_kernel (MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED const u32 salt_pos, MAYBE_UNUSED const u32 digest_pos)
{
return KERN_RUN_3;
}

bool module_unstable_warning (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hc_device_param_t *device_param)
{
// problem with this kernel is the huge amount of register pressure on u8 tmp[TMPSIZ];
Expand Down Expand Up @@ -191,13 +197,8 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE

// fake salt

salt->salt_buf[0] = esalt->data_buf[0];
salt->salt_buf[1] = esalt->data_buf[1];
salt->salt_buf[2] = esalt->data_buf[2];
salt->salt_buf[3] = esalt->data_buf[3];

salt->salt_len = 16;

salt->salt_buf[0] = 0;
salt->salt_len = 0;
salt->salt_iter = 1024 - 1;

return (PARSER_OK);
Expand Down Expand Up @@ -271,7 +272,7 @@ void module_init (module_ctx_t *module_ctx)
module_ctx->module_benchmark_charset = 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_deep_comp_kernel = module_deep_comp_kernel;
module_ctx->module_deprecated_notice = MODULE_DEFAULT;
module_ctx->module_dgst_pos0 = module_dgst_pos0;
module_ctx->module_dgst_pos1 = module_dgst_pos1;
Expand Down

0 comments on commit 6716447

Please sign in to comment.