From 3ef69f2919b5cfe0e0fb25c64dd1caf712285e39 Mon Sep 17 00:00:00 2001 From: philsmd Date: Wed, 4 Jan 2023 15:52:48 +0100 Subject: [PATCH] added -m 3090x = Bitcoin raw private key --- OpenCL/m30901_a0-pure.cl | 294 +++++++++++++++++++++++++ OpenCL/m30901_a1-pure.cl | 348 ++++++++++++++++++++++++++++++ OpenCL/m30901_a3-pure.cl | 365 +++++++++++++++++++++++++++++++ OpenCL/m30902_a0-pure.cl | 306 ++++++++++++++++++++++++++ OpenCL/m30902_a1-pure.cl | 360 +++++++++++++++++++++++++++++++ OpenCL/m30902_a3-pure.cl | 335 ++++++++++++++++++++++++++++ OpenCL/m30905_a0-pure.cl | 342 +++++++++++++++++++++++++++++ OpenCL/m30905_a1-pure.cl | 396 ++++++++++++++++++++++++++++++++++ OpenCL/m30905_a3-pure.cl | 372 ++++++++++++++++++++++++++++++++ OpenCL/m30906_a0-pure.cl | 354 ++++++++++++++++++++++++++++++ OpenCL/m30906_a1-pure.cl | 408 +++++++++++++++++++++++++++++++++++ OpenCL/m30906_a3-pure.cl | 383 ++++++++++++++++++++++++++++++++ docs/changes.txt | 3 + docs/readme.txt | 3 + src/modules/module_30901.c | 218 +++++++++++++++++++ src/modules/module_30902.c | 218 +++++++++++++++++++ src/modules/module_30903.c | 400 ++++++++++++++++++++++++++++++++++ src/modules/module_30904.c | 400 ++++++++++++++++++++++++++++++++++ src/modules/module_30905.c | 217 +++++++++++++++++++ src/modules/module_30906.c | 217 +++++++++++++++++++ tools/test.sh | 2 +- tools/test_modules/m30901.pm | 85 ++++++++ tools/test_modules/m30902.pm | 85 ++++++++ tools/test_modules/m30903.pm | 80 +++++++ tools/test_modules/m30904.pm | 83 +++++++ tools/test_modules/m30905.pm | 85 ++++++++ tools/test_modules/m30906.pm | 85 ++++++++ 27 files changed, 6443 insertions(+), 1 deletion(-) create mode 100644 OpenCL/m30901_a0-pure.cl create mode 100644 OpenCL/m30901_a1-pure.cl create mode 100644 OpenCL/m30901_a3-pure.cl create mode 100644 OpenCL/m30902_a0-pure.cl create mode 100644 OpenCL/m30902_a1-pure.cl create mode 100644 OpenCL/m30902_a3-pure.cl create mode 100644 OpenCL/m30905_a0-pure.cl create mode 100644 OpenCL/m30905_a1-pure.cl create mode 100644 OpenCL/m30905_a3-pure.cl create mode 100644 OpenCL/m30906_a0-pure.cl create mode 100644 OpenCL/m30906_a1-pure.cl create mode 100644 OpenCL/m30906_a3-pure.cl create mode 100644 src/modules/module_30901.c create mode 100644 src/modules/module_30902.c create mode 100644 src/modules/module_30903.c create mode 100644 src/modules/module_30904.c create mode 100644 src/modules/module_30905.c create mode 100644 src/modules/module_30906.c create mode 100644 tools/test_modules/m30901.pm create mode 100644 tools/test_modules/m30902.pm create mode 100644 tools/test_modules/m30903.pm create mode 100644 tools/test_modules/m30904.pm create mode 100644 tools/test_modules/m30905.pm create mode 100644 tools/test_modules/m30906.pm diff --git a/OpenCL/m30901_a0-pure.cl b/OpenCL/m30901_a0-pure.cl new file mode 100644 index 000000000..0709c22d2 --- /dev/null +++ b/OpenCL/m30901_a0-pure.cl @@ -0,0 +1,294 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_rp.h) +#include M2S(INCLUDE_PATH/inc_rp.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30901_mxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + COPY_PW (pws[gid]); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t p = PASTE_PW; + + p.pw_len = apply_rules (rules_buf[il_pos].cmds, p.i, p.pw_len); + + if (p.pw_len != 64) continue; + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (p.i[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (p.i[j + 0], p.i[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30901_sxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + + /** + * base + */ + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + COPY_PW (pws[gid]); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t p = PASTE_PW; + + p.pw_len = apply_rules (rules_buf[il_pos].cmds, p.i, p.pw_len); + + if (p.pw_len != 64) continue; + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (p.i[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (p.i[j + 0], p.i[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30901_a1-pure.cl b/OpenCL/m30901_a1-pure.cl new file mode 100644 index 000000000..097351c8d --- /dev/null +++ b/OpenCL/m30901_a1-pure.cl @@ -0,0 +1,348 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30901_mxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + // copy password to w + + u32 w[16] = { 0 }; + + // for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + for (u32 idx = 0; idx < 16; idx++) + { + w[idx] = pws[gid].i[idx]; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + if ((pw_len + comb_len) != 64) continue; + + u32 c[64] = { 0 }; + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] = combs_buf[il_pos].i[i]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] |= w[i]; + } + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (c[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (c[j + 0], c[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30901_sxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + // copy password to w + + u32 w[16] = { 0 }; + + // for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + for (u32 idx = 0; idx < 16; idx++) + { + w[idx] = pws[gid].i[idx]; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + if ((pw_len + comb_len) != 64) continue; + + u32 c[64] = { 0 }; + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] = combs_buf[il_pos].i[i]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] |= w[i]; + } + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (c[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (c[j + 0], c[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30901_a3-pure.cl b/OpenCL/m30901_a3-pure.cl new file mode 100644 index 000000000..6df675272 --- /dev/null +++ b/OpenCL/m30901_a3-pure.cl @@ -0,0 +1,365 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +// #define SECP256K1_TMPS_TYPE CONSTANT_AS +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +// or use set_precomputed_basepoint_g () instead: +// (set SECP256K1_TMPS_TYPE to CONSTANT_AS above:) + +// CONSTANT_AS const secp256k1_t preG = +// { +// { +// SECP256K1_G_PRE_COMPUTED_00, SECP256K1_G_PRE_COMPUTED_01, SECP256K1_G_PRE_COMPUTED_02, +// SECP256K1_G_PRE_COMPUTED_03, SECP256K1_G_PRE_COMPUTED_04, SECP256K1_G_PRE_COMPUTED_05, +// SECP256K1_G_PRE_COMPUTED_06, SECP256K1_G_PRE_COMPUTED_07, SECP256K1_G_PRE_COMPUTED_08, +// SECP256K1_G_PRE_COMPUTED_09, SECP256K1_G_PRE_COMPUTED_10, SECP256K1_G_PRE_COMPUTED_11, +// SECP256K1_G_PRE_COMPUTED_12, SECP256K1_G_PRE_COMPUTED_13, SECP256K1_G_PRE_COMPUTED_14, +// SECP256K1_G_PRE_COMPUTED_15, SECP256K1_G_PRE_COMPUTED_16, SECP256K1_G_PRE_COMPUTED_17, +// SECP256K1_G_PRE_COMPUTED_18, SECP256K1_G_PRE_COMPUTED_19, SECP256K1_G_PRE_COMPUTED_20, +// SECP256K1_G_PRE_COMPUTED_21, SECP256K1_G_PRE_COMPUTED_22, SECP256K1_G_PRE_COMPUTED_23, +// SECP256K1_G_PRE_COMPUTED_24, SECP256K1_G_PRE_COMPUTED_25, SECP256K1_G_PRE_COMPUTED_26, +// SECP256K1_G_PRE_COMPUTED_27, SECP256K1_G_PRE_COMPUTED_28, SECP256K1_G_PRE_COMPUTED_29, +// SECP256K1_G_PRE_COMPUTED_30, SECP256K1_G_PRE_COMPUTED_31, SECP256K1_G_PRE_COMPUTED_32, +// SECP256K1_G_PRE_COMPUTED_33, SECP256K1_G_PRE_COMPUTED_34, SECP256K1_G_PRE_COMPUTED_35, +// SECP256K1_G_PRE_COMPUTED_36, SECP256K1_G_PRE_COMPUTED_37, SECP256K1_G_PRE_COMPUTED_38, +// SECP256K1_G_PRE_COMPUTED_39, SECP256K1_G_PRE_COMPUTED_40, SECP256K1_G_PRE_COMPUTED_41, +// SECP256K1_G_PRE_COMPUTED_42, SECP256K1_G_PRE_COMPUTED_43, SECP256K1_G_PRE_COMPUTED_44, +// SECP256K1_G_PRE_COMPUTED_45, SECP256K1_G_PRE_COMPUTED_46, SECP256K1_G_PRE_COMPUTED_47, +// SECP256K1_G_PRE_COMPUTED_48, SECP256K1_G_PRE_COMPUTED_49, SECP256K1_G_PRE_COMPUTED_50, +// SECP256K1_G_PRE_COMPUTED_51, SECP256K1_G_PRE_COMPUTED_52, SECP256K1_G_PRE_COMPUTED_53, +// SECP256K1_G_PRE_COMPUTED_54, SECP256K1_G_PRE_COMPUTED_55, SECP256K1_G_PRE_COMPUTED_56, +// SECP256K1_G_PRE_COMPUTED_57, SECP256K1_G_PRE_COMPUTED_58, SECP256K1_G_PRE_COMPUTED_59, +// SECP256K1_G_PRE_COMPUTED_60, SECP256K1_G_PRE_COMPUTED_61, SECP256K1_G_PRE_COMPUTED_62, +// SECP256K1_G_PRE_COMPUTED_63, SECP256K1_G_PRE_COMPUTED_64, SECP256K1_G_PRE_COMPUTED_65, +// SECP256K1_G_PRE_COMPUTED_66, SECP256K1_G_PRE_COMPUTED_67, SECP256K1_G_PRE_COMPUTED_68, +// SECP256K1_G_PRE_COMPUTED_69, SECP256K1_G_PRE_COMPUTED_70, SECP256K1_G_PRE_COMPUTED_71, +// SECP256K1_G_PRE_COMPUTED_72, SECP256K1_G_PRE_COMPUTED_73, SECP256K1_G_PRE_COMPUTED_74, +// SECP256K1_G_PRE_COMPUTED_75, SECP256K1_G_PRE_COMPUTED_76, SECP256K1_G_PRE_COMPUTED_77, +// SECP256K1_G_PRE_COMPUTED_78, SECP256K1_G_PRE_COMPUTED_79, SECP256K1_G_PRE_COMPUTED_80, +// SECP256K1_G_PRE_COMPUTED_81, SECP256K1_G_PRE_COMPUTED_82, SECP256K1_G_PRE_COMPUTED_83, +// SECP256K1_G_PRE_COMPUTED_84, SECP256K1_G_PRE_COMPUTED_85, SECP256K1_G_PRE_COMPUTED_86, +// SECP256K1_G_PRE_COMPUTED_87, SECP256K1_G_PRE_COMPUTED_88, SECP256K1_G_PRE_COMPUTED_89, +// SECP256K1_G_PRE_COMPUTED_90, SECP256K1_G_PRE_COMPUTED_91, SECP256K1_G_PRE_COMPUTED_92, +// SECP256K1_G_PRE_COMPUTED_93, SECP256K1_G_PRE_COMPUTED_94, SECP256K1_G_PRE_COMPUTED_95, +// } +// }; + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30901_mxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + if (pw_len != 64) return; + + + // copy password to w + + u32 w[16]; + + for (u32 i = 0; i < 16; i++) // pw_len / 4 + { + w[i] = pws[gid].i[i]; + } + + for (u32 i = 1; i < 16; i++) + { + if (is_valid_hex_32 (w[i]) == 0) return; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32 w0 = w0l | w0r; + + w[0] = w0; + + if (is_valid_hex_32 (w[0]) == 0) continue; + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (w[j + 0], w[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30901_sxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + if (pw_len != 64) return; + + + // copy password to w + + u32 w[16]; + + for (u32 i = 0; i < 16; i++) // pw_len / 4 + { + w[i] = pws[gid].i[i]; + } + + for (u32 i = 1; i < 16; i++) + { + if (is_valid_hex_32 (w[i]) == 0) return; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32 w0 = w0l | w0r; + + w[0] = w0; + + if (is_valid_hex_32 (w[0]) == 0) continue; + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (w[j + 0], w[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30902_a0-pure.cl b/OpenCL/m30902_a0-pure.cl new file mode 100644 index 000000000..570f54fb4 --- /dev/null +++ b/OpenCL/m30902_a0-pure.cl @@ -0,0 +1,306 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_rp.h) +#include M2S(INCLUDE_PATH/inc_rp.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30902_mxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + COPY_PW (pws[gid]); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t p = PASTE_PW; + + p.pw_len = apply_rules (rules_buf[il_pos].cmds, p.i, p.pw_len); + + if (p.pw_len != 64) continue; + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (p.i[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (p.i[j + 0], p.i[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30902_sxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + + /** + * base + */ + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + COPY_PW (pws[gid]); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t p = PASTE_PW; + + p.pw_len = apply_rules (rules_buf[il_pos].cmds, p.i, p.pw_len); + + if (p.pw_len != 64) continue; + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (p.i[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (p.i[j + 0], p.i[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30902_a1-pure.cl b/OpenCL/m30902_a1-pure.cl new file mode 100644 index 000000000..d1e478296 --- /dev/null +++ b/OpenCL/m30902_a1-pure.cl @@ -0,0 +1,360 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30902_mxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + // copy password to w + + u32 w[16] = { 0 }; + + // for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + for (u32 idx = 0; idx < 16; idx++) + { + w[idx] = pws[gid].i[idx]; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + if ((pw_len + comb_len) != 64) continue; + + u32 c[64] = { 0 }; + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] = combs_buf[il_pos].i[i]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] |= w[i]; + } + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (c[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (c[j + 0], c[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30902_sxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + // copy password to w + + u32 w[16] = { 0 }; + + // for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + for (u32 idx = 0; idx < 16; idx++) + { + w[idx] = pws[gid].i[idx]; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + if ((pw_len + comb_len) != 64) continue; + + u32 c[64] = { 0 }; + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] = combs_buf[il_pos].i[i]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] |= w[i]; + } + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (c[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (c[j + 0], c[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30902_a3-pure.cl b/OpenCL/m30902_a3-pure.cl new file mode 100644 index 000000000..13f949bab --- /dev/null +++ b/OpenCL/m30902_a3-pure.cl @@ -0,0 +1,335 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30902_mxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + if (pw_len != 64) return; + + + // copy password to w + + u32 w[16]; + + for (u32 i = 0; i < 16; i++) // pw_len / 4 + { + w[i] = pws[gid].i[i]; + } + + for (u32 i = 1; i < 16; i++) + { + if (is_valid_hex_32 (w[i]) == 0) return; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32 w0 = w0l | w0r; + + w[0] = w0; + + if (is_valid_hex_32 (w[0]) == 0) continue; + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (w[j + 0], w[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30902_sxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + if (pw_len != 64) return; + + + // copy password to w + + u32 w[16]; + + for (u32 i = 0; i < 16; i++) // pw_len / 4 + { + w[i] = pws[gid].i[i]; + } + + for (u32 i = 1; i < 16; i++) + { + if (is_valid_hex_32 (w[i]) == 0) return; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32 w0 = w0l | w0r; + + w[0] = w0; + + if (is_valid_hex_32 (w[0]) == 0) continue; + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (w[j + 0], w[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30905_a0-pure.cl b/OpenCL/m30905_a0-pure.cl new file mode 100644 index 000000000..d72376414 --- /dev/null +++ b/OpenCL/m30905_a0-pure.cl @@ -0,0 +1,342 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_rp.h) +#include M2S(INCLUDE_PATH/inc_rp.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30905_mxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + COPY_PW (pws[gid]); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t p = PASTE_PW; + + p.pw_len = apply_rules (rules_buf[il_pos].cmds, p.i, p.pw_len); + + if (p.pw_len != 64) continue; + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (p.i[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (p.i[j + 0], p.i[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30905_sxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + + /** + * base + */ + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + COPY_PW (pws[gid]); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t p = PASTE_PW; + + p.pw_len = apply_rules (rules_buf[il_pos].cmds, p.i, p.pw_len); + + if (p.pw_len != 64) continue; + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (p.i[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (p.i[j + 0], p.i[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30905_a1-pure.cl b/OpenCL/m30905_a1-pure.cl new file mode 100644 index 000000000..2493a1741 --- /dev/null +++ b/OpenCL/m30905_a1-pure.cl @@ -0,0 +1,396 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30905_mxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + // copy password to w + + u32 w[16] = { 0 }; + + // for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + for (u32 idx = 0; idx < 16; idx++) + { + w[idx] = pws[gid].i[idx]; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + if ((pw_len + comb_len) != 64) continue; + + u32 c[64] = { 0 }; + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] = combs_buf[il_pos].i[i]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] |= w[i]; + } + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (c[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (c[j + 0], c[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30905_sxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + // copy password to w + + u32 w[16] = { 0 }; + + // for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + for (u32 idx = 0; idx < 16; idx++) + { + w[idx] = pws[gid].i[idx]; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + if ((pw_len + comb_len) != 64) continue; + + u32 c[64] = { 0 }; + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] = combs_buf[il_pos].i[i]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] |= w[i]; + } + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (c[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (c[j + 0], c[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30905_a3-pure.cl b/OpenCL/m30905_a3-pure.cl new file mode 100644 index 000000000..624d21ec6 --- /dev/null +++ b/OpenCL/m30905_a3-pure.cl @@ -0,0 +1,372 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +// #define SECP256K1_TMPS_TYPE CONSTANT_AS +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30905_mxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + if (pw_len != 64) return; + + + // copy password to w + + u32 w[16]; + + for (u32 i = 0; i < 16; i++) // pw_len / 4 + { + w[i] = pws[gid].i[i]; + } + + for (u32 i = 1; i < 16; i++) + { + if (is_valid_hex_32 (w[i]) == 0) return; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32 w0 = w0l | w0r; + + w[0] = w0; + + if (is_valid_hex_32 (w[0]) == 0) continue; + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (w[j + 0], w[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30905_sxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + if (pw_len != 64) return; + + + // copy password to w + + u32 w[16]; + + for (u32 i = 0; i < 16; i++) // pw_len / 4 + { + w[i] = pws[gid].i[i]; + } + + for (u32 i = 1; i < 16; i++) + { + if (is_valid_hex_32 (w[i]) == 0) return; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32 w0 = w0l | w0r; + + w[0] = w0; + + if (is_valid_hex_32 (w[0]) == 0) continue; + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (w[j + 0], w[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[16] = { 0 }; // why is re-using the "tmp" variable here slower ? + + const u32 type = 0x02 | (y[0] & 1); + + pub_key[8] = (x[0] << 24); + pub_key[7] = (x[0] >> 8) | (x[1] << 24); + pub_key[6] = (x[1] >> 8) | (x[2] << 24); + pub_key[5] = (x[2] >> 8) | (x[3] << 24); + pub_key[4] = (x[3] >> 8) | (x[4] << 24); + pub_key[3] = (x[4] >> 8) | (x[5] << 24); + pub_key[2] = (x[5] >> 8) | (x[6] << 24); + pub_key[1] = (x[6] >> 8) | (x[7] << 24); + pub_key[0] = (x[7] >> 8) | (type << 24); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 33); // length of public key: 33 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30906_a0-pure.cl b/OpenCL/m30906_a0-pure.cl new file mode 100644 index 000000000..95549f36a --- /dev/null +++ b/OpenCL/m30906_a0-pure.cl @@ -0,0 +1,354 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_rp.h) +#include M2S(INCLUDE_PATH/inc_rp.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30906_mxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + COPY_PW (pws[gid]); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t p = PASTE_PW; + + p.pw_len = apply_rules (rules_buf[il_pos].cmds, p.i, p.pw_len); + + if (p.pw_len != 64) continue; + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (p.i[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (p.i[j + 0], p.i[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30906_sxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + + /** + * base + */ + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + COPY_PW (pws[gid]); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t p = PASTE_PW; + + p.pw_len = apply_rules (rules_buf[il_pos].cmds, p.i, p.pw_len); + + if (p.pw_len != 64) continue; + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (p.i[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (p.i[j + 0], p.i[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30906_a1-pure.cl b/OpenCL/m30906_a1-pure.cl new file mode 100644 index 000000000..fd76b12c4 --- /dev/null +++ b/OpenCL/m30906_a1-pure.cl @@ -0,0 +1,408 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30906_mxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + // copy password to w + + u32 w[16] = { 0 }; + + // for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + for (u32 idx = 0; idx < 16; idx++) + { + w[idx] = pws[gid].i[idx]; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + if ((pw_len + comb_len) != 64) continue; + + u32 c[64] = { 0 }; + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] = combs_buf[il_pos].i[i]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] |= w[i]; + } + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (c[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (c[j + 0], c[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30906_sxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + // copy password to w + + u32 w[16] = { 0 }; + + // for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + for (u32 idx = 0; idx < 16; idx++) + { + w[idx] = pws[gid].i[idx]; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + if ((pw_len + comb_len) != 64) continue; + + u32 c[64] = { 0 }; + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] = combs_buf[il_pos].i[i]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < 16; i++) + { + c[i] |= w[i]; + } + + for (u32 i = 0; i < 16; i++) + { + if (is_valid_hex_32 (c[i]) == 0) continue; + } + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (c[j + 0], c[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m30906_a3-pure.cl b/OpenCL/m30906_a3-pure.cl new file mode 100644 index 000000000..033d9e1c4 --- /dev/null +++ b/OpenCL/m30906_a3-pure.cl @@ -0,0 +1,383 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#define SECP256K1_TMPS_TYPE PRIVATE_AS + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd160.cl) +#include M2S(INCLUDE_PATH/inc_ecc_secp256k1.cl) +#endif + +DECLSPEC u32 hex_convert_u32 (PRIVATE_AS const u32 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +DECLSPEC u32 hex_u32_to_u32 (PRIVATE_AS const u32 hex0, PRIVATE_AS const u32 hex1) +{ + u32 v = 0; + + v |= hex_convert_u32 ((hex0 >> 0) & 0xff) << 28; + v |= hex_convert_u32 ((hex0 >> 8) & 0xff) << 24; + v |= hex_convert_u32 ((hex0 >> 16) & 0xff) << 20; + v |= hex_convert_u32 ((hex0 >> 24) & 0xff) << 16; + + v |= hex_convert_u32 ((hex1 >> 0) & 0xff) << 12; + v |= hex_convert_u32 ((hex1 >> 8) & 0xff) << 8; + v |= hex_convert_u32 ((hex1 >> 16) & 0xff) << 4; + v |= hex_convert_u32 ((hex1 >> 24) & 0xff) << 0; + + return (v); +} + +KERNEL_FQ void m30906_mxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + if (pw_len != 64) return; + + + // copy password to w + + u32 w[16]; + + for (u32 i = 0; i < 16; i++) // pw_len / 4 + { + w[i] = pws[gid].i[i]; + } + + for (u32 i = 1; i < 16; i++) + { + if (is_valid_hex_32 (w[i]) == 0) return; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32 w0 = w0l | w0r; + + w[0] = w0; + + if (is_valid_hex_32 (w[0]) == 0) continue; + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (w[j + 0], w[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m30906_sxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + if (pw_len != 64) return; + + + // copy password to w + + u32 w[16]; + + for (u32 i = 0; i < 16; i++) // pw_len / 4 + { + w[i] = pws[gid].i[i]; + } + + for (u32 i = 1; i < 16; i++) + { + if (is_valid_hex_32 (w[i]) == 0) return; + } + + secp256k1_t preG; // need to change SECP256K1_TMPS_TYPE above to: PRIVATE_AS + + set_precomputed_basepoint_g (&preG); + + + /** + * loop + */ + + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32 w0 = w0l | w0r; + + w[0] = w0; + + if (is_valid_hex_32 (w[0]) == 0) continue; + + + // convert password from hex to binary + + u32 tmp[16] = { 0 }; + + for (u32 i = 0, j = 0; i < 8; i += 1, j += 2) + { + tmp[i] = hex_u32_to_u32 (w[j + 0], w[j + 1]); + } + + u32 prv_key[9]; + + prv_key[0] = tmp[7]; + prv_key[1] = tmp[6]; + prv_key[2] = tmp[5]; + prv_key[3] = tmp[4]; + prv_key[4] = tmp[3]; + prv_key[5] = tmp[2]; + prv_key[6] = tmp[1]; + prv_key[7] = tmp[0]; + + + // convert: pub_key = G * prv_key + + u32 x[8]; + u32 y[8]; + + point_mul_xy (x, y, prv_key, &preG); + + + // to public key: + + u32 pub_key[32] = { 0 }; + + pub_key[16] = (y[0] << 24); + pub_key[15] = (y[0] >> 8) | (y[1] << 24); + pub_key[14] = (y[1] >> 8) | (y[2] << 24); + pub_key[13] = (y[2] >> 8) | (y[3] << 24); + pub_key[12] = (y[3] >> 8) | (y[4] << 24); + pub_key[11] = (y[4] >> 8) | (y[5] << 24); + pub_key[10] = (y[5] >> 8) | (y[6] << 24); + pub_key[ 9] = (y[6] >> 8) | (y[7] << 24); + pub_key[ 8] = (y[7] >> 8) | (x[0] << 24); + pub_key[ 7] = (x[0] >> 8) | (x[1] << 24); + pub_key[ 6] = (x[1] >> 8) | (x[2] << 24); + pub_key[ 5] = (x[2] >> 8) | (x[3] << 24); + pub_key[ 4] = (x[3] >> 8) | (x[4] << 24); + pub_key[ 3] = (x[4] >> 8) | (x[5] << 24); + pub_key[ 2] = (x[5] >> 8) | (x[6] << 24); + pub_key[ 1] = (x[6] >> 8) | (x[7] << 24); + pub_key[ 0] = (x[7] >> 8) | (0x04000000); + + + // calculate HASH160 for pub key + + sha256_ctx_t ctx; + + sha256_init (&ctx); + sha256_update (&ctx, pub_key, 65); // length of public key: 65 + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + // tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0; + // tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0; + + for (u32 i = 8; i < 16; i++) tmp[i] = 0; + + + // now let's do RIPEMD-160 on the sha256sum + + ripemd160_ctx_t rctx; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + + /* + * 2nd RIPEMD160 (SHA256 ()): + */ + + tmp[0] = (rctx.h[0] << 16) | ( 0x1400); // (swapped) OP_0 operation (0x00), + tmp[1] = (rctx.h[1] << 16) | (rctx.h[0] >> 16); // 0x14 == 20, this indicates the + tmp[2] = (rctx.h[2] << 16) | (rctx.h[1] >> 16); // data len + tmp[3] = (rctx.h[3] << 16) | (rctx.h[2] >> 16); + tmp[4] = (rctx.h[4] << 16) | (rctx.h[3] >> 16); + tmp[5] = (rctx.h[4] >> 16); + + for (u32 i = 6; i < 16; i++) tmp[i] = 0; + + sha256_init (&ctx); + sha256_update_swap (&ctx, tmp, 22); + sha256_final (&ctx); + + for (u32 i = 0; i < 8; i++) tmp[i] = ctx.h[i]; + + ripemd160_init (&rctx); + ripemd160_update_swap (&rctx, tmp, 32); + ripemd160_final (&rctx); + + const u32 r0 = rctx.h[0]; + const u32 r1 = rctx.h[1]; + const u32 r2 = rctx.h[2]; + const u32 r3 = rctx.h[3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/docs/changes.txt b/docs/changes.txt index 37a58be6f..4a42c4ccb 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -6,6 +6,9 @@ - Added hash-mode: Anope IRC Services (enc_sha256) - Added hash-mode: Bisq .wallet (scrypt) +- Added hash-mode: Bitcoin raw private key (P2PKH) +- Added hash-mode: Bitcoin raw private key (P2SH(P2WPKH)) +- Added hash-mode: Bitcoin raw private key (P2WPKH, Bech32) - Added hash-mode: ENCsecurity Datavault (PBKDF2/no keychain) - Added hash-mode: ENCsecurity Datavault (PBKDF2/keychain) - Added hash-mode: ENCsecurity Datavault (MD5/no keychain) diff --git a/docs/readme.txt b/docs/readme.txt index b034d6e79..289d3e935 100644 --- a/docs/readme.txt +++ b/docs/readme.txt @@ -412,6 +412,9 @@ NVIDIA GPUs require "NVIDIA Driver" (440.64 or later) and "CUDA Toolkit" (9.0 or - Bitcoin WIF private key (P2PKH) - Bitcoin WIF private key (P2SH(P2WPKH)) - Bitcoin WIF private key (P2WPKH, Bech32) +- Bitcoin raw private key (P2PKH) +- Bitcoin raw private key (P2SH(P2WPKH)) +- Bitcoin raw private key (P2WPKH, Bech32) - Electrum Wallet (Salt-Type 1-3) - Electrum Wallet (Salt-Type 4) - Electrum Wallet (Salt-Type 5) diff --git a/src/modules/module_30901.c b/src/modules/module_30901.c new file mode 100644 index 000000000..af4021761 --- /dev/null +++ b/src/modules/module_30901.c @@ -0,0 +1,218 @@ +/** + * 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" +#include "memory.h" + +#include "emu_inc_hash_base58.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_5; +static const u32 HASH_CATEGORY = HASH_CATEGORY_CRYPTOCURRENCY_WALLET; +static const char *HASH_NAME = "Bitcoin raw private key (P2PKH), compressed"; +static const u64 KERN_TYPE = 30901; +static const u32 OPTI_TYPE = OPTI_TYPE_NOT_SALTED; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE; +static const u32 SALT_TYPE = SALT_TYPE_NONE; +static const char *ST_PASS = "59887ec9920239bd45b6a9f82b7c4e024f80beaf887e5ee6aac5de0a899d3068"; +static const char *ST_HASH = "14Fqy5AGRehazZ4NLzxFWy2E4BiNFdH9Ut"; +static const char *BENCHMARK_MASK = "?h?h?h?h?h?h?h9920239bd45b6a9f82b7c4e024f80beaf887e5ee6aac5de0a899d3068"; +static const u32 PUBKEY_MAXLEN = 64; // our max is actually always 25 (21 + 4) +static const u32 RAW_LEN = 64; + + +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; } +const char *module_benchmark_mask (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 BENCHMARK_MASK; } + +u32 module_kernel_loops_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) +{ + const u32 kernel_loops_max = 16; + + return kernel_loops_max; +} + +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) +{ + return RAW_LEN; +} + +u32 module_pw_min (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 RAW_LEN; +} + +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) +{ + u8 *digest = (u8 *) digest_buf; + + u8 pubkey[PUBKEY_MAXLEN]; + + hc_token_t token; + + token.token_cnt = 1; + + token.len_min[0] = 26; + token.len_max[0] = 34; + token.attr[0] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_BASE58; + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + u32 pubkey_len = PUBKEY_MAXLEN; + + bool res = b58dec (pubkey, &pubkey_len, (u8 *) line_buf, line_len); + + if (res == false) return (PARSER_HASH_LENGTH); + + // for now we support only P2PKH addresses + + if (pubkey_len != 25) return (PARSER_HASH_LENGTH); // most likely wrong Bitcoin address type + + u32 l = PUBKEY_MAXLEN - pubkey_len; + + if (pubkey[l] != 0) return (PARSER_HASH_VALUE); // wrong Bitcoin address type + + // check if pubkey has correct sha256 sum included + + u32 npubkey[16] = { 0 }; + + u8 *npubkey_ptr = (u8 *) npubkey; + + for (u32 i = 0, j = PUBKEY_MAXLEN - pubkey_len; i < pubkey_len; i++, j++) + { + npubkey_ptr[i] = pubkey[j]; + } + + // if (b58check (npubkey_ptr, pubkey_len) == false) return (PARSER_HASH_ENCODING); + // if (b58check64 (npubkey, pubkey_len) == false) return (PARSER_HASH_ENCODING); + + if (b58check_25 (npubkey) == false) return (PARSER_HASH_ENCODING); + + + for (u32 i = 0; i < 20; i++) // DGST_SIZE + { + digest[i] = pubkey[PUBKEY_MAXLEN - pubkey_len + i + 1]; + } + + 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) +{ + u8 *digest = (u8 *) digest_buf; + + u8 buf[64] = { 0 }; + + u32 len = 64; + + b58check_enc (buf, &len, 0, digest, 20); + + return snprintf (line_buf, line_size, "%s", buf); +} + +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_benchmark_mask; + 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_deprecated_notice = 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_DEFAULT; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_extra_tuningdb_block = 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_postprocess = 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_kernel_loops_max; + 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_pw_min; + 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; +} diff --git a/src/modules/module_30902.c b/src/modules/module_30902.c new file mode 100644 index 000000000..c38f9ecd2 --- /dev/null +++ b/src/modules/module_30902.c @@ -0,0 +1,218 @@ +/** + * 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" +#include "memory.h" + +#include "emu_inc_hash_base58.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_5; +static const u32 HASH_CATEGORY = HASH_CATEGORY_CRYPTOCURRENCY_WALLET; +static const char *HASH_NAME = "Bitcoin raw private key (P2PKH), uncompressed"; +static const u64 KERN_TYPE = 30902; +static const u32 OPTI_TYPE = OPTI_TYPE_NOT_SALTED; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE; +static const u32 SALT_TYPE = SALT_TYPE_NONE; +static const char *ST_PASS = "2006a306cf8f61c18c4e78e5fc0f5a7aa473b5ffb41f34344a32f8e042786fa1"; +static const char *ST_HASH = "12sLRz1TKPZurKCwVqeT5FkW3Y7usipPbZ"; +static const char *BENCHMARK_MASK = "?h?h?h?h?h?h?h6cf8f61c18c4e78e5fc0f5a7aa473b5ffb41f34344a32f8e042786fa1"; +static const u32 PUBKEY_MAXLEN = 64; // our max is actually always 25 (21 + 4) +static const u32 RAW_LEN = 64; + + +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; } +const char *module_benchmark_mask (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 BENCHMARK_MASK; } + +u32 module_kernel_loops_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) +{ + const u32 kernel_loops_max = 16; + + return kernel_loops_max; +} + +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) +{ + return RAW_LEN; +} + +u32 module_pw_min (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 RAW_LEN; +} + +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) +{ + u8 *digest = (u8 *) digest_buf; + + u8 pubkey[PUBKEY_MAXLEN]; + + hc_token_t token; + + token.token_cnt = 1; + + token.len_min[0] = 26; + token.len_max[0] = 34; + token.attr[0] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_BASE58; + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + u32 pubkey_len = PUBKEY_MAXLEN; + + bool res = b58dec (pubkey, &pubkey_len, (u8 *) line_buf, line_len); + + if (res == false) return (PARSER_HASH_LENGTH); + + // for now we support only P2PKH addresses + + if (pubkey_len != 25) return (PARSER_HASH_LENGTH); // most likely wrong Bitcoin address type + + u32 l = PUBKEY_MAXLEN - pubkey_len; + + if (pubkey[l] != 0) return (PARSER_HASH_VALUE); // wrong Bitcoin address type + + // check if pubkey has correct sha256 sum included + + u32 npubkey[16] = { 0 }; + + u8 *npubkey_ptr = (u8 *) npubkey; + + for (u32 i = 0, j = PUBKEY_MAXLEN - pubkey_len; i < pubkey_len; i++, j++) + { + npubkey_ptr[i] = pubkey[j]; + } + + // if (b58check (npubkey_ptr, pubkey_len) == false) return (PARSER_HASH_ENCODING); + // if (b58check64 (npubkey, pubkey_len) == false) return (PARSER_HASH_ENCODING); + + if (b58check_25 (npubkey) == false) return (PARSER_HASH_ENCODING); + + + for (u32 i = 0; i < 20; i++) // DGST_SIZE + { + digest[i] = pubkey[PUBKEY_MAXLEN - pubkey_len + i + 1]; + } + + 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) +{ + u8 *digest = (u8 *) digest_buf; + + u8 buf[64] = { 0 }; + + u32 len = 64; + + b58check_enc (buf, &len, 0, digest, 20); + + return snprintf (line_buf, line_size, "%s", buf); +} + +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_benchmark_mask; + 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_deprecated_notice = 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_DEFAULT; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_extra_tuningdb_block = 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_postprocess = 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_kernel_loops_max; + 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_pw_min; + 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; +} diff --git a/src/modules/module_30903.c b/src/modules/module_30903.c new file mode 100644 index 000000000..a6ccee5e1 --- /dev/null +++ b/src/modules/module_30903.c @@ -0,0 +1,400 @@ +/** + * 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" +#include "memory.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_5; +static const u32 HASH_CATEGORY = HASH_CATEGORY_CRYPTOCURRENCY_WALLET; +static const char *HASH_NAME = "Bitcoin raw private key (P2WPKH, Bech32), compressed"; +static const u64 KERN_TYPE = 30901; +static const u32 OPTI_TYPE = OPTI_TYPE_NOT_SALTED; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE; +static const u32 SALT_TYPE = SALT_TYPE_NONE; +static const char *ST_PASS = "4d1987d7a341d51557af59996845740135ab2506515426ada57cc8ec05adf794"; +static const char *ST_HASH = "bc1q926ca6n7wz7gm2gfd8xc5p0vu687ngvnknpx74"; +static const char *BENCHMARK_MASK = "?h?h?h?h?h?h?h7a341d51557af59996845740135ab2506515426ada57cc8ec05adf794"; +static const u32 RAW_LEN = 64; + +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; } +const char *module_benchmark_mask (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 BENCHMARK_MASK; } + +u32 module_kernel_loops_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) +{ + const u32 kernel_loops_max = 16; + + return kernel_loops_max; +} + +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) +{ + return RAW_LEN; +} + +u32 module_pw_min (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 RAW_LEN; +} + +static u32 polymod_checksum (const u8 *data, const u32 data_len) +{ + const u32 CONSTS[5] = { 0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3 }; + + u32 c = 1; + + for (u32 i = 0; i < data_len; i++) // data_len is always 44 for us + { + const u32 b = c >> 25; + + c = ((c & 0x01ffffff) << 5) ^ data[i]; + + for (u32 j = 0; j < 5; j++) + { + const u32 bit_set = (b >> j) & 1; + + if (bit_set == 0) continue; + + c ^= CONSTS[j]; + } + } + + return c; +} + +static const char *SIGNATURE_BITCOIN_BECH32 = "bc1"; // human readable part (HRP) + "1" +static const char *BECH32_BASE32_ALPHABET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; + +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; + + hc_token_t token; + + token.token_cnt = 2; + + token.signatures_cnt = 1; + token.signatures_buf[0] = SIGNATURE_BITCOIN_BECH32; + + token.len[0] = 3; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_SIGNATURE; + + token.len[1] = 39; // 42 - 3 (SIGNATURE_BITCOIN_BECH32) + token.attr[1] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_BECH32; + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + // Bech32 decode: + + u8 t[64] = { 0 }; // only 42 - 3 = 39 needed + + for (u32 i = 3; i < 42; i++) // skip first 3 bytes ("bc1") + { + // this is actually a search that we could do also with strstr (): + // note: we always have a hit, because we verified this with TOKEN_ATTR_VERIFY_BECH32 + + for (u32 j = 0; j < 32; j++) + { + if (BECH32_BASE32_ALPHABET[j] == line_buf[i]) + { + t[i - 3] = j; + + break; + } + } + } + + if (t[0] != 0) // check if "version"/type is BECH32, we do NOT accept BECH32M + { + return (PARSER_HASH_ENCODING); + } + + /* + * Check the checksum of the address: + */ + + u32 checksum = t[33] << 25 + | t[34] << 20 + | t[35] << 15 + | t[36] << 10 + | t[37] << 5 + | t[38] << 0; + + u8 data[64] = { 0 }; // only 44 bytes actually needed + + data[0] = 3; // HRP = Human Readable Part, 3 base32 chars => 5 bytes prefix + data[1] = 3; // these 5 bytes come from: hrp_expand ("bc"), human readable part + data[2] = 0; + data[3] = 2; + data[4] = 3; + + for (u32 i = 0; i < 42 - 3 - 6; i++) // skip "bc1" (start) and checksum (end) + { + data[i + 5] = t[i]; + } + + data[38] = 0; // "clear" the 6 checksum bytes (for correct "polymod" checksum below) + data[39] = 0; + data[40] = 0; + data[41] = 0; + data[42] = 0; + data[43] = 0; + + u32 polymod = polymod_checksum (data, 44) ^ 1; // BECH32M would xor with 0x2bc830a3 + + if (polymod != checksum) // or (polymod_checksum (data, 44) ^ checksum) != 1 + { + return (PARSER_HASH_ENCODING); + } + + + /* + * transform/convert back to the ripemd hash (reverse translate_8to5 (), i.e. translate_5to8). + * We extend the 8 bit blocks here to 32 bit blocks (4 * 8 = 32 bits), therefore we convert + * 5 bit "blocks" to 32 bit blocks (from the base32 range: 0..31 to u32: 0..0xffffffff): + */ + + // note: t[0] needs to be skipped (version info) + + digest[0] = (t[ 1] << 27) | (t[ 2] << 22) | (t[ 3] << 17) | (t[ 4] << 12) + | (t[ 5] << 7) | (t[ 6] << 2) | (t[ 7] >> 3); + + digest[1] = (t[ 7] << 29) | (t[ 8] << 24) | (t[ 9] << 19) | (t[10] << 14) + | (t[11] << 9) | (t[12] << 4) | (t[13] >> 1); + + digest[2] = (t[13] << 31) | (t[14] << 26) | (t[15] << 21) | (t[16] << 16) + | (t[17] << 11) | (t[18] << 6) | (t[19] << 1) | (t[20] >> 4); + + digest[3] = (t[20] << 28) | (t[21] << 23) | (t[22] << 18) | (t[23] << 13) + | (t[24] << 8) | (t[25] << 3) | (t[26] >> 2); + + digest[4] = (t[26] << 30) | (t[27] << 25) | (t[28] << 20) | (t[29] << 15) + | (t[30] << 10) | (t[31] << 5) | (t[32] << 0); + + // a final byte swap is needed for the kernel code: + + for (u32 i = 0; i < 5; i++) + { + digest[i] = byte_swap_32 (digest[i]); + } + + 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) +{ + // note: here we work mostly with char/u8 type because it's easier to base32 encode + // (at least conceptually), but this could be easily extended to u32 variable types: + + u8 *digest = (u8 *) digest_buf; + + u8 b[20] = { 0 }; + + for (u32 i = 0; i < 20; i++) // i < length (digest) + { + b[i] = digest[i]; + } + + + /* + * convert 8 bit "blocks" to 5 bit blocks, translate_8to5 () (for base32, 0..31): + */ + + u8 t[64] = { 0 }; // only 39 bytes actually needed + + t[ 0] = 0; // set "version"/type to BECH32, we do NOT support BECH32M + + t[ 1] = ( (b[ 0] >> 3)) & 31; + t[ 2] = ((b[ 0] << 2) | (b[ 1] >> 6)) & 31; + t[ 3] = ( (b[ 1] >> 1)) & 31; + t[ 4] = ((b[ 1] << 4) | (b[ 2] >> 4)) & 31; + t[ 5] = ((b[ 2] << 1) | (b[ 3] >> 7)) & 31; + t[ 6] = ( (b[ 3] >> 2)) & 31; + t[ 7] = ((b[ 3] << 3) | (b[ 4] >> 5)) & 31; + t[ 8] = ( (b[ 4] >> 0)) & 31; + + t[ 9] = ( (b[ 5] >> 3)) & 31; + t[10] = ((b[ 5] << 2) | (b[ 6] >> 6)) & 31; + t[11] = ( (b[ 6] >> 1)) & 31; + t[12] = ((b[ 6] << 4) | (b[ 7] >> 4)) & 31; + t[13] = ((b[ 7] << 1) | (b[ 8] >> 7)) & 31; + t[14] = ( (b[ 8] >> 2)) & 31; + t[15] = ((b[ 8] << 3) | (b[ 9] >> 5)) & 31; + t[16] = ( (b[ 9] >> 0)) & 31; + + t[17] = ( (b[10] >> 3)) & 31; + t[18] = ((b[10] << 2) | (b[11] >> 6)) & 31; + t[19] = ( (b[11] >> 1)) & 31; + t[20] = ((b[11] << 4) | (b[12] >> 4)) & 31; + t[21] = ((b[12] << 1) | (b[13] >> 7)) & 31; + t[22] = ( (b[13] >> 2)) & 31; + t[23] = ((b[13] << 3) | (b[14] >> 5)) & 31; + t[24] = ( (b[14] >> 0)) & 31; + + t[25] = ( (b[15] >> 3)) & 31; + t[26] = ((b[15] << 2) | (b[16] >> 6)) & 31; + t[27] = ( (b[16] >> 1)) & 31; + t[28] = ((b[16] << 4) | (b[17] >> 4)) & 31; + t[29] = ((b[17] << 1) | (b[18] >> 7)) & 31; + t[30] = ( (b[18] >> 2)) & 31; + t[31] = ((b[18] << 3) | (b[19] >> 5)) & 31; + t[32] = ( (b[19] >> 0)) & 31; + + // note: some further t[] array items will be set after we know the checksum of this part + + + /* + * Checksum: + */ + + u8 data[64] = { 0 }; // only 44 bytes actually needed + + data[0] = 3; // hrp_expand ("bc"), human readable part + data[1] = 3; + data[2] = 0; + data[3] = 2; + data[4] = 3; + + for (u32 i = 0; i < 33; i++) + { + data[i + 5] = t[i]; + } + + // data[38] = data[39] = data[40] = data[41] = data[42] = data[43] = 0; + + u32 polymod = polymod_checksum (data, 44) ^ 1; // BECH32M would xor with 0x2bc830a3 + + t[33] = (polymod >> 25) & 31; + t[34] = (polymod >> 20) & 31; + t[35] = (polymod >> 15) & 31; + t[36] = (polymod >> 10) & 31; + t[37] = (polymod >> 5) & 31; + t[38] = (polymod >> 0) & 31; + + + /* + * BASE32 encode: + */ + + u8 bech32_address[64] = { 0 }; // only 39 bytes needed: 1 + 32 + 6 + + for (u32 i = 0; i < 39; i++) + { + const u32 idx = t[i]; + + bech32_address[i] = BECH32_BASE32_ALPHABET[idx]; + } + + bech32_address[39] = 0; // be extra safe, terminate the "C" string with NUL byte + + return snprintf (line_buf, line_size, "%s%s", SIGNATURE_BITCOIN_BECH32, bech32_address); +} + +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_benchmark_mask; + 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_deprecated_notice = 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_DEFAULT; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_extra_tuningdb_block = 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_postprocess = 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_kernel_loops_max; + 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_pw_min; + 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; +} diff --git a/src/modules/module_30904.c b/src/modules/module_30904.c new file mode 100644 index 000000000..4dcc4a9c1 --- /dev/null +++ b/src/modules/module_30904.c @@ -0,0 +1,400 @@ +/** + * 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" +#include "memory.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_5; +static const u32 HASH_CATEGORY = HASH_CATEGORY_CRYPTOCURRENCY_WALLET; +static const char *HASH_NAME = "Bitcoin raw private key (P2WPKH, Bech32), uncompressed"; +static const u64 KERN_TYPE = 30902; +static const u32 OPTI_TYPE = OPTI_TYPE_NOT_SALTED; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE; +static const u32 SALT_TYPE = SALT_TYPE_NONE; +static const char *ST_PASS = "25c9f8f734d87aacd9308705ca50b9819a57425ffbfae41cef869b19764d72c2"; +static const char *ST_HASH = "bc1qq6samcuksd2f6rsc48eu3lkq87zp33vfud0p0t"; +static const char *BENCHMARK_MASK = "?h?h?h?h?h?h?h734d87aacd9308705ca50b9819a57425ffbfae41cef869b19764d72c2"; +static const u32 RAW_LEN = 64; + +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; } +const char *module_benchmark_mask (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 BENCHMARK_MASK; } + +u32 module_kernel_loops_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) +{ + const u32 kernel_loops_max = 16; + + return kernel_loops_max; +} + +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) +{ + return RAW_LEN; +} + +u32 module_pw_min (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 RAW_LEN; +} + +static u32 polymod_checksum (const u8 *data, const u32 data_len) +{ + const u32 CONSTS[5] = { 0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3 }; + + u32 c = 1; + + for (u32 i = 0; i < data_len; i++) // data_len is always 44 for us + { + const u32 b = c >> 25; + + c = ((c & 0x01ffffff) << 5) ^ data[i]; + + for (u32 j = 0; j < 5; j++) + { + const u32 bit_set = (b >> j) & 1; + + if (bit_set == 0) continue; + + c ^= CONSTS[j]; + } + } + + return c; +} + +static const char *SIGNATURE_BITCOIN_BECH32 = "bc1"; // human readable part (HRP) + "1" +static const char *BECH32_BASE32_ALPHABET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; + +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; + + hc_token_t token; + + token.token_cnt = 2; + + token.signatures_cnt = 1; + token.signatures_buf[0] = SIGNATURE_BITCOIN_BECH32; + + token.len[0] = 3; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_SIGNATURE; + + token.len[1] = 39; // 42 - 3 (SIGNATURE_BITCOIN_BECH32) + token.attr[1] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_BECH32; + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + // Bech32 decode: + + u8 t[64] = { 0 }; // only 42 - 3 = 39 needed + + for (u32 i = 3; i < 42; i++) // skip first 3 bytes ("bc1") + { + // this is actually a search that we could do also with strstr (): + // note: we always have a hit, because we verified this with TOKEN_ATTR_VERIFY_BECH32 + + for (u32 j = 0; j < 32; j++) + { + if (BECH32_BASE32_ALPHABET[j] == line_buf[i]) + { + t[i - 3] = j; + + break; + } + } + } + + if (t[0] != 0) // check if "version"/type is BECH32, we do NOT accept BECH32M + { + return (PARSER_HASH_ENCODING); + } + + /* + * Check the checksum of the address: + */ + + u32 checksum = t[33] << 25 + | t[34] << 20 + | t[35] << 15 + | t[36] << 10 + | t[37] << 5 + | t[38] << 0; + + u8 data[64] = { 0 }; // only 44 bytes actually needed + + data[0] = 3; // HRP = Human Readable Part, 3 base32 chars => 5 bytes prefix + data[1] = 3; // these 5 bytes come from: hrp_expand ("bc"), human readable part + data[2] = 0; + data[3] = 2; + data[4] = 3; + + for (u32 i = 0; i < 42 - 3 - 6; i++) // skip "bc1" (start) and checksum (end) + { + data[i + 5] = t[i]; + } + + data[38] = 0; // "clear" the 6 checksum bytes (for correct "polymod" checksum below) + data[39] = 0; + data[40] = 0; + data[41] = 0; + data[42] = 0; + data[43] = 0; + + u32 polymod = polymod_checksum (data, 44) ^ 1; // BECH32M would xor with 0x2bc830a3 + + if (polymod != checksum) // or (polymod_checksum (data, 44) ^ checksum) != 1 + { + return (PARSER_HASH_ENCODING); + } + + + /* + * transform/convert back to the ripemd hash (reverse translate_8to5 (), i.e. translate_5to8). + * We extend the 8 bit blocks here to 32 bit blocks (4 * 8 = 32 bits), therefore we convert + * 5 bit "blocks" to 32 bit blocks (from the base32 range: 0..31 to u32: 0..0xffffffff): + */ + + // note: t[0] needs to be skipped (version info) + + digest[0] = (t[ 1] << 27) | (t[ 2] << 22) | (t[ 3] << 17) | (t[ 4] << 12) + | (t[ 5] << 7) | (t[ 6] << 2) | (t[ 7] >> 3); + + digest[1] = (t[ 7] << 29) | (t[ 8] << 24) | (t[ 9] << 19) | (t[10] << 14) + | (t[11] << 9) | (t[12] << 4) | (t[13] >> 1); + + digest[2] = (t[13] << 31) | (t[14] << 26) | (t[15] << 21) | (t[16] << 16) + | (t[17] << 11) | (t[18] << 6) | (t[19] << 1) | (t[20] >> 4); + + digest[3] = (t[20] << 28) | (t[21] << 23) | (t[22] << 18) | (t[23] << 13) + | (t[24] << 8) | (t[25] << 3) | (t[26] >> 2); + + digest[4] = (t[26] << 30) | (t[27] << 25) | (t[28] << 20) | (t[29] << 15) + | (t[30] << 10) | (t[31] << 5) | (t[32] << 0); + + // a final byte swap is needed for the kernel code: + + for (u32 i = 0; i < 5; i++) + { + digest[i] = byte_swap_32 (digest[i]); + } + + 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) +{ + // note: here we work mostly with char/u8 type because it's easier to base32 encode + // (at least conceptually), but this could be easily extended to u32 variable types: + + u8 *digest = (u8 *) digest_buf; + + u8 b[20] = { 0 }; + + for (u32 i = 0; i < 20; i++) // i < length (digest) + { + b[i] = digest[i]; + } + + + /* + * convert 8 bit "blocks" to 5 bit blocks, translate_8to5 () (for base32, 0..31): + */ + + u8 t[64] = { 0 }; // only 39 bytes actually needed + + t[ 0] = 0; // set "version"/type to BECH32, we do NOT support BECH32M + + t[ 1] = ( (b[ 0] >> 3)) & 31; + t[ 2] = ((b[ 0] << 2) | (b[ 1] >> 6)) & 31; + t[ 3] = ( (b[ 1] >> 1)) & 31; + t[ 4] = ((b[ 1] << 4) | (b[ 2] >> 4)) & 31; + t[ 5] = ((b[ 2] << 1) | (b[ 3] >> 7)) & 31; + t[ 6] = ( (b[ 3] >> 2)) & 31; + t[ 7] = ((b[ 3] << 3) | (b[ 4] >> 5)) & 31; + t[ 8] = ( (b[ 4] >> 0)) & 31; + + t[ 9] = ( (b[ 5] >> 3)) & 31; + t[10] = ((b[ 5] << 2) | (b[ 6] >> 6)) & 31; + t[11] = ( (b[ 6] >> 1)) & 31; + t[12] = ((b[ 6] << 4) | (b[ 7] >> 4)) & 31; + t[13] = ((b[ 7] << 1) | (b[ 8] >> 7)) & 31; + t[14] = ( (b[ 8] >> 2)) & 31; + t[15] = ((b[ 8] << 3) | (b[ 9] >> 5)) & 31; + t[16] = ( (b[ 9] >> 0)) & 31; + + t[17] = ( (b[10] >> 3)) & 31; + t[18] = ((b[10] << 2) | (b[11] >> 6)) & 31; + t[19] = ( (b[11] >> 1)) & 31; + t[20] = ((b[11] << 4) | (b[12] >> 4)) & 31; + t[21] = ((b[12] << 1) | (b[13] >> 7)) & 31; + t[22] = ( (b[13] >> 2)) & 31; + t[23] = ((b[13] << 3) | (b[14] >> 5)) & 31; + t[24] = ( (b[14] >> 0)) & 31; + + t[25] = ( (b[15] >> 3)) & 31; + t[26] = ((b[15] << 2) | (b[16] >> 6)) & 31; + t[27] = ( (b[16] >> 1)) & 31; + t[28] = ((b[16] << 4) | (b[17] >> 4)) & 31; + t[29] = ((b[17] << 1) | (b[18] >> 7)) & 31; + t[30] = ( (b[18] >> 2)) & 31; + t[31] = ((b[18] << 3) | (b[19] >> 5)) & 31; + t[32] = ( (b[19] >> 0)) & 31; + + // note: some further t[] array items will be set after we know the checksum of this part + + + /* + * Checksum: + */ + + u8 data[64] = { 0 }; // only 44 bytes actually needed + + data[0] = 3; // hrp_expand ("bc"), human readable part + data[1] = 3; + data[2] = 0; + data[3] = 2; + data[4] = 3; + + for (u32 i = 0; i < 33; i++) + { + data[i + 5] = t[i]; + } + + // data[38] = data[39] = data[40] = data[41] = data[42] = data[43] = 0; + + u32 polymod = polymod_checksum (data, 44) ^ 1; // BECH32M would xor with 0x2bc830a3 + + t[33] = (polymod >> 25) & 31; + t[34] = (polymod >> 20) & 31; + t[35] = (polymod >> 15) & 31; + t[36] = (polymod >> 10) & 31; + t[37] = (polymod >> 5) & 31; + t[38] = (polymod >> 0) & 31; + + + /* + * BASE32 encode: + */ + + u8 bech32_address[64] = { 0 }; // only 39 bytes needed: 1 + 32 + 6 + + for (u32 i = 0; i < 39; i++) + { + const u32 idx = t[i]; + + bech32_address[i] = BECH32_BASE32_ALPHABET[idx]; + } + + bech32_address[39] = 0; // be extra safe, terminate the "C" string with NUL byte + + return snprintf (line_buf, line_size, "%s%s", SIGNATURE_BITCOIN_BECH32, bech32_address); +} + +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_benchmark_mask; + 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_deprecated_notice = 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_DEFAULT; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_extra_tuningdb_block = 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_postprocess = 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_kernel_loops_max; + 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_pw_min; + 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; +} diff --git a/src/modules/module_30905.c b/src/modules/module_30905.c new file mode 100644 index 000000000..ba739be2f --- /dev/null +++ b/src/modules/module_30905.c @@ -0,0 +1,217 @@ +/** + * 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" +#include "memory.h" + +#include "emu_inc_hash_base58.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_5; +static const u32 HASH_CATEGORY = HASH_CATEGORY_CRYPTOCURRENCY_WALLET; +static const char *HASH_NAME = "Bitcoin raw private key (P2SH(P2WPKH)), compressed"; +static const u64 KERN_TYPE = 30905; +static const u32 OPTI_TYPE = OPTI_TYPE_NOT_SALTED; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE; +static const u32 SALT_TYPE = SALT_TYPE_NONE; +static const char *ST_PASS = "83b45ff8d85f37aafc05a8accd1f1cd5e50868b57e2ef0ef6f287bb4d8d17786"; +static const char *ST_HASH = "3JqAMRQN3Gd6i8yV3Kw7v55RmFxW7iW2Aq"; +static const char *BENCHMARK_MASK = "?h?h?h?h?h?h?h8d85f37aafc05a8accd1f1cd5e50868b57e2ef0ef6f287bb4d8d17786"; +static const u32 PUBKEY_MAXLEN = 64; // our max is actually always 25 (21 + 4) +static const u32 RAW_LEN = 64; + + +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; } +const char *module_benchmark_mask (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 BENCHMARK_MASK; } + +u32 module_kernel_loops_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) +{ + const u32 kernel_loops_max = 16; + + return kernel_loops_max; +} + +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) +{ + return RAW_LEN; +} + +u32 module_pw_min (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 RAW_LEN; +} + +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) +{ + u8 *digest = (u8 *) digest_buf; + + u8 pubkey[PUBKEY_MAXLEN]; + + hc_token_t token; + + token.token_cnt = 1; + + token.len[0] = 34; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_BASE58; + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + u32 pubkey_len = PUBKEY_MAXLEN; + + bool res = b58dec (pubkey, &pubkey_len, (u8 *) line_buf, line_len); + + if (res == false) return (PARSER_HASH_LENGTH); + + // for now we support only P2SH(P2WPKH) addresses + + if (pubkey_len != 25) return (PARSER_HASH_LENGTH); // most likely wrong Bitcoin address type + + u32 l = PUBKEY_MAXLEN - pubkey_len; + + if (pubkey[l] != 0x05) return (PARSER_HASH_VALUE); // wrong Bitcoin address type + + // check if pubkey has correct sha256 sum included + + u32 npubkey[16] = { 0 }; + + u8 *npubkey_ptr = (u8 *) npubkey; + + for (u32 i = 0, j = PUBKEY_MAXLEN - pubkey_len; i < pubkey_len; i++, j++) + { + npubkey_ptr[i] = pubkey[j]; + } + + // if (b58check (npubkey_ptr, pubkey_len) == false) return (PARSER_HASH_ENCODING); + // if (b58check64 (npubkey, pubkey_len) == false) return (PARSER_HASH_ENCODING); + + if (b58check_25 (npubkey) == false) return (PARSER_HASH_ENCODING); + + + for (u32 i = 0; i < 20; i++) // DGST_SIZE + { + digest[i] = pubkey[PUBKEY_MAXLEN - pubkey_len + i + 1]; + } + + 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) +{ + u8 *digest = (u8 *) digest_buf; + + u8 buf[64] = { 0 }; + + u32 len = 64; + + b58check_enc (buf, &len, 0x05, digest, 20); + + return snprintf (line_buf, line_size, "%s", buf); +} + +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_benchmark_mask; + 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_deprecated_notice = 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_DEFAULT; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_extra_tuningdb_block = 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_postprocess = 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_kernel_loops_max; + 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_pw_min; + 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; +} diff --git a/src/modules/module_30906.c b/src/modules/module_30906.c new file mode 100644 index 000000000..4e0e9fe1f --- /dev/null +++ b/src/modules/module_30906.c @@ -0,0 +1,217 @@ +/** + * 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" +#include "memory.h" + +#include "emu_inc_hash_base58.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_5; +static const u32 HASH_CATEGORY = HASH_CATEGORY_CRYPTOCURRENCY_WALLET; +static const char *HASH_NAME = "Bitcoin raw private key (P2SH(P2WPKH)), uncompressed"; +static const u64 KERN_TYPE = 30906; +static const u32 OPTI_TYPE = OPTI_TYPE_NOT_SALTED; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE; +static const u32 SALT_TYPE = SALT_TYPE_NONE; +static const char *ST_PASS = "4c969ccc86d9e1f557b4ff1f19badc9a99718dd2aec8fcf66460612e05f5f7dd"; +static const char *ST_HASH = "3PmD8zdrFD8KVgLrguVDCP2RJB4Rh35G9Z"; +static const char *BENCHMARK_MASK = "?h?h?h?h?h?h?hc86d9e1f557b4ff1f19badc9a99718dd2aec8fcf66460612e05f5f7dd"; +static const u32 PUBKEY_MAXLEN = 64; // our max is actually always 25 (21 + 4) +static const u32 RAW_LEN = 64; + + +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; } +const char *module_benchmark_mask (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 BENCHMARK_MASK; } + +u32 module_kernel_loops_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) +{ + const u32 kernel_loops_max = 16; + + return kernel_loops_max; +} + +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) +{ + return RAW_LEN; +} + +u32 module_pw_min (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 RAW_LEN; +} + +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) +{ + u8 *digest = (u8 *) digest_buf; + + u8 pubkey[PUBKEY_MAXLEN]; + + hc_token_t token; + + token.token_cnt = 1; + + token.len[0] = 34; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_BASE58; + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + u32 pubkey_len = PUBKEY_MAXLEN; + + bool res = b58dec (pubkey, &pubkey_len, (u8 *) line_buf, line_len); + + if (res == false) return (PARSER_HASH_LENGTH); + + // for now we support only P2SH(P2WPKH) addresses + + if (pubkey_len != 25) return (PARSER_HASH_LENGTH); // most likely wrong Bitcoin address type + + u32 l = PUBKEY_MAXLEN - pubkey_len; + + if (pubkey[l] != 0x05) return (PARSER_HASH_VALUE); // wrong Bitcoin address type + + // check if pubkey has correct sha256 sum included + + u32 npubkey[16] = { 0 }; + + u8 *npubkey_ptr = (u8 *) npubkey; + + for (u32 i = 0, j = PUBKEY_MAXLEN - pubkey_len; i < pubkey_len; i++, j++) + { + npubkey_ptr[i] = pubkey[j]; + } + + // if (b58check (npubkey_ptr, pubkey_len) == false) return (PARSER_HASH_ENCODING); + // if (b58check64 (npubkey, pubkey_len) == false) return (PARSER_HASH_ENCODING); + + if (b58check_25 (npubkey) == false) return (PARSER_HASH_ENCODING); + + + for (u32 i = 0; i < 20; i++) // DGST_SIZE + { + digest[i] = pubkey[PUBKEY_MAXLEN - pubkey_len + i + 1]; + } + + 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) +{ + u8 *digest = (u8 *) digest_buf; + + u8 buf[64] = { 0 }; + + u32 len = 64; + + b58check_enc (buf, &len, 0x05, digest, 20); + + return snprintf (line_buf, line_size, "%s", buf); +} + +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_benchmark_mask; + 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_deprecated_notice = 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_DEFAULT; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_extra_tuningdb_block = 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_postprocess = 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_kernel_loops_max; + 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_pw_min; + 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; +} diff --git a/tools/test.sh b/tools/test.sh index 1fd7d3998..e2440b564 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -42,7 +42,7 @@ SLOW_ALGOS=$( grep -l ATTACK_EXEC_OUTSIDE_KERNEL "${TDIR}"/../src/modules/modu # fake slow algos, due to specific password pattern (e.g. ?d from "mask_3" is invalid): # ("only" drawback is that just -a 0 is tested with this workaround) -SLOW_ALGOS="${SLOW_ALGOS} 28501 28502 28503 28504 28505 28506" +SLOW_ALGOS="${SLOW_ALGOS} 28501 28502 28503 28504 28505 28506 30901 30902 30903 30904 30905 30906" OUTD="test_$(date +%s)" diff --git a/tools/test_modules/m30901.pm b/tools/test_modules/m30901.pm new file mode 100644 index 000000000..0e035a3f9 --- /dev/null +++ b/tools/test_modules/m30901.pm @@ -0,0 +1,85 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Bitcoin::Crypto qw (btc_prv btc_extprv); +use Bitcoin::Crypto::Base58 qw (decode_base58check); + +sub module_constraints { [[64, 64], [-1, -1], [-1, -1], [-1, -1], [-1, -1]] } + +# Note: +# We have introduced the function: module_get_random_password () +# that will help to generate random valid passwords from a given seed. + +sub module_generate_hash +{ + my $word = shift; # expecting valid raw private key + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + my $priv = ""; + + my @is_valid_hex = eval + { + $priv = btc_prv->from_hex ($word); + }; + + return if (! @is_valid_hex); + + my $IS_COMPRESSED = 1; + + $priv->set_compressed ($IS_COMPRESSED); + + my $pub = $priv->get_public_key (); + my $hash = $pub->get_legacy_address (); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my $idx = rindex ($line, ':'); + + return unless $idx >= 0; + + my $hash = substr ($line, 0, $idx); + my $word = substr ($line, $idx + 1); + + return unless (defined ($hash)); + return unless (defined ($word)); + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + my @is_valid_base58 = eval + { + decode_base58check ($hash); + }; + + return unless (@is_valid_base58); + + my $new_hash = module_generate_hash ($word); + + return ($new_hash, $word); +} + +sub module_get_random_password +{ + my $seed = shift; + + my $master_key = btc_extprv->from_seed ($seed); # expecting random seed from test.pl + my $derived_key = $master_key->derive_key ("m/0'"); + + my $priv = $derived_key->get_basic_key (); + + return $priv->to_hex (); # the result is padded (32 raw bytes) +} + +1; diff --git a/tools/test_modules/m30902.pm b/tools/test_modules/m30902.pm new file mode 100644 index 000000000..99f4ea6fe --- /dev/null +++ b/tools/test_modules/m30902.pm @@ -0,0 +1,85 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Bitcoin::Crypto qw (btc_prv btc_extprv); +use Bitcoin::Crypto::Base58 qw (decode_base58check); + +sub module_constraints { [[64, 64], [-1, -1], [-1, -1], [-1, -1], [-1, -1]] } + +# Note: +# We have introduced the function: module_get_random_password () +# that will help to generate random valid passwords from a given seed. + +sub module_generate_hash +{ + my $word = shift; # expecting valid raw private key + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + my $priv = ""; + + my @is_valid_hex = eval + { + $priv = btc_prv->from_hex ($word); + }; + + return if (! @is_valid_hex); + + my $IS_COMPRESSED = 0; + + $priv->set_compressed ($IS_COMPRESSED); + + my $pub = $priv->get_public_key (); + my $hash = $pub->get_legacy_address (); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my $idx = rindex ($line, ':'); + + return unless $idx >= 0; + + my $hash = substr ($line, 0, $idx); + my $word = substr ($line, $idx + 1); + + return unless (defined ($hash)); + return unless (defined ($word)); + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + my @is_valid_base58 = eval + { + decode_base58check ($hash); + }; + + return unless (@is_valid_base58); + + my $new_hash = module_generate_hash ($word); + + return ($new_hash, $word); +} + +sub module_get_random_password +{ + my $seed = shift; + + my $master_key = btc_extprv->from_seed ($seed); # expecting random seed from test.pl + my $derived_key = $master_key->derive_key ("m/0'"); + + my $priv = $derived_key->get_basic_key (); + + return $priv->to_hex (); # the result is padded (32 raw bytes) +} + +1; diff --git a/tools/test_modules/m30903.pm b/tools/test_modules/m30903.pm new file mode 100644 index 000000000..31ce5b2db --- /dev/null +++ b/tools/test_modules/m30903.pm @@ -0,0 +1,80 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Bitcoin::Crypto qw (btc_prv btc_extprv); +use Bitcoin::Crypto::Base58 qw (decode_base58check); + +sub module_constraints { [[64, 64], [-1, -1], [-1, -1], [-1, -1], [-1, -1]] } + +# Note: +# We have introduced the function: module_get_random_password () +# that will help to generate random valid passwords from a given seed. + +sub module_generate_hash +{ + my $word = shift; # expecting valid raw private key + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + my $priv = ""; + + my @is_valid_hex = eval + { + $priv = btc_prv->from_hex ($word); + }; + + return if (! @is_valid_hex); + + my $IS_COMPRESSED = 1; + + $priv->set_compressed ($IS_COMPRESSED); + + my $pub = $priv->get_public_key (); + my $hash = $pub->get_segwit_address (); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my $idx = rindex ($line, ':'); + + return unless $idx >= 0; + + my $hash = substr ($line, 0, $idx); + my $word = substr ($line, $idx + 1); + + return unless (defined ($hash)); + return unless (defined ($word)); + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + return unless ($hash =~ m/^bc1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*$/); # bech32/base32 encoding + + my $new_hash = module_generate_hash ($word); + + return ($new_hash, $word); +} + +sub module_get_random_password +{ + my $seed = shift; + + my $master_key = btc_extprv->from_seed ($seed); # expecting random seed from test.pl + my $derived_key = $master_key->derive_key ("m/0'"); + + my $priv = $derived_key->get_basic_key (); + + return $priv->to_hex (); # the result is padded (32 raw bytes) +} + +1; diff --git a/tools/test_modules/m30904.pm b/tools/test_modules/m30904.pm new file mode 100644 index 000000000..d8cbd447f --- /dev/null +++ b/tools/test_modules/m30904.pm @@ -0,0 +1,83 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Bitcoin::Crypto qw (btc_prv btc_extprv); +use Bitcoin::Crypto::Base58 qw (decode_base58check); + +sub module_constraints { [[64, 64], [-1, -1], [-1, -1], [-1, -1], [-1, -1]] } + +# Note: +# We have introduced the function: module_get_random_password () +# that will help to generate random valid passwords from a given seed. + +sub module_generate_hash +{ + my $word = shift; # expecting valid raw private key + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + my $priv = ""; + + my @is_valid_hex = eval + { + $priv = btc_prv->from_hex ($word); + }; + + return if (! @is_valid_hex); + + my $IS_COMPRESSED = 0; + + $priv->set_compressed ($IS_COMPRESSED); + + my $pub = $priv->get_public_key (); + my $hash = $pub->get_segwit_address (); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my $idx = rindex ($line, ':'); + + return unless $idx >= 0; + + my $hash = substr ($line, 0, $idx); + my $word = substr ($line, $idx + 1); + + return unless (defined ($hash)); + return unless (defined ($word)); + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + return unless ($hash =~ m/^bc1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*$/); # bech32/base32 encoding + + my $new_hash = module_generate_hash ($word); + + return ($new_hash, $word); +} + +sub module_get_random_password +{ + # new function added to generate valid password for an algorithm + # from a given seed as a parameter + + my $seed = shift; + + my $master_key = btc_extprv->from_seed ($seed); # expecting random seed from test.pl + my $derived_key = $master_key->derive_key ("m/0'"); + + my $priv = $derived_key->get_basic_key (); + + return $priv->to_hex (); # the result is padded (32 raw bytes) +} + +1; diff --git a/tools/test_modules/m30905.pm b/tools/test_modules/m30905.pm new file mode 100644 index 000000000..ec17e7ea9 --- /dev/null +++ b/tools/test_modules/m30905.pm @@ -0,0 +1,85 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Bitcoin::Crypto qw (btc_prv btc_extprv); +use Bitcoin::Crypto::Base58 qw (decode_base58check); + +sub module_constraints { [[64, 64], [-1, -1], [-1, -1], [-1, -1], [-1, -1]] } + +# Note: +# We have introduced the function: module_get_random_password () +# that will help to generate random valid passwords from a given seed. + +sub module_generate_hash +{ + my $word = shift; # expecting valid raw private key + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + my $priv = ""; + + my @is_valid_hex = eval + { + $priv = btc_prv->from_hex ($word); + }; + + return if (! @is_valid_hex); + + my $IS_COMPRESSED = 1; + + $priv->set_compressed ($IS_COMPRESSED); + + my $pub = $priv->get_public_key (); + my $hash = $pub->get_compat_address (); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my $idx = rindex ($line, ':'); + + return unless $idx >= 0; + + my $hash = substr ($line, 0, $idx); + my $word = substr ($line, $idx + 1); + + return unless (defined ($hash)); + return unless (defined ($word)); + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + my @is_valid_base58 = eval + { + decode_base58check ($hash); + }; + + return unless (@is_valid_base58); + + my $new_hash = module_generate_hash ($word); + + return ($new_hash, $word); +} + +sub module_get_random_password +{ + my $seed = shift; + + my $master_key = btc_extprv->from_seed ($seed); # expecting random seed from test.pl + my $derived_key = $master_key->derive_key ("m/0'"); + + my $priv = $derived_key->get_basic_key (); + + return $priv->to_hex (); # the result is padded (32 raw bytes) +} + +1; diff --git a/tools/test_modules/m30906.pm b/tools/test_modules/m30906.pm new file mode 100644 index 000000000..07ef19fcd --- /dev/null +++ b/tools/test_modules/m30906.pm @@ -0,0 +1,85 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Bitcoin::Crypto qw (btc_prv btc_extprv); +use Bitcoin::Crypto::Base58 qw (decode_base58check); + +sub module_constraints { [[51, 51], [-1, -1], [-1, -1], [-1, -1], [-1, -1]] } + +# Note: +# We have introduced the function: module_get_random_password () +# that will help to generate random valid passwords from a given seed. + +sub module_generate_hash +{ + my $word = shift; # expecting valid raw private key + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + my $priv = ""; + + my @is_valid_hex = eval + { + $priv = btc_prv->from_hex ($word); + }; + + return if (! @is_valid_hex); + + my $IS_COMPRESSED = 0; + + $priv->set_compressed ($IS_COMPRESSED); + + my $pub = $priv->get_public_key (); + my $hash = $pub->get_compat_address (); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my $idx = rindex ($line, ':'); + + return unless $idx >= 0; + + my $hash = substr ($line, 0, $idx); + my $word = substr ($line, $idx + 1); + + return unless (defined ($hash)); + return unless (defined ($word)); + + return unless ($word =~ m/^[0-9a-fA-F]{64}$/); + + my @is_valid_base58 = eval + { + decode_base58check ($hash); + }; + + return unless (@is_valid_base58); + + my $new_hash = module_generate_hash ($word); + + return ($new_hash, $word); +} + +sub module_get_random_password +{ + my $seed = shift; + + my $master_key = btc_extprv->from_seed ($seed); # expecting random seed from test.pl + my $derived_key = $master_key->derive_key ("m/0'"); + + my $priv = $derived_key->get_basic_key (); + + return $priv->to_hex (); # the result is padded (32 raw bytes) +} + +1;