From a0de388bb92cf832ee513a207991379805d9bab6 Mon Sep 17 00:00:00 2001 From: Flaggx1 Date: Sun, 21 May 2023 00:05:08 -0400 Subject: [PATCH 001/252] Increase number of user-defined charsets from 4 to 9 This feature change increases the number of user-defined charsets from a maximum of 4 to 9. This enables more advanced and efficient attacks in certain cases. --- include/types.h | 12 ++++++- src/brain.c | 71 +++++++++++++++++++++++++++++++++++++++++ src/mpsp.c | 78 ++++++++++++++++++++++++++++++++++++++++++++-- src/status.c | 19 +++++++++-- src/usage.c | 5 +++ src/user_options.c | 58 +++++++++++++++++++++++++++++++--- 6 files changed, 234 insertions(+), 9 deletions(-) diff --git a/include/types.h b/include/types.h index 6fd4c4553..d059ab416 100644 --- a/include/types.h +++ b/include/types.h @@ -757,6 +757,11 @@ typedef enum user_options_map IDX_CUSTOM_CHARSET_2 = '2', IDX_CUSTOM_CHARSET_3 = '3', IDX_CUSTOM_CHARSET_4 = '4', + IDX_CUSTOM_CHARSET_5 = '5', + IDX_CUSTOM_CHARSET_6 = '6', + IDX_CUSTOM_CHARSET_7 = '7', + IDX_CUSTOM_CHARSET_8 = '8', + IDX_CUSTOM_CHARSET_9 = '9', IDX_DEBUG_FILE = 0xff12, IDX_DEBUG_MODE = 0xff13, IDX_DEPRECATED_CHECK_DISABLE = 0xff14, @@ -2377,7 +2382,7 @@ typedef struct user_options char *brain_session_whitelist; #endif char *cpu_affinity; - char *custom_charset_4; + char *custom_charset_9; char *debug_file; char *induction_dir; char *keyboard_layout_mapping; @@ -2396,6 +2401,11 @@ typedef struct user_options const char *custom_charset_1; const char *custom_charset_2; const char *custom_charset_3; + const char *custom_charset_4; + const char *custom_charset_5; + const char *custom_charset_6; + const char *custom_charset_7; + const char *custom_charset_8; const char *encoding_from; const char *encoding_to; const char *rule_buf_l; diff --git a/src/brain.c b/src/brain.c index bd97d9695..480170bb1 100644 --- a/src/brain.c +++ b/src/brain.c @@ -345,7 +345,43 @@ u32 brain_compute_attack (hashcat_ctx_t *hashcat_ctx) XXH64_update (state, custom_charset_4, strlen (custom_charset_4)); } + + if (user_options->custom_charset_5) + { + const char *custom_charset_5 = user_options->custom_charset_5; + + XXH64_update (state, custom_charset_5, strlen (custom_charset_5)); + } + + if (user_options->custom_charset_6) + { + const char *custom_charset_6 = user_options->custom_charset_6; + + XXH64_update (state, custom_charset_6, strlen (custom_charset_6)); + } + + if (user_options->custom_charset_7) + { + const char *custom_charset_7 = user_options->custom_charset_7; + + XXH64_update (state, custom_charset_7, strlen (custom_charset_7)); + } + + if (user_options->custom_charset_8) + { + const char *custom_charset_8 = user_options->custom_charset_8; + + XXH64_update (state, custom_charset_8, strlen (custom_charset_8)); + } + + if (user_options->custom_charset_9) + { + const char *custom_charset_9 = user_options->custom_charset_9; + + XXH64_update (state, custom_charset_9, strlen (custom_charset_9)); + } } + else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { const u64 wordlist_hash = brain_compute_attack_wordlist (straight_ctx->dict); @@ -405,6 +441,41 @@ u32 brain_compute_attack (hashcat_ctx_t *hashcat_ctx) XXH64_update (state, custom_charset_4, strlen (custom_charset_4)); } + if (user_options->custom_charset_5) + { + const char *custom_charset_5 = user_options->custom_charset_5; + + XXH64_update (state, custom_charset_5, strlen (custom_charset_5)); + } + + if (user_options->custom_charset_6) + { + const char *custom_charset_6 = user_options->custom_charset_6; + + XXH64_update (state, custom_charset_6, strlen (custom_charset_6)); + } + + if (user_options->custom_charset_7) + { + const char *custom_charset_7 = user_options->custom_charset_7; + + XXH64_update (state, custom_charset_7, strlen (custom_charset_7)); + } + + if (user_options->custom_charset_8) + { + const char *custom_charset_8 = user_options->custom_charset_8; + + XXH64_update (state, custom_charset_8, strlen (custom_charset_8)); + } + + if (user_options->custom_charset_9) + { + const char *custom_charset_9 = user_options->custom_charset_9; + + XXH64_update (state, custom_charset_9, strlen (custom_charset_9)); + } + const int hex_wordlist = user_options->hex_wordlist; XXH64_update (state, &hex_wordlist, sizeof (hex_wordlist)); diff --git a/src/mpsp.c b/src/mpsp.c index ba5511616..8e84cdba0 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -18,7 +18,7 @@ static const char *const DEF_MASK = "?1?2?2?2?2?2?2?3?3?3?3?d?d?d?d"; -#define MAX_MFS 5 // 4*charset, 1*mask +#define MAX_MFS 10 // 9*charset, 1*mask static int sp_comp_val (const void *p1, const void *p2) { @@ -314,6 +314,21 @@ static int mp_expand (hashcat_ctx_t *hashcat_ctx, const char *in_buf, size_t in_ case '4': if (mp_usr[3].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 4 is undefined."); return -1; } rc = mp_add_cs_buf (hashcat_ctx, mp_usr[3].cs_buf, mp_usr[3].cs_len, mp_usr, mp_usr_offset); break; + case '5': if (mp_usr[4].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 5 is undefined."); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[4].cs_buf, mp_usr[4].cs_len, mp_usr, mp_usr_offset); + break; + case '6': if (mp_usr[5].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 6 is undefined."); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[5].cs_buf, mp_usr[5].cs_len, mp_usr, mp_usr_offset); + break; + case '7': if (mp_usr[6].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 7 is undefined."); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[6].cs_buf, mp_usr[6].cs_len, mp_usr, mp_usr_offset); + break; + case '8': if (mp_usr[7].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 8 is undefined."); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[7].cs_buf, mp_usr[7].cs_len, mp_usr, mp_usr_offset); + break; + case '9': if (mp_usr[8].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 9 is undefined."); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[8].cs_buf, mp_usr[8].cs_len, mp_usr, mp_usr_offset); + break; case '?': rc = mp_add_cs_buf (hashcat_ctx, &p0, 1, mp_usr, mp_usr_offset); break; default: event_log_error (hashcat_ctx, "Syntax error in mask: %s", in_buf); @@ -427,6 +442,21 @@ static int mp_gen_css (hashcat_ctx_t *hashcat_ctx, char *mask_buf, size_t mask_l case '4': if (mp_usr[3].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 4 is undefined."); return -1; } rc = mp_add_cs_buf (hashcat_ctx, mp_usr[3].cs_buf, mp_usr[3].cs_len, css_buf, css_pos); break; + case '5': if (mp_usr[4].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 5 is undefined."); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[4].cs_buf, mp_usr[4].cs_len, css_buf, css_pos); + break; + case '6': if (mp_usr[5].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 6 is undefined."); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[5].cs_buf, mp_usr[5].cs_len, css_buf, css_pos); + break; + case '7': if (mp_usr[6].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 7 is undefined."); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[6].cs_buf, mp_usr[6].cs_len, css_buf, css_pos); + break; + case '8': if (mp_usr[7].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 8 is undefined."); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[7].cs_buf, mp_usr[7].cs_len, css_buf, css_pos); + break; + case '9': if (mp_usr[8].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 9 is undefined."); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[8].cs_buf, mp_usr[8].cs_len, css_buf, css_pos); + break; case '?': rc = mp_add_cs_buf (hashcat_ctx, &chr, 1, css_buf, css_pos); break; default: event_log_error (hashcat_ctx, "Syntax error in mask: %s", mask_buf); @@ -1416,7 +1446,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) mask_ctx->enabled = true; mask_ctx->mp_sys = (cs_t *) hccalloc (8, sizeof (cs_t)); - mask_ctx->mp_usr = (cs_t *) hccalloc (4, sizeof (cs_t)); + mask_ctx->mp_usr = (cs_t *) hccalloc (9, sizeof (cs_t)); mask_ctx->css_buf = (cs_t *) hccalloc (256, sizeof (cs_t)); mask_ctx->css_cnt = 0; @@ -1443,6 +1473,11 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (user_options->custom_charset_2) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1) == -1) return -1; } if (user_options->custom_charset_3) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2) == -1) return -1; } if (user_options->custom_charset_4) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3) == -1) return -1; } + if (user_options->custom_charset_5) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_5, 4) == -1) return -1; } + if (user_options->custom_charset_6) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_6, 5) == -1) return -1; } + if (user_options->custom_charset_7) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_7, 6) == -1) return -1; } + if (user_options->custom_charset_8) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_8, 7) == -1) return -1; } + if (user_options->custom_charset_9) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_9, 8) == -1) return -1; } if (user_options->benchmark == true) { @@ -1739,6 +1774,10 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx) mfs_buf[2].mf_len = 0; mfs_buf[3].mf_len = 0; mfs_buf[4].mf_len = 0; + mfs_buf[5].mf_len = 0; + mfs_buf[6].mf_len = 0; + mfs_buf[7].mf_len = 0; + mfs_buf[8].mf_len = 0; size_t mfs_cnt = 0; @@ -1796,11 +1835,21 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_2 = NULL; user_options->custom_charset_3 = NULL; user_options->custom_charset_4 = NULL; + user_options->custom_charset_5 = NULL; + user_options->custom_charset_6 = NULL; + user_options->custom_charset_7 = NULL; + user_options->custom_charset_8 = NULL; + user_options->custom_charset_9 = NULL; mp_reset_usr (mask_ctx->mp_usr, 0); mp_reset_usr (mask_ctx->mp_usr, 1); mp_reset_usr (mask_ctx->mp_usr, 2); mp_reset_usr (mask_ctx->mp_usr, 3); + mp_reset_usr (mask_ctx->mp_usr, 4); + mp_reset_usr (mask_ctx->mp_usr, 5); + mp_reset_usr (mask_ctx->mp_usr, 6); + mp_reset_usr (mask_ctx->mp_usr, 7); + mp_reset_usr (mask_ctx->mp_usr, 8); for (size_t i = 0; i < mfs_cnt; i++) { @@ -1825,6 +1874,31 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_4 = mfs_buf[3].mf_buf; mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3); break; + + case 4: + user_options->custom_charset_5 = mfs_buf[4].mf_buf; + mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_5, 4); + break; + + case 5: + user_options->custom_charset_6 = mfs_buf[5].mf_buf; + mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_6, 5); + break; + + case 6: + user_options->custom_charset_7 = mfs_buf[6].mf_buf; + mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_7, 6); + break; + + case 7: + user_options->custom_charset_8 = mfs_buf[7].mf_buf; + mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_8, 7); + break; + + case 8: + user_options->custom_charset_9 = mfs_buf[8].mf_buf; + mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_9, 8); + break; } } diff --git a/src/status.c b/src/status.c index 4e964fd3b..ccdf520f2 100644 --- a/src/status.c +++ b/src/status.c @@ -394,6 +394,11 @@ int status_get_guess_mode (const hashcat_ctx_t *hashcat_ctx) if (user_options->custom_charset_2) has_mask_cs = true; if (user_options->custom_charset_3) has_mask_cs = true; if (user_options->custom_charset_4) has_mask_cs = true; + if (user_options->custom_charset_5) has_mask_cs = true; + if (user_options->custom_charset_6) has_mask_cs = true; + if (user_options->custom_charset_7) has_mask_cs = true; + if (user_options->custom_charset_8) has_mask_cs = true; + if (user_options->custom_charset_9) has_mask_cs = true; if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)) { @@ -778,8 +783,13 @@ char *status_get_guess_charset (const hashcat_ctx_t *hashcat_ctx) const char *custom_charset_2 = user_options->custom_charset_2; const char *custom_charset_3 = user_options->custom_charset_3; const char *custom_charset_4 = user_options->custom_charset_4; + const char *custom_charset_5 = user_options->custom_charset_5; + const char *custom_charset_6 = user_options->custom_charset_6; + const char *custom_charset_7 = user_options->custom_charset_7; + const char *custom_charset_8 = user_options->custom_charset_8; + const char *custom_charset_9 = user_options->custom_charset_9; - if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) + if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL) || (custom_charset_5 != NULL) || (custom_charset_6 != NULL) || (custom_charset_7 != NULL) || (custom_charset_8 != NULL) || (custom_charset_9 != NULL)) { char *tmp_buf; @@ -787,8 +797,13 @@ char *status_get_guess_charset (const hashcat_ctx_t *hashcat_ctx) if (custom_charset_2 == NULL) custom_charset_2 = "Undefined"; if (custom_charset_3 == NULL) custom_charset_3 = "Undefined"; if (custom_charset_4 == NULL) custom_charset_4 = "Undefined"; + if (custom_charset_5 == NULL) custom_charset_5 = "Undefined"; + if (custom_charset_6 == NULL) custom_charset_6 = "Undefined"; + if (custom_charset_7 == NULL) custom_charset_7 = "Undefined"; + if (custom_charset_8 == NULL) custom_charset_8 = "Undefined"; + if (custom_charset_9 == NULL) custom_charset_9 = "Undefined"; - hc_asprintf (&tmp_buf, "-1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); + hc_asprintf (&tmp_buf, "-1 %s, -2 %s, -3 %s, -4 %s, -5 %s, -6 %s, -7 %s, -8 %s, -9 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4, custom_charset_5, custom_charset_6, custom_charset_7, custom_charset_8, custom_charset_9); return tmp_buf; } diff --git a/src/usage.c b/src/usage.c index c79a8c6ac..6de2fab85 100644 --- a/src/usage.c +++ b/src/usage.c @@ -128,6 +128,11 @@ static const char *const USAGE_BIG_PRE_HASHMODES[] = " -2, --custom-charset2 | CS | User-defined charset ?2 | -2 ?l?d?s", " -3, --custom-charset3 | CS | User-defined charset ?3 |", " -4, --custom-charset4 | CS | User-defined charset ?4 |", + " -5, --custom-charset5 | CS | User-defined charset ?5 |", + " -6, --custom-charset6 | CS | User-defined charset ?6 |", + " -7, --custom-charset7 | CS | User-defined charset ?7 |", + " -8, --custom-charset8 | CS | User-defined charset ?8 |", + " -9, --custom-charset9 | CS | User-defined charset ?9 |", " --identify | | Shows all supported algorithms for input hashes | --identify my.hash", " -i, --increment | | Enable mask increment mode |", " --increment-min | Num | Start mask incrementing at X | --increment-min=4", diff --git a/src/user_options.c b/src/user_options.c index a510c1d69..de84bd017 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -21,9 +21,9 @@ #endif #ifdef WITH_BRAIN -static const char *const short_options = "hVvm:a:r:j:k:g:o:t:d:D:n:u:T:c:p:s:l:1:2:3:4:iIbw:OMSY:z"; +static const char *const short_options = "hVvm:a:r:j:k:g:o:t:d:D:n:u:T:c:p:s:l:1:2:3:4:5:6:7:8:9:iIbw:OMSY:z"; #else -static const char *const short_options = "hVvm:a:r:j:k:g:o:t:d:D:n:u:T:c:p:s:l:1:2:3:4:iIbw:OMSY:"; +static const char *const short_options = "hVvm:a:r:j:k:g:o:t:d:D:n:u:T:c:p:s:l:1:2:3:4:5:6:7:8:9:iIbw:OMSY:"; #endif static char *const SEPARATOR = ":"; @@ -51,6 +51,11 @@ static const struct option long_options[] = {"custom-charset2", required_argument, NULL, IDX_CUSTOM_CHARSET_2}, {"custom-charset3", required_argument, NULL, IDX_CUSTOM_CHARSET_3}, {"custom-charset4", required_argument, NULL, IDX_CUSTOM_CHARSET_4}, + {"custom-charset5", required_argument, NULL, IDX_CUSTOM_CHARSET_5}, + {"custom-charset6", required_argument, NULL, IDX_CUSTOM_CHARSET_6}, + {"custom-charset7", required_argument, NULL, IDX_CUSTOM_CHARSET_7}, + {"custom-charset8", required_argument, NULL, IDX_CUSTOM_CHARSET_8}, + {"custom-charset9", required_argument, NULL, IDX_CUSTOM_CHARSET_9}, {"debug-file", required_argument, NULL, IDX_DEBUG_FILE}, {"debug-mode", required_argument, NULL, IDX_DEBUG_MODE}, {"deprecated-check-disable", no_argument, NULL, IDX_DEPRECATED_CHECK_DISABLE}, @@ -164,6 +169,11 @@ static const char *const RULE_BUF_L = ":"; static const char *const DEF_MASK_CS_1 = "?l?d?u"; static const char *const DEF_MASK_CS_2 = "?l?d"; static const char *const DEF_MASK_CS_3 = "?l?d*!$@_"; +static const char *const DEF_MASK_CS_4 = "a"; +static const char *const DEF_MASK_CS_5 = "b"; +static const char *const DEF_MASK_CS_6 = "c"; +static const char *const DEF_MASK_CS_7 = "d"; +static const char *const DEF_MASK_CS_8 = "e"; int user_options_init (hashcat_ctx_t *hashcat_ctx) { @@ -201,6 +211,11 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_2 = NULL; user_options->custom_charset_3 = NULL; user_options->custom_charset_4 = NULL; + user_options->custom_charset_5 = NULL; + user_options->custom_charset_6 = NULL; + user_options->custom_charset_7 = NULL; + user_options->custom_charset_8 = NULL; + user_options->custom_charset_9 = NULL; user_options->debug_file = NULL; user_options->debug_mode = DEBUG_MODE; user_options->deprecated_check_disable = DEPRECATED_CHECK_DISABLE; @@ -523,6 +538,11 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) case IDX_CUSTOM_CHARSET_2: user_options->custom_charset_2 = optarg; break; case IDX_CUSTOM_CHARSET_3: user_options->custom_charset_3 = optarg; break; case IDX_CUSTOM_CHARSET_4: user_options->custom_charset_4 = optarg; break; + case IDX_CUSTOM_CHARSET_5: user_options->custom_charset_5 = optarg; break; + case IDX_CUSTOM_CHARSET_6: user_options->custom_charset_6 = optarg; break; + case IDX_CUSTOM_CHARSET_7: user_options->custom_charset_7 = optarg; break; + case IDX_CUSTOM_CHARSET_8: user_options->custom_charset_8 = optarg; break; + case IDX_CUSTOM_CHARSET_9: user_options->custom_charset_9 = optarg; break; case IDX_SLOW_CANDIDATES: user_options->slow_candidates = true; break; #ifdef WITH_BRAIN case IDX_BRAIN_CLIENT: user_options->brain_client = true; break; @@ -1313,7 +1333,12 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) if ((user_options->custom_charset_1 != NULL) || (user_options->custom_charset_2 != NULL) || (user_options->custom_charset_3 != NULL) - || (user_options->custom_charset_4 != NULL)) + || (user_options->custom_charset_4 != NULL) + || (user_options->custom_charset_5 != NULL) + || (user_options->custom_charset_6 != NULL) + || (user_options->custom_charset_7 != NULL) + || (user_options->custom_charset_8 != NULL) + || (user_options->custom_charset_9 != NULL)) { if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)) { @@ -1465,7 +1490,12 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) if ((user_options->custom_charset_1 != NULL) || (user_options->custom_charset_2 != NULL) || (user_options->custom_charset_3 != NULL) - || (user_options->custom_charset_4 != NULL)) + || (user_options->custom_charset_4 != NULL) + || (user_options->custom_charset_5 != NULL) + || (user_options->custom_charset_6 != NULL) + || (user_options->custom_charset_7 != NULL) + || (user_options->custom_charset_8 != NULL) + || (user_options->custom_charset_9 != NULL)) { if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { @@ -2009,6 +2039,11 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_1 = DEF_MASK_CS_1; user_options->custom_charset_2 = DEF_MASK_CS_2; user_options->custom_charset_3 = DEF_MASK_CS_3; + user_options->custom_charset_4 = DEF_MASK_CS_4; + user_options->custom_charset_5 = DEF_MASK_CS_5; + user_options->custom_charset_6 = DEF_MASK_CS_6; + user_options->custom_charset_7 = DEF_MASK_CS_7; + user_options->custom_charset_8 = DEF_MASK_CS_8; user_options->increment = true; } @@ -2020,6 +2055,11 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_1 = DEF_MASK_CS_1; user_options->custom_charset_2 = DEF_MASK_CS_2; user_options->custom_charset_3 = DEF_MASK_CS_3; + user_options->custom_charset_4 = DEF_MASK_CS_4; + user_options->custom_charset_5 = DEF_MASK_CS_5; + user_options->custom_charset_6 = DEF_MASK_CS_6; + user_options->custom_charset_7 = DEF_MASK_CS_7; + user_options->custom_charset_8 = DEF_MASK_CS_8; user_options->increment = true; } @@ -2031,6 +2071,11 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_1 = DEF_MASK_CS_1; user_options->custom_charset_2 = DEF_MASK_CS_2; user_options->custom_charset_3 = DEF_MASK_CS_3; + user_options->custom_charset_4 = DEF_MASK_CS_4; + user_options->custom_charset_5 = DEF_MASK_CS_5; + user_options->custom_charset_6 = DEF_MASK_CS_6; + user_options->custom_charset_7 = DEF_MASK_CS_7; + user_options->custom_charset_8 = DEF_MASK_CS_8; user_options->increment = true; } @@ -3167,6 +3212,11 @@ void user_options_logger (hashcat_ctx_t *hashcat_ctx) logfile_top_string (user_options->custom_charset_2); logfile_top_string (user_options->custom_charset_3); logfile_top_string (user_options->custom_charset_4); + logfile_top_string (user_options->custom_charset_5); + logfile_top_string (user_options->custom_charset_6); + logfile_top_string (user_options->custom_charset_7); + logfile_top_string (user_options->custom_charset_8); + logfile_top_string (user_options->custom_charset_9); logfile_top_string (user_options->debug_file); logfile_top_string (user_options->encoding_from); logfile_top_string (user_options->encoding_to); From b437459e5ba0e7d3428a59cd1460050e90f347af Mon Sep 17 00:00:00 2001 From: Flaggx1 Date: Sun, 21 May 2023 02:10:14 -0400 Subject: [PATCH 002/252] Rename "Undefined" to "Undef" in status output for unused user charsets --- src/status.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/status.c b/src/status.c index ccdf520f2..4c973bdab 100644 --- a/src/status.c +++ b/src/status.c @@ -793,15 +793,15 @@ char *status_get_guess_charset (const hashcat_ctx_t *hashcat_ctx) { char *tmp_buf; - if (custom_charset_1 == NULL) custom_charset_1 = "Undefined"; - if (custom_charset_2 == NULL) custom_charset_2 = "Undefined"; - if (custom_charset_3 == NULL) custom_charset_3 = "Undefined"; - if (custom_charset_4 == NULL) custom_charset_4 = "Undefined"; - if (custom_charset_5 == NULL) custom_charset_5 = "Undefined"; - if (custom_charset_6 == NULL) custom_charset_6 = "Undefined"; - if (custom_charset_7 == NULL) custom_charset_7 = "Undefined"; - if (custom_charset_8 == NULL) custom_charset_8 = "Undefined"; - if (custom_charset_9 == NULL) custom_charset_9 = "Undefined"; + if (custom_charset_1 == NULL) custom_charset_1 = "Undef"; + if (custom_charset_2 == NULL) custom_charset_2 = "Undef"; + if (custom_charset_3 == NULL) custom_charset_3 = "Undef"; + if (custom_charset_4 == NULL) custom_charset_4 = "Undef"; + if (custom_charset_5 == NULL) custom_charset_5 = "Undef"; + if (custom_charset_6 == NULL) custom_charset_6 = "Undef"; + if (custom_charset_7 == NULL) custom_charset_7 = "Undef"; + if (custom_charset_8 == NULL) custom_charset_8 = "Undef"; + if (custom_charset_9 == NULL) custom_charset_9 = "Undef"; hc_asprintf (&tmp_buf, "-1 %s, -2 %s, -3 %s, -4 %s, -5 %s, -6 %s, -7 %s, -8 %s, -9 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4, custom_charset_5, custom_charset_6, custom_charset_7, custom_charset_8, custom_charset_9); From cd5dc9e3ce5834ef394a09641143add7f87d8a0f Mon Sep 17 00:00:00 2001 From: Royce Williams Date: Tue, 12 Dec 2023 23:00:20 -0900 Subject: [PATCH 003/252] summarize invalid rule chains --- src/rp.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/rp.c b/src/rp.c index 67ebd9322..ace86877b 100644 --- a/src/rp.c +++ b/src/rp.c @@ -906,6 +906,7 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 } u32 invalid_cnt = 0; + u32 valid_cnt = 0; for (u32 i = 0; i < kernel_rules_cnt; i++) { @@ -924,18 +925,27 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 { if (out_pos == RULES_MAX - 1) { - event_log_warning (hashcat_ctx, "Maximum functions per rule exceeded during chaining of rules, skipping..."); - invalid_cnt++; break; } + else + { + valid_cnt++; + } out->cmds[out_pos] = in->cmds[in_pos]; } } } + if (invalid_cnt > 0) + { + event_log_warning (hashcat_ctx, "Maximum functions per rule exceeded during chaining of rules."); + event_log_warning (hashcat_ctx, "Skipped %u rule chains, %u valid chains remain.", invalid_cnt, valid_cnt); + event_log_warning (hashcat_ctx, NULL); + } + hcfree (repeats); kernel_rules_cnt -= invalid_cnt; From 892bb5183cf2b377f5183bfde62c895f8eec352a Mon Sep 17 00:00:00 2001 From: philsmd Date: Sun, 7 Jan 2024 11:56:16 +0100 Subject: [PATCH 004/252] update license year to 2024 --- docs/license.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/license.txt b/docs/license.txt index 93d2971ae..88a5d2361 100644 --- a/docs/license.txt +++ b/docs/license.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015-2023 Jens Steube +Copyright (c) 2015-2024 Jens Steube Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 08f6cf7e0af48cfb1ec01e42f0f072cf8455a63c Mon Sep 17 00:00:00 2001 From: Mayank Date: Thu, 8 Feb 2024 10:16:25 +0530 Subject: [PATCH 005/252] Updated HIP SDK detection to use ENV variable on Windows --- src/ext_hiprtc.c | 51 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/ext_hiprtc.c b/src/ext_hiprtc.c index ad7d14be9..8ca343147 100644 --- a/src/ext_hiprtc.c +++ b/src/ext_hiprtc.c @@ -11,6 +11,42 @@ #include "dynloader.h" + +char* hiprtcDllPath(char* hipSDKPath) +{ + /* + AMD HIP RTC DLLs is stored at "C:\Program Files\ROCm\X.Y\bin\hiprtc0X0Y.dll" + Tried using regex to simplify, but had compilation issues on mingw64 (linker + had troubles with pcre.h) + + This function can return complete dll path based on major release version + X.Y parsed from the ENV variable HIP_PATH. + */ + + // Identifying major release version X.Y + char* majorVersion = malloc(strlen("X.Y")+1); + memcpy(majorVersion, hipSDKPath + (strlen(hipSDKPath) - 4), 3); + memcpy(majorVersion+0x3, "\0", 1); + + // Preparing DLL name "hiprtc0X0Y.dll" + char* hiprtcDllName = malloc(strlen("hiprtcXXXX.dll")+1); + memcpy(hiprtcDllName, "hiprtc0", strlen("hiprtc0")); + + memcpy(hiprtcDllName + 0x7, majorVersion, 1); + memcpy(hiprtcDllName + 0x8, "0", 1); + memcpy(hiprtcDllName + 0x9, majorVersion + 2, 1); + memcpy(hiprtcDllName + 0xa, ".dll\0", 5); + + // Preparing complete path as "C:\Program Files\ROCm\X.Y\bin\hiprtc0X0Y.dll" to + // return to the caller. + char* hiprtcDllPath = malloc(strlen(hipSDKPath) + strlen("bin/") + strlen("hiprtcXXXX.dll") + 1); + strcpy(hiprtcDllPath, hipSDKPath); + strcat(hiprtcDllPath, "bin\\"); + strcat(hiprtcDllPath, hiprtcDllName); + return(hiprtcDllPath); +} + + int hiprtc_make_options_array_from_string (char *string, char **options) { char *saveptr = NULL; @@ -41,14 +77,23 @@ int hiprtc_init (void *hashcat_ctx) #if defined (_WIN) hiprtc->lib = hc_dlopen ("hiprtc.dll"); - if (hiprtc->lib == NULL) hiprtc->lib = hc_dlopen ("C:/Program Files/AMD/ROCm/5.5/bin/hiprtc0505.dll"); + // Check for HIP SDK installation from ENV + const char* hipSDKPath = getenv("HIP_PATH"); + if (hipSDKPath != NULL && hiprtc->lib == NULL) + { + hiprtc->lib = hc_dlopen (hiprtcDllPath(hipSDKPath)); + } if (hiprtc->lib == NULL) hiprtc->lib = hc_dlopen ("amdhip64.dll"); #elif defined (__APPLE__) hiprtc->lib = hc_dlopen ("fixme.dylib"); #elif defined (__CYGWIN__) hiprtc->lib = hc_dlopen ("hiprtc.dll"); - - if (hiprtc->lib == NULL) hiprtc->lib = hc_dlopen ("C:/Program Files/AMD/ROCm/5.5/bin/hiprtc0505.dll"); + // Check for HIP SDK installation from ENV + const char* hipSDKPath = getenv("HIP_PATH"); + if (hipSDKPath != NULL && hiprtc->lib == NULL) + { + hiprtc->lib = hc_dlopen (hiprtcDllPath(hipSDKPath)); + } if (hiprtc->lib == NULL) hiprtc->lib = hc_dlopen ("amdhip64.dll"); #else hiprtc->lib = hc_dlopen ("libhiprtc.so"); From 992f1c13ba85c73fd4497b0c7cdeac85a7c01821 Mon Sep 17 00:00:00 2001 From: Mayank Date: Fri, 9 Feb 2024 23:15:54 +0530 Subject: [PATCH 006/252] Removed -nocudalib from hiprtc_options to fix LLVMBitcode compilation error when using HIP Backend --- src/backend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend.c b/src/backend.c index f7c916e1d..d4cf54be4 100644 --- a/src/backend.c +++ b/src/backend.c @@ -8755,7 +8755,7 @@ static bool load_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_p */ hiprtc_options[1] = "-nocudainc"; - hiprtc_options[2] = "-nocudalib"; + hiprtc_options[2] = ""; hiprtc_options[3] = ""; hiprtc_options[4] = ""; From c4bb788ad5cda4f656680f67e3caa0c84a57d175 Mon Sep 17 00:00:00 2001 From: its5Q Date: Thu, 22 Feb 2024 03:39:05 +1000 Subject: [PATCH 007/252] Add hashmodes 26620 and 26630 with dynamic iteration count --- OpenCL/m26620-pure.cl | 375 +++++++++++++++++++++++++++++++++ OpenCL/m26630-pure.cl | 413 ++++++++++++++++++++++++++++++++++++ src/modules/module_26620.c | 415 +++++++++++++++++++++++++++++++++++++ src/modules/module_26630.c | 395 +++++++++++++++++++++++++++++++++++ tools/metamask2hashcat.py | 16 +- 5 files changed, 1612 insertions(+), 2 deletions(-) create mode 100644 OpenCL/m26620-pure.cl create mode 100644 OpenCL/m26630-pure.cl create mode 100644 src/modules/module_26620.c create mode 100644 src/modules/module_26630.c mode change 100755 => 100644 tools/metamask2hashcat.py diff --git a/OpenCL/m26620-pure.cl b/OpenCL/m26620-pure.cl new file mode 100644 index 000000000..26ad55595 --- /dev/null +++ b/OpenCL/m26620-pure.cl @@ -0,0 +1,375 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#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_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_cipher_aes.cl) +#include M2S(INCLUDE_PATH/inc_cipher_aes-gcm.cl) +#endif + +#define COMPARE_S M2S(INCLUDE_PATH/inc_comp_single.cl) +#define COMPARE_M M2S(INCLUDE_PATH/inc_comp_multi.cl) + +typedef struct pbkdf2_sha256_tmp +{ + u32 ipad[8]; + u32 opad[8]; + + u32 dgst[32]; + u32 out[32]; + +} pbkdf2_sha256_tmp_t; + +typedef struct pbkdf2_sha256_aes_gcm +{ + u32 salt_buf[64]; + u32 iv_buf[4]; + u32 iv_len; + u32 ct_buf[784]; + u32 ct_len; + +} pbkdf2_sha256_aes_gcm_t; + +DECLSPEC void hmac_sha256_run_V (PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, PRIVATE_AS u32x *ipad, PRIVATE_AS u32x *opad, PRIVATE_AS u32x *digest) +{ + digest[0] = ipad[0]; + digest[1] = ipad[1]; + digest[2] = ipad[2]; + digest[3] = ipad[3]; + digest[4] = ipad[4]; + digest[5] = ipad[5]; + digest[6] = ipad[6]; + digest[7] = ipad[7]; + + sha256_transform_vector (w0, w1, w2, w3, digest); + + w0[0] = digest[0]; + w0[1] = digest[1]; + w0[2] = digest[2]; + w0[3] = digest[3]; + w1[0] = digest[4]; + w1[1] = digest[5]; + w1[2] = digest[6]; + w1[3] = digest[7]; + w2[0] = 0x80000000; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = (64 + 32) * 8; + + digest[0] = opad[0]; + digest[1] = opad[1]; + digest[2] = opad[2]; + digest[3] = opad[3]; + digest[4] = opad[4]; + digest[5] = opad[5]; + digest[6] = opad[6]; + digest[7] = opad[7]; + + sha256_transform_vector (w0, w1, w2, w3, digest); +} + +KERNEL_FQ void m26620_init (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) +{ + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + sha256_hmac_ctx_t sha256_hmac_ctx; + + sha256_hmac_init_global_swap (&sha256_hmac_ctx, pws[gid].i, pws[gid].pw_len); + + tmps[gid].ipad[0] = sha256_hmac_ctx.ipad.h[0]; + tmps[gid].ipad[1] = sha256_hmac_ctx.ipad.h[1]; + tmps[gid].ipad[2] = sha256_hmac_ctx.ipad.h[2]; + tmps[gid].ipad[3] = sha256_hmac_ctx.ipad.h[3]; + tmps[gid].ipad[4] = sha256_hmac_ctx.ipad.h[4]; + tmps[gid].ipad[5] = sha256_hmac_ctx.ipad.h[5]; + tmps[gid].ipad[6] = sha256_hmac_ctx.ipad.h[6]; + tmps[gid].ipad[7] = sha256_hmac_ctx.ipad.h[7]; + + tmps[gid].opad[0] = sha256_hmac_ctx.opad.h[0]; + tmps[gid].opad[1] = sha256_hmac_ctx.opad.h[1]; + tmps[gid].opad[2] = sha256_hmac_ctx.opad.h[2]; + tmps[gid].opad[3] = sha256_hmac_ctx.opad.h[3]; + tmps[gid].opad[4] = sha256_hmac_ctx.opad.h[4]; + tmps[gid].opad[5] = sha256_hmac_ctx.opad.h[5]; + tmps[gid].opad[6] = sha256_hmac_ctx.opad.h[6]; + tmps[gid].opad[7] = sha256_hmac_ctx.opad.h[7]; + + sha256_hmac_update_global_swap (&sha256_hmac_ctx, esalt_bufs[DIGESTS_OFFSET_HOST].salt_buf, salt_bufs[SALT_POS_HOST].salt_len); + + for (u32 i = 0, j = 1; i < 8; i += 8, j += 1) + { + sha256_hmac_ctx_t sha256_hmac_ctx2 = sha256_hmac_ctx; + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + w0[0] = j; + w0[1] = 0; + w0[2] = 0; + w0[3] = 0; + w1[0] = 0; + w1[1] = 0; + w1[2] = 0; + w1[3] = 0; + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + + sha256_hmac_update_64 (&sha256_hmac_ctx2, w0, w1, w2, w3, 4); + + sha256_hmac_final (&sha256_hmac_ctx2); + + tmps[gid].dgst[i + 0] = sha256_hmac_ctx2.opad.h[0]; + tmps[gid].dgst[i + 1] = sha256_hmac_ctx2.opad.h[1]; + tmps[gid].dgst[i + 2] = sha256_hmac_ctx2.opad.h[2]; + tmps[gid].dgst[i + 3] = sha256_hmac_ctx2.opad.h[3]; + tmps[gid].dgst[i + 4] = sha256_hmac_ctx2.opad.h[4]; + tmps[gid].dgst[i + 5] = sha256_hmac_ctx2.opad.h[5]; + tmps[gid].dgst[i + 6] = sha256_hmac_ctx2.opad.h[6]; + tmps[gid].dgst[i + 7] = sha256_hmac_ctx2.opad.h[7]; + + tmps[gid].out[i + 0] = tmps[gid].dgst[i + 0]; + tmps[gid].out[i + 1] = tmps[gid].dgst[i + 1]; + tmps[gid].out[i + 2] = tmps[gid].dgst[i + 2]; + tmps[gid].out[i + 3] = tmps[gid].dgst[i + 3]; + tmps[gid].out[i + 4] = tmps[gid].dgst[i + 4]; + tmps[gid].out[i + 5] = tmps[gid].dgst[i + 5]; + tmps[gid].out[i + 6] = tmps[gid].dgst[i + 6]; + tmps[gid].out[i + 7] = tmps[gid].dgst[i + 7]; + } +} + +KERNEL_FQ void m26620_loop (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) +{ + const u64 gid = get_global_id (0); + + if ((gid * VECT_SIZE) >= GID_CNT) return; + + u32x ipad[8]; + u32x opad[8]; + + ipad[0] = packv (tmps, ipad, gid, 0); + ipad[1] = packv (tmps, ipad, gid, 1); + ipad[2] = packv (tmps, ipad, gid, 2); + ipad[3] = packv (tmps, ipad, gid, 3); + ipad[4] = packv (tmps, ipad, gid, 4); + ipad[5] = packv (tmps, ipad, gid, 5); + ipad[6] = packv (tmps, ipad, gid, 6); + ipad[7] = packv (tmps, ipad, gid, 7); + + opad[0] = packv (tmps, opad, gid, 0); + opad[1] = packv (tmps, opad, gid, 1); + opad[2] = packv (tmps, opad, gid, 2); + opad[3] = packv (tmps, opad, gid, 3); + opad[4] = packv (tmps, opad, gid, 4); + opad[5] = packv (tmps, opad, gid, 5); + opad[6] = packv (tmps, opad, gid, 6); + opad[7] = packv (tmps, opad, gid, 7); + + for (u32 i = 0; i < 8; i += 8) + { + u32x dgst[8]; + u32x out[8]; + + dgst[0] = packv (tmps, dgst, gid, i + 0); + dgst[1] = packv (tmps, dgst, gid, i + 1); + dgst[2] = packv (tmps, dgst, gid, i + 2); + dgst[3] = packv (tmps, dgst, gid, i + 3); + dgst[4] = packv (tmps, dgst, gid, i + 4); + dgst[5] = packv (tmps, dgst, gid, i + 5); + dgst[6] = packv (tmps, dgst, gid, i + 6); + dgst[7] = packv (tmps, dgst, gid, i + 7); + + out[0] = packv (tmps, out, gid, i + 0); + out[1] = packv (tmps, out, gid, i + 1); + out[2] = packv (tmps, out, gid, i + 2); + out[3] = packv (tmps, out, gid, i + 3); + out[4] = packv (tmps, out, gid, i + 4); + out[5] = packv (tmps, out, gid, i + 5); + out[6] = packv (tmps, out, gid, i + 6); + out[7] = packv (tmps, out, gid, i + 7); + + for (u32 j = 0; j < LOOP_CNT; j++) + { + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + w0[0] = dgst[0]; + w0[1] = dgst[1]; + w0[2] = dgst[2]; + w0[3] = dgst[3]; + w1[0] = dgst[4]; + w1[1] = dgst[5]; + w1[2] = dgst[6]; + w1[3] = dgst[7]; + w2[0] = 0x80000000; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = (64 + 32) * 8; + + hmac_sha256_run_V (w0, w1, w2, w3, ipad, opad, dgst); + + out[0] ^= dgst[0]; + out[1] ^= dgst[1]; + out[2] ^= dgst[2]; + out[3] ^= dgst[3]; + out[4] ^= dgst[4]; + out[5] ^= dgst[5]; + out[6] ^= dgst[6]; + out[7] ^= dgst[7]; + } + + unpackv (tmps, dgst, gid, i + 0, dgst[0]); + unpackv (tmps, dgst, gid, i + 1, dgst[1]); + unpackv (tmps, dgst, gid, i + 2, dgst[2]); + unpackv (tmps, dgst, gid, i + 3, dgst[3]); + unpackv (tmps, dgst, gid, i + 4, dgst[4]); + unpackv (tmps, dgst, gid, i + 5, dgst[5]); + unpackv (tmps, dgst, gid, i + 6, dgst[6]); + unpackv (tmps, dgst, gid, i + 7, dgst[7]); + + unpackv (tmps, out, gid, i + 0, out[0]); + unpackv (tmps, out, gid, i + 1, out[1]); + unpackv (tmps, out, gid, i + 2, out[2]); + unpackv (tmps, out, gid, i + 3, out[3]); + unpackv (tmps, out, gid, i + 4, out[4]); + unpackv (tmps, out, gid, i + 5, out[5]); + unpackv (tmps, out, gid, i + 6, out[6]); + unpackv (tmps, out, gid, i + 7, out[7]); + } +} + +KERNEL_FQ void m26620_comp (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) +{ + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /** + * aes shared + */ + + #ifdef REAL_SHM + + LOCAL_VK u32 s_te0[256]; + LOCAL_VK u32 s_te1[256]; + LOCAL_VK u32 s_te2[256]; + LOCAL_VK u32 s_te3[256]; + LOCAL_VK u32 s_te4[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + s_te0[i] = te0[i]; + s_te1[i] = te1[i]; + s_te2[i] = te2[i]; + s_te3[i] = te3[i]; + s_te4[i] = te4[i]; + } + + SYNC_THREADS (); + + #else + + CONSTANT_AS u32a *s_te0 = te0; + CONSTANT_AS u32a *s_te1 = te1; + CONSTANT_AS u32a *s_te2 = te2; + CONSTANT_AS u32a *s_te3 = te3; + CONSTANT_AS u32a *s_te4 = te4; + + #endif + + if (gid >= GID_CNT) return; + + // keys + + u32 ukey[8]; + + ukey[0] = tmps[gid].out[0]; + ukey[1] = tmps[gid].out[1]; + ukey[2] = tmps[gid].out[2]; + ukey[3] = tmps[gid].out[3]; + ukey[4] = tmps[gid].out[4]; + ukey[5] = tmps[gid].out[5]; + ukey[6] = tmps[gid].out[6]; + ukey[7] = tmps[gid].out[7]; + + u32 key_len = 32 * 8; + + u32 key[60] = { 0 }; + u32 subKey[4] = { 0 }; + + AES_GCM_Init (ukey, key_len, key, subKey, s_te0, s_te1, s_te2, s_te3, s_te4); + + // iv + + u32 iv[4]; + + iv[0] = esalt_bufs[DIGESTS_OFFSET_HOST].iv_buf[0]; + iv[1] = esalt_bufs[DIGESTS_OFFSET_HOST].iv_buf[1]; + iv[2] = esalt_bufs[DIGESTS_OFFSET_HOST].iv_buf[2]; + iv[3] = esalt_bufs[DIGESTS_OFFSET_HOST].iv_buf[3]; + + const u32 iv_len = esalt_bufs[DIGESTS_OFFSET_HOST].iv_len; + + u32 J0[4] = { 0 }; + + AES_GCM_Prepare_J0 (iv, iv_len, subKey, J0); + + // ct + + u32 T[4] = { 0 }; + u32 S[4] = { 0 }; + + u32 S_len = 16; + u32 aad_buf[4] = { 0 }; + u32 aad_len = 0; + + AES_GCM_GHASH_GLOBAL (subKey, aad_buf, aad_len, esalt_bufs[DIGESTS_OFFSET_HOST].ct_buf, esalt_bufs[DIGESTS_OFFSET_HOST].ct_len, S); + + AES_GCM_GCTR (key, J0, S, S_len, T, s_te0, s_te1, s_te2, s_te3, s_te4); + + /* compare tag */ + + const u32 r0 = T[0]; + const u32 r1 = T[1]; + const u32 r2 = T[2]; + const u32 r3 = T[3]; + + #define il_pos 0 + + #ifdef KERNEL_STATIC + #include COMPARE_M + #endif +} diff --git a/OpenCL/m26630-pure.cl b/OpenCL/m26630-pure.cl new file mode 100644 index 000000000..39727b730 --- /dev/null +++ b/OpenCL/m26630-pure.cl @@ -0,0 +1,413 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#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_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#include M2S(INCLUDE_PATH/inc_cipher_aes.cl) +#include M2S(INCLUDE_PATH/inc_cipher_aes-gcm.cl) +#endif + +#define COMPARE_S M2S(INCLUDE_PATH/inc_comp_single.cl) +#define COMPARE_M M2S(INCLUDE_PATH/inc_comp_multi.cl) + +typedef struct pbkdf2_sha256_tmp +{ + u32 ipad[8]; + u32 opad[8]; + + u32 dgst[32]; + u32 out[32]; + +} pbkdf2_sha256_tmp_t; + +typedef struct pbkdf2_sha256_aes_gcm +{ + u32 salt_buf[64]; + u32 iv_buf[4]; + u32 iv_len; + u32 ct_buf[16]; + u32 ct_len; + +} pbkdf2_sha256_aes_gcm_t; + +DECLSPEC void hmac_sha256_run_V (PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, PRIVATE_AS u32x *ipad, PRIVATE_AS u32x *opad, PRIVATE_AS u32x *digest) +{ + digest[0] = ipad[0]; + digest[1] = ipad[1]; + digest[2] = ipad[2]; + digest[3] = ipad[3]; + digest[4] = ipad[4]; + digest[5] = ipad[5]; + digest[6] = ipad[6]; + digest[7] = ipad[7]; + + sha256_transform_vector (w0, w1, w2, w3, digest); + + w0[0] = digest[0]; + w0[1] = digest[1]; + w0[2] = digest[2]; + w0[3] = digest[3]; + w1[0] = digest[4]; + w1[1] = digest[5]; + w1[2] = digest[6]; + w1[3] = digest[7]; + w2[0] = 0x80000000; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = (64 + 32) * 8; + + digest[0] = opad[0]; + digest[1] = opad[1]; + digest[2] = opad[2]; + digest[3] = opad[3]; + digest[4] = opad[4]; + digest[5] = opad[5]; + digest[6] = opad[6]; + digest[7] = opad[7]; + + sha256_transform_vector (w0, w1, w2, w3, digest); +} + +KERNEL_FQ void m26630_init (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) +{ + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + sha256_hmac_ctx_t sha256_hmac_ctx; + + sha256_hmac_init_global_swap (&sha256_hmac_ctx, pws[gid].i, pws[gid].pw_len); + + tmps[gid].ipad[0] = sha256_hmac_ctx.ipad.h[0]; + tmps[gid].ipad[1] = sha256_hmac_ctx.ipad.h[1]; + tmps[gid].ipad[2] = sha256_hmac_ctx.ipad.h[2]; + tmps[gid].ipad[3] = sha256_hmac_ctx.ipad.h[3]; + tmps[gid].ipad[4] = sha256_hmac_ctx.ipad.h[4]; + tmps[gid].ipad[5] = sha256_hmac_ctx.ipad.h[5]; + tmps[gid].ipad[6] = sha256_hmac_ctx.ipad.h[6]; + tmps[gid].ipad[7] = sha256_hmac_ctx.ipad.h[7]; + + tmps[gid].opad[0] = sha256_hmac_ctx.opad.h[0]; + tmps[gid].opad[1] = sha256_hmac_ctx.opad.h[1]; + tmps[gid].opad[2] = sha256_hmac_ctx.opad.h[2]; + tmps[gid].opad[3] = sha256_hmac_ctx.opad.h[3]; + tmps[gid].opad[4] = sha256_hmac_ctx.opad.h[4]; + tmps[gid].opad[5] = sha256_hmac_ctx.opad.h[5]; + tmps[gid].opad[6] = sha256_hmac_ctx.opad.h[6]; + tmps[gid].opad[7] = sha256_hmac_ctx.opad.h[7]; + + sha256_hmac_update_global_swap (&sha256_hmac_ctx, esalt_bufs[DIGESTS_OFFSET_HOST].salt_buf, salt_bufs[SALT_POS_HOST].salt_len); + + for (u32 i = 0, j = 1; i < 8; i += 8, j += 1) + { + sha256_hmac_ctx_t sha256_hmac_ctx2 = sha256_hmac_ctx; + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + w0[0] = j; + w0[1] = 0; + w0[2] = 0; + w0[3] = 0; + w1[0] = 0; + w1[1] = 0; + w1[2] = 0; + w1[3] = 0; + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + + sha256_hmac_update_64 (&sha256_hmac_ctx2, w0, w1, w2, w3, 4); + + sha256_hmac_final (&sha256_hmac_ctx2); + + tmps[gid].dgst[i + 0] = sha256_hmac_ctx2.opad.h[0]; + tmps[gid].dgst[i + 1] = sha256_hmac_ctx2.opad.h[1]; + tmps[gid].dgst[i + 2] = sha256_hmac_ctx2.opad.h[2]; + tmps[gid].dgst[i + 3] = sha256_hmac_ctx2.opad.h[3]; + tmps[gid].dgst[i + 4] = sha256_hmac_ctx2.opad.h[4]; + tmps[gid].dgst[i + 5] = sha256_hmac_ctx2.opad.h[5]; + tmps[gid].dgst[i + 6] = sha256_hmac_ctx2.opad.h[6]; + tmps[gid].dgst[i + 7] = sha256_hmac_ctx2.opad.h[7]; + + tmps[gid].out[i + 0] = tmps[gid].dgst[i + 0]; + tmps[gid].out[i + 1] = tmps[gid].dgst[i + 1]; + tmps[gid].out[i + 2] = tmps[gid].dgst[i + 2]; + tmps[gid].out[i + 3] = tmps[gid].dgst[i + 3]; + tmps[gid].out[i + 4] = tmps[gid].dgst[i + 4]; + tmps[gid].out[i + 5] = tmps[gid].dgst[i + 5]; + tmps[gid].out[i + 6] = tmps[gid].dgst[i + 6]; + tmps[gid].out[i + 7] = tmps[gid].dgst[i + 7]; + } +} + +KERNEL_FQ void m26630_loop (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) +{ + const u64 gid = get_global_id (0); + + if ((gid * VECT_SIZE) >= GID_CNT) return; + + u32x ipad[8]; + u32x opad[8]; + + ipad[0] = packv (tmps, ipad, gid, 0); + ipad[1] = packv (tmps, ipad, gid, 1); + ipad[2] = packv (tmps, ipad, gid, 2); + ipad[3] = packv (tmps, ipad, gid, 3); + ipad[4] = packv (tmps, ipad, gid, 4); + ipad[5] = packv (tmps, ipad, gid, 5); + ipad[6] = packv (tmps, ipad, gid, 6); + ipad[7] = packv (tmps, ipad, gid, 7); + + opad[0] = packv (tmps, opad, gid, 0); + opad[1] = packv (tmps, opad, gid, 1); + opad[2] = packv (tmps, opad, gid, 2); + opad[3] = packv (tmps, opad, gid, 3); + opad[4] = packv (tmps, opad, gid, 4); + opad[5] = packv (tmps, opad, gid, 5); + opad[6] = packv (tmps, opad, gid, 6); + opad[7] = packv (tmps, opad, gid, 7); + + for (u32 i = 0; i < 8; i += 8) + { + u32x dgst[8]; + u32x out[8]; + + dgst[0] = packv (tmps, dgst, gid, i + 0); + dgst[1] = packv (tmps, dgst, gid, i + 1); + dgst[2] = packv (tmps, dgst, gid, i + 2); + dgst[3] = packv (tmps, dgst, gid, i + 3); + dgst[4] = packv (tmps, dgst, gid, i + 4); + dgst[5] = packv (tmps, dgst, gid, i + 5); + dgst[6] = packv (tmps, dgst, gid, i + 6); + dgst[7] = packv (tmps, dgst, gid, i + 7); + + out[0] = packv (tmps, out, gid, i + 0); + out[1] = packv (tmps, out, gid, i + 1); + out[2] = packv (tmps, out, gid, i + 2); + out[3] = packv (tmps, out, gid, i + 3); + out[4] = packv (tmps, out, gid, i + 4); + out[5] = packv (tmps, out, gid, i + 5); + out[6] = packv (tmps, out, gid, i + 6); + out[7] = packv (tmps, out, gid, i + 7); + + for (u32 j = 0; j < LOOP_CNT; j++) + { + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + w0[0] = dgst[0]; + w0[1] = dgst[1]; + w0[2] = dgst[2]; + w0[3] = dgst[3]; + w1[0] = dgst[4]; + w1[1] = dgst[5]; + w1[2] = dgst[6]; + w1[3] = dgst[7]; + w2[0] = 0x80000000; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = (64 + 32) * 8; + + hmac_sha256_run_V (w0, w1, w2, w3, ipad, opad, dgst); + + out[0] ^= dgst[0]; + out[1] ^= dgst[1]; + out[2] ^= dgst[2]; + out[3] ^= dgst[3]; + out[4] ^= dgst[4]; + out[5] ^= dgst[5]; + out[6] ^= dgst[6]; + out[7] ^= dgst[7]; + } + + unpackv (tmps, dgst, gid, i + 0, dgst[0]); + unpackv (tmps, dgst, gid, i + 1, dgst[1]); + unpackv (tmps, dgst, gid, i + 2, dgst[2]); + unpackv (tmps, dgst, gid, i + 3, dgst[3]); + unpackv (tmps, dgst, gid, i + 4, dgst[4]); + unpackv (tmps, dgst, gid, i + 5, dgst[5]); + unpackv (tmps, dgst, gid, i + 6, dgst[6]); + unpackv (tmps, dgst, gid, i + 7, dgst[7]); + + unpackv (tmps, out, gid, i + 0, out[0]); + unpackv (tmps, out, gid, i + 1, out[1]); + unpackv (tmps, out, gid, i + 2, out[2]); + unpackv (tmps, out, gid, i + 3, out[3]); + unpackv (tmps, out, gid, i + 4, out[4]); + unpackv (tmps, out, gid, i + 5, out[5]); + unpackv (tmps, out, gid, i + 6, out[6]); + unpackv (tmps, out, gid, i + 7, out[7]); + } +} + +KERNEL_FQ void m26630_comp (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) +{ + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /** + * aes shared + */ + + #ifdef REAL_SHM + + LOCAL_VK u32 s_te0[256]; + LOCAL_VK u32 s_te1[256]; + LOCAL_VK u32 s_te2[256]; + LOCAL_VK u32 s_te3[256]; + LOCAL_VK u32 s_te4[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + s_te0[i] = te0[i]; + s_te1[i] = te1[i]; + s_te2[i] = te2[i]; + s_te3[i] = te3[i]; + s_te4[i] = te4[i]; + } + + SYNC_THREADS (); + + #else + + CONSTANT_AS u32a *s_te0 = te0; + CONSTANT_AS u32a *s_te1 = te1; + CONSTANT_AS u32a *s_te2 = te2; + CONSTANT_AS u32a *s_te3 = te3; + CONSTANT_AS u32a *s_te4 = te4; + + #endif + + if (gid >= GID_CNT) return; + + const u32 digest_pos = LOOP_POS; + + const u32 digest_cur = DIGESTS_OFFSET_HOST + digest_pos; + + GLOBAL_AS const pbkdf2_sha256_aes_gcm_t *pbkdf2_sha256_aes_gcm = &esalt_bufs[digest_cur]; + + // keys + + u32 ukey[8]; + + ukey[0] = tmps[gid].out[0]; + ukey[1] = tmps[gid].out[1]; + ukey[2] = tmps[gid].out[2]; + ukey[3] = tmps[gid].out[3]; + ukey[4] = tmps[gid].out[4]; + ukey[5] = tmps[gid].out[5]; + ukey[6] = tmps[gid].out[6]; + ukey[7] = tmps[gid].out[7]; + + u32 key_len = 32 * 8; + + u32 key[60] = { 0 }; + u32 subKey[4] = { 0 }; + + AES_GCM_Init (ukey, key_len, key, subKey, s_te0, s_te1, s_te2, s_te3, s_te4); + + // iv + + u32 iv[4]; + + iv[0] = pbkdf2_sha256_aes_gcm->iv_buf[0]; + iv[1] = pbkdf2_sha256_aes_gcm->iv_buf[1]; + iv[2] = pbkdf2_sha256_aes_gcm->iv_buf[2]; + iv[3] = pbkdf2_sha256_aes_gcm->iv_buf[3]; + + const u32 iv_len = pbkdf2_sha256_aes_gcm->iv_len; + + u32 J0[4] = { 0 }; + + AES_GCM_Prepare_J0 (iv, iv_len, subKey, J0); + + u32 ct[8]; + + ct[0] = pbkdf2_sha256_aes_gcm->ct_buf[0]; // first block of ciphertext + ct[1] = pbkdf2_sha256_aes_gcm->ct_buf[1]; + ct[2] = pbkdf2_sha256_aes_gcm->ct_buf[2]; + ct[3] = pbkdf2_sha256_aes_gcm->ct_buf[3]; + ct[4] = pbkdf2_sha256_aes_gcm->ct_buf[4]; // second block of ciphertext + ct[5] = pbkdf2_sha256_aes_gcm->ct_buf[5]; + ct[6] = pbkdf2_sha256_aes_gcm->ct_buf[6]; + ct[7] = pbkdf2_sha256_aes_gcm->ct_buf[7]; + + u32 pt[8] = { 0 }; + + AES_GCM_decrypt (key, J0, ct, 32, pt, s_te0, s_te1, s_te2, s_te3, s_te4); + + const int correct = is_valid_printable_32 (pt[0]) + + is_valid_printable_32 (pt[1]) + + is_valid_printable_32 (pt[2]) + + is_valid_printable_32 (pt[3]) + + is_valid_printable_32 (pt[4]) + + is_valid_printable_32 (pt[5]) + + is_valid_printable_32 (pt[6]) + + is_valid_printable_32 (pt[7]); + + if (correct != 8) return; + + /* + const int pt_len = 28; // not using 32 byte but 28 because our UTF8 allows up to 4 byte per character and since we decrypt 32 byte + // only we can't guarantee it is not in the middle of a UTF8 byte stream at that point + + if (hc_enc_scan (pt, pt_len)) + { + hc_enc_t hc_enc; + + hc_enc_init (&hc_enc); + + while (hc_enc_has_next (&hc_enc, pt_len)) + { + u32 enc_buf[16] = { 0 }; + + const int enc_len = hc_enc_next (&hc_enc, pt, pt_len, 32, enc_buf, sizeof (enc_buf)); + + if (enc_len == -1) return; + } + } + */ + + const u32 r0 = ct[0]; + const u32 r1 = ct[1]; + const u32 r2 = ct[2]; + const u32 r3 = ct[3]; + + #define il_pos 0 + + #ifdef KERNEL_STATIC + #include COMPARE_M + #endif +} diff --git a/src/modules/module_26620.c b/src/modules/module_26620.c new file mode 100644 index 000000000..f3c4509ad --- /dev/null +++ b/src/modules/module_26620.c @@ -0,0 +1,415 @@ +/** + * 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_OUTSIDE_KERNEL; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 1; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 3; +static const u32 DGST_SIZE = DGST_SIZE_4_4; +static const u32 HASH_CATEGORY = HASH_CATEGORY_CRYPTOCURRENCY_WALLET; +static const char *HASH_NAME = "MetaMask Wallet (needs all data, checks AES-GCM tag, dynamic iterations)"; +static const u64 KERN_TYPE = 26620; +static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE + | OPTI_TYPE_SLOW_HASH_SIMD_LOOP; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE; +static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; +static const char *ST_PASS = "hashcat1"; +// hash generated using with python3 tools/metamask2hashcat.py --vault tools/2hashcat_tests/metamask2hashcat.json +static const char *ST_HASH = "$metamask$600000$MBdUsmTcBHGCASECYr3gmD8XaJROwjhOegSWweCFhco=$N1aDRjt2ZD5x15Q1X9zVUw==$G2Qsp8BtQNz9E1vFlSebykcGkps5iJ53fBjJV8GIE7eolAQpz5m25MTZv0b0t2tpqXvfgEYKYZKsoLvuWWRHqj2ommt+U0l6fEGPY6lTn5PYzDtMKNpPWHKCIS/QYhwEA9/X5RtyIwDL6VqcRp6owV+/icmRlQa+TI5buHWZ+99Z1kBbpTDVYLBwhMRsODM1vYizQDg0vFIo3cQDtpRWUqpAKXhFcpgRD+9grS3pP/zdlIUn//87DZ3ue6Sn6WFOe08EvuY8sYZqTiN3GxcfESOltNbZJGcedMubt/jGsk+qIwUWC/f456UgeX9DN7i2pQBBI+L7qkY5v1WT5Y0i8uho1c2M2G8M9miO8HSm/j4bpMN1J6lPtjFhfAzEPS1go1w2vTmOtr1y+2A4M6HEOcxIrPJ8lUUH9pcN7Xpd+u/tQv8BYFxd6RlNYKLyA6OChbF+TD5Zz6oFZQtkprXqzZUFOlxeWJ373kHMISZtXOx44YGaiT2178fXgHFXavw="; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +typedef struct pbkdf2_sha256_tmp +{ + u32 ipad[8]; + u32 opad[8]; + + u32 dgst[32]; + u32 out[32]; + +} pbkdf2_sha256_tmp_t; + +typedef struct pbkdf2_sha256_aes_gcm +{ + u32 salt_buf[64]; + u32 iv_buf[4]; + u32 iv_len; + u32 ct_buf[784]; + u32 ct_len; + +} pbkdf2_sha256_aes_gcm_t; + +static const char *SIGNATURE_METAMASK_WALLET = "$metamask$"; + +char *module_jit_build_options (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED const hc_device_param_t *device_param) +{ + char *jit_build_options = NULL; + + // Extra treatment for Apple systems + if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE) + { + return jit_build_options; + } + + // HIP + if (device_param->opencl_device_vendor_id == VENDOR_ID_AMD_USE_HIP) + { + hc_asprintf (&jit_build_options, "-D _unroll"); + } + + // ROCM + if ((device_param->opencl_device_vendor_id == VENDOR_ID_AMD) && (device_param->has_vperm == true)) + { + hc_asprintf (&jit_build_options, "-D _unroll"); + } + + return jit_build_options; +} + +u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + const u64 esalt_size = (const u64) sizeof (pbkdf2_sha256_aes_gcm_t); + + return esalt_size; +} + +u64 module_tmp_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + const u64 tmp_size = (const u64) sizeof (pbkdf2_sha256_tmp_t); + + return tmp_size; +} + +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) +{ + const u32 pw_min = 8; + + return pw_min; +} + +u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + // this overrides the reductions of PW_MAX in case optimized kernel is selected + // IOW, even in optimized kernel mode it support length 256 + + const u32 pw_max = PW_MAX; + + return pw_max; +} + +int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) +{ + u32 *digest = (u32 *) digest_buf; + + pbkdf2_sha256_aes_gcm_t *metamask = (pbkdf2_sha256_aes_gcm_t *) esalt_buf; + + #define CT_MAX_LEN_BASE64 (((3136+16) * 8) / 6) + 3 + + hc_token_t token; + + memset (&token, 0, sizeof (hc_token_t)); + + token.token_cnt = 5; + + token.signatures_cnt = 1; + token.signatures_buf[0] = SIGNATURE_METAMASK_WALLET; + + token.len[0] = 10; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_SIGNATURE; + + token.sep[1] = '$'; + token.len_min[1] = 1; + token.len_max[1] = 6; + token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_DIGIT; + + token.sep[2] = '$'; + token.len[2] = 44; + token.attr[2] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_BASE64A; + + token.sep[3] = '$'; + token.len[3] = 24; + token.attr[3] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_BASE64A; + + token.sep[4] = '$'; + token.len_min[4] = 64; + token.len_max[4] = CT_MAX_LEN_BASE64; + token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_BASE64A; + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + u8 tmp_buf[CT_MAX_LEN_BASE64] = { 0 }; + + size_t tmp_len = 0; + + // iter + + const u8 *iter_pos = token.buf[1]; + + const int iter = strtol ((const char *) iter_pos, NULL, 10); + + if (iter < 1) return (PARSER_SALT_ITERATION); + + salt->salt_iter = iter - 1; + + // salt + + const u8 *salt_pos = token.buf[2]; + const int salt_len = token.len[2]; + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + tmp_len = base64_decode (base64_to_int, salt_pos, salt_len, tmp_buf); + + if (tmp_len != 32) return (PARSER_SALT_LENGTH); + + memcpy (salt->salt_buf, tmp_buf, tmp_len); + + salt->salt_len = tmp_len; + + metamask->salt_buf[0] = salt->salt_buf[0]; + metamask->salt_buf[1] = salt->salt_buf[1]; + metamask->salt_buf[2] = salt->salt_buf[2]; + metamask->salt_buf[3] = salt->salt_buf[3]; + metamask->salt_buf[4] = salt->salt_buf[4]; + metamask->salt_buf[5] = salt->salt_buf[5]; + metamask->salt_buf[6] = salt->salt_buf[6]; + metamask->salt_buf[7] = salt->salt_buf[7]; + + // iv + + const u8 *iv_pos = token.buf[3]; + const int iv_len = token.len[3]; + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + tmp_len = base64_decode (base64_to_int, iv_pos, iv_len, tmp_buf); + + if (tmp_len != 16) return (PARSER_IV_LENGTH); + + memcpy ((u8 *) metamask->iv_buf, tmp_buf, tmp_len); + + metamask->iv_buf[0] = byte_swap_32 (metamask->iv_buf[0]); + metamask->iv_buf[1] = byte_swap_32 (metamask->iv_buf[1]); + metamask->iv_buf[2] = byte_swap_32 (metamask->iv_buf[2]); + metamask->iv_buf[3] = byte_swap_32 (metamask->iv_buf[3]); + + metamask->iv_len = tmp_len; + + // ciphertext + + const u8 *ct_pos = token.buf[4]; + const int ct_len = token.len[4]; + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + tmp_len = base64_decode (base64_to_int, ct_pos, ct_len, tmp_buf); + + if (tmp_len <= 16) return (PARSER_CT_LENGTH); + + tmp_len -= 16; + + if (tmp_len < 30 || tmp_len > 3136) return (PARSER_CT_LENGTH); + + memcpy ((u8 *) metamask->ct_buf, tmp_buf, tmp_len); + + u32 j = tmp_len / 4; + + if ((tmp_len % 4) > 0) j++; + + for (u32 i = 0; i < j; i++) metamask->ct_buf[i] = byte_swap_32 (metamask->ct_buf[i]); + + metamask->ct_len = tmp_len; + + // tag + + u32 tag_buf[4] = { 0 }; + + memcpy ((u8 *) tag_buf, tmp_buf+metamask->ct_len, 16); + + digest[0] = byte_swap_32 (tag_buf[0]); + digest[1] = byte_swap_32 (tag_buf[1]); + digest[2] = byte_swap_32 (tag_buf[2]); + digest[3] = byte_swap_32 (tag_buf[3]); + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + const pbkdf2_sha256_aes_gcm_t *metamask = (const pbkdf2_sha256_aes_gcm_t *) esalt_buf; + + // salt + + #define SALT_LEN_BASE64 ((32 * 8) / 6) + 3 + #define IV_LEN_BASE64 ((16 * 8) / 6) + 3 + #define CT_MAX_LEN_BASE64 (((3136+16) * 8) / 6) + 3 + + u8 salt_buf[SALT_LEN_BASE64] = { 0 }; + + base64_encode (int_to_base64, (const u8 *) salt->salt_buf, (const int) salt->salt_len, salt_buf); + + // iv + + u32 tmp_iv_buf[4] = { 0 }; + + tmp_iv_buf[0] = byte_swap_32 (metamask->iv_buf[0]); + tmp_iv_buf[1] = byte_swap_32 (metamask->iv_buf[1]); + tmp_iv_buf[2] = byte_swap_32 (metamask->iv_buf[2]); + tmp_iv_buf[3] = byte_swap_32 (metamask->iv_buf[3]); + + u8 iv_buf[IV_LEN_BASE64+1] = { 0 }; + + base64_encode (int_to_base64, (const u8 *) tmp_iv_buf, (const int) metamask->iv_len, iv_buf); + + // ct + + u32 ct_len = metamask->ct_len; + + u32 j = ct_len / 4; + + if ((ct_len % 4) > 0) j++; + + u32 tmp_buf[788] = { 0 }; + + for (u32 i = 0; i < j; i++) tmp_buf[i] = byte_swap_32 (metamask->ct_buf[i]); + + u32 tmp_tag[4] = { 0 }; + + tmp_tag[0] = byte_swap_32 (digest[0]); + tmp_tag[1] = byte_swap_32 (digest[1]); + tmp_tag[2] = byte_swap_32 (digest[2]); + tmp_tag[3] = byte_swap_32 (digest[3]); + + u8 *tmp_buf_str = (u8 *) tmp_buf; + u8 *tmp_tag_str = (u8 *) tmp_tag; + + memcpy (tmp_buf_str+metamask->ct_len, tmp_tag_str, 16); + + u8 ct_buf[CT_MAX_LEN_BASE64] = { 0 }; + + base64_encode (int_to_base64, (const u8 *) tmp_buf, (const int) metamask->ct_len+16, ct_buf); + + u8 *out_buf = (u8 *) line_buf; + + int out_len = snprintf ((char *) out_buf, line_size, "%s%s$%s$%s", + SIGNATURE_METAMASK_WALLET, + salt_buf, + iv_buf, + ct_buf); + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_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_esalt_size; + 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_jit_build_options; + module_ctx->module_jit_cache_disable = MODULE_DEFAULT; + module_ctx->module_kernel_accel_max = MODULE_DEFAULT; + module_ctx->module_kernel_accel_min = MODULE_DEFAULT; + module_ctx->module_kernel_loops_max = MODULE_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = module_pw_max; + module_ctx->module_pw_min = module_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_tmp_size; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} diff --git a/src/modules/module_26630.c b/src/modules/module_26630.c new file mode 100644 index 000000000..f6d6f596f --- /dev/null +++ b/src/modules/module_26630.c @@ -0,0 +1,395 @@ +/** + * 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_OUTSIDE_KERNEL; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 1; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 3; +static const u32 DGST_SIZE = DGST_SIZE_4_4; +static const u32 HASH_CATEGORY = HASH_CATEGORY_CRYPTOCURRENCY_WALLET; +static const char *HASH_NAME = "MetaMask Wallet (short hash, plaintext check, dynamic iterations)"; +static const u64 KERN_TYPE = 26630; +static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE + | OPTI_TYPE_SLOW_HASH_SIMD_LOOP; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE + | OPTS_TYPE_DEEP_COMP_KERNEL; +static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; +static const char *ST_PASS = "hashcat1"; +static const char *ST_HASH = "$metamask-short$600000$MBdUsmTcBHGCASECYr3gmD8XaJROwjhOegSWweCFhco=$N1aDRjt2ZD5x15Q1X9zVUw==$G2Qsp8BtQNz9E1vFlSebykcGkps5iJ53fBjJV8GIE7eolAQpz5m25MTZv0b0t2tpqXvfgEYKYZKsoLvuWWRHqg=="; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +typedef struct pbkdf2_sha256_tmp +{ + u32 ipad[8]; + u32 opad[8]; + + u32 dgst[32]; + u32 out[32]; + +} pbkdf2_sha256_tmp_t; + +typedef struct pbkdf2_sha256_aes_gcm +{ + u32 salt_buf[64]; + u32 iv_buf[4]; + u32 iv_len; + u32 ct_buf[16]; + u32 ct_len; + +} pbkdf2_sha256_aes_gcm_t; + +static const char *SIGNATURE_METAMASK_WALLET = "$metamask-short$"; + +char *module_jit_build_options (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED const hc_device_param_t *device_param) +{ + char *jit_build_options = NULL; + + // Extra treatment for Apple systems + if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE) + { + return jit_build_options; + } + + // HIP + if (device_param->opencl_device_vendor_id == VENDOR_ID_AMD_USE_HIP) + { + hc_asprintf (&jit_build_options, "-D _unroll"); + } + + // ROCM + if ((device_param->opencl_device_vendor_id == VENDOR_ID_AMD) && (device_param->has_vperm == true)) + { + hc_asprintf (&jit_build_options, "-D _unroll"); + } + + return jit_build_options; +} + +u32 module_deep_comp_kernel (MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED const u32 salt_pos, MAYBE_UNUSED const u32 digest_pos) +{ + return KERN_RUN_3; +} + +u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + const u64 esalt_size = (const u64) sizeof (pbkdf2_sha256_aes_gcm_t); + + return esalt_size; +} + +u64 module_tmp_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + const u64 tmp_size = (const u64) sizeof (pbkdf2_sha256_tmp_t); + + return tmp_size; +} + +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) +{ + const u32 pw_min = 8; + + return pw_min; +} + +u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + // this overrides the reductions of PW_MAX in case optimized kernel is selected + // IOW, even in optimized kernel mode it support length 256 + + const u32 pw_max = PW_MAX; + + return pw_max; +} + +int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) +{ + u32 *digest = (u32 *) digest_buf; + + pbkdf2_sha256_aes_gcm_t *metamask = (pbkdf2_sha256_aes_gcm_t *) esalt_buf; + + hc_token_t token; + + memset (&token, 0, sizeof (hc_token_t)); + + token.token_cnt = 5; + + token.signatures_cnt = 1; + token.signatures_buf[0] = SIGNATURE_METAMASK_WALLET; + + token.len[0] = 16; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_SIGNATURE; + + token.sep[1] = '$'; + token.len_min[1] = 1; + token.len_max[1] = 6; + token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_DIGIT; + + token.sep[2] = '$'; + token.len[2] = 44; + token.attr[2] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_BASE64A; + + token.sep[3] = '$'; + token.len[3] = 24; + token.attr[3] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_BASE64A; + + token.sep[4] = '$'; + token.len_min[4] = 88; + token.len_max[4] = 88; + token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_BASE64A; + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + // iter + + const u8 *iter_pos = token.buf[1]; + + const int iter = strtol ((const char *) iter_pos, NULL, 10); + + if (iter < 1) return (PARSER_SALT_ITERATION); + + salt->salt_iter = iter - 1; + + // salt + + const u8 *salt_pos = token.buf[2]; + const int salt_len = token.len[2]; + + u8 tmp_buf[88+1]; + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + size_t tmp_len = base64_decode (base64_to_int, salt_pos, salt_len, tmp_buf); + + if (tmp_len != 32) return (PARSER_SALT_LENGTH); + + memcpy (salt->salt_buf, tmp_buf, tmp_len); + + salt->salt_len = tmp_len; + + metamask->salt_buf[0] = salt->salt_buf[0]; + metamask->salt_buf[1] = salt->salt_buf[1]; + metamask->salt_buf[2] = salt->salt_buf[2]; + metamask->salt_buf[3] = salt->salt_buf[3]; + metamask->salt_buf[4] = salt->salt_buf[4]; + metamask->salt_buf[5] = salt->salt_buf[5]; + metamask->salt_buf[6] = salt->salt_buf[6]; + metamask->salt_buf[7] = salt->salt_buf[7]; + + // iv + + const u8 *iv_pos = token.buf[3]; + const int iv_len = token.len[3]; + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + tmp_len = base64_decode (base64_to_int, iv_pos, iv_len, tmp_buf); + + if (tmp_len != 16) return (PARSER_IV_LENGTH); + + memcpy ((u8 *) metamask->iv_buf, tmp_buf, tmp_len); + + metamask->iv_buf[0] = byte_swap_32 (metamask->iv_buf[0]); + metamask->iv_buf[1] = byte_swap_32 (metamask->iv_buf[1]); + metamask->iv_buf[2] = byte_swap_32 (metamask->iv_buf[2]); + metamask->iv_buf[3] = byte_swap_32 (metamask->iv_buf[3]); + + metamask->iv_len = tmp_len; + + // ciphertext + + const u8 *ct_pos = token.buf[4]; + const int ct_len = token.len[4]; + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + tmp_len = base64_decode (base64_to_int, ct_pos, ct_len, tmp_buf); + + if (tmp_len != 64) return (PARSER_CT_LENGTH); + + memcpy ((u8 *) metamask->ct_buf, tmp_buf, tmp_len); + + u32 j = tmp_len / 4; + + for (u32 i = 0; i < j; i++) + { + metamask->ct_buf[i] = byte_swap_32 (metamask->ct_buf[i]); + } + + metamask->ct_len = tmp_len; + + digest[0] = metamask->ct_buf[0]; + digest[1] = metamask->ct_buf[1]; + digest[2] = metamask->ct_buf[2]; + digest[3] = metamask->ct_buf[3]; + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const pbkdf2_sha256_aes_gcm_t *metamask = (const pbkdf2_sha256_aes_gcm_t *) esalt_buf; + + // salt + + u8 salt_buf[44+1]; + + memset (salt_buf, 0, sizeof (salt_buf)); + + base64_encode (int_to_base64, (const u8 *) salt->salt_buf, (const int) salt->salt_len, salt_buf); + + // iv + + u32 tmp_iv_buf[4]; + + tmp_iv_buf[0] = byte_swap_32 (metamask->iv_buf[0]); + tmp_iv_buf[1] = byte_swap_32 (metamask->iv_buf[1]); + tmp_iv_buf[2] = byte_swap_32 (metamask->iv_buf[2]); + tmp_iv_buf[3] = byte_swap_32 (metamask->iv_buf[3]); + + u8 iv_buf[24+1]; + + memset (iv_buf, 0, sizeof (iv_buf)); + + base64_encode (int_to_base64, (const u8 *) tmp_iv_buf, (const int) metamask->iv_len, iv_buf); + + // ct + + u32 tmp_buf[16]; + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + u32 ct_len = metamask->ct_len; + + u32 j = ct_len / 4; + + for (u32 i = 0; i < j; i++) tmp_buf[i] = byte_swap_32 (metamask->ct_buf[i]); + + u8 ct_buf[88+1]; + + memset (ct_buf, 0, sizeof (ct_buf)); + + base64_encode (int_to_base64, (const u8 *) tmp_buf, (const int) metamask->ct_len, ct_buf); + + u8 *out_buf = (u8 *) line_buf; + + int out_len = snprintf ((char *) out_buf, line_size, "%s%s$%s$%s", + SIGNATURE_METAMASK_WALLET, + salt_buf, + iv_buf, + ct_buf); + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_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_deep_comp_kernel; + module_ctx->module_deprecated_notice = MODULE_DEFAULT; + module_ctx->module_dgst_pos0 = module_dgst_pos0; + module_ctx->module_dgst_pos1 = module_dgst_pos1; + module_ctx->module_dgst_pos2 = module_dgst_pos2; + module_ctx->module_dgst_pos3 = module_dgst_pos3; + module_ctx->module_dgst_size = module_dgst_size; + module_ctx->module_dictstat_disable = MODULE_DEFAULT; + module_ctx->module_esalt_size = module_esalt_size; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_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_jit_build_options; + module_ctx->module_jit_cache_disable = MODULE_DEFAULT; + module_ctx->module_kernel_accel_max = MODULE_DEFAULT; + module_ctx->module_kernel_accel_min = MODULE_DEFAULT; + module_ctx->module_kernel_loops_max = MODULE_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = module_pw_max; + module_ctx->module_pw_min = module_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_tmp_size; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} diff --git a/tools/metamask2hashcat.py b/tools/metamask2hashcat.py old mode 100755 new mode 100644 index a2aa99774..6c32e82c7 --- a/tools/metamask2hashcat.py +++ b/tools/metamask2hashcat.py @@ -51,8 +51,14 @@ def metamask_parser(file, shortdata): parser.print_help() exit(1) + if isMobile is False: + if 'keyMetadata' in j and 'params' in j['keyMetadata'] and 'iterations' in j['keyMetadata']['params']: + iter_count = j['keyMetadata']['params']['iterations'] + else: + iter_count = 10000 + if((len(j['data']) > 3000) or shortdata): data_bin = base64.b64decode(j['data']) # TODO limit data to 16 bytes, we only check the first block of data, so we don't need more data. @@ -60,9 +66,15 @@ def metamask_parser(file, shortdata): # Still the pbkdf 10k iter will be taking the most time by far probably. j['data'] = base64.b64encode(data_bin[0:64]).decode("ascii") - print('$metamask-short$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) + if iter_count != 10000: + print('$metamask-short$' + str(iter_count) + '$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) + else: + print('$metamask-short$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) else: - print('$metamask$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) + if iter_count != 10000: + print('$metamask$' + str(iter_count) + '$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) + else: + print('$metamask$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) else: From 205e7f6e71da6509005b06dde2833584f8b84dbf Mon Sep 17 00:00:00 2001 From: its5Q Date: Thu, 22 Feb 2024 03:40:36 +1000 Subject: [PATCH 008/252] Update metamask2hashcat help string --- tools/metamask2hashcat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/metamask2hashcat.py b/tools/metamask2hashcat.py index 6c32e82c7..1e4de119c 100644 --- a/tools/metamask2hashcat.py +++ b/tools/metamask2hashcat.py @@ -94,7 +94,7 @@ def metamask_parser(file, shortdata): if __name__ == "__main__": parser = argparse.ArgumentParser(description="metamask2hashcat.py extraction tool") parser.add_argument('--vault', required=True, help='set metamask vault (json) file from path', type=str) - parser.add_argument('--shortdata', help='force short data, can only be used with m26610, ', action='store_true') + parser.add_argument('--shortdata', help='force short data, can only be used with m26610/m26630, ', action='store_true') args = parser.parse_args() From 55406d8342732f6eafa86b92820ace5e4fe32912 Mon Sep 17 00:00:00 2001 From: its5Q Date: Thu, 22 Feb 2024 22:48:00 +1000 Subject: [PATCH 009/252] Cleaner JSON key handling in metamask2hashcat Co-authored-by: kgolawski --- tools/metamask2hashcat.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/metamask2hashcat.py b/tools/metamask2hashcat.py index 1e4de119c..a31d600f8 100644 --- a/tools/metamask2hashcat.py +++ b/tools/metamask2hashcat.py @@ -54,11 +54,10 @@ def metamask_parser(file, shortdata): if isMobile is False: - if 'keyMetadata' in j and 'params' in j['keyMetadata'] and 'iterations' in j['keyMetadata']['params']: + try: iter_count = j['keyMetadata']['params']['iterations'] - else: - iter_count = 10000 - + except KeyError: + iter_count = 10_000 if((len(j['data']) > 3000) or shortdata): data_bin = base64.b64decode(j['data']) # TODO limit data to 16 bytes, we only check the first block of data, so we don't need more data. From d725b4b928d5a0487a58c310235228e2b26ce0ab Mon Sep 17 00:00:00 2001 From: its5Q Date: Fri, 23 Feb 2024 06:22:27 +1000 Subject: [PATCH 010/252] Switch to using TOKEN_ATTR_OPTIONAL_ROUNDS for Metamask hashmodes --- src/modules/module_26600.c | 38 ++-- src/modules/module_26610.c | 36 +++- src/modules/module_26620.c | 415 ------------------------------------- src/modules/module_26630.c | 395 ----------------------------------- tools/metamask2hashcat.py | 2 +- 5 files changed, 52 insertions(+), 834 deletions(-) delete mode 100644 src/modules/module_26620.c delete mode 100644 src/modules/module_26630.c diff --git a/src/modules/module_26600.c b/src/modules/module_26600.c index 4f6d0de3b..1f211310d 100644 --- a/src/modules/module_26600.c +++ b/src/modules/module_26600.c @@ -29,6 +29,8 @@ static const char *ST_PASS = "hashcat1"; // hash generated using with python3 tools/metamask2hashcat.py --vault tools/2hashcat_tests/metamask2hashcat.json static const char *ST_HASH = "$metamask$jfGI3TXguhb8GPnKSXFrMzRk2NCEc131Gt5G3kZr5+s=$h+BoIf2CQ5BEjaIOShFE7g==$R95fzGt4UQ0uwrcrVYnIi4UcSlWn9wlmer+//526ZDwYAp50K82F1u1oacYcdjjhuEvbZnWk/uBG00UkgLLlO3WbINljqmu2QWdDEwjTgo/qWR6MU9d/82rxNiONHQE8UrZ8SV+htVr6XIB0ze3aCV0E+fwI93EeP79ZeDxuOEhuHoiYT0bHWMv5nA48AdluG4DbOo7SrDAWBVCBsEdXsOfYsS3/TIh0a/iFCMX4uhxY2824JwcWp4H36SFWyBYMZCJ3/U4DYFbbjWZtGRthoJlIik5BJq4FLu3Y1jEgza0AWlAvu4MKTEqrYSpUIghfxf1a1f+kPvxsHNq0as0kRwCXu09DObbdsiggbmeoBkxMZiFq0d9ar/3Gon0r3hfc3c124Wlivzbzu1JcZ3wURhLSsUS7b5cfG86aXHJkxmQDA5urBz6lw3bsIvlEUB2ErkQy/zD+cPwCG1Rs/WKt7KNh45lppCUkHccbf+xlpdc8OfUwj01Xp7BdH8LMR7Vx1C4hZCvSdtURVl0VaAMxHDX0MjRkwmqS"; +static const u32 ROUNDS_METAMASK = 10000; + 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; } @@ -144,9 +146,10 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len[1] = 44; - token.attr[1] = TOKEN_ATTR_FIXED_LENGTH - | TOKEN_ATTR_VERIFY_BASE64A; + token.len_min[1] = 0; + token.len_max[1] = 60; + token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_OPTIONAL_ROUNDS; token.sep[2] = '$'; token.len[2] = 24; @@ -169,7 +172,12 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // iter - salt->salt_iter = 10000 - 1; + salt->salt_iter = ROUNDS_METAMASK - 1; + + if (token.opt_len != -1) + { + salt->salt_iter = hc_strtoul ((const char *) token.opt_buf + 7, NULL, 10) - 1; // 7 = "rounds=" + } // salt @@ -312,14 +320,20 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE base64_encode (int_to_base64, (const u8 *) tmp_buf, (const int) metamask->ct_len+16, ct_buf); u8 *out_buf = (u8 *) line_buf; - - int out_len = snprintf ((char *) out_buf, line_size, "%s%s$%s$%s", - SIGNATURE_METAMASK_WALLET, - salt_buf, - iv_buf, - ct_buf); - - return out_len; + + if (salt->salt_iter + 1 != ROUNDS_METAMASK) + return snprintf ((char *) out_buf, line_size, "%srounds=%d$%s$%s$%s", + SIGNATURE_METAMASK_WALLET, + salt->salt_iter + 1, + salt_buf, + iv_buf, + ct_buf); + else + return snprintf ((char *) out_buf, line_size, "%s%s$%s$%s", + SIGNATURE_METAMASK_WALLET, + salt_buf, + iv_buf, + ct_buf); } void module_init (module_ctx_t *module_ctx) diff --git a/src/modules/module_26610.c b/src/modules/module_26610.c index 532246128..64cf20f4b 100644 --- a/src/modules/module_26610.c +++ b/src/modules/module_26610.c @@ -29,6 +29,8 @@ static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat1"; static const char *ST_HASH = "$metamask-short$jfGI3TXguhb8GPnKSXFrMzRk2NCEc131Gt5G3kZr5+s=$h+BoIf2CQ5BEjaIOShFE7g==$R95fzGt4UQ0uwrcrVYnIi4UcSlWn9wlmer+//526ZDwYAp50K82F1u1oacYcdjjhuEvbZnWk/uBG00UkgLLlOw=="; +static const u32 ROUNDS_METAMASK = 10000; + 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; } @@ -147,9 +149,10 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len[1] = 44; - token.attr[1] = TOKEN_ATTR_FIXED_LENGTH - | TOKEN_ATTR_VERIFY_BASE64A; + token.len_min[1] = 0; + token.len_max[1] = 60; + token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_OPTIONAL_ROUNDS; token.sep[2] = '$'; token.len[2] = 24; @@ -168,7 +171,12 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // iter - salt->salt_iter = 10000 - 1; + salt->salt_iter = ROUNDS_METAMASK - 1; + + if (token.opt_len != -1) + { + salt->salt_iter = hc_strtoul ((const char *) token.opt_buf + 7, NULL, 10) - 1; // 7 = "rounds=" + } // salt @@ -293,13 +301,19 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE u8 *out_buf = (u8 *) line_buf; - int out_len = snprintf ((char *) out_buf, line_size, "%s%s$%s$%s", - SIGNATURE_METAMASK_WALLET, - salt_buf, - iv_buf, - ct_buf); - - return out_len; + if (salt->salt_iter + 1 != ROUNDS_METAMASK) + return snprintf ((char *) out_buf, line_size, "%srounds=%d$%s$%s$%s", + SIGNATURE_METAMASK_WALLET, + salt->salt_iter + 1, + salt_buf, + iv_buf, + ct_buf); + else + return snprintf ((char *) out_buf, line_size, "%s%s$%s$%s", + SIGNATURE_METAMASK_WALLET, + salt_buf, + iv_buf, + ct_buf); } void module_init (module_ctx_t *module_ctx) diff --git a/src/modules/module_26620.c b/src/modules/module_26620.c deleted file mode 100644 index f3c4509ad..000000000 --- a/src/modules/module_26620.c +++ /dev/null @@ -1,415 +0,0 @@ -/** - * 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_OUTSIDE_KERNEL; -static const u32 DGST_POS0 = 0; -static const u32 DGST_POS1 = 1; -static const u32 DGST_POS2 = 2; -static const u32 DGST_POS3 = 3; -static const u32 DGST_SIZE = DGST_SIZE_4_4; -static const u32 HASH_CATEGORY = HASH_CATEGORY_CRYPTOCURRENCY_WALLET; -static const char *HASH_NAME = "MetaMask Wallet (needs all data, checks AES-GCM tag, dynamic iterations)"; -static const u64 KERN_TYPE = 26620; -static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE - | OPTI_TYPE_SLOW_HASH_SIMD_LOOP; -static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE - | OPTS_TYPE_PT_GENERATE_LE; -static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; -static const char *ST_PASS = "hashcat1"; -// hash generated using with python3 tools/metamask2hashcat.py --vault tools/2hashcat_tests/metamask2hashcat.json -static const char *ST_HASH = "$metamask$600000$MBdUsmTcBHGCASECYr3gmD8XaJROwjhOegSWweCFhco=$N1aDRjt2ZD5x15Q1X9zVUw==$G2Qsp8BtQNz9E1vFlSebykcGkps5iJ53fBjJV8GIE7eolAQpz5m25MTZv0b0t2tpqXvfgEYKYZKsoLvuWWRHqj2ommt+U0l6fEGPY6lTn5PYzDtMKNpPWHKCIS/QYhwEA9/X5RtyIwDL6VqcRp6owV+/icmRlQa+TI5buHWZ+99Z1kBbpTDVYLBwhMRsODM1vYizQDg0vFIo3cQDtpRWUqpAKXhFcpgRD+9grS3pP/zdlIUn//87DZ3ue6Sn6WFOe08EvuY8sYZqTiN3GxcfESOltNbZJGcedMubt/jGsk+qIwUWC/f456UgeX9DN7i2pQBBI+L7qkY5v1WT5Y0i8uho1c2M2G8M9miO8HSm/j4bpMN1J6lPtjFhfAzEPS1go1w2vTmOtr1y+2A4M6HEOcxIrPJ8lUUH9pcN7Xpd+u/tQv8BYFxd6RlNYKLyA6OChbF+TD5Zz6oFZQtkprXqzZUFOlxeWJ373kHMISZtXOx44YGaiT2178fXgHFXavw="; - -u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } -u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } -u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } -u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } -u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } -u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } -u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } -const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } -u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } -u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } -u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } -u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } -const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } -const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } - -typedef struct pbkdf2_sha256_tmp -{ - u32 ipad[8]; - u32 opad[8]; - - u32 dgst[32]; - u32 out[32]; - -} pbkdf2_sha256_tmp_t; - -typedef struct pbkdf2_sha256_aes_gcm -{ - u32 salt_buf[64]; - u32 iv_buf[4]; - u32 iv_len; - u32 ct_buf[784]; - u32 ct_len; - -} pbkdf2_sha256_aes_gcm_t; - -static const char *SIGNATURE_METAMASK_WALLET = "$metamask$"; - -char *module_jit_build_options (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED const hc_device_param_t *device_param) -{ - char *jit_build_options = NULL; - - // Extra treatment for Apple systems - if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE) - { - return jit_build_options; - } - - // HIP - if (device_param->opencl_device_vendor_id == VENDOR_ID_AMD_USE_HIP) - { - hc_asprintf (&jit_build_options, "-D _unroll"); - } - - // ROCM - if ((device_param->opencl_device_vendor_id == VENDOR_ID_AMD) && (device_param->has_vperm == true)) - { - hc_asprintf (&jit_build_options, "-D _unroll"); - } - - return jit_build_options; -} - -u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) -{ - const u64 esalt_size = (const u64) sizeof (pbkdf2_sha256_aes_gcm_t); - - return esalt_size; -} - -u64 module_tmp_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) -{ - const u64 tmp_size = (const u64) sizeof (pbkdf2_sha256_tmp_t); - - return tmp_size; -} - -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) -{ - const u32 pw_min = 8; - - return pw_min; -} - -u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) -{ - // this overrides the reductions of PW_MAX in case optimized kernel is selected - // IOW, even in optimized kernel mode it support length 256 - - const u32 pw_max = PW_MAX; - - return pw_max; -} - -int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) -{ - u32 *digest = (u32 *) digest_buf; - - pbkdf2_sha256_aes_gcm_t *metamask = (pbkdf2_sha256_aes_gcm_t *) esalt_buf; - - #define CT_MAX_LEN_BASE64 (((3136+16) * 8) / 6) + 3 - - hc_token_t token; - - memset (&token, 0, sizeof (hc_token_t)); - - token.token_cnt = 5; - - token.signatures_cnt = 1; - token.signatures_buf[0] = SIGNATURE_METAMASK_WALLET; - - token.len[0] = 10; - token.attr[0] = TOKEN_ATTR_FIXED_LENGTH - | TOKEN_ATTR_VERIFY_SIGNATURE; - - token.sep[1] = '$'; - token.len_min[1] = 1; - token.len_max[1] = 6; - token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH - | TOKEN_ATTR_VERIFY_DIGIT; - - token.sep[2] = '$'; - token.len[2] = 44; - token.attr[2] = TOKEN_ATTR_FIXED_LENGTH - | TOKEN_ATTR_VERIFY_BASE64A; - - token.sep[3] = '$'; - token.len[3] = 24; - token.attr[3] = TOKEN_ATTR_FIXED_LENGTH - | TOKEN_ATTR_VERIFY_BASE64A; - - token.sep[4] = '$'; - token.len_min[4] = 64; - token.len_max[4] = CT_MAX_LEN_BASE64; - token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH - | TOKEN_ATTR_VERIFY_BASE64A; - - const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); - - if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); - - u8 tmp_buf[CT_MAX_LEN_BASE64] = { 0 }; - - size_t tmp_len = 0; - - // iter - - const u8 *iter_pos = token.buf[1]; - - const int iter = strtol ((const char *) iter_pos, NULL, 10); - - if (iter < 1) return (PARSER_SALT_ITERATION); - - salt->salt_iter = iter - 1; - - // salt - - const u8 *salt_pos = token.buf[2]; - const int salt_len = token.len[2]; - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - tmp_len = base64_decode (base64_to_int, salt_pos, salt_len, tmp_buf); - - if (tmp_len != 32) return (PARSER_SALT_LENGTH); - - memcpy (salt->salt_buf, tmp_buf, tmp_len); - - salt->salt_len = tmp_len; - - metamask->salt_buf[0] = salt->salt_buf[0]; - metamask->salt_buf[1] = salt->salt_buf[1]; - metamask->salt_buf[2] = salt->salt_buf[2]; - metamask->salt_buf[3] = salt->salt_buf[3]; - metamask->salt_buf[4] = salt->salt_buf[4]; - metamask->salt_buf[5] = salt->salt_buf[5]; - metamask->salt_buf[6] = salt->salt_buf[6]; - metamask->salt_buf[7] = salt->salt_buf[7]; - - // iv - - const u8 *iv_pos = token.buf[3]; - const int iv_len = token.len[3]; - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - tmp_len = base64_decode (base64_to_int, iv_pos, iv_len, tmp_buf); - - if (tmp_len != 16) return (PARSER_IV_LENGTH); - - memcpy ((u8 *) metamask->iv_buf, tmp_buf, tmp_len); - - metamask->iv_buf[0] = byte_swap_32 (metamask->iv_buf[0]); - metamask->iv_buf[1] = byte_swap_32 (metamask->iv_buf[1]); - metamask->iv_buf[2] = byte_swap_32 (metamask->iv_buf[2]); - metamask->iv_buf[3] = byte_swap_32 (metamask->iv_buf[3]); - - metamask->iv_len = tmp_len; - - // ciphertext - - const u8 *ct_pos = token.buf[4]; - const int ct_len = token.len[4]; - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - tmp_len = base64_decode (base64_to_int, ct_pos, ct_len, tmp_buf); - - if (tmp_len <= 16) return (PARSER_CT_LENGTH); - - tmp_len -= 16; - - if (tmp_len < 30 || tmp_len > 3136) return (PARSER_CT_LENGTH); - - memcpy ((u8 *) metamask->ct_buf, tmp_buf, tmp_len); - - u32 j = tmp_len / 4; - - if ((tmp_len % 4) > 0) j++; - - for (u32 i = 0; i < j; i++) metamask->ct_buf[i] = byte_swap_32 (metamask->ct_buf[i]); - - metamask->ct_len = tmp_len; - - // tag - - u32 tag_buf[4] = { 0 }; - - memcpy ((u8 *) tag_buf, tmp_buf+metamask->ct_len, 16); - - digest[0] = byte_swap_32 (tag_buf[0]); - digest[1] = byte_swap_32 (tag_buf[1]); - digest[2] = byte_swap_32 (tag_buf[2]); - digest[3] = byte_swap_32 (tag_buf[3]); - - return (PARSER_OK); -} - -int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) -{ - const u32 *digest = (const u32 *) digest_buf; - - const pbkdf2_sha256_aes_gcm_t *metamask = (const pbkdf2_sha256_aes_gcm_t *) esalt_buf; - - // salt - - #define SALT_LEN_BASE64 ((32 * 8) / 6) + 3 - #define IV_LEN_BASE64 ((16 * 8) / 6) + 3 - #define CT_MAX_LEN_BASE64 (((3136+16) * 8) / 6) + 3 - - u8 salt_buf[SALT_LEN_BASE64] = { 0 }; - - base64_encode (int_to_base64, (const u8 *) salt->salt_buf, (const int) salt->salt_len, salt_buf); - - // iv - - u32 tmp_iv_buf[4] = { 0 }; - - tmp_iv_buf[0] = byte_swap_32 (metamask->iv_buf[0]); - tmp_iv_buf[1] = byte_swap_32 (metamask->iv_buf[1]); - tmp_iv_buf[2] = byte_swap_32 (metamask->iv_buf[2]); - tmp_iv_buf[3] = byte_swap_32 (metamask->iv_buf[3]); - - u8 iv_buf[IV_LEN_BASE64+1] = { 0 }; - - base64_encode (int_to_base64, (const u8 *) tmp_iv_buf, (const int) metamask->iv_len, iv_buf); - - // ct - - u32 ct_len = metamask->ct_len; - - u32 j = ct_len / 4; - - if ((ct_len % 4) > 0) j++; - - u32 tmp_buf[788] = { 0 }; - - for (u32 i = 0; i < j; i++) tmp_buf[i] = byte_swap_32 (metamask->ct_buf[i]); - - u32 tmp_tag[4] = { 0 }; - - tmp_tag[0] = byte_swap_32 (digest[0]); - tmp_tag[1] = byte_swap_32 (digest[1]); - tmp_tag[2] = byte_swap_32 (digest[2]); - tmp_tag[3] = byte_swap_32 (digest[3]); - - u8 *tmp_buf_str = (u8 *) tmp_buf; - u8 *tmp_tag_str = (u8 *) tmp_tag; - - memcpy (tmp_buf_str+metamask->ct_len, tmp_tag_str, 16); - - u8 ct_buf[CT_MAX_LEN_BASE64] = { 0 }; - - base64_encode (int_to_base64, (const u8 *) tmp_buf, (const int) metamask->ct_len+16, ct_buf); - - u8 *out_buf = (u8 *) line_buf; - - int out_len = snprintf ((char *) out_buf, line_size, "%s%s$%s$%s", - SIGNATURE_METAMASK_WALLET, - salt_buf, - iv_buf, - ct_buf); - - return out_len; -} - -void module_init (module_ctx_t *module_ctx) -{ - module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; - module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; - - module_ctx->module_attack_exec = module_attack_exec; - module_ctx->module_benchmark_esalt = MODULE_DEFAULT; - module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; - module_ctx->module_benchmark_mask = MODULE_DEFAULT; - module_ctx->module_benchmark_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_esalt_size; - 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_jit_build_options; - module_ctx->module_jit_cache_disable = MODULE_DEFAULT; - module_ctx->module_kernel_accel_max = MODULE_DEFAULT; - module_ctx->module_kernel_accel_min = MODULE_DEFAULT; - module_ctx->module_kernel_loops_max = MODULE_DEFAULT; - module_ctx->module_kernel_loops_min = MODULE_DEFAULT; - module_ctx->module_kernel_threads_max = MODULE_DEFAULT; - module_ctx->module_kernel_threads_min = MODULE_DEFAULT; - module_ctx->module_kern_type = module_kern_type; - module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; - module_ctx->module_opti_type = module_opti_type; - module_ctx->module_opts_type = module_opts_type; - module_ctx->module_outfile_check_disable = MODULE_DEFAULT; - module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; - module_ctx->module_potfile_custom_check = MODULE_DEFAULT; - module_ctx->module_potfile_disable = MODULE_DEFAULT; - module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; - module_ctx->module_pwdump_column = MODULE_DEFAULT; - module_ctx->module_pw_max = module_pw_max; - module_ctx->module_pw_min = module_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_tmp_size; - module_ctx->module_unstable_warning = MODULE_DEFAULT; - module_ctx->module_warmup_disable = MODULE_DEFAULT; -} diff --git a/src/modules/module_26630.c b/src/modules/module_26630.c deleted file mode 100644 index f6d6f596f..000000000 --- a/src/modules/module_26630.c +++ /dev/null @@ -1,395 +0,0 @@ -/** - * 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_OUTSIDE_KERNEL; -static const u32 DGST_POS0 = 0; -static const u32 DGST_POS1 = 1; -static const u32 DGST_POS2 = 2; -static const u32 DGST_POS3 = 3; -static const u32 DGST_SIZE = DGST_SIZE_4_4; -static const u32 HASH_CATEGORY = HASH_CATEGORY_CRYPTOCURRENCY_WALLET; -static const char *HASH_NAME = "MetaMask Wallet (short hash, plaintext check, dynamic iterations)"; -static const u64 KERN_TYPE = 26630; -static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE - | OPTI_TYPE_SLOW_HASH_SIMD_LOOP; -static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE - | OPTS_TYPE_PT_GENERATE_LE - | OPTS_TYPE_DEEP_COMP_KERNEL; -static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; -static const char *ST_PASS = "hashcat1"; -static const char *ST_HASH = "$metamask-short$600000$MBdUsmTcBHGCASECYr3gmD8XaJROwjhOegSWweCFhco=$N1aDRjt2ZD5x15Q1X9zVUw==$G2Qsp8BtQNz9E1vFlSebykcGkps5iJ53fBjJV8GIE7eolAQpz5m25MTZv0b0t2tpqXvfgEYKYZKsoLvuWWRHqg=="; - -u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } -u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } -u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } -u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } -u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } -u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } -u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } -const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } -u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } -u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } -u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } -u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } -const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } -const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } - -typedef struct pbkdf2_sha256_tmp -{ - u32 ipad[8]; - u32 opad[8]; - - u32 dgst[32]; - u32 out[32]; - -} pbkdf2_sha256_tmp_t; - -typedef struct pbkdf2_sha256_aes_gcm -{ - u32 salt_buf[64]; - u32 iv_buf[4]; - u32 iv_len; - u32 ct_buf[16]; - u32 ct_len; - -} pbkdf2_sha256_aes_gcm_t; - -static const char *SIGNATURE_METAMASK_WALLET = "$metamask-short$"; - -char *module_jit_build_options (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED const hc_device_param_t *device_param) -{ - char *jit_build_options = NULL; - - // Extra treatment for Apple systems - if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE) - { - return jit_build_options; - } - - // HIP - if (device_param->opencl_device_vendor_id == VENDOR_ID_AMD_USE_HIP) - { - hc_asprintf (&jit_build_options, "-D _unroll"); - } - - // ROCM - if ((device_param->opencl_device_vendor_id == VENDOR_ID_AMD) && (device_param->has_vperm == true)) - { - hc_asprintf (&jit_build_options, "-D _unroll"); - } - - return jit_build_options; -} - -u32 module_deep_comp_kernel (MAYBE_UNUSED const hashes_t *hashes, MAYBE_UNUSED const u32 salt_pos, MAYBE_UNUSED const u32 digest_pos) -{ - return KERN_RUN_3; -} - -u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) -{ - const u64 esalt_size = (const u64) sizeof (pbkdf2_sha256_aes_gcm_t); - - return esalt_size; -} - -u64 module_tmp_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) -{ - const u64 tmp_size = (const u64) sizeof (pbkdf2_sha256_tmp_t); - - return tmp_size; -} - -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) -{ - const u32 pw_min = 8; - - return pw_min; -} - -u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) -{ - // this overrides the reductions of PW_MAX in case optimized kernel is selected - // IOW, even in optimized kernel mode it support length 256 - - const u32 pw_max = PW_MAX; - - return pw_max; -} - -int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) -{ - u32 *digest = (u32 *) digest_buf; - - pbkdf2_sha256_aes_gcm_t *metamask = (pbkdf2_sha256_aes_gcm_t *) esalt_buf; - - hc_token_t token; - - memset (&token, 0, sizeof (hc_token_t)); - - token.token_cnt = 5; - - token.signatures_cnt = 1; - token.signatures_buf[0] = SIGNATURE_METAMASK_WALLET; - - token.len[0] = 16; - token.attr[0] = TOKEN_ATTR_FIXED_LENGTH - | TOKEN_ATTR_VERIFY_SIGNATURE; - - token.sep[1] = '$'; - token.len_min[1] = 1; - token.len_max[1] = 6; - token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH - | TOKEN_ATTR_VERIFY_DIGIT; - - token.sep[2] = '$'; - token.len[2] = 44; - token.attr[2] = TOKEN_ATTR_FIXED_LENGTH - | TOKEN_ATTR_VERIFY_BASE64A; - - token.sep[3] = '$'; - token.len[3] = 24; - token.attr[3] = TOKEN_ATTR_FIXED_LENGTH - | TOKEN_ATTR_VERIFY_BASE64A; - - token.sep[4] = '$'; - token.len_min[4] = 88; - token.len_max[4] = 88; - token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH - | TOKEN_ATTR_VERIFY_BASE64A; - - const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); - - if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); - - // iter - - const u8 *iter_pos = token.buf[1]; - - const int iter = strtol ((const char *) iter_pos, NULL, 10); - - if (iter < 1) return (PARSER_SALT_ITERATION); - - salt->salt_iter = iter - 1; - - // salt - - const u8 *salt_pos = token.buf[2]; - const int salt_len = token.len[2]; - - u8 tmp_buf[88+1]; - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - size_t tmp_len = base64_decode (base64_to_int, salt_pos, salt_len, tmp_buf); - - if (tmp_len != 32) return (PARSER_SALT_LENGTH); - - memcpy (salt->salt_buf, tmp_buf, tmp_len); - - salt->salt_len = tmp_len; - - metamask->salt_buf[0] = salt->salt_buf[0]; - metamask->salt_buf[1] = salt->salt_buf[1]; - metamask->salt_buf[2] = salt->salt_buf[2]; - metamask->salt_buf[3] = salt->salt_buf[3]; - metamask->salt_buf[4] = salt->salt_buf[4]; - metamask->salt_buf[5] = salt->salt_buf[5]; - metamask->salt_buf[6] = salt->salt_buf[6]; - metamask->salt_buf[7] = salt->salt_buf[7]; - - // iv - - const u8 *iv_pos = token.buf[3]; - const int iv_len = token.len[3]; - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - tmp_len = base64_decode (base64_to_int, iv_pos, iv_len, tmp_buf); - - if (tmp_len != 16) return (PARSER_IV_LENGTH); - - memcpy ((u8 *) metamask->iv_buf, tmp_buf, tmp_len); - - metamask->iv_buf[0] = byte_swap_32 (metamask->iv_buf[0]); - metamask->iv_buf[1] = byte_swap_32 (metamask->iv_buf[1]); - metamask->iv_buf[2] = byte_swap_32 (metamask->iv_buf[2]); - metamask->iv_buf[3] = byte_swap_32 (metamask->iv_buf[3]); - - metamask->iv_len = tmp_len; - - // ciphertext - - const u8 *ct_pos = token.buf[4]; - const int ct_len = token.len[4]; - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - tmp_len = base64_decode (base64_to_int, ct_pos, ct_len, tmp_buf); - - if (tmp_len != 64) return (PARSER_CT_LENGTH); - - memcpy ((u8 *) metamask->ct_buf, tmp_buf, tmp_len); - - u32 j = tmp_len / 4; - - for (u32 i = 0; i < j; i++) - { - metamask->ct_buf[i] = byte_swap_32 (metamask->ct_buf[i]); - } - - metamask->ct_len = tmp_len; - - digest[0] = metamask->ct_buf[0]; - digest[1] = metamask->ct_buf[1]; - digest[2] = metamask->ct_buf[2]; - digest[3] = metamask->ct_buf[3]; - - return (PARSER_OK); -} - -int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) -{ - const pbkdf2_sha256_aes_gcm_t *metamask = (const pbkdf2_sha256_aes_gcm_t *) esalt_buf; - - // salt - - u8 salt_buf[44+1]; - - memset (salt_buf, 0, sizeof (salt_buf)); - - base64_encode (int_to_base64, (const u8 *) salt->salt_buf, (const int) salt->salt_len, salt_buf); - - // iv - - u32 tmp_iv_buf[4]; - - tmp_iv_buf[0] = byte_swap_32 (metamask->iv_buf[0]); - tmp_iv_buf[1] = byte_swap_32 (metamask->iv_buf[1]); - tmp_iv_buf[2] = byte_swap_32 (metamask->iv_buf[2]); - tmp_iv_buf[3] = byte_swap_32 (metamask->iv_buf[3]); - - u8 iv_buf[24+1]; - - memset (iv_buf, 0, sizeof (iv_buf)); - - base64_encode (int_to_base64, (const u8 *) tmp_iv_buf, (const int) metamask->iv_len, iv_buf); - - // ct - - u32 tmp_buf[16]; - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - u32 ct_len = metamask->ct_len; - - u32 j = ct_len / 4; - - for (u32 i = 0; i < j; i++) tmp_buf[i] = byte_swap_32 (metamask->ct_buf[i]); - - u8 ct_buf[88+1]; - - memset (ct_buf, 0, sizeof (ct_buf)); - - base64_encode (int_to_base64, (const u8 *) tmp_buf, (const int) metamask->ct_len, ct_buf); - - u8 *out_buf = (u8 *) line_buf; - - int out_len = snprintf ((char *) out_buf, line_size, "%s%s$%s$%s", - SIGNATURE_METAMASK_WALLET, - salt_buf, - iv_buf, - ct_buf); - - return out_len; -} - -void module_init (module_ctx_t *module_ctx) -{ - module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; - module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; - - module_ctx->module_attack_exec = module_attack_exec; - module_ctx->module_benchmark_esalt = MODULE_DEFAULT; - module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; - module_ctx->module_benchmark_mask = MODULE_DEFAULT; - module_ctx->module_benchmark_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_deep_comp_kernel; - module_ctx->module_deprecated_notice = MODULE_DEFAULT; - module_ctx->module_dgst_pos0 = module_dgst_pos0; - module_ctx->module_dgst_pos1 = module_dgst_pos1; - module_ctx->module_dgst_pos2 = module_dgst_pos2; - module_ctx->module_dgst_pos3 = module_dgst_pos3; - module_ctx->module_dgst_size = module_dgst_size; - module_ctx->module_dictstat_disable = MODULE_DEFAULT; - module_ctx->module_esalt_size = module_esalt_size; - module_ctx->module_extra_buffer_size = MODULE_DEFAULT; - module_ctx->module_extra_tmp_size = MODULE_DEFAULT; - module_ctx->module_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_jit_build_options; - module_ctx->module_jit_cache_disable = MODULE_DEFAULT; - module_ctx->module_kernel_accel_max = MODULE_DEFAULT; - module_ctx->module_kernel_accel_min = MODULE_DEFAULT; - module_ctx->module_kernel_loops_max = MODULE_DEFAULT; - module_ctx->module_kernel_loops_min = MODULE_DEFAULT; - module_ctx->module_kernel_threads_max = MODULE_DEFAULT; - module_ctx->module_kernel_threads_min = MODULE_DEFAULT; - module_ctx->module_kern_type = module_kern_type; - module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; - module_ctx->module_opti_type = module_opti_type; - module_ctx->module_opts_type = module_opts_type; - module_ctx->module_outfile_check_disable = MODULE_DEFAULT; - module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; - module_ctx->module_potfile_custom_check = MODULE_DEFAULT; - module_ctx->module_potfile_disable = MODULE_DEFAULT; - module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; - module_ctx->module_pwdump_column = MODULE_DEFAULT; - module_ctx->module_pw_max = module_pw_max; - module_ctx->module_pw_min = module_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_tmp_size; - module_ctx->module_unstable_warning = MODULE_DEFAULT; - module_ctx->module_warmup_disable = MODULE_DEFAULT; -} diff --git a/tools/metamask2hashcat.py b/tools/metamask2hashcat.py index 1e4de119c..6c32e82c7 100644 --- a/tools/metamask2hashcat.py +++ b/tools/metamask2hashcat.py @@ -94,7 +94,7 @@ def metamask_parser(file, shortdata): if __name__ == "__main__": parser = argparse.ArgumentParser(description="metamask2hashcat.py extraction tool") parser.add_argument('--vault', required=True, help='set metamask vault (json) file from path', type=str) - parser.add_argument('--shortdata', help='force short data, can only be used with m26610/m26630, ', action='store_true') + parser.add_argument('--shortdata', help='force short data, can only be used with m26610, ', action='store_true') args = parser.parse_args() From 5f9caed13db94572a00e1ba7831ad6da05abf2ad Mon Sep 17 00:00:00 2001 From: its5Q Date: Fri, 23 Feb 2024 06:24:24 +1000 Subject: [PATCH 011/252] Remove unused Metamask OpenCL kernels --- OpenCL/m26620-pure.cl | 375 -------------------------------------- OpenCL/m26630-pure.cl | 413 ------------------------------------------ 2 files changed, 788 deletions(-) delete mode 100644 OpenCL/m26620-pure.cl delete mode 100644 OpenCL/m26630-pure.cl diff --git a/OpenCL/m26620-pure.cl b/OpenCL/m26620-pure.cl deleted file mode 100644 index 26ad55595..000000000 --- a/OpenCL/m26620-pure.cl +++ /dev/null @@ -1,375 +0,0 @@ -/** - * Author......: See docs/credits.txt - * License.....: MIT - */ - -#define NEW_SIMD_CODE - -#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_simd.cl) -#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) -#include M2S(INCLUDE_PATH/inc_cipher_aes.cl) -#include M2S(INCLUDE_PATH/inc_cipher_aes-gcm.cl) -#endif - -#define COMPARE_S M2S(INCLUDE_PATH/inc_comp_single.cl) -#define COMPARE_M M2S(INCLUDE_PATH/inc_comp_multi.cl) - -typedef struct pbkdf2_sha256_tmp -{ - u32 ipad[8]; - u32 opad[8]; - - u32 dgst[32]; - u32 out[32]; - -} pbkdf2_sha256_tmp_t; - -typedef struct pbkdf2_sha256_aes_gcm -{ - u32 salt_buf[64]; - u32 iv_buf[4]; - u32 iv_len; - u32 ct_buf[784]; - u32 ct_len; - -} pbkdf2_sha256_aes_gcm_t; - -DECLSPEC void hmac_sha256_run_V (PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, PRIVATE_AS u32x *ipad, PRIVATE_AS u32x *opad, PRIVATE_AS u32x *digest) -{ - digest[0] = ipad[0]; - digest[1] = ipad[1]; - digest[2] = ipad[2]; - digest[3] = ipad[3]; - digest[4] = ipad[4]; - digest[5] = ipad[5]; - digest[6] = ipad[6]; - digest[7] = ipad[7]; - - sha256_transform_vector (w0, w1, w2, w3, digest); - - w0[0] = digest[0]; - w0[1] = digest[1]; - w0[2] = digest[2]; - w0[3] = digest[3]; - w1[0] = digest[4]; - w1[1] = digest[5]; - w1[2] = digest[6]; - w1[3] = digest[7]; - w2[0] = 0x80000000; - w2[1] = 0; - w2[2] = 0; - w2[3] = 0; - w3[0] = 0; - w3[1] = 0; - w3[2] = 0; - w3[3] = (64 + 32) * 8; - - digest[0] = opad[0]; - digest[1] = opad[1]; - digest[2] = opad[2]; - digest[3] = opad[3]; - digest[4] = opad[4]; - digest[5] = opad[5]; - digest[6] = opad[6]; - digest[7] = opad[7]; - - sha256_transform_vector (w0, w1, w2, w3, digest); -} - -KERNEL_FQ void m26620_init (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) -{ - /** - * base - */ - - const u64 gid = get_global_id (0); - - if (gid >= GID_CNT) return; - - sha256_hmac_ctx_t sha256_hmac_ctx; - - sha256_hmac_init_global_swap (&sha256_hmac_ctx, pws[gid].i, pws[gid].pw_len); - - tmps[gid].ipad[0] = sha256_hmac_ctx.ipad.h[0]; - tmps[gid].ipad[1] = sha256_hmac_ctx.ipad.h[1]; - tmps[gid].ipad[2] = sha256_hmac_ctx.ipad.h[2]; - tmps[gid].ipad[3] = sha256_hmac_ctx.ipad.h[3]; - tmps[gid].ipad[4] = sha256_hmac_ctx.ipad.h[4]; - tmps[gid].ipad[5] = sha256_hmac_ctx.ipad.h[5]; - tmps[gid].ipad[6] = sha256_hmac_ctx.ipad.h[6]; - tmps[gid].ipad[7] = sha256_hmac_ctx.ipad.h[7]; - - tmps[gid].opad[0] = sha256_hmac_ctx.opad.h[0]; - tmps[gid].opad[1] = sha256_hmac_ctx.opad.h[1]; - tmps[gid].opad[2] = sha256_hmac_ctx.opad.h[2]; - tmps[gid].opad[3] = sha256_hmac_ctx.opad.h[3]; - tmps[gid].opad[4] = sha256_hmac_ctx.opad.h[4]; - tmps[gid].opad[5] = sha256_hmac_ctx.opad.h[5]; - tmps[gid].opad[6] = sha256_hmac_ctx.opad.h[6]; - tmps[gid].opad[7] = sha256_hmac_ctx.opad.h[7]; - - sha256_hmac_update_global_swap (&sha256_hmac_ctx, esalt_bufs[DIGESTS_OFFSET_HOST].salt_buf, salt_bufs[SALT_POS_HOST].salt_len); - - for (u32 i = 0, j = 1; i < 8; i += 8, j += 1) - { - sha256_hmac_ctx_t sha256_hmac_ctx2 = sha256_hmac_ctx; - - u32 w0[4]; - u32 w1[4]; - u32 w2[4]; - u32 w3[4]; - - w0[0] = j; - w0[1] = 0; - w0[2] = 0; - w0[3] = 0; - w1[0] = 0; - w1[1] = 0; - w1[2] = 0; - w1[3] = 0; - w2[0] = 0; - w2[1] = 0; - w2[2] = 0; - w2[3] = 0; - w3[0] = 0; - w3[1] = 0; - w3[2] = 0; - w3[3] = 0; - - sha256_hmac_update_64 (&sha256_hmac_ctx2, w0, w1, w2, w3, 4); - - sha256_hmac_final (&sha256_hmac_ctx2); - - tmps[gid].dgst[i + 0] = sha256_hmac_ctx2.opad.h[0]; - tmps[gid].dgst[i + 1] = sha256_hmac_ctx2.opad.h[1]; - tmps[gid].dgst[i + 2] = sha256_hmac_ctx2.opad.h[2]; - tmps[gid].dgst[i + 3] = sha256_hmac_ctx2.opad.h[3]; - tmps[gid].dgst[i + 4] = sha256_hmac_ctx2.opad.h[4]; - tmps[gid].dgst[i + 5] = sha256_hmac_ctx2.opad.h[5]; - tmps[gid].dgst[i + 6] = sha256_hmac_ctx2.opad.h[6]; - tmps[gid].dgst[i + 7] = sha256_hmac_ctx2.opad.h[7]; - - tmps[gid].out[i + 0] = tmps[gid].dgst[i + 0]; - tmps[gid].out[i + 1] = tmps[gid].dgst[i + 1]; - tmps[gid].out[i + 2] = tmps[gid].dgst[i + 2]; - tmps[gid].out[i + 3] = tmps[gid].dgst[i + 3]; - tmps[gid].out[i + 4] = tmps[gid].dgst[i + 4]; - tmps[gid].out[i + 5] = tmps[gid].dgst[i + 5]; - tmps[gid].out[i + 6] = tmps[gid].dgst[i + 6]; - tmps[gid].out[i + 7] = tmps[gid].dgst[i + 7]; - } -} - -KERNEL_FQ void m26620_loop (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) -{ - const u64 gid = get_global_id (0); - - if ((gid * VECT_SIZE) >= GID_CNT) return; - - u32x ipad[8]; - u32x opad[8]; - - ipad[0] = packv (tmps, ipad, gid, 0); - ipad[1] = packv (tmps, ipad, gid, 1); - ipad[2] = packv (tmps, ipad, gid, 2); - ipad[3] = packv (tmps, ipad, gid, 3); - ipad[4] = packv (tmps, ipad, gid, 4); - ipad[5] = packv (tmps, ipad, gid, 5); - ipad[6] = packv (tmps, ipad, gid, 6); - ipad[7] = packv (tmps, ipad, gid, 7); - - opad[0] = packv (tmps, opad, gid, 0); - opad[1] = packv (tmps, opad, gid, 1); - opad[2] = packv (tmps, opad, gid, 2); - opad[3] = packv (tmps, opad, gid, 3); - opad[4] = packv (tmps, opad, gid, 4); - opad[5] = packv (tmps, opad, gid, 5); - opad[6] = packv (tmps, opad, gid, 6); - opad[7] = packv (tmps, opad, gid, 7); - - for (u32 i = 0; i < 8; i += 8) - { - u32x dgst[8]; - u32x out[8]; - - dgst[0] = packv (tmps, dgst, gid, i + 0); - dgst[1] = packv (tmps, dgst, gid, i + 1); - dgst[2] = packv (tmps, dgst, gid, i + 2); - dgst[3] = packv (tmps, dgst, gid, i + 3); - dgst[4] = packv (tmps, dgst, gid, i + 4); - dgst[5] = packv (tmps, dgst, gid, i + 5); - dgst[6] = packv (tmps, dgst, gid, i + 6); - dgst[7] = packv (tmps, dgst, gid, i + 7); - - out[0] = packv (tmps, out, gid, i + 0); - out[1] = packv (tmps, out, gid, i + 1); - out[2] = packv (tmps, out, gid, i + 2); - out[3] = packv (tmps, out, gid, i + 3); - out[4] = packv (tmps, out, gid, i + 4); - out[5] = packv (tmps, out, gid, i + 5); - out[6] = packv (tmps, out, gid, i + 6); - out[7] = packv (tmps, out, gid, i + 7); - - for (u32 j = 0; j < LOOP_CNT; j++) - { - u32x w0[4]; - u32x w1[4]; - u32x w2[4]; - u32x w3[4]; - - w0[0] = dgst[0]; - w0[1] = dgst[1]; - w0[2] = dgst[2]; - w0[3] = dgst[3]; - w1[0] = dgst[4]; - w1[1] = dgst[5]; - w1[2] = dgst[6]; - w1[3] = dgst[7]; - w2[0] = 0x80000000; - w2[1] = 0; - w2[2] = 0; - w2[3] = 0; - w3[0] = 0; - w3[1] = 0; - w3[2] = 0; - w3[3] = (64 + 32) * 8; - - hmac_sha256_run_V (w0, w1, w2, w3, ipad, opad, dgst); - - out[0] ^= dgst[0]; - out[1] ^= dgst[1]; - out[2] ^= dgst[2]; - out[3] ^= dgst[3]; - out[4] ^= dgst[4]; - out[5] ^= dgst[5]; - out[6] ^= dgst[6]; - out[7] ^= dgst[7]; - } - - unpackv (tmps, dgst, gid, i + 0, dgst[0]); - unpackv (tmps, dgst, gid, i + 1, dgst[1]); - unpackv (tmps, dgst, gid, i + 2, dgst[2]); - unpackv (tmps, dgst, gid, i + 3, dgst[3]); - unpackv (tmps, dgst, gid, i + 4, dgst[4]); - unpackv (tmps, dgst, gid, i + 5, dgst[5]); - unpackv (tmps, dgst, gid, i + 6, dgst[6]); - unpackv (tmps, dgst, gid, i + 7, dgst[7]); - - unpackv (tmps, out, gid, i + 0, out[0]); - unpackv (tmps, out, gid, i + 1, out[1]); - unpackv (tmps, out, gid, i + 2, out[2]); - unpackv (tmps, out, gid, i + 3, out[3]); - unpackv (tmps, out, gid, i + 4, out[4]); - unpackv (tmps, out, gid, i + 5, out[5]); - unpackv (tmps, out, gid, i + 6, out[6]); - unpackv (tmps, out, gid, i + 7, out[7]); - } -} - -KERNEL_FQ void m26620_comp (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) -{ - const u64 gid = get_global_id (0); - const u64 lid = get_local_id (0); - const u64 lsz = get_local_size (0); - - /** - * aes shared - */ - - #ifdef REAL_SHM - - LOCAL_VK u32 s_te0[256]; - LOCAL_VK u32 s_te1[256]; - LOCAL_VK u32 s_te2[256]; - LOCAL_VK u32 s_te3[256]; - LOCAL_VK u32 s_te4[256]; - - for (u32 i = lid; i < 256; i += lsz) - { - s_te0[i] = te0[i]; - s_te1[i] = te1[i]; - s_te2[i] = te2[i]; - s_te3[i] = te3[i]; - s_te4[i] = te4[i]; - } - - SYNC_THREADS (); - - #else - - CONSTANT_AS u32a *s_te0 = te0; - CONSTANT_AS u32a *s_te1 = te1; - CONSTANT_AS u32a *s_te2 = te2; - CONSTANT_AS u32a *s_te3 = te3; - CONSTANT_AS u32a *s_te4 = te4; - - #endif - - if (gid >= GID_CNT) return; - - // keys - - u32 ukey[8]; - - ukey[0] = tmps[gid].out[0]; - ukey[1] = tmps[gid].out[1]; - ukey[2] = tmps[gid].out[2]; - ukey[3] = tmps[gid].out[3]; - ukey[4] = tmps[gid].out[4]; - ukey[5] = tmps[gid].out[5]; - ukey[6] = tmps[gid].out[6]; - ukey[7] = tmps[gid].out[7]; - - u32 key_len = 32 * 8; - - u32 key[60] = { 0 }; - u32 subKey[4] = { 0 }; - - AES_GCM_Init (ukey, key_len, key, subKey, s_te0, s_te1, s_te2, s_te3, s_te4); - - // iv - - u32 iv[4]; - - iv[0] = esalt_bufs[DIGESTS_OFFSET_HOST].iv_buf[0]; - iv[1] = esalt_bufs[DIGESTS_OFFSET_HOST].iv_buf[1]; - iv[2] = esalt_bufs[DIGESTS_OFFSET_HOST].iv_buf[2]; - iv[3] = esalt_bufs[DIGESTS_OFFSET_HOST].iv_buf[3]; - - const u32 iv_len = esalt_bufs[DIGESTS_OFFSET_HOST].iv_len; - - u32 J0[4] = { 0 }; - - AES_GCM_Prepare_J0 (iv, iv_len, subKey, J0); - - // ct - - u32 T[4] = { 0 }; - u32 S[4] = { 0 }; - - u32 S_len = 16; - u32 aad_buf[4] = { 0 }; - u32 aad_len = 0; - - AES_GCM_GHASH_GLOBAL (subKey, aad_buf, aad_len, esalt_bufs[DIGESTS_OFFSET_HOST].ct_buf, esalt_bufs[DIGESTS_OFFSET_HOST].ct_len, S); - - AES_GCM_GCTR (key, J0, S, S_len, T, s_te0, s_te1, s_te2, s_te3, s_te4); - - /* compare tag */ - - const u32 r0 = T[0]; - const u32 r1 = T[1]; - const u32 r2 = T[2]; - const u32 r3 = T[3]; - - #define il_pos 0 - - #ifdef KERNEL_STATIC - #include COMPARE_M - #endif -} diff --git a/OpenCL/m26630-pure.cl b/OpenCL/m26630-pure.cl deleted file mode 100644 index 39727b730..000000000 --- a/OpenCL/m26630-pure.cl +++ /dev/null @@ -1,413 +0,0 @@ -/** - * Author......: See docs/credits.txt - * License.....: MIT - */ - -#define NEW_SIMD_CODE - -#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_simd.cl) -#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) -#include M2S(INCLUDE_PATH/inc_cipher_aes.cl) -#include M2S(INCLUDE_PATH/inc_cipher_aes-gcm.cl) -#endif - -#define COMPARE_S M2S(INCLUDE_PATH/inc_comp_single.cl) -#define COMPARE_M M2S(INCLUDE_PATH/inc_comp_multi.cl) - -typedef struct pbkdf2_sha256_tmp -{ - u32 ipad[8]; - u32 opad[8]; - - u32 dgst[32]; - u32 out[32]; - -} pbkdf2_sha256_tmp_t; - -typedef struct pbkdf2_sha256_aes_gcm -{ - u32 salt_buf[64]; - u32 iv_buf[4]; - u32 iv_len; - u32 ct_buf[16]; - u32 ct_len; - -} pbkdf2_sha256_aes_gcm_t; - -DECLSPEC void hmac_sha256_run_V (PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, PRIVATE_AS u32x *ipad, PRIVATE_AS u32x *opad, PRIVATE_AS u32x *digest) -{ - digest[0] = ipad[0]; - digest[1] = ipad[1]; - digest[2] = ipad[2]; - digest[3] = ipad[3]; - digest[4] = ipad[4]; - digest[5] = ipad[5]; - digest[6] = ipad[6]; - digest[7] = ipad[7]; - - sha256_transform_vector (w0, w1, w2, w3, digest); - - w0[0] = digest[0]; - w0[1] = digest[1]; - w0[2] = digest[2]; - w0[3] = digest[3]; - w1[0] = digest[4]; - w1[1] = digest[5]; - w1[2] = digest[6]; - w1[3] = digest[7]; - w2[0] = 0x80000000; - w2[1] = 0; - w2[2] = 0; - w2[3] = 0; - w3[0] = 0; - w3[1] = 0; - w3[2] = 0; - w3[3] = (64 + 32) * 8; - - digest[0] = opad[0]; - digest[1] = opad[1]; - digest[2] = opad[2]; - digest[3] = opad[3]; - digest[4] = opad[4]; - digest[5] = opad[5]; - digest[6] = opad[6]; - digest[7] = opad[7]; - - sha256_transform_vector (w0, w1, w2, w3, digest); -} - -KERNEL_FQ void m26630_init (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) -{ - /** - * base - */ - - const u64 gid = get_global_id (0); - - if (gid >= GID_CNT) return; - - sha256_hmac_ctx_t sha256_hmac_ctx; - - sha256_hmac_init_global_swap (&sha256_hmac_ctx, pws[gid].i, pws[gid].pw_len); - - tmps[gid].ipad[0] = sha256_hmac_ctx.ipad.h[0]; - tmps[gid].ipad[1] = sha256_hmac_ctx.ipad.h[1]; - tmps[gid].ipad[2] = sha256_hmac_ctx.ipad.h[2]; - tmps[gid].ipad[3] = sha256_hmac_ctx.ipad.h[3]; - tmps[gid].ipad[4] = sha256_hmac_ctx.ipad.h[4]; - tmps[gid].ipad[5] = sha256_hmac_ctx.ipad.h[5]; - tmps[gid].ipad[6] = sha256_hmac_ctx.ipad.h[6]; - tmps[gid].ipad[7] = sha256_hmac_ctx.ipad.h[7]; - - tmps[gid].opad[0] = sha256_hmac_ctx.opad.h[0]; - tmps[gid].opad[1] = sha256_hmac_ctx.opad.h[1]; - tmps[gid].opad[2] = sha256_hmac_ctx.opad.h[2]; - tmps[gid].opad[3] = sha256_hmac_ctx.opad.h[3]; - tmps[gid].opad[4] = sha256_hmac_ctx.opad.h[4]; - tmps[gid].opad[5] = sha256_hmac_ctx.opad.h[5]; - tmps[gid].opad[6] = sha256_hmac_ctx.opad.h[6]; - tmps[gid].opad[7] = sha256_hmac_ctx.opad.h[7]; - - sha256_hmac_update_global_swap (&sha256_hmac_ctx, esalt_bufs[DIGESTS_OFFSET_HOST].salt_buf, salt_bufs[SALT_POS_HOST].salt_len); - - for (u32 i = 0, j = 1; i < 8; i += 8, j += 1) - { - sha256_hmac_ctx_t sha256_hmac_ctx2 = sha256_hmac_ctx; - - u32 w0[4]; - u32 w1[4]; - u32 w2[4]; - u32 w3[4]; - - w0[0] = j; - w0[1] = 0; - w0[2] = 0; - w0[3] = 0; - w1[0] = 0; - w1[1] = 0; - w1[2] = 0; - w1[3] = 0; - w2[0] = 0; - w2[1] = 0; - w2[2] = 0; - w2[3] = 0; - w3[0] = 0; - w3[1] = 0; - w3[2] = 0; - w3[3] = 0; - - sha256_hmac_update_64 (&sha256_hmac_ctx2, w0, w1, w2, w3, 4); - - sha256_hmac_final (&sha256_hmac_ctx2); - - tmps[gid].dgst[i + 0] = sha256_hmac_ctx2.opad.h[0]; - tmps[gid].dgst[i + 1] = sha256_hmac_ctx2.opad.h[1]; - tmps[gid].dgst[i + 2] = sha256_hmac_ctx2.opad.h[2]; - tmps[gid].dgst[i + 3] = sha256_hmac_ctx2.opad.h[3]; - tmps[gid].dgst[i + 4] = sha256_hmac_ctx2.opad.h[4]; - tmps[gid].dgst[i + 5] = sha256_hmac_ctx2.opad.h[5]; - tmps[gid].dgst[i + 6] = sha256_hmac_ctx2.opad.h[6]; - tmps[gid].dgst[i + 7] = sha256_hmac_ctx2.opad.h[7]; - - tmps[gid].out[i + 0] = tmps[gid].dgst[i + 0]; - tmps[gid].out[i + 1] = tmps[gid].dgst[i + 1]; - tmps[gid].out[i + 2] = tmps[gid].dgst[i + 2]; - tmps[gid].out[i + 3] = tmps[gid].dgst[i + 3]; - tmps[gid].out[i + 4] = tmps[gid].dgst[i + 4]; - tmps[gid].out[i + 5] = tmps[gid].dgst[i + 5]; - tmps[gid].out[i + 6] = tmps[gid].dgst[i + 6]; - tmps[gid].out[i + 7] = tmps[gid].dgst[i + 7]; - } -} - -KERNEL_FQ void m26630_loop (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) -{ - const u64 gid = get_global_id (0); - - if ((gid * VECT_SIZE) >= GID_CNT) return; - - u32x ipad[8]; - u32x opad[8]; - - ipad[0] = packv (tmps, ipad, gid, 0); - ipad[1] = packv (tmps, ipad, gid, 1); - ipad[2] = packv (tmps, ipad, gid, 2); - ipad[3] = packv (tmps, ipad, gid, 3); - ipad[4] = packv (tmps, ipad, gid, 4); - ipad[5] = packv (tmps, ipad, gid, 5); - ipad[6] = packv (tmps, ipad, gid, 6); - ipad[7] = packv (tmps, ipad, gid, 7); - - opad[0] = packv (tmps, opad, gid, 0); - opad[1] = packv (tmps, opad, gid, 1); - opad[2] = packv (tmps, opad, gid, 2); - opad[3] = packv (tmps, opad, gid, 3); - opad[4] = packv (tmps, opad, gid, 4); - opad[5] = packv (tmps, opad, gid, 5); - opad[6] = packv (tmps, opad, gid, 6); - opad[7] = packv (tmps, opad, gid, 7); - - for (u32 i = 0; i < 8; i += 8) - { - u32x dgst[8]; - u32x out[8]; - - dgst[0] = packv (tmps, dgst, gid, i + 0); - dgst[1] = packv (tmps, dgst, gid, i + 1); - dgst[2] = packv (tmps, dgst, gid, i + 2); - dgst[3] = packv (tmps, dgst, gid, i + 3); - dgst[4] = packv (tmps, dgst, gid, i + 4); - dgst[5] = packv (tmps, dgst, gid, i + 5); - dgst[6] = packv (tmps, dgst, gid, i + 6); - dgst[7] = packv (tmps, dgst, gid, i + 7); - - out[0] = packv (tmps, out, gid, i + 0); - out[1] = packv (tmps, out, gid, i + 1); - out[2] = packv (tmps, out, gid, i + 2); - out[3] = packv (tmps, out, gid, i + 3); - out[4] = packv (tmps, out, gid, i + 4); - out[5] = packv (tmps, out, gid, i + 5); - out[6] = packv (tmps, out, gid, i + 6); - out[7] = packv (tmps, out, gid, i + 7); - - for (u32 j = 0; j < LOOP_CNT; j++) - { - u32x w0[4]; - u32x w1[4]; - u32x w2[4]; - u32x w3[4]; - - w0[0] = dgst[0]; - w0[1] = dgst[1]; - w0[2] = dgst[2]; - w0[3] = dgst[3]; - w1[0] = dgst[4]; - w1[1] = dgst[5]; - w1[2] = dgst[6]; - w1[3] = dgst[7]; - w2[0] = 0x80000000; - w2[1] = 0; - w2[2] = 0; - w2[3] = 0; - w3[0] = 0; - w3[1] = 0; - w3[2] = 0; - w3[3] = (64 + 32) * 8; - - hmac_sha256_run_V (w0, w1, w2, w3, ipad, opad, dgst); - - out[0] ^= dgst[0]; - out[1] ^= dgst[1]; - out[2] ^= dgst[2]; - out[3] ^= dgst[3]; - out[4] ^= dgst[4]; - out[5] ^= dgst[5]; - out[6] ^= dgst[6]; - out[7] ^= dgst[7]; - } - - unpackv (tmps, dgst, gid, i + 0, dgst[0]); - unpackv (tmps, dgst, gid, i + 1, dgst[1]); - unpackv (tmps, dgst, gid, i + 2, dgst[2]); - unpackv (tmps, dgst, gid, i + 3, dgst[3]); - unpackv (tmps, dgst, gid, i + 4, dgst[4]); - unpackv (tmps, dgst, gid, i + 5, dgst[5]); - unpackv (tmps, dgst, gid, i + 6, dgst[6]); - unpackv (tmps, dgst, gid, i + 7, dgst[7]); - - unpackv (tmps, out, gid, i + 0, out[0]); - unpackv (tmps, out, gid, i + 1, out[1]); - unpackv (tmps, out, gid, i + 2, out[2]); - unpackv (tmps, out, gid, i + 3, out[3]); - unpackv (tmps, out, gid, i + 4, out[4]); - unpackv (tmps, out, gid, i + 5, out[5]); - unpackv (tmps, out, gid, i + 6, out[6]); - unpackv (tmps, out, gid, i + 7, out[7]); - } -} - -KERNEL_FQ void m26630_comp (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sha256_aes_gcm_t)) -{ - const u64 gid = get_global_id (0); - const u64 lid = get_local_id (0); - const u64 lsz = get_local_size (0); - - /** - * aes shared - */ - - #ifdef REAL_SHM - - LOCAL_VK u32 s_te0[256]; - LOCAL_VK u32 s_te1[256]; - LOCAL_VK u32 s_te2[256]; - LOCAL_VK u32 s_te3[256]; - LOCAL_VK u32 s_te4[256]; - - for (u32 i = lid; i < 256; i += lsz) - { - s_te0[i] = te0[i]; - s_te1[i] = te1[i]; - s_te2[i] = te2[i]; - s_te3[i] = te3[i]; - s_te4[i] = te4[i]; - } - - SYNC_THREADS (); - - #else - - CONSTANT_AS u32a *s_te0 = te0; - CONSTANT_AS u32a *s_te1 = te1; - CONSTANT_AS u32a *s_te2 = te2; - CONSTANT_AS u32a *s_te3 = te3; - CONSTANT_AS u32a *s_te4 = te4; - - #endif - - if (gid >= GID_CNT) return; - - const u32 digest_pos = LOOP_POS; - - const u32 digest_cur = DIGESTS_OFFSET_HOST + digest_pos; - - GLOBAL_AS const pbkdf2_sha256_aes_gcm_t *pbkdf2_sha256_aes_gcm = &esalt_bufs[digest_cur]; - - // keys - - u32 ukey[8]; - - ukey[0] = tmps[gid].out[0]; - ukey[1] = tmps[gid].out[1]; - ukey[2] = tmps[gid].out[2]; - ukey[3] = tmps[gid].out[3]; - ukey[4] = tmps[gid].out[4]; - ukey[5] = tmps[gid].out[5]; - ukey[6] = tmps[gid].out[6]; - ukey[7] = tmps[gid].out[7]; - - u32 key_len = 32 * 8; - - u32 key[60] = { 0 }; - u32 subKey[4] = { 0 }; - - AES_GCM_Init (ukey, key_len, key, subKey, s_te0, s_te1, s_te2, s_te3, s_te4); - - // iv - - u32 iv[4]; - - iv[0] = pbkdf2_sha256_aes_gcm->iv_buf[0]; - iv[1] = pbkdf2_sha256_aes_gcm->iv_buf[1]; - iv[2] = pbkdf2_sha256_aes_gcm->iv_buf[2]; - iv[3] = pbkdf2_sha256_aes_gcm->iv_buf[3]; - - const u32 iv_len = pbkdf2_sha256_aes_gcm->iv_len; - - u32 J0[4] = { 0 }; - - AES_GCM_Prepare_J0 (iv, iv_len, subKey, J0); - - u32 ct[8]; - - ct[0] = pbkdf2_sha256_aes_gcm->ct_buf[0]; // first block of ciphertext - ct[1] = pbkdf2_sha256_aes_gcm->ct_buf[1]; - ct[2] = pbkdf2_sha256_aes_gcm->ct_buf[2]; - ct[3] = pbkdf2_sha256_aes_gcm->ct_buf[3]; - ct[4] = pbkdf2_sha256_aes_gcm->ct_buf[4]; // second block of ciphertext - ct[5] = pbkdf2_sha256_aes_gcm->ct_buf[5]; - ct[6] = pbkdf2_sha256_aes_gcm->ct_buf[6]; - ct[7] = pbkdf2_sha256_aes_gcm->ct_buf[7]; - - u32 pt[8] = { 0 }; - - AES_GCM_decrypt (key, J0, ct, 32, pt, s_te0, s_te1, s_te2, s_te3, s_te4); - - const int correct = is_valid_printable_32 (pt[0]) - + is_valid_printable_32 (pt[1]) - + is_valid_printable_32 (pt[2]) - + is_valid_printable_32 (pt[3]) - + is_valid_printable_32 (pt[4]) - + is_valid_printable_32 (pt[5]) - + is_valid_printable_32 (pt[6]) - + is_valid_printable_32 (pt[7]); - - if (correct != 8) return; - - /* - const int pt_len = 28; // not using 32 byte but 28 because our UTF8 allows up to 4 byte per character and since we decrypt 32 byte - // only we can't guarantee it is not in the middle of a UTF8 byte stream at that point - - if (hc_enc_scan (pt, pt_len)) - { - hc_enc_t hc_enc; - - hc_enc_init (&hc_enc); - - while (hc_enc_has_next (&hc_enc, pt_len)) - { - u32 enc_buf[16] = { 0 }; - - const int enc_len = hc_enc_next (&hc_enc, pt, pt_len, 32, enc_buf, sizeof (enc_buf)); - - if (enc_len == -1) return; - } - } - */ - - const u32 r0 = ct[0]; - const u32 r1 = ct[1]; - const u32 r2 = ct[2]; - const u32 r3 = ct[3]; - - #define il_pos 0 - - #ifdef KERNEL_STATIC - #include COMPARE_M - #endif -} From 9a14c99bb129fb6e67f4b5566b0d47a10c826499 Mon Sep 17 00:00:00 2001 From: its5Q Date: Sat, 24 Feb 2024 16:42:08 +1000 Subject: [PATCH 012/252] Update metamask2hashcat to use new format and add test vault JSON --- tools/2hashcat_tests/metamask2hashcat.withrounds.json | 1 + tools/metamask2hashcat.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 tools/2hashcat_tests/metamask2hashcat.withrounds.json diff --git a/tools/2hashcat_tests/metamask2hashcat.withrounds.json b/tools/2hashcat_tests/metamask2hashcat.withrounds.json new file mode 100644 index 000000000..b865647fd --- /dev/null +++ b/tools/2hashcat_tests/metamask2hashcat.withrounds.json @@ -0,0 +1 @@ +{"data":"G2Qsp8BtQNz9E1vFlSebykcGkps5iJ53fBjJV8GIE7eolAQpz5m25MTZv0b0t2tpqXvfgEYKYZKsoLvuWWRHqj2ommt+U0l6fEGPY6lTn5PYzDtMKNpPWHKCIS/QYhwEA9/X5RtyIwDL6VqcRp6owV+/icmRlQa+TI5buHWZ+99Z1kBbpTDVYLBwhMRsODM1vYizQDg0vFIo3cQDtpRWUqpAKXhFcpgRD+9grS3pP/zdlIUn//87DZ3ue6Sn6WFOe08EvuY8sYZqTiN3GxcfESOltNbZJGcedMubt/jGsk+qIwUWC/f456UgeX9DN7i2pQBBI+L7qkY5v1WT5Y0i8uho1c2M2G8M9miO8HSm/j4bpMN1J6lPtjFhfAzEPS1go1w2vTmOtr1y+2A4M6HEOcxIrPJ8lUUH9pcN7Xpd+u/tQv8BYFxd6RlNYKLyA6OChbF+TD5Zz6oFZQtkprXqzZUFOlxeWJ373kHMISZtXOx44YGaiT2178fXgHFXavw=","iv":"N1aDRjt2ZD5x15Q1X9zVUw==","keyMetadata":{"algorithm":"PBKDF2","params":{"iterations":600000}},"salt":"MBdUsmTcBHGCASECYr3gmD8XaJROwjhOegSWweCFhco="} diff --git a/tools/metamask2hashcat.py b/tools/metamask2hashcat.py index 823f528b6..319889c60 100644 --- a/tools/metamask2hashcat.py +++ b/tools/metamask2hashcat.py @@ -58,6 +58,7 @@ def metamask_parser(file, shortdata): iter_count = j['keyMetadata']['params']['iterations'] except KeyError: iter_count = 10_000 + if((len(j['data']) > 3000) or shortdata): data_bin = base64.b64decode(j['data']) # TODO limit data to 16 bytes, we only check the first block of data, so we don't need more data. @@ -66,12 +67,12 @@ def metamask_parser(file, shortdata): j['data'] = base64.b64encode(data_bin[0:64]).decode("ascii") if iter_count != 10000: - print('$metamask-short$' + str(iter_count) + '$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) + print('$metamask-short$rounds=' + str(iter_count) + '$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) else: print('$metamask-short$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) else: if iter_count != 10000: - print('$metamask$' + str(iter_count) + '$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) + print('$metamask$rounds=' + str(iter_count) + '$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) else: print('$metamask$' + j['salt'] + '$' + j['iv'] + '$' + j['data']) From d299b2833eb80f56e555efbdf486d3f48db51c9b Mon Sep 17 00:00:00 2001 From: Flaggx1 Date: Thu, 25 Jul 2024 07:07:27 -0400 Subject: [PATCH 013/252] Reduce user-defined charsets to 8. Remove unnecessary code. --- include/types.h | 2 -- src/brain.c | 14 -------------- src/mpsp.c | 19 ++----------------- src/status.c | 23 ++++++++++------------- src/usage.c | 1 - src/user_options.c | 34 ++++------------------------------ 6 files changed, 16 insertions(+), 77 deletions(-) diff --git a/include/types.h b/include/types.h index 02b83da2b..961cde915 100644 --- a/include/types.h +++ b/include/types.h @@ -759,7 +759,6 @@ typedef enum user_options_map IDX_CUSTOM_CHARSET_6 = '6', IDX_CUSTOM_CHARSET_7 = '7', IDX_CUSTOM_CHARSET_8 = '8', - IDX_CUSTOM_CHARSET_9 = '9', IDX_DEBUG_FILE = 0xff12, IDX_DEBUG_MODE = 0xff13, IDX_DEPRECATED_CHECK_DISABLE = 0xff14, @@ -2396,7 +2395,6 @@ typedef struct user_options char *brain_session_whitelist; #endif char *cpu_affinity; - char *custom_charset_9; char *debug_file; char *induction_dir; char *keyboard_layout_mapping; diff --git a/src/brain.c b/src/brain.c index 646a334d3..f313b5536 100644 --- a/src/brain.c +++ b/src/brain.c @@ -373,13 +373,6 @@ u32 brain_compute_attack (hashcat_ctx_t *hashcat_ctx) XXH64_update (state, custom_charset_8, strlen (custom_charset_8)); } - - if (user_options->custom_charset_9) - { - const char *custom_charset_9 = user_options->custom_charset_9; - - XXH64_update (state, custom_charset_9, strlen (custom_charset_9)); - } } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) @@ -469,13 +462,6 @@ u32 brain_compute_attack (hashcat_ctx_t *hashcat_ctx) XXH64_update (state, custom_charset_8, strlen (custom_charset_8)); } - if (user_options->custom_charset_9) - { - const char *custom_charset_9 = user_options->custom_charset_9; - - XXH64_update (state, custom_charset_9, strlen (custom_charset_9)); - } - const int hex_wordlist = user_options->hex_wordlist; XXH64_update (state, &hex_wordlist, sizeof (hex_wordlist)); diff --git a/src/mpsp.c b/src/mpsp.c index d694dc242..02d5b7f45 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -18,7 +18,7 @@ static const char *const DEF_MASK = "?1?2?2?2?2?2?2?3?3?3?3?d?d?d?d"; -#define MAX_MFS 10 // 9*charset, 1*mask +#define MAX_MFS 9 // 8*charset, 1*mask static int sp_comp_val (const void *p1, const void *p2) { @@ -326,9 +326,6 @@ static int mp_expand (hashcat_ctx_t *hashcat_ctx, const char *in_buf, size_t in_ case '8': if (mp_usr[7].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 8 is undefined."); return -1; } rc = mp_add_cs_buf (hashcat_ctx, mp_usr[7].cs_buf, mp_usr[7].cs_len, mp_usr, mp_usr_offset); break; - case '9': if (mp_usr[8].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 9 is undefined."); return -1; } - rc = mp_add_cs_buf (hashcat_ctx, mp_usr[8].cs_buf, mp_usr[8].cs_len, mp_usr, mp_usr_offset); - break; case '?': rc = mp_add_cs_buf (hashcat_ctx, &p0, 1, mp_usr, mp_usr_offset); break; default: event_log_error (hashcat_ctx, "Syntax error in mask: %s", in_buf); @@ -454,9 +451,6 @@ static int mp_gen_css (hashcat_ctx_t *hashcat_ctx, char *mask_buf, size_t mask_l case '8': if (mp_usr[7].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 8 is undefined."); return -1; } rc = mp_add_cs_buf (hashcat_ctx, mp_usr[7].cs_buf, mp_usr[7].cs_len, css_buf, css_pos); break; - case '9': if (mp_usr[8].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 9 is undefined."); return -1; } - rc = mp_add_cs_buf (hashcat_ctx, mp_usr[8].cs_buf, mp_usr[8].cs_len, css_buf, css_pos); - break; case '?': rc = mp_add_cs_buf (hashcat_ctx, &chr, 1, css_buf, css_pos); break; default: event_log_error (hashcat_ctx, "Syntax error in mask: %s", mask_buf); @@ -1446,7 +1440,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) mask_ctx->enabled = true; mask_ctx->mp_sys = (cs_t *) hccalloc (8, sizeof (cs_t)); - mask_ctx->mp_usr = (cs_t *) hccalloc (9, sizeof (cs_t)); + mask_ctx->mp_usr = (cs_t *) hccalloc (8, sizeof (cs_t)); mask_ctx->css_buf = (cs_t *) hccalloc (256, sizeof (cs_t)); mask_ctx->css_cnt = 0; @@ -1477,7 +1471,6 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (user_options->custom_charset_6) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_6, 5) == -1) return -1; } if (user_options->custom_charset_7) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_7, 6) == -1) return -1; } if (user_options->custom_charset_8) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_8, 7) == -1) return -1; } - if (user_options->custom_charset_9) { if (mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_9, 8) == -1) return -1; } if (user_options->benchmark == true) { @@ -1777,7 +1770,6 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx) mfs_buf[5].mf_len = 0; mfs_buf[6].mf_len = 0; mfs_buf[7].mf_len = 0; - mfs_buf[8].mf_len = 0; size_t mfs_cnt = 0; @@ -1839,7 +1831,6 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_6 = NULL; user_options->custom_charset_7 = NULL; user_options->custom_charset_8 = NULL; - user_options->custom_charset_9 = NULL; mp_reset_usr (mask_ctx->mp_usr, 0); mp_reset_usr (mask_ctx->mp_usr, 1); @@ -1849,7 +1840,6 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx) mp_reset_usr (mask_ctx->mp_usr, 5); mp_reset_usr (mask_ctx->mp_usr, 6); mp_reset_usr (mask_ctx->mp_usr, 7); - mp_reset_usr (mask_ctx->mp_usr, 8); for (size_t i = 0; i < mfs_cnt; i++) { @@ -1894,11 +1884,6 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_8 = mfs_buf[7].mf_buf; mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_8, 7); break; - - case 8: - user_options->custom_charset_9 = mfs_buf[8].mf_buf; - mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_9, 8); - break; } } diff --git a/src/status.c b/src/status.c index 4c973bdab..ac661acd4 100644 --- a/src/status.c +++ b/src/status.c @@ -398,7 +398,6 @@ int status_get_guess_mode (const hashcat_ctx_t *hashcat_ctx) if (user_options->custom_charset_6) has_mask_cs = true; if (user_options->custom_charset_7) has_mask_cs = true; if (user_options->custom_charset_8) has_mask_cs = true; - if (user_options->custom_charset_9) has_mask_cs = true; if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)) { @@ -787,23 +786,21 @@ char *status_get_guess_charset (const hashcat_ctx_t *hashcat_ctx) const char *custom_charset_6 = user_options->custom_charset_6; const char *custom_charset_7 = user_options->custom_charset_7; const char *custom_charset_8 = user_options->custom_charset_8; - const char *custom_charset_9 = user_options->custom_charset_9; - if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL) || (custom_charset_5 != NULL) || (custom_charset_6 != NULL) || (custom_charset_7 != NULL) || (custom_charset_8 != NULL) || (custom_charset_9 != NULL)) + if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL) || (custom_charset_5 != NULL) || (custom_charset_6 != NULL) || (custom_charset_7 != NULL) || (custom_charset_8 != NULL)); { char *tmp_buf; - if (custom_charset_1 == NULL) custom_charset_1 = "Undef"; - if (custom_charset_2 == NULL) custom_charset_2 = "Undef"; - if (custom_charset_3 == NULL) custom_charset_3 = "Undef"; - if (custom_charset_4 == NULL) custom_charset_4 = "Undef"; - if (custom_charset_5 == NULL) custom_charset_5 = "Undef"; - if (custom_charset_6 == NULL) custom_charset_6 = "Undef"; - if (custom_charset_7 == NULL) custom_charset_7 = "Undef"; - if (custom_charset_8 == NULL) custom_charset_8 = "Undef"; - if (custom_charset_9 == NULL) custom_charset_9 = "Undef"; + if (custom_charset_1 == NULL) custom_charset_1 = "N/A"; + if (custom_charset_2 == NULL) custom_charset_2 = "N/A"; + if (custom_charset_3 == NULL) custom_charset_3 = "N/A"; + if (custom_charset_4 == NULL) custom_charset_4 = "N/A"; + if (custom_charset_5 == NULL) custom_charset_5 = "N/A"; + if (custom_charset_6 == NULL) custom_charset_6 = "N/A"; + if (custom_charset_7 == NULL) custom_charset_7 = "N/A"; + if (custom_charset_8 == NULL) custom_charset_8 = "N/A"; - hc_asprintf (&tmp_buf, "-1 %s, -2 %s, -3 %s, -4 %s, -5 %s, -6 %s, -7 %s, -8 %s, -9 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4, custom_charset_5, custom_charset_6, custom_charset_7, custom_charset_8, custom_charset_9); + hc_asprintf (&tmp_buf, "-1 %s, -2 %s, -3 %s, -4 %s, -5 %s, -6 %s, -7 %s, -8 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4, custom_charset_5, custom_charset_6, custom_charset_7, custom_charset_8); return tmp_buf; } diff --git a/src/usage.c b/src/usage.c index 0b735fe0d..51f658981 100644 --- a/src/usage.c +++ b/src/usage.c @@ -134,7 +134,6 @@ static const char *const USAGE_BIG_PRE_HASHMODES[] = " -6, --custom-charset6 | CS | User-defined charset ?6 |", " -7, --custom-charset7 | CS | User-defined charset ?7 |", " -8, --custom-charset8 | CS | User-defined charset ?8 |", - " -9, --custom-charset9 | CS | User-defined charset ?9 |", " --identify | | Shows all supported algorithms for input hashes | --identify my.hash", " -i, --increment | | Enable mask increment mode |", " --increment-min | Num | Start mask incrementing at X | --increment-min=4", diff --git a/src/user_options.c b/src/user_options.c index 5093301e9..427351939 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -21,9 +21,9 @@ #endif #ifdef WITH_BRAIN -static const char *const short_options = "hVvm:a:r:j:k:g:o:t:d:D:n:u:T:c:p:s:l:1:2:3:4:5:6:7:8:9:iIbw:OMSY:z"; +static const char *const short_options = "hVvm:a:r:j:k:g:o:t:d:D:n:u:T:c:p:s:l:1:2:3:4:5:6:7:8:iIbw:OMSY:z"; #else -static const char *const short_options = "hVvm:a:r:j:k:g:o:t:d:D:n:u:T:c:p:s:l:1:2:3:4:5:6:7:8:9:iIbw:OMSY:"; +static const char *const short_options = "hVvm:a:r:j:k:g:o:t:d:D:n:u:T:c:p:s:l:1:2:3:4:5:6:7:8:iIbw:OMSY:"; #endif static char *const SEPARATOR = ":"; @@ -55,7 +55,6 @@ static const struct option long_options[] = {"custom-charset6", required_argument, NULL, IDX_CUSTOM_CHARSET_6}, {"custom-charset7", required_argument, NULL, IDX_CUSTOM_CHARSET_7}, {"custom-charset8", required_argument, NULL, IDX_CUSTOM_CHARSET_8}, - {"custom-charset9", required_argument, NULL, IDX_CUSTOM_CHARSET_9}, {"debug-file", required_argument, NULL, IDX_DEBUG_FILE}, {"debug-mode", required_argument, NULL, IDX_DEBUG_MODE}, {"deprecated-check-disable", no_argument, NULL, IDX_DEPRECATED_CHECK_DISABLE}, @@ -171,11 +170,6 @@ static const char *const RULE_BUF_L = ":"; static const char *const DEF_MASK_CS_1 = "?l?d?u"; static const char *const DEF_MASK_CS_2 = "?l?d"; static const char *const DEF_MASK_CS_3 = "?l?d*!$@_"; -static const char *const DEF_MASK_CS_4 = "a"; -static const char *const DEF_MASK_CS_5 = "b"; -static const char *const DEF_MASK_CS_6 = "c"; -static const char *const DEF_MASK_CS_7 = "d"; -static const char *const DEF_MASK_CS_8 = "e"; int user_options_init (hashcat_ctx_t *hashcat_ctx) { @@ -217,7 +211,6 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_6 = NULL; user_options->custom_charset_7 = NULL; user_options->custom_charset_8 = NULL; - user_options->custom_charset_9 = NULL; user_options->debug_file = NULL; user_options->debug_mode = DEBUG_MODE; user_options->deprecated_check = DEPRECATED_CHECK; @@ -551,7 +544,6 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) case IDX_CUSTOM_CHARSET_6: user_options->custom_charset_6 = optarg; break; case IDX_CUSTOM_CHARSET_7: user_options->custom_charset_7 = optarg; break; case IDX_CUSTOM_CHARSET_8: user_options->custom_charset_8 = optarg; break; - case IDX_CUSTOM_CHARSET_9: user_options->custom_charset_9 = optarg; break; case IDX_SLOW_CANDIDATES: user_options->slow_candidates = true; break; #ifdef WITH_BRAIN case IDX_BRAIN_CLIENT: user_options->brain_client = true; break; @@ -1353,8 +1345,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) || (user_options->custom_charset_5 != NULL) || (user_options->custom_charset_6 != NULL) || (user_options->custom_charset_7 != NULL) - || (user_options->custom_charset_8 != NULL) - || (user_options->custom_charset_9 != NULL)) + || (user_options->custom_charset_8 != NULL)) { if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)) { @@ -1526,8 +1517,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) || (user_options->custom_charset_5 != NULL) || (user_options->custom_charset_6 != NULL) || (user_options->custom_charset_7 != NULL) - || (user_options->custom_charset_8 != NULL) - || (user_options->custom_charset_9 != NULL)) + || (user_options->custom_charset_8 != NULL)) { if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { @@ -2071,11 +2061,6 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_1 = DEF_MASK_CS_1; user_options->custom_charset_2 = DEF_MASK_CS_2; user_options->custom_charset_3 = DEF_MASK_CS_3; - user_options->custom_charset_4 = DEF_MASK_CS_4; - user_options->custom_charset_5 = DEF_MASK_CS_5; - user_options->custom_charset_6 = DEF_MASK_CS_6; - user_options->custom_charset_7 = DEF_MASK_CS_7; - user_options->custom_charset_8 = DEF_MASK_CS_8; user_options->increment = true; } @@ -2087,11 +2072,6 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_1 = DEF_MASK_CS_1; user_options->custom_charset_2 = DEF_MASK_CS_2; user_options->custom_charset_3 = DEF_MASK_CS_3; - user_options->custom_charset_4 = DEF_MASK_CS_4; - user_options->custom_charset_5 = DEF_MASK_CS_5; - user_options->custom_charset_6 = DEF_MASK_CS_6; - user_options->custom_charset_7 = DEF_MASK_CS_7; - user_options->custom_charset_8 = DEF_MASK_CS_8; user_options->increment = true; } @@ -2103,11 +2083,6 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) user_options->custom_charset_1 = DEF_MASK_CS_1; user_options->custom_charset_2 = DEF_MASK_CS_2; user_options->custom_charset_3 = DEF_MASK_CS_3; - user_options->custom_charset_4 = DEF_MASK_CS_4; - user_options->custom_charset_5 = DEF_MASK_CS_5; - user_options->custom_charset_6 = DEF_MASK_CS_6; - user_options->custom_charset_7 = DEF_MASK_CS_7; - user_options->custom_charset_8 = DEF_MASK_CS_8; user_options->increment = true; } @@ -3248,7 +3223,6 @@ void user_options_logger (hashcat_ctx_t *hashcat_ctx) logfile_top_string (user_options->custom_charset_6); logfile_top_string (user_options->custom_charset_7); logfile_top_string (user_options->custom_charset_8); - logfile_top_string (user_options->custom_charset_9); logfile_top_string (user_options->debug_file); logfile_top_string (user_options->encoding_from); logfile_top_string (user_options->encoding_to); From 4e0fc2099eef1f2e367a4290fdc305f9edb710d1 Mon Sep 17 00:00:00 2001 From: Flaggx1 Date: Thu, 25 Jul 2024 07:29:26 -0400 Subject: [PATCH 014/252] Removed incorrect semicolon and blank line --- src/brain.c | 1 - src/status.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/brain.c b/src/brain.c index f313b5536..2aec26300 100644 --- a/src/brain.c +++ b/src/brain.c @@ -374,7 +374,6 @@ u32 brain_compute_attack (hashcat_ctx_t *hashcat_ctx) XXH64_update (state, custom_charset_8, strlen (custom_charset_8)); } } - else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { const u64 wordlist_hash = brain_compute_attack_wordlist (straight_ctx->dict); diff --git a/src/status.c b/src/status.c index ac661acd4..b33fba85e 100644 --- a/src/status.c +++ b/src/status.c @@ -787,7 +787,7 @@ char *status_get_guess_charset (const hashcat_ctx_t *hashcat_ctx) const char *custom_charset_7 = user_options->custom_charset_7; const char *custom_charset_8 = user_options->custom_charset_8; - if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL) || (custom_charset_5 != NULL) || (custom_charset_6 != NULL) || (custom_charset_7 != NULL) || (custom_charset_8 != NULL)); + if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL) || (custom_charset_5 != NULL) || (custom_charset_6 != NULL) || (custom_charset_7 != NULL) || (custom_charset_8 != NULL)) { char *tmp_buf; From 55ca7fb27b3167ca9fe31a3f1b580642960d23a5 Mon Sep 17 00:00:00 2001 From: holly-o <128481388+holly-o@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:19:27 +0100 Subject: [PATCH 015/252] Add bitlocker2hashcat.py For generating hashes for mode 22100. Hashcat supports modes $bitlocker$0$ and $bitlocker$1$ and therefore this script will output hashes that relate to a VMK protected by a user password only. Script created since bitlocker2john takes an extremely long time to run and sometimes fails to output a hash, or outputs incorrect information. Script created using information at https://github.com/libyal/libbde/blob/main/documentation/BitLocker%20Drive%20Encryption%20(BDE)%20format.asciidoc#encryption_methods and tested on Windows hard drives and USB sticks. --- tools/bitlocker2hashcat.py | 234 +++++++++++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 tools/bitlocker2hashcat.py diff --git a/tools/bitlocker2hashcat.py b/tools/bitlocker2hashcat.py new file mode 100644 index 000000000..56e185311 --- /dev/null +++ b/tools/bitlocker2hashcat.py @@ -0,0 +1,234 @@ +# Construct a hash for use with hashcat mode 22100 +# Usage: python3 bitlocker2hashcat.py -o +# Hashcat supports modes $bitlocker$0$ and $bitlocker$1$ and therefore this script will output hashes that relate to a VMK protected by a user password only. +# It is not possible to create a hash for VMKs protected by a TPM, and is infeasible to attempt to crack a hash of the recovery password. +# Refs: https://github.com/libyal/libbde/blob/main/documentation/BitLocker%20Drive%20Encryption%20(BDE)%20format.asciidoc#encryption_methods + +import argparse + +BITLOCKER_SIGNATURE = '-FVE-FS-' +BITLOCKER_TO_GO_SIGNATURE = 'MSWIN4.1' +BITLOCKER_GUIDS = {'4967D63B-2E29-4AD8-8399-F6A339E3D001' : 'BitLocker', '4967D63B-2E29-4AD8-8399-F6A339E3D01' : 'BitLocker To Go', '92A84D3B-DD80-4D0E-9E4E-B1E3284EAED8' : 'BitLocker Used Disk Space Only'} +PROTECTION_TYPES = {0x0: 'VMK protected with clear key', 0x100: 'VMK protected with TPM', 0x200: 'VMK protected with startup key', 0x500: 'VMK protected with TPM and PIN', 0x800: 'VMK protected with recovery password', 0x2000: 'VMK protected with password'} +FVE_ENTRY_TYPES = {0x0: 'None', 0x2: 'VMK', 0x3: 'FVEK', 0x4: 'Validation', 0x6: 'Startup key', 0x7: 'Computer description', 0xb: 'FVEK backup', 0xf: 'Volume header block'} +FVE_VALUE_TYPES = {0x0: 'Erased', 0x1: 'Key', 0x2: 'UTF-16 string', 0x3: 'Stretch key', 0x4: 'Use key', 0x5: 'AES-CCM encrypted key', 0x6: 'TPM encoded key', 0x7: 'Validation', 0x8: 'VMK', 0x9: 'External key', 0xa: 'Update', 0xb: 'Error', 0xf: 'Offset and size'} +ITERATION_COUNT = 0x100000 +BITLOCKER_HASH_VERSIONS = [0,1] # 0,1 both supported on hashcat +HASHCAT_HASH = [] + +def guid_to_hex(guid): + guid_parts = guid.split('-') + + search_target = ''.join([guid_parts[0][i:i+2] for i in range(0, len(guid_parts[0]), 2)][::-1]) + search_target += ''.join([guid_parts[1][i:i+2] for i in range(0, len(guid_parts[1]), 2)][::-1]) + search_target += ''.join([guid_parts[2][i:i+2] for i in range(0, len(guid_parts[2]), 2)][::-1]) + search_target += guid_parts[3] + search_target += guid_parts[4] + + return search_target + +def hex_to_guid(hex_str): + + guid_parts = [0] * 5 + guid_parts[0] = hex_str[0:8] + guid_parts[1] = hex_str[8:12] + guid_parts[2] = hex_str[12:16] + guid_parts[3] = hex_str[16:20] + guid_parts[4] = hex_str[20:] + + guid = ''.join([guid_parts[0][i:i+2] for i in range(0, len(guid_parts[0]), 2)][::-1]) + guid += '-' + guid += ''.join([guid_parts[1][i:i+2] for i in range(0, len(guid_parts[1]), 2)][::-1]) + guid += '-' + guid += ''.join([guid_parts[2][i:i+2] for i in range(0, len(guid_parts[2]), 2)][::-1]) + guid += '-' + guid += guid_parts[3] + guid += '-' + guid += guid_parts[4] + + return guid.upper() + +def uint_to_int(b): + return int(b[::-1].hex(), 16) + +def parse_FVEK(fvek_data): + print("\nParsing FVEK...") + nonce = fvek_data[:12] + mac = fvek_data[12:28] + enc_data = fvek_data[28:] + + print("Mac:", mac.hex()) + print("Nonce:", nonce.hex()) + print("Encrypted data:", enc_data.hex()) + + return nonce, mac, enc_data + +def parse_stretch_key(data): + print("\nParsing stretch key...") + encryption_method = hex(uint_to_int(data[0:4])) + salt = data[4:20] + print("Encryption method:", encryption_method) + print("Salt:", salt.hex()) + current_pos = 0 + aes_ccm_data = data[20:] + current_pos, data, value_type = parse_fve_metadata_entry(current_pos, aes_ccm_data) + nonce, mac, enc_data = parse_aes_ccm_encrypted_key(data) + + return salt, nonce, mac, enc_data + +def generate_hashcat_hash(salt, nonce, mac, enc_data): + print("\nFound hashcat hash!") + for version in BITLOCKER_HASH_VERSIONS: + generated_hash = f"$bitlocker${version}${len(salt)}${salt.hex()}${ITERATION_COUNT}${len(nonce)}${nonce.hex()}${len(mac + enc_data)}${(mac + enc_data).hex()}" + print(generated_hash) + HASHCAT_HASH.append(generated_hash) + +def parse_aes_ccm_encrypted_key(data): + print("Parsing AES CCM key...") + nonce, mac, enc_data = parse_FVEK(data) + return nonce, mac, enc_data + +def parse_description(data): + print("\nParsing description...") + print(f"Info: {data.decode('utf-16')}") + return + +def parse_volume_header_block(data): + print("\nParsing volume header block...") + block_offset = uint_to_int(data[0:8]) + block_size = uint_to_int(data[8:16]) + print(f"Block offset: {hex(block_offset)}") + print(f"Block size: {block_size}") + +def parse_VMK(VMK_data): + print("\nParsing VMK...") + guid = hex_to_guid(VMK_data[:16].hex()) + protection_type = uint_to_int(VMK_data[26:28]) + properties = VMK_data[28:] + print("GUID:", guid) + print(f"Protection type: {hex(protection_type)} = {PROTECTION_TYPES.get(protection_type)}") + + # only try parse properties if correct protection type + if protection_type == 0x2000: + current_pos = 28 + while current_pos < len(properties): + current_pos, data, value_type = parse_fve_metadata_entry(current_pos, VMK_data[current_pos:]) + if value_type == 0x3: + salt, strech_nonce, stretch_mac, stretch_enc_data = parse_stretch_key(data) + if value_type == 0x5: + nonce, mac, enc_data = parse_aes_ccm_encrypted_key(data) + generate_hashcat_hash(salt, nonce, mac, enc_data) + + return + +def parse_fve_metadata_block(block): + print('\nParsing FVE block...') + signature = block[0:8] + fve_metadata_header = block[64:64+48] + metadata_size = parse_fve_metadata_header(fve_metadata_header) + + entry_size = uint_to_int(block[112:114]) + current_pos = 112 + while current_pos < metadata_size: + current_pos, data, value_type = parse_fve_metadata_entry(current_pos, block[current_pos:current_pos+entry_size]) + if value_type == 0x2: + parse_description(data) + if value_type == 0x5: + parse_aes_ccm_encrypted_key(data) + if value_type == 0x8: + parse_VMK(data) + if value_type == 0xf: + parse_volume_header_block(data) + + try: + entry_size = uint_to_int(block[current_pos:current_pos+2]) + except: + return + +def parse_fve_metadata_entry(current_pos, block): + print("\nParsing FVE metadata entry...") + entry_size = uint_to_int(block[0:2]) + entry_type = uint_to_int(block[2:4]) + value_type = uint_to_int(block[4:6]) + version = hex(uint_to_int(block[6:8])) + data = block[8:entry_size] + + print(f"Entry size: {entry_size}") + print(f"Entry type: {hex(entry_type)} = {FVE_ENTRY_TYPES.get(entry_type)}") + print(f"Value type: {hex(value_type)} = {FVE_VALUE_TYPES.get(value_type)}") + + current_pos = current_pos + entry_size + + return current_pos, data, value_type + +def parse_fve_metadata_header(block): + print("\nParsing FVE metadata header...") + metadata_size = uint_to_int(block[0:4]) + volume_guid = hex_to_guid(block[16:32].hex()) + nonce_counter = uint_to_int(block[32:36]) + encryption_method = hex(uint_to_int(block[36:40])) + + print("Metadata size:", metadata_size) + print("Volume GUID:", volume_guid) + print("Encryption method:", encryption_method) + + return metadata_size + +def main(): + + p = argparse.ArgumentParser() + p.add_argument('image_path', help="Path to encrypted BitLocker image") + p.add_argument('-o', '--offset', help='Offset in image where BitLocker partition starts, default=0') + args = p.parse_args() + bitlocker_partition = args.image_path + + bitlocker_offset = 0 + if args.offset: + bitlocker_offset = int(args.offset) + + with open(bitlocker_partition, 'rb') as fp: + + fp.seek(bitlocker_offset) + boot_entry_point = fp.read(3) + + header = fp.read(8) + if header.decode('latin-1') not in [BITLOCKER_SIGNATURE, BITLOCKER_TO_GO_SIGNATURE]: + print("[!] Supplied image path is not a BitLocker partition. Try specifiying the offset of the BitLocker partition with -o") + exit() + print(f'[+] BitLocker signature found: {header.decode()}') + sector_size = uint_to_int(fp.read(2)) + + if header.decode('latin-1') == BITLOCKER_SIGNATURE: + guid_offset = 0xa0 + if header.decode('latin-1') == BITLOCKER_TO_GO_SIGNATURE: + guid_offset = 0x1a8 + + fp.seek(guid_offset + bitlocker_offset) + volume_guid = fp.read(16) + print(f'[+] Identified volume GUID: {hex_to_guid(volume_guid.hex())} = {BITLOCKER_GUIDS.get(hex_to_guid(volume_guid.hex()))}') + + # get FVE metadata block addresses + FVE_metadata_offsets = [hex(uint_to_int(fp.read(8)) + bitlocker_offset) for _ in range(3)] + print(f'[+] FVE metadata info found at offsets {FVE_metadata_offsets}') + + # all metadata blocks should be the same + for f in FVE_metadata_offsets: + + fp.seek(int(f, 16)) + FVE_metadata_block = fp.read(2048) + parse_fve_metadata_block(FVE_metadata_block) + + break + + if HASHCAT_HASH == []: + print("\nNo hashes associated with the user password found. Exiting...") + else: + print("\nThe following hashcat hashes were found:") + for bitlocker_hash in HASHCAT_HASH: + print(bitlocker_hash) + + return + + +if __name__ == "__main__": + main() \ No newline at end of file From 7c1688a266909c4987346dd8e9363bfee935aae0 Mon Sep 17 00:00:00 2001 From: holly-o <128481388+holly-o@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:07:01 +0100 Subject: [PATCH 016/252] Update tools/bitlocker2hashcat.py Co-authored-by: kgolawski --- tools/bitlocker2hashcat.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/bitlocker2hashcat.py b/tools/bitlocker2hashcat.py index 56e185311..19d0be2d7 100644 --- a/tools/bitlocker2hashcat.py +++ b/tools/bitlocker2hashcat.py @@ -178,13 +178,11 @@ def main(): p = argparse.ArgumentParser() p.add_argument('image_path', help="Path to encrypted BitLocker image") - p.add_argument('-o', '--offset', help='Offset in image where BitLocker partition starts, default=0') + p.add_argument('-o', '--offset', default=0, type=int, help='Offset in image where BitLocker partition starts') args = p.parse_args() bitlocker_partition = args.image_path - bitlocker_offset = 0 - if args.offset: - bitlocker_offset = int(args.offset) + bitlocker_offset = args.offset with open(bitlocker_partition, 'rb') as fp: From cbc21cf767a30105aef31cfe1e69407249445317 Mon Sep 17 00:00:00 2001 From: holly-o <128481388+holly-o@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:08:31 +0100 Subject: [PATCH 017/252] Update tools/bitlocker2hashcat.py Co-authored-by: kgolawski --- tools/bitlocker2hashcat.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/bitlocker2hashcat.py b/tools/bitlocker2hashcat.py index 19d0be2d7..f7501a37b 100644 --- a/tools/bitlocker2hashcat.py +++ b/tools/bitlocker2hashcat.py @@ -29,12 +29,13 @@ def guid_to_hex(guid): def hex_to_guid(hex_str): - guid_parts = [0] * 5 - guid_parts[0] = hex_str[0:8] - guid_parts[1] = hex_str[8:12] - guid_parts[2] = hex_str[12:16] - guid_parts[3] = hex_str[16:20] - guid_parts[4] = hex_str[20:] + guid_parts = [ + hex_str[0:8], + hex_str[8:12], + hex_str[12:16], + hex_str[16:20], + hex_str[20:], + ] guid = ''.join([guid_parts[0][i:i+2] for i in range(0, len(guid_parts[0]), 2)][::-1]) guid += '-' From 7398b03be30b45d1e89dd7b7ec7799ee5d5b0f52 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 24 Oct 2024 20:15:08 +0200 Subject: [PATCH 018/252] User Options: limit --bitmap-max value to 31 --- docs/changes.txt | 1 + src/bitmap.c | 2 ++ src/usage.c | 2 +- src/user_options.c | 7 +++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..ef9be50bb 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -130,6 +130,7 @@ - Metal Backend: allow use of devices with Metal if runtime version is >= 200 - Metal Backend: disable Metal devices only if at least one OpenCL device is active - User Options: added --metal-compiler-runtime option +- User Options: limit --bitmap-max value to 31 - Hardware Monitor: avoid sprintf in src/ext_iokit.c - Help: show supported hash-modes only with -hh - Makefile: prevent make failure with Apple Silicon in case of partial rebuild diff --git a/src/bitmap.c b/src/bitmap.c index 367b16a7c..12f701fe5 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -110,6 +110,8 @@ int bitmap_ctx_init (hashcat_ctx_t *hashcat_ctx) u32 *bitmap_s2_c = (u32 *) hcmalloc ((1U << bitmap_max) * sizeof (u32)); u32 *bitmap_s2_d = (u32 *) hcmalloc ((1U << bitmap_max) * sizeof (u32)); + if (!bitmap_s1_a || !bitmap_s1_b || !bitmap_s1_c || !bitmap_s1_d || !bitmap_s2_a || !bitmap_s2_b || !bitmap_s2_c || !bitmap_s2_d) return -1; + u32 bitmap_bits; u32 bitmap_nums; u32 bitmap_mask; diff --git a/src/usage.c b/src/usage.c index 7cbf22348..1bee7c547 100644 --- a/src/usage.c +++ b/src/usage.c @@ -91,7 +91,7 @@ static const char *const USAGE_BIG_PRE_HASHMODES[] = " --progress-only | | Return ideal progress step size and time to process |", " -c, --segment-size | Num | Sets size in MB to cache from the wordfile to X | -c 32", " --bitmap-min | Num | Sets minimum bits allowed for bitmaps to X | --bitmap-min=24", - " --bitmap-max | Num | Sets maximum bits allowed for bitmaps to X | --bitmap-max=24", + " --bitmap-max | Num | Sets maximum bits allowed for bitmaps to X (max: 31) | --bitmap-max=24", " --cpu-affinity | Str | Locks to CPU devices, separated with commas | --cpu-affinity=1,2,3", " --hook-threads | Num | Sets number of threads for a hook (per compute unit) | --hook-threads=8", " --hash-info | | Show information for each hash-mode |", diff --git a/src/user_options.c b/src/user_options.c index b1ed588f4..1bf346d13 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -945,6 +945,13 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) return -1; } + if (user_options->bitmap_max > 31) + { + event_log_error (hashcat_ctx, "Invalid --bitmap-max value specified - must be lower than 32."); + + return -1; + } + if (user_options->rp_gen_func_min > user_options->rp_gen_func_max) { event_log_error (hashcat_ctx, "Invalid --rp-gen-func-min value specified."); From a66c93ae1e3b3f4b299a220322821dfa5599e6ee Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 24 Oct 2024 21:13:11 +0200 Subject: [PATCH 019/252] Fixed bug in --stdout when multiple computing devices are active --- docs/changes.txt | 1 + include/types.h | 2 ++ src/outfile.c | 5 +++++ src/stdout.c | 11 +++++++++++ 4 files changed, 19 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..a4a17bfd8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -82,6 +82,7 @@ - Fixed bug in grep out-of-memory workaround on Unit Test - Fixed bug in input_tokenizer when TOKEN_ATTR_FIXED_LENGTH is used and refactor modules - Fixed bug in --stdout that caused certain rules to malfunction +- Fixed bug in --stdout when multiple computing devices are active - Fixed build failed for 10700 optimized with Apple Metal - Fixed build failed for 13772 and 13773 with Apple Metal - Fixed build failed for 18400 with Apple Metal diff --git a/include/types.h b/include/types.h index e6ea946f9..6b508d7f0 100644 --- a/include/types.h +++ b/include/types.h @@ -2122,6 +2122,8 @@ typedef struct outfile_ctx char *filename; + hc_thread_mutex_t mux_outfile; + } outfile_ctx_t; typedef struct pot diff --git a/src/outfile.c b/src/outfile.c index b14b56a7a..43ddb8611 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -15,6 +15,7 @@ #include "backend.h" #include "shared.h" #include "locking.h" +#include "thread.h" #include "outfile.h" u32 outfile_format_parse (const char *format_string) @@ -506,6 +507,8 @@ int outfile_init (hashcat_ctx_t *hashcat_ctx) outfile_ctx->outfile_json = user_options->outfile_json; outfile_ctx->is_fifo = hc_path_is_fifo (outfile_ctx->filename); + hc_thread_mutex_init (outfile_ctx->mux_outfile); + return 0; } @@ -513,6 +516,8 @@ void outfile_destroy (hashcat_ctx_t *hashcat_ctx) { outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; + hc_thread_mutex_delete (outfile_ctx->mux_outfile); + if (outfile_ctx->is_fifo == true && outfile_ctx->fp.pfp != NULL) { hc_unlockfile (&outfile_ctx->fp); diff --git a/src/stdout.c b/src/stdout.c index 429836793..127232d0e 100644 --- a/src/stdout.c +++ b/src/stdout.c @@ -12,6 +12,7 @@ #include "mpsp.h" #include "backend.h" #include "shared.h" +#include "thread.h" #include "stdout.h" static void out_flush (out_t *out) @@ -59,6 +60,10 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; user_options_t *user_options = hashcat_ctx->user_options; + // prevent wrong candidates in output when backend_ctx->backend_devices_active > 1 + + hc_thread_mutex_lock (outfile_ctx->mux_outfile); + char *filename = outfile_ctx->filename; out_t out; @@ -69,6 +74,8 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, { event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno)); + hc_thread_mutex_unlock (outfile_ctx->mux_outfile); + return -1; } @@ -78,6 +85,8 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno)); + hc_thread_mutex_unlock (outfile_ctx->mux_outfile); + return -1; } } @@ -341,5 +350,7 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, hc_fclose (&out.fp); } + hc_thread_mutex_unlock (outfile_ctx->mux_outfile); + return rc; } From 0788fd9ae745dacc3b697cdae8534f73329bdc91 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sat, 26 Oct 2024 13:24:00 +0200 Subject: [PATCH 020/252] Fixed stack buffer overflow in PKZIP modules (17200, 17210, 17220, 17225, 17230) --- docs/changes.txt | 1 + src/modules/module_17200.c | 9 +++++++-- src/modules/module_17210.c | 9 +++++++-- src/modules/module_17220.c | 9 +++++++-- src/modules/module_17225.c | 9 +++++++-- src/modules/module_17230.c | 9 +++++++-- 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..e1aab3de3 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -98,6 +98,7 @@ - Fixed minimum password length in module of hash-mode 28200 - Fixed minimum password length in module of hash-mode 29800 - Fixed out-of-boundary read when a fast hash defines a kernel_loops_min value higher than the amplifiers provided by the user +- Fixed stack buffer overflow in PKZIP modules (17200, 17210, 17220, 17225, 17230) - Fixed vector datatypes usage for HIP - Fix missing check for -j and -k before writing hashcat.dictstat2 which can lead to false negatives - Handle signed/unsigned PDF permission P value for all PDF hash-modes diff --git a/src/modules/module_17200.c b/src/modules/module_17200.c index 24f77798f..2125812e2 100644 --- a/src/modules/module_17200.c +++ b/src/modules/module_17200.c @@ -91,6 +91,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #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; @@ -206,9 +207,11 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE u32 *digest = (u32 *) digest_buf; - char input[line_len + 1]; + char *input = (char *) hcmalloc (line_len + 1); + if (!input) return PARSER_HAVE_ERRNO; + + memcpy (input, line_buf, line_len); input[line_len] = '\0'; - memcpy (&input, line_buf, line_len); char *saveptr = NULL; @@ -318,6 +321,8 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE digest[2] = 0; digest[3] = 0; + hcfree (input); + return (PARSER_OK); } diff --git a/src/modules/module_17210.c b/src/modules/module_17210.c index 307757689..58edcf343 100644 --- a/src/modules/module_17210.c +++ b/src/modules/module_17210.c @@ -91,6 +91,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #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; @@ -186,9 +187,11 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE u32 *digest = (u32 *) digest_buf; - char input[line_len + 1]; + char *input = (char *) hcmalloc (line_len + 1); + if (!input) return PARSER_HAVE_ERRNO; + + memcpy (input, line_buf, line_len); input[line_len] = '\0'; - memcpy (&input, line_buf, line_len); char *saveptr = NULL; @@ -297,6 +300,8 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE digest[2] = 0; digest[3] = 0; + hcfree (input); + return (PARSER_OK); } diff --git a/src/modules/module_17220.c b/src/modules/module_17220.c index c2ac82b2c..1356cf5e5 100644 --- a/src/modules/module_17220.c +++ b/src/modules/module_17220.c @@ -91,6 +91,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #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; @@ -206,9 +207,11 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE u32 *digest = (u32 *) digest_buf; - char input[line_len + 1]; + char *input = (char *) hcmalloc (line_len + 1); + if (!input) return PARSER_HAVE_ERRNO; + + memcpy (input, line_buf, line_len); input[line_len] = '\0'; - memcpy (&input, line_buf, line_len); char *saveptr = NULL; @@ -314,6 +317,8 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE salt->salt_len = pkzip->hash_count << 2; + hcfree (input); + return (PARSER_OK); } diff --git a/src/modules/module_17225.c b/src/modules/module_17225.c index 3cbf0f51b..376d77e60 100644 --- a/src/modules/module_17225.c +++ b/src/modules/module_17225.c @@ -91,6 +91,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #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; @@ -207,9 +208,11 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE u32 *digest = (u32 *) digest_buf; - char input[line_len + 1]; + char *input = (char *) hcmalloc (line_len + 1); + if (!input) return PARSER_HAVE_ERRNO; + + memcpy (input, line_buf, line_len); input[line_len] = '\0'; - memcpy (&input, line_buf, line_len); char *saveptr = NULL; @@ -315,6 +318,8 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE salt->salt_len = pkzip->hash_count << 2; + hcfree (input); + return (PARSER_OK); } diff --git a/src/modules/module_17230.c b/src/modules/module_17230.c index 2b3ef24c9..2166c3f6d 100644 --- a/src/modules/module_17230.c +++ b/src/modules/module_17230.c @@ -91,6 +91,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #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; @@ -199,9 +200,11 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE u32 *digest = (u32 *) digest_buf; - char input[line_len + 1]; + char *input = (char *) hcmalloc (line_len + 1); + if (!input) return PARSER_HAVE_ERRNO; + + memcpy (input, line_buf, line_len); input[line_len] = '\0'; - memcpy (&input, line_buf, line_len); char *saveptr = NULL; @@ -308,6 +311,8 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE salt->salt_len = pkzip->hash_count << 2; + hcfree (input); + return (PARSER_OK); } From e3c097c88bca1a9395fdf91738e3b2aab314c1bc Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sat, 26 Oct 2024 14:51:11 +0200 Subject: [PATCH 021/252] do not allow --show and --restore --- src/hashcat.c | 2 ++ src/user_options.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/hashcat.c b/src/hashcat.c index a6dd823d1..642a13952 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1430,6 +1430,8 @@ bool autodetect_hashmode_test (hashcat_ctx_t *hashcat_ctx) { char *input_buf = user_options_extra->hc_hash; + if (!input_buf) return false; + size_t input_len = strlen (input_buf); char *hash_buf = NULL; diff --git a/src/user_options.c b/src/user_options.c index b1ed588f4..3576cb3d2 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -1059,6 +1059,13 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) return 0; } + if (user_options->show == true && user_options->restore == true) + { + event_log_error (hashcat_ctx, "Mixing --show and --restore is not allowed."); + + return -1; + } + if (user_options->show == true || user_options->left == true) { if (user_options->remove == true) From b67638ab36224a3201cea67696b25ebc7f962dc9 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sat, 26 Oct 2024 15:11:45 +0200 Subject: [PATCH 022/252] do not allow --stdout and --slow-candidates --- src/user_options.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/user_options.c b/src/user_options.c index b1ed588f4..f9bf491ea 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -1052,6 +1052,13 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) } } + if (user_options->stdout_flag == true && user_options->slow_candidates == true) + { + event_log_error (hashcat_ctx, "Slow candidates (-S) is not allowed in stdout mode."); + + return -1; + } + if ((user_options->show == true) && ((user_options->username == true) || (user_options->dynamic_x == true))) { event_log_error (hashcat_ctx, "Mixing --show with --username or --dynamic-x can cause exponential delay in output."); From 356ad9f927a16a85ec490c70112f8553f3811d36 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sun, 27 Oct 2024 00:45:44 +0200 Subject: [PATCH 023/252] Fixed memory leaks in tuning_db_init in tuningdb.c --- docs/changes.txt | 1 + src/tuningdb.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..727f93bf2 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -95,6 +95,7 @@ - Fixed keys extraction in luks2hashcat - now extracts all active keys - Fixed maximum password length in module/test_module of hash-mode 2400 - Fixed maximum password length in module/test_module of hash-mode 2410 +- Fixed memory leaks in tuning_db_init in tuningdb.c - Fixed minimum password length in module of hash-mode 28200 - Fixed minimum password length in module of hash-mode 29800 - Fixed out-of-boundary read when a fast hash defines a kernel_loops_min value higher than the amplifiers provided by the user diff --git a/src/tuningdb.c b/src/tuningdb.c index 2f983b31e..332ab51cb 100644 --- a/src/tuningdb.c +++ b/src/tuningdb.c @@ -72,6 +72,8 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) char **tuning_db_files = scan_directory (tuning_db_folder); + hcfree (tuning_db_folder); + for (int i = 0; tuning_db_files[i] != NULL; i++) { char *tuning_db_file = tuning_db_files[i]; @@ -80,9 +82,19 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) const size_t dblen = strlen (tuning_db_file); - if (dblen < suflen) continue; // make sure to not do any out-of-boundary reads + if (dblen < suflen) + { + hcfree (tuning_db_file); - if (memcmp (tuning_db_file + dblen - suflen, TUNING_DB_SUFFIX, suflen) != 0) continue; + continue; // make sure to not do any out-of-boundary reads + } + + if (memcmp (tuning_db_file + dblen - suflen, TUNING_DB_SUFFIX, suflen) != 0) + { + hcfree (tuning_db_file); + + continue; + } HCFILE fp; @@ -90,6 +102,8 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "%s: %s", tuning_db_file, strerror (errno)); + for (int j = 0; tuning_db_files[j] != NULL; j++) hcfree (tuning_db_files[j]); + return -1; } From d756a6617c8b2a6f7342a56ee74b8da910952221 Mon Sep 17 00:00:00 2001 From: Mathias Date: Tue, 29 Oct 2024 15:35:10 +0100 Subject: [PATCH 024/252] Update backend.c Fixes hiprtcCompileProgram(): HIPRTC_ERROR_COMPILATION on AMD 6900XT. ```bash hiprtcCompileProgram(): HIPRTC_ERROR_COMPILATION ld.lld: error: undefined hidden symbol: __ockl_get_group_id >>> referenced by /home/mathias/.local/share/hashcat/comgr-69ec34/input/shared_kernel.o:(gpu_decompress) >>> referenced by /home/mathias/.local/share/hashcat/comgr-69ec34/input/shared_kernel.o:(gpu_decompress) >>> referenced by /home/mathias/.local/share/hashcat/comgr-69ec34/input/shared_kernel.o:(gpu_memset) >>> referenced 7 more times ld.lld: error: undefined hidden symbol: __ockl_get_local_size >>> referenced by /home/mathias/.local/share/hashcat/comgr-69ec34/input/shared_kernel.o:(gpu_decompress) >>> referenced by /home/mathias/.local/share/hashcat/comgr-69ec34/input/shared_kernel.o:(gpu_decompress) >>> referenced by /home/mathias/.local/share/hashcat/comgr-69ec34/input/shared_kernel.o:(gpu_memset) >>> referenced 7 more times ld.lld: error: undefined hidden symbol: __ockl_get_local_id >>> referenced by /home/mathias/.local/share/hashcat/comgr-69ec34/input/shared_kernel.o:(gpu_decompress) >>> referenced by /home/mathias/.local/share/hashcat/comgr-69ec34/input/shared_kernel.o:(gpu_decompress) >>> referenced by /home/mathias/.local/share/hashcat/comgr-69ec34/input/shared_kernel.o:(gpu_memset) >>> referenced 7 more times * Device #1: Kernel /usr/local/share/hashcat/OpenCL/shared.cl build failed. * Device #1: Kernel /usr/local/share/hashcat/OpenCL/shared.cl build failed. ``` --- src/backend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend.c b/src/backend.c index f7c916e1d..4120f449d 100644 --- a/src/backend.c +++ b/src/backend.c @@ -8754,8 +8754,8 @@ static bool load_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_p hiprtc_options[5] = "-I"; */ - hiprtc_options[1] = "-nocudainc"; - hiprtc_options[2] = "-nocudalib"; + hiprtc_options[1] = ""; + hiprtc_options[2] = ""; hiprtc_options[3] = ""; hiprtc_options[4] = ""; From a80d68731ef2b33cc1c4325d2581b26de712429f Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 31 Oct 2024 18:04:58 +0100 Subject: [PATCH 025/252] Kernel: Renamed multiple defines in CAST cipher to fit expected naming convention of the C++ language standard --- OpenCL/inc_cipher_cast.cl | 80 +++++++++++++++++++-------------------- OpenCL/inc_cipher_cast.h | 22 +++++------ docs/changes.txt | 1 + 3 files changed, 50 insertions(+), 53 deletions(-) diff --git a/OpenCL/inc_cipher_cast.cl b/OpenCL/inc_cipher_cast.cl index e2c5a6fb1..f37b09072 100644 --- a/OpenCL/inc_cipher_cast.cl +++ b/OpenCL/inc_cipher_cast.cl @@ -569,22 +569,22 @@ DECLSPEC void Cast5Encrypt (PRIVATE_AS const u8 *inBlock, PRIVATE_AS u8 *outBloc u32 t; /* Do the work */ - _CAST_F1(l, r, 0, 16); - _CAST_F2(r, l, 1, 16); - _CAST_F3(l, r, 2, 16); - _CAST_F1(r, l, 3, 16); - _CAST_F2(l, r, 4, 16); - _CAST_F3(r, l, 5, 16); - _CAST_F1(l, r, 6, 16); - _CAST_F2(r, l, 7, 16); - _CAST_F3(l, r, 8, 16); - _CAST_F1(r, l, 9, 16); - _CAST_F2(l, r, 10, 16); - _CAST_F3(r, l, 11, 16); - _CAST_F1(l, r, 12, 16); - _CAST_F2(r, l, 13, 16); - _CAST_F3(l, r, 14, 16); - _CAST_F1(r, l, 15, 16); + CAST_F1(l, r, 0, 16); + CAST_F2(r, l, 1, 16); + CAST_F3(l, r, 2, 16); + CAST_F1(r, l, 3, 16); + CAST_F2(l, r, 4, 16); + CAST_F3(r, l, 5, 16); + CAST_F1(l, r, 6, 16); + CAST_F2(r, l, 7, 16); + CAST_F3(l, r, 8, 16); + CAST_F1(r, l, 9, 16); + CAST_F2(l, r, 10, 16); + CAST_F3(r, l, 11, 16); + CAST_F1(l, r, 12, 16); + CAST_F2(r, l, 13, 16); + CAST_F3(l, r, 14, 16); + CAST_F1(r, l, 15, 16); /* Put l,r into outblock */ PUT_UINT32BE(r, outBlock, 0); @@ -599,22 +599,22 @@ DECLSPEC void Cast5Decrypt (PRIVATE_AS const u8 *inBlock, PRIVATE_AS u8 *outBloc u32 t; /* Only do full 16 rounds if key length > 80 bits */ - _CAST_F1(r, l, 15, 16); - _CAST_F3(l, r, 14, 16); - _CAST_F2(r, l, 13, 16); - _CAST_F1(l, r, 12, 16); - _CAST_F3(r, l, 11, 16); - _CAST_F2(l, r, 10, 16); - _CAST_F1(r, l, 9, 16); - _CAST_F3(l, r, 8, 16); - _CAST_F2(r, l, 7, 16); - _CAST_F1(l, r, 6, 16); - _CAST_F3(r, l, 5, 16); - _CAST_F2(l, r, 4, 16); - _CAST_F1(r, l, 3, 16); - _CAST_F3(l, r, 2, 16); - _CAST_F2(r, l, 1, 16); - _CAST_F1(l, r, 0, 16); + CAST_F1(r, l, 15, 16); + CAST_F3(l, r, 14, 16); + CAST_F2(r, l, 13, 16); + CAST_F1(l, r, 12, 16); + CAST_F3(r, l, 11, 16); + CAST_F2(l, r, 10, 16); + CAST_F1(r, l, 9, 16); + CAST_F3(l, r, 8, 16); + CAST_F2(r, l, 7, 16); + CAST_F1(l, r, 6, 16); + CAST_F3(r, l, 5, 16); + CAST_F2(l, r, 4, 16); + CAST_F1(r, l, 3, 16); + CAST_F3(l, r, 2, 16); + CAST_F2(r, l, 1, 16); + CAST_F1(l, r, 0, 16); /* Put l,r into outblock */ PUT_UINT32BE(r, outBlock, 0); PUT_UINT32BE(l, outBlock, 4); @@ -633,8 +633,8 @@ DECLSPEC void Cast5SetKey (PRIVATE_AS CAST_KEY *key, u32 keylength, PRIVATE_AS c GET_UINT32BE(X[2], userKey, 8); GET_UINT32BE(X[3], userKey, 12); - #define x(i) GETBYTE(X[i/4], 3-i%4) - #define z(i) GETBYTE(Z[i/4], 3-i%4) + #define x(i) GETBYTE(X[i/4], 3-i%4) + #define z(i) GETBYTE(Z[i/4], 3-i%4) for (i=0; i<=16; i+=16) { // this part is copied directly from RFC 2144 (with some search and replace) by Wei Dai @@ -673,11 +673,11 @@ DECLSPEC void Cast5SetKey (PRIVATE_AS CAST_KEY *key, u32 keylength, PRIVATE_AS c } u32 data[32]; - for (i = 0; i < 16; i++) { - data[i * 2] = K[i]; - data[i * 2 + 1] = ((K[i + 16]) + 16) & 0x1f; // here only the lowest 5 bits are set.. - } - for (i=16; i<32; i++) - K[i] &= 0x1f; + for (i = 0; i < 16; i++) { + data[i * 2] = K[i]; + data[i * 2 + 1] = ((K[i + 16]) + 16) & 0x1f; // here only the lowest 5 bits are set.. + } + + for (i=16; i<32; i++) K[i] &= 0x1f; } diff --git a/OpenCL/inc_cipher_cast.h b/OpenCL/inc_cipher_cast.h index 7b96dc558..46a511ec7 100644 --- a/OpenCL/inc_cipher_cast.h +++ b/OpenCL/inc_cipher_cast.h @@ -1,7 +1,5 @@ - - -#ifndef _OPENCL_CAST_H -#define _OPENCL_CAST_H +#ifndef INC_CIPHER_CAST_H +#define INC_CIPHER_CAST_H // #include "opencl_misc.h" #define GET_UINT32BE(n, b, i) \ @@ -32,28 +30,26 @@ typedef struct { #define U8d(x) GETBYTE(x,0) /* CAST uses three different round functions */ -#define _CAST_f1(l, r, km, kr) \ +#define CAST_f1(l, r, km, kr) \ t = hc_rotl32_S(km + r, kr); \ l ^= ((s_S[0][U8a(t)] ^ s_S[1][U8b(t)]) - \ s_S[2][U8c(t)]) + s_S[3][U8d(t)]; -#define _CAST_f2(l, r, km, kr) \ +#define CAST_f2(l, r, km, kr) \ t = hc_rotl32_S(km ^ r, kr); \ l ^= ((s_S[0][U8a(t)] - s_S[1][U8b(t)]) + \ s_S[2][U8c(t)]) ^ s_S[3][U8d(t)]; -#define _CAST_f3(l, r, km, kr) \ +#define CAST_f3(l, r, km, kr) \ t = hc_rotl32_S(km - r, kr); \ l ^= ((s_S[0][U8a(t)] + s_S[1][U8b(t)]) ^ \ s_S[2][U8c(t)]) - s_S[3][U8d(t)]; -#define _CAST_F1(l, r, i, j) _CAST_f1(l, r, K[i], K[i+j]) -#define _CAST_F2(l, r, i, j) _CAST_f2(l, r, K[i], K[i+j]) -#define _CAST_F3(l, r, i, j) _CAST_f3(l, r, K[i], K[i+j]) - +#define CAST_F1(l, r, i, j) CAST_f1(l, r, K[i], K[i+j]) +#define CAST_F2(l, r, i, j) CAST_f2(l, r, K[i], K[i+j]) +#define CAST_F3(l, r, i, j) CAST_f3(l, r, K[i], K[i+j]) /* OpenSSL API compatibility */ #define CAST_set_key(ckey, len, key) Cast5SetKey(ckey, len, key) #define CAST_ecb_encrypt(in, out, ckey) Cast5Encrypt(in, out, ckey) #define CAST_ecb_decrypt(in, out, ckey) Cast5Decrypt(in, out, ckey) - -#endif /* _OPENCL_CAST_H */ +#endif /* INC_CIPHER_CAST_H */ diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..aef8969c1 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -134,6 +134,7 @@ - Help: show supported hash-modes only with -hh - Makefile: prevent make failure with Apple Silicon in case of partial rebuild - Rules: Rename best64.rule to best66.rule and remove the unknown section from it +- Kernel: Renamed multiple defines in CAST cipher to fit expected naming convention of the C++ language standard * changes v6.2.5 -> v6.2.6 From 5efbd2f435511fd055a648759a2d8d1aec47c9c6 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 31 Oct 2024 18:17:34 +0100 Subject: [PATCH 026/252] Fixed clang identification in src/Makefile --- docs/changes.txt | 1 + src/Makefile | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..96dd0e729 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -88,6 +88,7 @@ - Fixed build failed for 18600 with Apple Metal - Fixed build failed for 4410 with vector width > 1 - Fixed build failure for almost all hash modes that make use of hc_swap64 and/or hc_swap64_S with Apple Metal +- Fixed clang identification in src/Makefile - Fixed debug mode 5 by adding the missing colon between original-word and finding-rule - Fixed display problem of the "Optimizers applied" list for algorithms using OPTI_TYPE_SLOW_HASH_SIMD_INIT2 and/or OPTI_TYPE_SLOW_HASH_SIMD_LOOP2 - Fixed incompatible pointer types (salt1 and salt2 buf) in 3730 a3 kernel diff --git a/src/Makefile b/src/Makefile index 1cd440645..786fb4b19 100644 --- a/src/Makefile +++ b/src/Makefile @@ -37,6 +37,8 @@ endif ifeq ($(DEBUG),1) $(info "## Detected Operating System : $(UNAME)") +$(info "## Detected CC : $(CC)") +$(info "## Detected CXX : $(CXX)") endif ## @@ -188,15 +190,17 @@ CFLAGS += -Wextra endif ## because LZMA SDK -ifeq ($(CC),clang) -#No longer supported in clang 10.0.0 -#CFLAGS += -Wno-enum-conversion +ifneq (,$(findstring clang, $(CC))) CFLAGS += -Wno-typedef-redefinition +else +ifeq ($(CC),cc) +CFLAGS += -Wno-typedef-redefinition +endif endif ifeq ($(USE_SYSTEM_LZMA),0) CFLAGS_LZMA += -D_7ZIP_ST -ifneq ($(CC),clang) +ifeq (,$(findstring clang, $(CC))) CFLAGS_LZMA += -Wno-misleading-indentation endif endif @@ -208,12 +212,15 @@ CFLAGS_ZLIB += -Wno-implicit-function-declaration CFLAGS_ZLIB += -Wno-unused-parameter CFLAGS_ZLIB += -DIOAPI_NO_64 CFLAGS_ZLIB += -DUNZ_BUFSIZE=262144 +ifneq (,$(findstring clang, $(CC))) +CFLAGS_ZLIB += -Wno-deprecated-non-prototype -Wno-unknown-warning-option +endif endif ## because UNRAR ifeq ($(ENABLE_UNRAR),1) ifeq ($(USE_SYSTEM_UNRAR),0) -ifneq ($(CC),clang) +ifeq (,$(findstring clang, $(CC))) CFLAGS_UNRAR += -Wno-class-memaccess CFLAGS_UNRAR += -Wno-misleading-indentation CFLAGS_UNRAR += -Wno-format-overflow From db814b583703a7f9ca3f3791f27a0b0f2637d4f9 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 31 Oct 2024 18:29:23 +0100 Subject: [PATCH 027/252] Update PR #3735 --- OpenCL/inc_common.cl | 4 ++-- docs/changes.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenCL/inc_common.cl b/OpenCL/inc_common.cl index 818b32e69..6976daed6 100644 --- a/OpenCL/inc_common.cl +++ b/OpenCL/inc_common.cl @@ -1317,7 +1317,7 @@ DECLSPEC u64x hc_swap64 (const u64x v) asm volatile ("mov.b64 %0, {%1, %2};" : "=l"(r.sf) : "r"(tr.sf), "r"(tl.sf)); #endif - #elif defined IS_METAL + #elif defined IS_METAL || defined IS_APPLE_SILICON const u32x a0 = h32_from_64 (v); const u32x a1 = l32_from_64 (v); @@ -1391,7 +1391,7 @@ DECLSPEC u64 hc_swap64_S (const u64 v) asm volatile ("mov.b64 %0, {%1, %2};" : "=l"(r) : "r"(tr), "r"(tl)); - #elif defined IS_METAL + #elif defined IS_METAL || defined IS_APPLE_SILICON const u32 v0 = h32_from_64_S (v); const u32 v1 = l32_from_64_S (v); diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..8e0579a0d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -87,7 +87,7 @@ - Fixed build failed for 18400 with Apple Metal - Fixed build failed for 18600 with Apple Metal - Fixed build failed for 4410 with vector width > 1 -- Fixed build failure for almost all hash modes that make use of hc_swap64 and/or hc_swap64_S with Apple Metal +- Fixed build failure for almost all hash modes that make use of hc_swap64 and/or hc_swap64_S with Apple Metal / Apple Silicon - Fixed debug mode 5 by adding the missing colon between original-word and finding-rule - Fixed display problem of the "Optimizers applied" list for algorithms using OPTI_TYPE_SLOW_HASH_SIMD_INIT2 and/or OPTI_TYPE_SLOW_HASH_SIMD_LOOP2 - Fixed incompatible pointer types (salt1 and salt2 buf) in 3730 a3 kernel From d93d208ad8174cded81346a64c9a34340188c0f0 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 31 Oct 2024 18:43:35 +0100 Subject: [PATCH 028/252] Modules: Added module_unstable_warning for 22500, update module_unstable_warning for 10700 --- docs/changes.txt | 1 + src/modules/module_10700.c | 7 ++----- src/modules/module_22500.c | 13 ++++++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..37d53e24d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -118,6 +118,7 @@ - Building: Support building windows binaries on macOS using MinGW - Dependencies: Updated OpenCL-Headers to v2023.04.17 - Documents: Updated BUILD.md and added BUILD_macOS.md (containing instructions for building windows binaries on macOS) +- Modules: Added module_unstable_warning for 22500, update module_unstable_warning for 10700 - Modules: Added support for non-zero IVs for -m 6800 (Lastpass). Also added `tools/lastpass2hashcat.py` - Open Document Format: Added support for small documents with content length < 1024 - Status Code: Add specific return code for self-test fail (-11) diff --git a/src/modules/module_10700.c b/src/modules/module_10700.c index 05be37b65..a28e79829 100644 --- a/src/modules/module_10700.c +++ b/src/modules/module_10700.c @@ -84,13 +84,10 @@ static const int ROUNDS_PDF17L8 = 64; bool module_unstable_warning (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hc_device_param_t *device_param) { - // AppleM1, OpenCL, MTLCompilerService, createKernel never-end with pure kernel + // AppleM1, OpenCL, MTLCompilerService, createKernel never-end with pure kernel and newComputePipelineState failed with optimized kernel if ((device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE) && (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)) { - if ((hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL) == 0) - { - return true; - } + return true; } return false; diff --git a/src/modules/module_22500.c b/src/modules/module_22500.c index 534539b4e..9f47c6689 100644 --- a/src/modules/module_22500.c +++ b/src/modules/module_22500.c @@ -43,6 +43,17 @@ const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, static const char *SIGNATURE_MULTIBIT = "$multibit$"; +bool module_unstable_warning (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra, MAYBE_UNUSED const hc_device_param_t *device_param) +{ + // AppleM1, OpenCL, MTLCompilerService never-end + if ((device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE) && (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)) + { + return true; + } + + return false; +} + 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) { const bool optimized_kernel = (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL); @@ -228,6 +239,6 @@ void module_init (module_ctx_t *module_ctx) 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_unstable_warning = module_unstable_warning; module_ctx->module_warmup_disable = MODULE_DEFAULT; } From 3a3453c9dd5300747b980e57e9c5bd38f3afd54f Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sun, 3 Nov 2024 03:23:20 +0100 Subject: [PATCH 029/252] Added hash-mode: md5(md5(md5($pass.$salt1)).$salt2) --- OpenCL/m32800_a0-pure.cl | 335 +++++++++++++++++++++++++++++++++ OpenCL/m32800_a1-pure.cl | 329 ++++++++++++++++++++++++++++++++ OpenCL/m32800_a3-pure.cl | 355 +++++++++++++++++++++++++++++++++++ docs/changes.txt | 1 + docs/readme.txt | 1 + src/modules/module_32800.c | 275 +++++++++++++++++++++++++++ tools/test_modules/m32800.pm | 46 +++++ 7 files changed, 1342 insertions(+) create mode 100644 OpenCL/m32800_a0-pure.cl create mode 100644 OpenCL/m32800_a1-pure.cl create mode 100644 OpenCL/m32800_a3-pure.cl create mode 100644 src/modules/module_32800.c create mode 100644 tools/test_modules/m32800.pm diff --git a/OpenCL/m32800_a0-pure.cl b/OpenCL/m32800_a0-pure.cl new file mode 100644 index 000000000..9df5a7b80 --- /dev/null +++ b/OpenCL/m32800_a0-pure.cl @@ -0,0 +1,335 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#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_md5.cl) +#endif + +#if VECT_SIZE == 1 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i)]) +#elif VECT_SIZE == 2 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1]) +#elif VECT_SIZE == 4 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3]) +#elif VECT_SIZE == 8 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7]) +#elif VECT_SIZE == 16 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7], l_bin2asc[(i).s8], l_bin2asc[(i).s9], l_bin2asc[(i).sa], l_bin2asc[(i).sb], l_bin2asc[(i).sc], l_bin2asc[(i).sd], l_bin2asc[(i).se], l_bin2asc[(i).sf]) +#endif + +typedef struct md5_double_salt +{ + u32 salt1_buf[64]; + int salt1_len; + + u32 salt2_buf[64]; + int salt2_len; + +} md5_double_salt_t; + +KERNEL_FQ void m32800_mxx (KERN_ATTR_RULES_ESALT (md5_double_salt_t)) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /** + * bin2asc uppercase table + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 8 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 0; + } + + SYNC_THREADS (); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + const u32 salt1_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_len; + + u32 salt1_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt1_len; i += 4, idx += 1) + { + salt1_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_buf[idx]; + } + + const u32 salt2_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_len; + + u32 salt2_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt2_len; i += 4, idx += 1) + { + salt2_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_buf[idx]; + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + md5_ctx_t ctx0; + + md5_init (&ctx0); + + md5_update (&ctx0, tmp.i, tmp.pw_len); + + md5_update (&ctx0, salt1_buf, salt1_len); + + md5_final (&ctx0); + + u32 a = ctx0.h[0]; + u32 b = ctx0.h[1]; + u32 c = ctx0.h[2]; + u32 d = ctx0.h[3]; + + md5_ctx_t ctx; + + md5_init (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_final (&ctx); + + a = ctx.h[0]; + b = ctx.h[1]; + c = ctx.h[2]; + d = ctx.h[3]; + + md5_init (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_update (&ctx, salt2_buf, salt2_len); + + md5_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m32800_sxx (KERN_ATTR_RULES_ESALT (md5_double_salt_t)) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /** + * bin2asc uppercase table + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 8 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 0; + } + + SYNC_THREADS (); + + 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 + */ + + COPY_PW (pws[gid]); + + const u32 salt1_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_len; + + u32 salt1_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt1_len; i += 4, idx += 1) + { + salt1_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_buf[idx]; + } + + const u32 salt2_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_len; + + u32 salt2_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt2_len; i += 4, idx += 1) + { + salt2_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_buf[idx]; + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + md5_ctx_t ctx0; + + md5_init (&ctx0); + + md5_update (&ctx0, tmp.i, tmp.pw_len); + + md5_update (&ctx0, salt1_buf, salt1_len); + + md5_final (&ctx0); + + u32 a = ctx0.h[0]; + u32 b = ctx0.h[1]; + u32 c = ctx0.h[2]; + u32 d = ctx0.h[3]; + + md5_ctx_t ctx; + + md5_init (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_final (&ctx); + + a = ctx.h[0]; + b = ctx.h[1]; + c = ctx.h[2]; + d = ctx.h[3]; + + md5_init (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_update (&ctx, salt2_buf, salt2_len); + + md5_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m32800_a1-pure.cl b/OpenCL/m32800_a1-pure.cl new file mode 100644 index 000000000..756df73ab --- /dev/null +++ b/OpenCL/m32800_a1-pure.cl @@ -0,0 +1,329 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#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_md5.cl) +#endif + +#if VECT_SIZE == 1 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i)]) +#elif VECT_SIZE == 2 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1]) +#elif VECT_SIZE == 4 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3]) +#elif VECT_SIZE == 8 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7]) +#elif VECT_SIZE == 16 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7], l_bin2asc[(i).s8], l_bin2asc[(i).s9], l_bin2asc[(i).sa], l_bin2asc[(i).sb], l_bin2asc[(i).sc], l_bin2asc[(i).sd], l_bin2asc[(i).se], l_bin2asc[(i).sf]) +#endif + +typedef struct md5_double_salt +{ + u32 salt1_buf[64]; + int salt1_len; + + u32 salt2_buf[64]; + int salt2_len; + +} md5_double_salt_t; + +KERNEL_FQ void m32800_mxx (KERN_ATTR_ESALT (md5_double_salt_t)) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /** + * bin2asc uppercase array + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 8 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 0; + } + + SYNC_THREADS (); + + if (gid >= GID_CNT) return; + + const u32 salt1_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_len; + + u32 salt1_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt1_len; i += 4, idx += 1) + { + salt1_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_buf[idx]; + } + + const u32 salt2_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_len; + + u32 salt2_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt2_len; i += 4, idx += 1) + { + salt2_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_buf[idx]; + } + + /** + * base + */ + + md5_ctx_t ctx0; + + md5_init (&ctx0); + + md5_update_global (&ctx0, pws[gid].i, pws[gid].pw_len); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + md5_ctx_t ctx1 = ctx0; + + md5_update_global (&ctx1, combs_buf[il_pos].i, combs_buf[il_pos].pw_len); + + md5_update (&ctx1, salt1_buf, salt1_len); + + md5_final (&ctx1); + + u32 a = ctx1.h[0]; + u32 b = ctx1.h[1]; + u32 c = ctx1.h[2]; + u32 d = ctx1.h[3]; + + md5_ctx_t ctx; + + md5_init (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_final (&ctx); + + a = ctx.h[0]; + b = ctx.h[1]; + c = ctx.h[2]; + d = ctx.h[3]; + + md5_init (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_update (&ctx, salt2_buf, salt2_len); + + md5_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m32800_sxx (KERN_ATTR_ESALT (md5_double_salt_t)) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /** + * bin2asc uppercase array + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 8 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 0; + } + + SYNC_THREADS (); + + 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] + }; + + const u32 salt1_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_len; + + u32 salt1_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt1_len; i += 4, idx += 1) + { + salt1_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_buf[idx]; + } + + const u32 salt2_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_len; + + u32 salt2_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt2_len; i += 4, idx += 1) + { + salt2_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_buf[idx]; + } + + /** + * base + */ + + md5_ctx_t ctx0; + + md5_init (&ctx0); + + md5_update_global (&ctx0, pws[gid].i, pws[gid].pw_len); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + md5_ctx_t ctx1 = ctx0; + + md5_update_global (&ctx1, combs_buf[il_pos].i, combs_buf[il_pos].pw_len); + + md5_update (&ctx1, salt1_buf, salt1_len); + + md5_final (&ctx1); + + u32 a = ctx1.h[0]; + u32 b = ctx1.h[1]; + u32 c = ctx1.h[2]; + u32 d = ctx1.h[3]; + + md5_ctx_t ctx; + + md5_init (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_final (&ctx); + + a = ctx.h[0]; + b = ctx.h[1]; + c = ctx.h[2]; + d = ctx.h[3]; + + md5_init (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_update (&ctx, salt2_buf, salt2_len); + + md5_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m32800_a3-pure.cl b/OpenCL/m32800_a3-pure.cl new file mode 100644 index 000000000..531785dde --- /dev/null +++ b/OpenCL/m32800_a3-pure.cl @@ -0,0 +1,355 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#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_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_md5.cl) +#endif + +#if VECT_SIZE == 1 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i)]) +#elif VECT_SIZE == 2 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1]) +#elif VECT_SIZE == 4 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3]) +#elif VECT_SIZE == 8 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7]) +#elif VECT_SIZE == 16 +#define uint_to_hex_lower8(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7], l_bin2asc[(i).s8], l_bin2asc[(i).s9], l_bin2asc[(i).sa], l_bin2asc[(i).sb], l_bin2asc[(i).sc], l_bin2asc[(i).sd], l_bin2asc[(i).se], l_bin2asc[(i).sf]) +#endif + +typedef struct md5_double_salt +{ + u32 salt1_buf[64]; + int salt1_len; + + u32 salt2_buf[64]; + int salt2_len; + +} md5_double_salt_t; + +KERNEL_FQ void m32800_mxx (KERN_ATTR_VECTOR_ESALT (md5_double_salt_t)) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /* + * bin2asc uppercase table + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 8 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 0; + } + + SYNC_THREADS (); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt1_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_len; + + u32x salt1_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt1_len; i += 4, idx += 1) + { + salt1_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_buf[idx]; + } + + const u32 salt2_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_len; + + u32x salt2_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt2_len; i += 4, idx += 1) + { + salt2_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_buf[idx]; + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + md5_ctx_vector_t ctx0; + + md5_init_vector (&ctx0); + + md5_update_vector (&ctx0, w, pw_len); + + md5_update_vector (&ctx0, salt1_buf, salt1_len); + + md5_final_vector (&ctx0); + + u32x a = ctx0.h[0]; + u32x b = ctx0.h[1]; + u32x c = ctx0.h[2]; + u32x d = ctx0.h[3]; + + md5_ctx_vector_t ctx; + + md5_init_vector (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_final_vector (&ctx); + + a = ctx.h[0]; + b = ctx.h[1]; + c = ctx.h[2]; + d = ctx.h[3]; + + md5_init_vector (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_update_vector (&ctx, salt2_buf, salt2_len); + + md5_final_vector (&ctx); + + const u32x r0 = ctx.h[DGST_R0]; + const u32x r1 = ctx.h[DGST_R1]; + const u32x r2 = ctx.h[DGST_R2]; + const u32x r3 = ctx.h[DGST_R3]; + + COMPARE_M_SIMD (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m32800_sxx (KERN_ATTR_VECTOR_ESALT (md5_double_salt_t)) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /* + * bin2asc uppercase table + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 8 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 0; + } + + SYNC_THREADS (); + + 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; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt1_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_len; + + u32x salt1_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt1_len; i += 4, idx += 1) + { + salt1_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt1_buf[idx]; + } + + const u32 salt2_len = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_len; + + u32x salt2_buf[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt2_len; i += 4, idx += 1) + { + salt2_buf[idx] = esalt_bufs[DIGESTS_OFFSET_HOST].salt2_buf[idx]; + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + md5_ctx_vector_t ctx0; + + md5_init_vector (&ctx0); + + md5_update_vector (&ctx0, w, pw_len); + + md5_update_vector (&ctx0, salt1_buf, salt1_len); + + md5_final_vector (&ctx0); + + u32x a = ctx0.h[0]; + u32x b = ctx0.h[1]; + u32x c = ctx0.h[2]; + u32x d = ctx0.h[3]; + + md5_ctx_vector_t ctx; + + md5_init_vector (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_final_vector (&ctx); + + a = ctx.h[0]; + b = ctx.h[1]; + c = ctx.h[2]; + d = ctx.h[3]; + + md5_init_vector (&ctx); + + ctx.w0[0] = uint_to_hex_lower8 ((a >> 0) & 255) << 0 + | uint_to_hex_lower8 ((a >> 8) & 255) << 16; + ctx.w0[1] = uint_to_hex_lower8 ((a >> 16) & 255) << 0 + | uint_to_hex_lower8 ((a >> 24) & 255) << 16; + ctx.w0[2] = uint_to_hex_lower8 ((b >> 0) & 255) << 0 + | uint_to_hex_lower8 ((b >> 8) & 255) << 16; + ctx.w0[3] = uint_to_hex_lower8 ((b >> 16) & 255) << 0 + | uint_to_hex_lower8 ((b >> 24) & 255) << 16; + ctx.w1[0] = uint_to_hex_lower8 ((c >> 0) & 255) << 0 + | uint_to_hex_lower8 ((c >> 8) & 255) << 16; + ctx.w1[1] = uint_to_hex_lower8 ((c >> 16) & 255) << 0 + | uint_to_hex_lower8 ((c >> 24) & 255) << 16; + ctx.w1[2] = uint_to_hex_lower8 ((d >> 0) & 255) << 0 + | uint_to_hex_lower8 ((d >> 8) & 255) << 16; + ctx.w1[3] = uint_to_hex_lower8 ((d >> 16) & 255) << 0 + | uint_to_hex_lower8 ((d >> 24) & 255) << 16; + + ctx.len = 32; + + md5_update_vector (&ctx, salt2_buf, salt2_len); + + md5_final_vector (&ctx); + + const u32x r0 = ctx.h[DGST_R0]; + const u32x r1 = ctx.h[DGST_R1]; + const u32x r2 = ctx.h[DGST_R2]; + const u32x r3 = ctx.h[DGST_R3]; + + COMPARE_S_SIMD (r0, r1, r2, r3); + } +} diff --git a/docs/changes.txt b/docs/changes.txt index 283e3c0d4..5cf5a62bc 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -49,6 +49,7 @@ - Added hash-mode: md5(md5($salt).md5(md5($pass))) - Added hash-mode: Domain Cached Credentials 2 (DCC2), MS Cache 2, (NT) - Added hash-mode: Domain Cached Credentials (DCC), MS Cache (NT) +- Added hash-mode: md5(md5(md5($pass.$salt1)).$salt2) - Added hash-mode: md5(md5(md5($pass).$salt1).$salt2) - Added hash-mode: md5(md5(md5($pass)).$salt) - Added hash-mode: md5(sha1($pass.$salt)) diff --git a/docs/readme.txt b/docs/readme.txt index e5fd69f25..4a5bfa7a7 100644 --- a/docs/readme.txt +++ b/docs/readme.txt @@ -94,6 +94,7 @@ NVIDIA GPUs require "NVIDIA Driver" (440.64 or later) and "CUDA Toolkit" (9.0 or - md5(md5(md5($pass))) - md5(md5(md5($pass)).$salt) - md5(md5(md5($pass).$salt1).$salt2) +- md5(md5(md5($pass.$salt1)).$salt2) - md5(sha1($pass)) - md5(sha1($pass).$salt) - md5(sha1($pass).md5($pass).sha1($pass)) diff --git a/src/modules/module_32800.c b/src/modules/module_32800.c new file mode 100644 index 000000000..0d2469591 --- /dev/null +++ b/src/modules/module_32800.c @@ -0,0 +1,275 @@ +/** + * 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 "emu_inc_hash_md5.h" + +static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 3; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 1; +static const u32 DGST_SIZE = DGST_SIZE_4_4; +static const u32 HASH_CATEGORY = HASH_CATEGORY_RAW_HASH_SALTED; +static const char *HASH_NAME = "md5(md5(md5($pass.$salt1)).$salt2)"; +static const u64 KERN_TYPE = 32800; +static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE + | OPTS_TYPE_PT_ADD80 + | OPTS_TYPE_PT_ADDBITS14; +static const u32 SALT_TYPE = SALT_TYPE_GENERIC; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "2c749af6c65cf3e82e5837e3056727f5:59331674906582121215362940957615121466283616005471:17254656838978443692786064919357750120910718779182716907569266"; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +typedef struct md5_double_salt +{ + u32 salt1_buf[64]; + int salt1_len; + + u32 salt2_buf[64]; + int salt2_len; + +} md5_double_salt_t; + +u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + const u64 esalt_size = (const u64) sizeof (md5_double_salt_t); + + return esalt_size; +} + +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; + + md5_double_salt_t *md5_double_salt = (md5_double_salt_t *) esalt_buf; + + hc_token_t token; + + memset (&token, 0, sizeof (hc_token_t)); + + token.token_cnt = 3; + + token.sep[0] = hashconfig->separator; + token.len[0] = 32; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_HEX; + + token.sep[1] = hashconfig->separator; + token.len_min[1] = SALT_MIN; + token.len_max[1] = SALT_MAX; + token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH; + + token.sep[2] = hashconfig->separator; + token.len_min[2] = SALT_MIN; + token.len_max[2] = SALT_MAX; + token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH; + + if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) + { + token.len_min[1] *= 2; + token.len_max[1] *= 2; + + token.attr[1] |= TOKEN_ATTR_VERIFY_HEX; + + token.len_min[2] *= 2; + token.len_max[2] *= 2; + + token.attr[2] |= TOKEN_ATTR_VERIFY_HEX; + } + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + const u8 *hash_pos = token.buf[0]; + + digest[0] = hex_to_u32 (hash_pos + 0); + digest[1] = hex_to_u32 (hash_pos + 8); + digest[2] = hex_to_u32 (hash_pos + 16); + digest[3] = hex_to_u32 (hash_pos + 24); + + if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL) + { + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + } + + const bool parse_rc1 = generic_salt_decode (hashconfig, token.buf[1], token.len[1], (u8 *) md5_double_salt->salt1_buf, &md5_double_salt->salt1_len); + + if (parse_rc1 == false) return (PARSER_SALT_LENGTH); + + const bool parse_rc2 = generic_salt_decode (hashconfig, token.buf[2], token.len[2], (u8 *) md5_double_salt->salt2_buf, &md5_double_salt->salt2_len); + + if (parse_rc2 == false) return (PARSER_SALT_LENGTH); + + // make salt sorter happy + + md5_ctx_t md5_ctx; + + md5_init (&md5_ctx); + md5_update (&md5_ctx, md5_double_salt->salt1_buf, md5_double_salt->salt1_len); + md5_update (&md5_ctx, md5_double_salt->salt2_buf, md5_double_salt->salt2_len); + md5_final (&md5_ctx); + + salt->salt_buf[0] = md5_ctx.h[0]; + salt->salt_buf[1] = md5_ctx.h[1]; + salt->salt_buf[2] = md5_ctx.h[2]; + salt->salt_buf[3] = md5_ctx.h[3]; + + salt->salt_len = 16; + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + const md5_double_salt_t *md5_double_salt = (const md5_double_salt_t *) esalt_buf; + + // we can not change anything in the original buffer, otherwise destroying sorting + // therefore create some local buffer + + u32 tmp[4]; + + tmp[0] = digest[0]; + tmp[1] = digest[1]; + tmp[2] = digest[2]; + tmp[3] = digest[3]; + + if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL) + { + tmp[0] += MD5M_A; + tmp[1] += MD5M_B; + tmp[2] += MD5M_C; + tmp[3] += MD5M_D; + } + + u8 *out_buf = (u8 *) line_buf; + + int out_len = 0; + + u32_to_hex (tmp[0], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[1], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[2], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[3], out_buf + out_len); out_len += 8; + + out_buf[out_len] = hashconfig->separator; + + out_len += 1; + + out_len += generic_salt_encode (hashconfig, (const u8 *) md5_double_salt->salt1_buf, md5_double_salt->salt1_len, out_buf + out_len); + + out_buf[out_len] = hashconfig->separator; + + out_len += 1; + + out_len += generic_salt_encode (hashconfig, (const u8 *) md5_double_salt->salt2_buf, md5_double_salt->salt2_len, out_buf + out_len); + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_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_esalt_size; + 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_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = MODULE_DEFAULT; + module_ctx->module_pw_min = MODULE_DEFAULT; + module_ctx->module_salt_max = MODULE_DEFAULT; + module_ctx->module_salt_min = MODULE_DEFAULT; + module_ctx->module_salt_type = module_salt_type; + module_ctx->module_separator = MODULE_DEFAULT; + module_ctx->module_st_hash = module_st_hash; + module_ctx->module_st_pass = module_st_pass; + module_ctx->module_tmp_size = MODULE_DEFAULT; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} diff --git a/tools/test_modules/m32800.pm b/tools/test_modules/m32800.pm new file mode 100644 index 000000000..e283dcafd --- /dev/null +++ b/tools/test_modules/m32800.pm @@ -0,0 +1,46 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Digest::MD5 qw (md5_hex); + +sub module_constraints { [[0, 256], [0, 256], [-1, -1], [-1, -1], [-1, -1]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt1 = shift; + my $salt2 = shift || random_numeric_string (random_number (1, 255)); + + my $digest = md5_hex (md5_hex (md5_hex ($word . $salt1)) . $salt2); + + my $hash = sprintf ("%s:%s:%s", $digest, $salt1, $salt2); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my ($hash, $salt1, $salt2, $word) = split (':', $line); + + return unless defined $hash; + return unless defined $salt1; + return unless defined $salt2; + return unless defined $word; + + my $word_packed = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word_packed, $salt1, $salt2); + + return ($new_hash, $word); +} + +1; From d6b50c7d0b495220e09fcbb079726af360fdf870 Mon Sep 17 00:00:00 2001 From: Nripesh Niketan Date: Wed, 6 Nov 2024 10:29:13 +0000 Subject: [PATCH 030/252] chore: update github workflow --- .github/workflows/build.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 81990ba77..44fa387e0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -49,13 +49,13 @@ jobs: name: Build Linux (${{ matrix.shared == 0 && 'Static' || 'Shared' }}) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build env: SHARED: ${{ matrix.shared }} run: make - name: Generate artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: hashcat-linux-${{ matrix.shared == 0 && 'static' || 'shared' }} path: ${{ env.include_paths }} @@ -68,13 +68,13 @@ jobs: name: Build macOS (${{ matrix.shared == 0 && 'Static' || 'Shared' }}) runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build env: SHARED: ${{ matrix.shared }} run: make - name: Generate artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: hashcat-macos-${{ matrix.shared == 0 && 'static' || 'shared' }} path: ${{ env.include_paths }} @@ -97,14 +97,14 @@ jobs: libiconv libiconv-devel make - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build shell: msys2 {0} env: SHARED: ${{ matrix.shared }} run: make - name: Generate artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: hashcat-windows-${{ matrix.shared == 0 && 'static' || 'shared' }} path: ${{ env.include_paths }} From 620731c8e8d9269a9eea4d4b3345600ffdaa3bde Mon Sep 17 00:00:00 2001 From: Nripesh Niketan Date: Wed, 6 Nov 2024 10:31:15 +0000 Subject: [PATCH 031/252] Optimize github workflow --- .github/workflows/build.yml | 77 ++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 44fa387e0..4dbbda26f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,53 +41,36 @@ on: - '.github/workflows/build.yml' jobs: - build-linux: + build: strategy: fail-fast: false matrix: - shared: [0, 1] - name: Build Linux (${{ matrix.shared == 0 && 'Static' || 'Shared' }}) - runs-on: ubuntu-latest + include: + - os: ubuntu-latest + os_name: linux + shared: 0 + - os: ubuntu-latest + os_name: linux + shared: 1 + - os: macos-latest + os_name: macos + shared: 0 + - os: macos-latest + os_name: macos + shared: 1 + - os: windows-latest + os_name: windows + shared: 0 + - os: windows-latest + os_name: windows + shared: 1 + name: Build ${{ matrix.os_name }} (${{ matrix.shared == 0 && 'Static' || 'Shared' }}) + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - - name: Build - env: - SHARED: ${{ matrix.shared }} - run: make - - name: Generate artifacts - uses: actions/upload-artifact@v4 - with: - name: hashcat-linux-${{ matrix.shared == 0 && 'static' || 'shared' }} - path: ${{ env.include_paths }} - build-macos: - strategy: - fail-fast: false - matrix: - shared: [0, 1] - name: Build macOS (${{ matrix.shared == 0 && 'Static' || 'Shared' }}) - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - name: Build - env: - SHARED: ${{ matrix.shared }} - run: make - - name: Generate artifacts - uses: actions/upload-artifact@v4 - with: - name: hashcat-macos-${{ matrix.shared == 0 && 'static' || 'shared' }} - path: ${{ env.include_paths }} - - build-windows: - strategy: - fail-fast: false - matrix: - shared: [0, 1] - name: Build Windows (${{ matrix.shared == 0 && 'Static' || 'Shared' }}) - runs-on: windows-latest - steps: - - name: Install libiconv + - name: Install dependencies (Windows only) + if: matrix.os_name == 'windows' uses: msys2/setup-msys2@v2 with: update: true @@ -97,14 +80,22 @@ jobs: libiconv libiconv-devel make - - uses: actions/checkout@v4 + - name: Build + if: matrix.os_name == 'windows' shell: msys2 {0} env: SHARED: ${{ matrix.shared }} run: make + + - name: Build + if: matrix.os_name != 'windows' + env: + SHARED: ${{ matrix.shared }} + run: make + - name: Generate artifacts uses: actions/upload-artifact@v4 with: - name: hashcat-windows-${{ matrix.shared == 0 && 'static' || 'shared' }} + name: hashcat-${{ matrix.os_name }}-${{ matrix.shared == 0 && 'static' || 'shared' }} path: ${{ env.include_paths }} From 0ba76629c0164e9c5b077fc0f5f06e3c7bbb873e Mon Sep 17 00:00:00 2001 From: wizardsd Date: Thu, 7 Nov 2024 12:47:36 +0300 Subject: [PATCH 032/252] Fixed a host buffer overflow bug when copying rules from host to device --- src/backend.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/backend.c b/src/backend.c index f7c916e1d..59b287cdc 100644 --- a/src/backend.c +++ b/src/backend.c @@ -9817,8 +9817,9 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) u32 aligned_rules_cnt = MAX (MAX (straight_ctx->kernel_rules_cnt, device_param->kernel_loops_min), KERNEL_RULES); - u64 size_rules = (u64) aligned_rules_cnt * sizeof (kernel_rule_t); - u64 size_rules_c = (u64) KERNEL_RULES * sizeof (kernel_rule_t); + u64 size_rules = (u64) aligned_rules_cnt * sizeof (kernel_rule_t); + u64 size_rules_src = (u64) straight_ctx->kernel_rules_cnt * sizeof (kernel_rule_t); // size of source rules buffer can be less than aligned_rules_cnt + u64 size_rules_c = (u64) KERNEL_RULES * sizeof (kernel_rule_t); device_param->size_rules = size_rules; device_param->size_rules_c = size_rules_c; @@ -10872,7 +10873,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_rules_c, size_rules_c) == -1) return -1; } - if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_rules, straight_ctx->kernel_rules_buf, size_rules, device_param->cuda_stream) == -1) return -1; + if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_rules, straight_ctx->kernel_rules_buf, size_rules_src, device_param->cuda_stream) == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { @@ -10983,7 +10984,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_rules_c, size_rules_c) == -1) return -1; } - if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_rules, straight_ctx->kernel_rules_buf, size_rules, device_param->hip_stream) == -1) return -1; + if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_rules, straight_ctx->kernel_rules_buf, size_rules_src, device_param->hip_stream) == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { @@ -11100,7 +11101,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) if (hc_mtlCreateBuffer (hashcat_ctx, device_param->metal_device, size_rules, NULL, &device_param->metal_d_rules) == -1) return -1; if (hc_mtlCreateBuffer (hashcat_ctx, device_param->metal_device, size_rules_c, NULL, &device_param->metal_d_rules_c) == -1) return -1; - if (hc_mtlMemcpyHtoD (hashcat_ctx, device_param->metal_command_queue, device_param->metal_d_rules, 0, straight_ctx->kernel_rules_buf, size_rules) == -1) return -1; + if (hc_mtlMemcpyHtoD (hashcat_ctx, device_param->metal_command_queue, device_param->metal_d_rules, 0, straight_ctx->kernel_rules_buf, size_rules_src) == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { @@ -11194,7 +11195,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_rules, NULL, &device_param->opencl_d_rules) == -1) return -1; if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_rules_c, NULL, &device_param->opencl_d_rules_c) == -1) return -1; - if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_rules, CL_FALSE, 0, size_rules, straight_ctx->kernel_rules_buf, 0, NULL, NULL) == -1) return -1; + if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_rules, CL_FALSE, 0, size_rules_src, straight_ctx->kernel_rules_buf, 0, NULL, NULL) == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { From 3e10c363dedbe3d1630c607e79287a2df919b12b Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Tue, 26 Nov 2024 00:08:26 +0000 Subject: [PATCH 033/252] Check additional blocks for safety --- OpenCL/m26610-pure.cl | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/OpenCL/m26610-pure.cl b/OpenCL/m26610-pure.cl index abd476395..cb02840f6 100644 --- a/OpenCL/m26610-pure.cl +++ b/OpenCL/m26610-pure.cl @@ -368,7 +368,7 @@ KERNEL_FQ void m26610_comp (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sh AES_GCM_decrypt (key, J0, ct, 32, pt, s_te0, s_te1, s_te2, s_te3, s_te4); - const int correct = is_valid_printable_32 (pt[0]) + int correct = is_valid_printable_32 (pt[0]) + is_valid_printable_32 (pt[1]) + is_valid_printable_32 (pt[2]) + is_valid_printable_32 (pt[3]) @@ -379,6 +379,37 @@ KERNEL_FQ void m26610_comp (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sh if (correct != 8) return; + u32 ct2[8]; + + ct2[0] = pbkdf2_sha256_aes_gcm->ct_buf[8]; // third block of ciphertext + ct2[1] = pbkdf2_sha256_aes_gcm->ct_buf[9]; + ct2[2] = pbkdf2_sha256_aes_gcm->ct_buf[10]; + ct2[3] = pbkdf2_sha256_aes_gcm->ct_buf[11]; + ct2[4] = pbkdf2_sha256_aes_gcm->ct_buf[12]; // fourth block of ciphertext + ct2[5] = pbkdf2_sha256_aes_gcm->ct_buf[13]; + ct2[6] = pbkdf2_sha256_aes_gcm->ct_buf[14]; + ct2[7] = pbkdf2_sha256_aes_gcm->ct_buf[15]; + + // Only a single increment as the previous AES_GCM_DECRYPT already does one for us + J0[3]++; + + u32 pt2[8] = { 0 }; + + AES_GCM_decrypt (key, J0, ct2, 32, pt2, s_te0, s_te1, s_te2, s_te3, s_te4); + + correct = is_valid_printable_32 (pt2[0]) + + is_valid_printable_32 (pt2[1]) + + is_valid_printable_32 (pt2[2]) + + is_valid_printable_32 (pt2[3]) + + is_valid_printable_32 (pt2[4]) + + is_valid_printable_32 (pt2[5]) + + is_valid_printable_32 (pt2[6]) + + is_valid_printable_32 (pt2[7]); + + // We need to check a second and third block to avoid extremely rare false-positives. See: + // https://github.com/hashcat/hashcat/issues/4121 + if (correct != 8) return; + /* const int pt_len = 28; // not using 32 byte but 28 because our UTF8 allows up to 4 byte per character and since we decrypt 32 byte // only we can't guarantee it is not in the middle of a UTF8 byte stream at that point From dcfa17100ea13b27f5bd18c8ed2bf1b99ce276e4 Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Tue, 26 Nov 2024 00:09:53 +0000 Subject: [PATCH 034/252] Minor typo fix --- OpenCL/m26610-pure.cl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenCL/m26610-pure.cl b/OpenCL/m26610-pure.cl index cb02840f6..9815eb8dd 100644 --- a/OpenCL/m26610-pure.cl +++ b/OpenCL/m26610-pure.cl @@ -406,7 +406,7 @@ KERNEL_FQ void m26610_comp (KERN_ATTR_TMPS_ESALT (pbkdf2_sha256_tmp_t, pbkdf2_sh + is_valid_printable_32 (pt2[6]) + is_valid_printable_32 (pt2[7]); - // We need to check a second and third block to avoid extremely rare false-positives. See: + // We need to check a third and fourth block to avoid extremely rare false-positives. See: // https://github.com/hashcat/hashcat/issues/4121 if (correct != 8) return; From 5b26392adb7d26f67961bfd8856d788b1287b2c6 Mon Sep 17 00:00:00 2001 From: Code Curiously <67614186+codecuriously@users.noreply.github.com> Date: Sun, 1 Dec 2024 19:20:26 +0000 Subject: [PATCH 035/252] Fix RAM usage bug for Linux Apple Silicon #4125 --- src/backend.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend.c b/src/backend.c index f7c916e1d..088cb40cb 100644 --- a/src/backend.c +++ b/src/backend.c @@ -8035,7 +8035,8 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) device_param->device_available_mem = device_param->device_global_mem - MAX_ALLOC_CHECKS_SIZE; - if ((device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) && ((device_param->opencl_platform_vendor_id != VENDOR_ID_INTEL_SDK) || (device_param->device_host_unified_memory == 0))) + if ((device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) && + (((device_param->opencl_platform_vendor_id != VENDOR_ID_INTEL_SDK) && (device_param->opencl_platform_vendor_id != VENDOR_ID_GENERIC)) || (device_param->device_host_unified_memory == 0))) { // OK, so the problem here is the following: // There's just CL_DEVICE_GLOBAL_MEM_SIZE to ask OpenCL about the total memory on the device, From 731aad106deb08af70b14a5f7d0ae42ef1adb8b8 Mon Sep 17 00:00:00 2001 From: Nripesh Niketan Date: Wed, 4 Dec 2024 17:45:51 +0000 Subject: [PATCH 036/252] Updated workflow as requested --- .github/workflows/build.yml | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4dbbda26f..aace6f77b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,32 +45,24 @@ jobs: strategy: fail-fast: false matrix: + shared: [0, 1] include: - os: ubuntu-latest - os_name: linux - shared: 0 - - os: ubuntu-latest - os_name: linux - shared: 1 + os_name: Linux + os_name_lowercase: linux - os: macos-latest - os_name: macos - shared: 0 - - os: macos-latest - os_name: macos - shared: 1 + os_name: MacOS + os_name_lowercase: macos - os: windows-latest - os_name: windows - shared: 0 - - os: windows-latest - os_name: windows - shared: 1 + os_name: Windows + os_name_lowercase: windows name: Build ${{ matrix.os_name }} (${{ matrix.shared == 0 && 'Static' || 'Shared' }}) runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Install dependencies (Windows only) - if: matrix.os_name == 'windows' + if: matrix.os_name_lowercase == 'windows' uses: msys2/setup-msys2@v2 with: update: true @@ -82,14 +74,14 @@ jobs: make - name: Build - if: matrix.os_name == 'windows' + if: matrix.os_name_lowercase == 'windows' shell: msys2 {0} env: SHARED: ${{ matrix.shared }} run: make - name: Build - if: matrix.os_name != 'windows' + if: matrix.os_name_lowercase != 'windows' env: SHARED: ${{ matrix.shared }} run: make @@ -97,5 +89,5 @@ jobs: - name: Generate artifacts uses: actions/upload-artifact@v4 with: - name: hashcat-${{ matrix.os_name }}-${{ matrix.shared == 0 && 'static' || 'shared' }} + name: hashcat-${{ matrix.os_name_lowercase }}-${{ matrix.shared == 0 && 'static' || 'shared' }} path: ${{ env.include_paths }} From 475512a80e81b3c83ffe912a12e342424fd6f81c Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Fri, 6 Dec 2024 05:43:10 +0000 Subject: [PATCH 037/252] Add [b] [c] and [f] functionality in pause state Add the ability to [b]ypass, [c]heckpoint and [f]inish an attack while paused. I'm not too sure why it was limited to only [r]unning states but have not found any bugs in testing --- src/status.c | 16 ++++++++++++++-- src/thread.c | 6 ------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/status.c b/src/status.c index 4e964fd3b..be64a0743 100644 --- a/src/status.c +++ b/src/status.c @@ -35,6 +35,8 @@ static const char *const ST_0013 = "Error"; static const char *const ST_0014 = "Aborted (Finish)"; static const char *const ST_0015 = "Running (Quit after attack requested)"; static const char *const ST_0016 = "Autodetect"; +static const char *const ST_0017 = "Paused (Checkpoint Quit requested)"; +static const char *const ST_0018 = "Paused (Quit after attack requested)"; static const char *const ST_9999 = "Unknown! Bug!"; static const char UNITS[7] = { ' ', 'k', 'M', 'G', 'T', 'P', 'E' }; @@ -262,8 +264,6 @@ const char *status_get_status_string (const hashcat_ctx_t *hashcat_ctx) const int devices_status = status_ctx->devices_status; - // special case: running but checkpoint quit requested - if (devices_status == STATUS_RUNNING) { if (status_ctx->checkpoint_shutdown == true) @@ -276,6 +276,18 @@ const char *status_get_status_string (const hashcat_ctx_t *hashcat_ctx) return ST_0015; } } + else if (devices_status == STATUS_PAUSED) + { + if (status_ctx->checkpoint_shutdown == true) + { + return ST_0017; + } + + if (status_ctx->finish_shutdown == true) + { + return ST_0018; + } + } switch (devices_status) { diff --git a/src/thread.c b/src/thread.c index c33d25b8d..bfad64c38 100644 --- a/src/thread.c +++ b/src/thread.c @@ -214,8 +214,6 @@ int bypass (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - if (status_ctx->devices_status != STATUS_RUNNING) return -1; - status_ctx->devices_status = STATUS_BYPASS; status_ctx->run_main_level1 = true; @@ -262,8 +260,6 @@ int stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - if (status_ctx->devices_status != STATUS_RUNNING) return -1; - // this feature only makes sense if --restore-disable was not specified restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; @@ -305,8 +301,6 @@ int finish_after_attack (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - if (status_ctx->devices_status != STATUS_RUNNING) return -1; - // Enable or Disable if (status_ctx->finish_shutdown == false) From 3617df2f2516688617c6267f53fb8d09c491cdf3 Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Tue, 10 Dec 2024 07:57:41 +0000 Subject: [PATCH 038/252] Gracefully handle corrupt .gz archives --- src/combinator.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ src/filehandling.c | 11 +++++++++ src/straight.c | 35 ++++++++++++++++++++++++++++ src/wordlist.c | 21 +++++++++++++---- 4 files changed, 121 insertions(+), 4 deletions(-) diff --git a/src/combinator.c b/src/combinator.c index 654ada03f..5ff52d8ac 100644 --- a/src/combinator.c +++ b/src/combinator.c @@ -96,6 +96,16 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc1 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile1); + + hc_fclose (&fp1); + hc_fclose (&fp2); + + return -1; + } + if (words1_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile1); @@ -122,6 +132,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc2 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile2); + + return -1; + } + if (words2_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile2); @@ -199,6 +216,16 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc1 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile1); + + hc_fclose (&fp1); + hc_fclose (&fp2); + + return -1; + } + if (words1_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile1); @@ -225,6 +252,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc2 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile2); + + return -1; + } + if (words2_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile2); @@ -330,6 +364,16 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc1 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile1); + + hc_fclose (&fp1); + hc_fclose (&fp2); + + return -1; + } + if (words1_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile1); @@ -356,6 +400,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc2 == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile2); + + return -1; + } + if (words2_cnt == 0) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile2); @@ -412,6 +463,13 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", dictfile); + + return -1; + } + combinator_ctx->combs_cnt = words_cnt; combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_LEFT; } diff --git a/src/filehandling.c b/src/filehandling.c index 9a2d0ea39..712ccdb66 100644 --- a/src/filehandling.c +++ b/src/filehandling.c @@ -410,6 +410,17 @@ size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp) else if (fp->gfp) { n = gzfread (ptr, size, nmemb, fp->gfp); + + // Double check to make sure that it successfully read 0 bytes instead of erroring + if (n == 0) + { + int errnum; + gzerror (fp->gfp, &errnum); + if (errnum != Z_OK) + { + return (size_t) -1; + } + } } else if (fp->ufp) { diff --git a/src/straight.c b/src/straight.c index 36d3a8eb8..7a75a7d66 100644 --- a/src/straight.c +++ b/src/straight.c @@ -91,6 +91,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", straight_ctx->dict); + + return -1; + } + if (status_ctx->words_cnt == 0) { logfile_sub_msg ("STOP"); @@ -125,6 +132,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) return -1; } + + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", combinator_ctx->dict1); + + return -1; + } } else if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_RIGHT) { @@ -147,6 +161,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) return -1; } + + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", combinator_ctx->dict2); + + return -1; + } } if (status_ctx->words_cnt == 0) @@ -194,6 +215,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", straight_ctx->dict); + + return -1; + } + if (status_ctx->words_cnt == 0) { logfile_sub_msg ("STOP"); @@ -234,6 +262,13 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) return -1; } + if (rc == -2) + { + event_log_error (hashcat_ctx, "Error reading wordlist: %s", straight_ctx->dict); + + return -1; + } + if ((status_ctx->words_cnt / straight_ctx->kernel_rules_cnt) != hashes->salts_cnt) { event_log_error (hashcat_ctx, "Number of words in wordlist '%s' is not in sync with number of unique salts", straight_ctx->dict); diff --git a/src/wordlist.c b/src/wordlist.c index 1776b4885..0511381b6 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -60,6 +60,11 @@ int load_segment (hashcat_ctx_t *hashcat_ctx, HCFILE *fp) wl_data->cnt = hc_fread (wl_data->buf, 1, wl_data->incr - 1000, fp); + if (wl_data->cnt == (size_t) -1) + { + return -1; + } + wl_data->buf[wl_data->cnt] = 0; if (wl_data->cnt == 0) return 0; @@ -339,7 +344,12 @@ void get_next_word (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, char **out_buf, u32 return; } - load_segment (hashcat_ctx, fp); + if (load_segment (hashcat_ctx, fp) == -1) + { + event_log_error (hashcat_ctx, "Error reading file!\n"); + + return; + } get_next_word (hashcat_ctx, fp, out_buf, out_len); } @@ -559,9 +569,12 @@ int count_words (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, const char *dictfile, u u64 cnt2 = 0; while (!hc_feof (fp)) - { - load_segment (hashcat_ctx, fp); - + { + if (load_segment (hashcat_ctx, fp) == -1) + { + return -2; + } + comp += wl_data->cnt; u64 i = 0; From 4395d1467812918a8b0ec0019a7b154d9a47dbfa Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Sun, 22 Dec 2024 19:27:19 +0100 Subject: [PATCH 039/252] Adding keybag2hashcat --- tools/keybag2hashcat.py | 171 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 tools/keybag2hashcat.py diff --git a/tools/keybag2hashcat.py b/tools/keybag2hashcat.py new file mode 100644 index 000000000..83da25c5e --- /dev/null +++ b/tools/keybag2hashcat.py @@ -0,0 +1,171 @@ +import argparse +import logging +import sys + +__VERSION__ = '1.0.0' + +# Set up logging +logger = logging.getLogger("keybag_logger") +handler = logging.StreamHandler() +formatter = logging.Formatter('%(message)s') +handler.setFormatter(formatter) +logger.addHandler(handler) + +class Keybag: + def __init__(self, file_obj): + self.size = 0 + self.uuid = '' + self.version = 0 + self.type = 0 + self.hmackey = '' + self.wrap = 0 + self.salt = '' + self.iterations = 0 + + + self._read_header(file_obj) + self.class_keys = self._read_class_keys(file_obj) + + def _read_header(self, file_obj): + while True: + tag = file_obj.read(4).decode('ascii') + if tag == 'DATA': # DATA + self.size = int.from_bytes(file_obj.read(4), byteorder='big') + else: + length = int.from_bytes(file_obj.read(4), byteorder='big') + data = file_obj.read(length) + + if tag == 'VERS': # VERS + self.version = int.from_bytes(data, byteorder='big') + elif tag == 'TYPE': + self.type = int.from_bytes(data, byteorder='big') + elif tag == 'UUID': + if not self.uuid: + self.uuid = data.hex() + else: + file_obj.seek(-length - 8, 1) + break + elif tag == 'HMCK': + self.hmackey = data.hex() + elif tag == 'WRAP': + self.wrap = int.from_bytes(data, byteorder='big') + elif tag == 'SALT': + self.salt = data.hex() + elif tag == 'ITER': + self.iterations = int.from_bytes(data, byteorder='big') + + def _read_class_keys(self, file_obj): + class_keys = {} + + for x in range(0, 10): + stop = False + while stop != True: + tag = file_obj.read(4).decode('ascii') + length = int.from_bytes(file_obj.read(4), byteorder='big') + data = file_obj.read(length) + # new class key + if tag == 'UUID': + if class_keys.get(x): + if class_keys[x].get('UUID'): + file_obj.seek(-length - 8, 1) + stop = True + else: + class_keys[x] = {} + else: + class_keys[x] = {} + if tag == 'WRAP' or tag == 'CLAS' or tag == 'KTYP': + class_keys[x][tag] = int.from_bytes(data, byteorder='big') + else: + class_keys[x][tag] = data.hex() + if file_obj.tell() > self.size: + stop = True + return class_keys + + + def print_keybag(self): + logger.debug(f'SIZE: {self.size}') + logger.debug(f'VERSION: {self.version}') + logger.debug(f'TYPE: {self.type}') + logger.debug(f'UUID: {self.uuid}') + logger.debug(f'HMACKEY: {self.hmackey}') + logger.debug(f'SALT: {self.salt}') + logger.debug(f'ITERATIONS: {self.iterations}') + for x, class_key in self.class_keys.items(): + logger.debug(f'{x}:') + for key, value in class_key.items(): + logger.debug(f' {key}: {value}') + +def main(): + # Create the argument parser + parser = argparse.ArgumentParser(description="Process a keybag file with a specified UID.") + + # Add the UID argument + parser.add_argument( + '--uid', + type=str, + required=True, + help="Specify the device UID." + ) + + # Add the keybag file argument + parser.add_argument( + 'keybag', + type=str, + help="Path to the keybag file." + ) + + # Add the debug flag + parser.add_argument( + '--debug', + action='store_true', + help="Enable debug logging." + ) + + # Parse the arguments + args = parser.parse_args() + + if args.debug: + logger.setLevel(logging.DEBUG) + else: + logger.setLevel(logging.WARNING) + + # Access the arguments + uid = args.uid[0:32] + keybag_path = args.keybag + + logger.debug(f'keybag2hashcat - version {__VERSION__}') + + with open(keybag_path, 'br') as keybag_file: + kb = Keybag(keybag_file) + kb.print_keybag() + if not kb.version: + logger.error('Unable to detect version of keybag, exiting.') + sys.exit(1) + if not kb.salt: + logger.error('Unable to detect salt, exiting.') + sys.exit(1) + if not kb.iterations: + logger.error('Unable to detect iterations, exiting.') + sys.exit(1) + if not kb.version in [3, 4]: + logger.error(f'This script has not been tested with version {kb.version}.') + sys.exit(1) + if not kb.class_keys: + logger.error(f'Unable to parse class keys, exiting.') + sys.exit(1) + classkey1 = 0 + for x, class_key in kb.class_keys.items(): + if class_key.get('WRAP') == 3: + class_type = class_key.get('CLAS') + if class_type == 1 or class_type == 33: + classkey1 = class_key.get('WPKY') + + if not classkey1: + logger.error(f'Unable to find a classkey of class NSFileProtectionComplete.') + logger.error(f'You could try to get another class key, make sure it is ktyp 0 and wrap 3.') + exit(1) + print(f'$uido${uid}${kb.salt}${kb.iterations}${classkey1}') + + +if __name__ == "__main__": + main() From 29259ff97315ef0899cdf52bc8ec3c16b124f67b Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Tue, 7 Jan 2025 02:43:31 +0000 Subject: [PATCH 040/252] Improve salt length reporting in hashconfig Increase the amount of hash modes that will have their salt min/max length showed by including SALT_TYPE_GENERIC --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 085ce38b4..9158698a9 100644 --- a/src/main.c +++ b/src/main.c @@ -996,7 +996,7 @@ static void main_hashconfig_post (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE if (hashconfig->is_salted == true) { - if (hashconfig->opti_type & OPTI_TYPE_RAW_HASH) + if (hashconfig->opti_type & OPTI_TYPE_RAW_HASH || hashconfig->salt_type & SALT_TYPE_GENERIC) { event_log_info (hashcat_ctx, "Minimum salt length supported by kernel: %u", hashconfig->salt_min); event_log_info (hashcat_ctx, "Maximum salt length supported by kernel: %u", hashconfig->salt_max); From ab77b8f5bafa86460d1a0eba2f28831ac19cd833 Mon Sep 17 00:00:00 2001 From: sc00bz Date: Mon, 3 Feb 2025 10:35:05 -0600 Subject: [PATCH 041/252] Added support for multiple TOTP codes --- OpenCL/m18100_a0-pure.cl | 277 +++++++++++++------ OpenCL/m18100_a1-pure.cl | 441 +++++++++++++++++++++++-------- OpenCL/m18100_a3-pure.cl | 529 +++++++++++++++++++++++-------------- src/modules/module_18100.c | 152 +++++++---- 4 files changed, 953 insertions(+), 446 deletions(-) diff --git a/OpenCL/m18100_a0-pure.cl b/OpenCL/m18100_a0-pure.cl index 9c8f047a9..396d896bc 100644 --- a/OpenCL/m18100_a0-pure.cl +++ b/OpenCL/m18100_a0-pure.cl @@ -16,6 +16,47 @@ #include M2S(INCLUDE_PATH/inc_hash_sha1.cl) #endif +DECLSPEC void _totp_calculate (PRIVATE_AS u32 *code, PRIVATE_AS const u32 *w, const u32 pw_len, PRIVATE_AS const u32 *s, const u32 salt_len) +{ + sha1_hmac_ctx_t ctx; + + sha1_hmac_init_swap (&ctx, w, pw_len); + + sha1_hmac_update (&ctx, s, salt_len); + + sha1_hmac_final (&ctx); + + // initialize a buffer for the otp code + u32 otp_code = 0; + + // grab 4 consecutive bytes of the hash, starting at offset + switch (ctx.opad.h[4] & 15) + { + case 0: otp_code = ctx.opad.h[0]; break; + case 1: otp_code = ctx.opad.h[0] << 8 | ctx.opad.h[1] >> 24; break; + case 2: otp_code = ctx.opad.h[0] << 16 | ctx.opad.h[1] >> 16; break; + case 3: otp_code = ctx.opad.h[0] << 24 | ctx.opad.h[1] >> 8; break; + case 4: otp_code = ctx.opad.h[1]; break; + case 5: otp_code = ctx.opad.h[1] << 8 | ctx.opad.h[2] >> 24; break; + case 6: otp_code = ctx.opad.h[1] << 16 | ctx.opad.h[2] >> 16; break; + case 7: otp_code = ctx.opad.h[1] << 24 | ctx.opad.h[2] >> 8; break; + case 8: otp_code = ctx.opad.h[2]; break; + case 9: otp_code = ctx.opad.h[2] << 8 | ctx.opad.h[3] >> 24; break; + case 10: otp_code = ctx.opad.h[2] << 16 | ctx.opad.h[3] >> 16; break; + case 11: otp_code = ctx.opad.h[2] << 24 | ctx.opad.h[3] >> 8; break; + case 12: otp_code = ctx.opad.h[3]; break; + case 13: otp_code = ctx.opad.h[3] << 8 | ctx.opad.h[4] >> 24; break; + case 14: otp_code = ctx.opad.h[3] << 16 | ctx.opad.h[4] >> 16; break; + case 15: otp_code = ctx.opad.h[3] << 24 | ctx.opad.h[4] >> 8; break; + } + + // take only the lower 31 bits + otp_code &= 0x7fffffff; + + // we want to generate only 6 digits of code + *code = otp_code % 1000000; +} + KERNEL_FQ void m18100_mxx (KERN_ATTR_RULES ()) { /** @@ -33,63 +74,85 @@ KERNEL_FQ void m18100_mxx (KERN_ATTR_RULES ()) COPY_PW (pws[gid]); - const u32 salt_len = 8; + const u32 count = salt_bufs[SALT_POS_HOST].salt_len / 16; u32 s[64] = { 0 }; - for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + for (u32 i = 0; i < count; i += 1) { - s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + s[16 * i + 0] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 0]); + s[16 * i + 1] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 1]); } /** * loop */ - for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + if (count == 1) { - pw_t tmp = PASTE_PW; - - tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); - - sha1_hmac_ctx_t ctx; - - sha1_hmac_init_swap (&ctx, tmp.i, tmp.pw_len); - - sha1_hmac_update (&ctx, s, salt_len); - - sha1_hmac_final (&ctx); - - // initialize a buffer for the otp code - u32 otp_code = 0; - - // grab 4 consecutive bytes of the hash, starting at offset - switch (ctx.opad.h[4] & 15) + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) { - case 0: otp_code = ctx.opad.h[0]; break; - case 1: otp_code = ctx.opad.h[0] << 8 | ctx.opad.h[1] >> 24; break; - case 2: otp_code = ctx.opad.h[0] << 16 | ctx.opad.h[1] >> 16; break; - case 3: otp_code = ctx.opad.h[0] << 24 | ctx.opad.h[1] >> 8; break; - case 4: otp_code = ctx.opad.h[1]; break; - case 5: otp_code = ctx.opad.h[1] << 8 | ctx.opad.h[2] >> 24; break; - case 6: otp_code = ctx.opad.h[1] << 16 | ctx.opad.h[2] >> 16; break; - case 7: otp_code = ctx.opad.h[1] << 24 | ctx.opad.h[2] >> 8; break; - case 8: otp_code = ctx.opad.h[2]; break; - case 9: otp_code = ctx.opad.h[2] << 8 | ctx.opad.h[3] >> 24; break; - case 10: otp_code = ctx.opad.h[2] << 16 | ctx.opad.h[3] >> 16; break; - case 11: otp_code = ctx.opad.h[2] << 24 | ctx.opad.h[3] >> 8; break; - case 12: otp_code = ctx.opad.h[3]; break; - case 13: otp_code = ctx.opad.h[3] << 8 | ctx.opad.h[4] >> 24; break; - case 14: otp_code = ctx.opad.h[3] << 16 | ctx.opad.h[4] >> 16; break; - case 15: otp_code = ctx.opad.h[3] << 24 | ctx.opad.h[4] >> 8; break; + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + u32 otp_code0; + + _totp_calculate (&otp_code0, tmp.i, tmp.pw_len, s, 8); + + COMPARE_M_SCALAR (otp_code0, 0, 0, 0); } + } + else if (count == 4) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; - // take only the lower 31 bits - otp_code &= 0x7fffffff; - // we want to generate only 6 digits of code - otp_code %= 1000000; + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); - COMPARE_M_SCALAR (otp_code, 0, 0, 0); + u32 otp_code0, otp_code1; + + _totp_calculate (&otp_code0, tmp.i, tmp.pw_len, s + 0, 8); + _totp_calculate (&otp_code1, tmp.i, tmp.pw_len, s + 16, 8); + + COMPARE_M_SCALAR (otp_code0, otp_code1, 0, 0); + } + } + else if (count == 4) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + u32 otp_code0, otp_code1, otp_code2; + + _totp_calculate (&otp_code0, tmp.i, tmp.pw_len, s + 0, 8); + _totp_calculate (&otp_code1, tmp.i, tmp.pw_len, s + 16, 8); + _totp_calculate (&otp_code2, tmp.i, tmp.pw_len, s + 32, 8); + + COMPARE_M_SCALAR (otp_code0, otp_code1, otp_code2, 0); + } + } + else if (count == 4) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + u32 otp_code0, otp_code1, otp_code2, otp_code3; + + _totp_calculate (&otp_code0, tmp.i, tmp.pw_len, s + 0, 8); + _totp_calculate (&otp_code1, tmp.i, tmp.pw_len, s + 16, 8); + _totp_calculate (&otp_code2, tmp.i, tmp.pw_len, s + 32, 8); + _totp_calculate (&otp_code3, tmp.i, tmp.pw_len, s + 48, 8); + + COMPARE_M_SCALAR (otp_code0, otp_code1, otp_code2, otp_code3); + } } } @@ -122,62 +185,108 @@ KERNEL_FQ void m18100_sxx (KERN_ATTR_RULES ()) COPY_PW (pws[gid]); - const u32 salt_len = 8; + const u32 count = salt_bufs[SALT_POS_HOST].salt_len / 16; u32 s[64] = { 0 }; - for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + for (u32 i = 0; i < count; i += 1) { - s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + s[16 * i + 0] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 0]); + s[16 * i + 1] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 1]); } /** * loop */ - for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + if (count == 1) { - pw_t tmp = PASTE_PW; - - tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); - - sha1_hmac_ctx_t ctx; - - sha1_hmac_init_swap (&ctx, tmp.i, tmp.pw_len); - - sha1_hmac_update (&ctx, s, salt_len); - - sha1_hmac_final (&ctx); - - // initialize a buffer for the otp code - u32 otp_code = 0; - - // grab 4 consecutive bytes of the hash, starting at offset - switch (ctx.opad.h[4] & 15) + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) { - case 0: otp_code = ctx.opad.h[0]; break; - case 1: otp_code = ctx.opad.h[0] << 8 | ctx.opad.h[1] >> 24; break; - case 2: otp_code = ctx.opad.h[0] << 16 | ctx.opad.h[1] >> 16; break; - case 3: otp_code = ctx.opad.h[0] << 24 | ctx.opad.h[1] >> 8; break; - case 4: otp_code = ctx.opad.h[1]; break; - case 5: otp_code = ctx.opad.h[1] << 8 | ctx.opad.h[2] >> 24; break; - case 6: otp_code = ctx.opad.h[1] << 16 | ctx.opad.h[2] >> 16; break; - case 7: otp_code = ctx.opad.h[1] << 24 | ctx.opad.h[2] >> 8; break; - case 8: otp_code = ctx.opad.h[2]; break; - case 9: otp_code = ctx.opad.h[2] << 8 | ctx.opad.h[3] >> 24; break; - case 10: otp_code = ctx.opad.h[2] << 16 | ctx.opad.h[3] >> 16; break; - case 11: otp_code = ctx.opad.h[2] << 24 | ctx.opad.h[3] >> 8; break; - case 12: otp_code = ctx.opad.h[3]; break; - case 13: otp_code = ctx.opad.h[3] << 8 | ctx.opad.h[4] >> 24; break; - case 14: otp_code = ctx.opad.h[3] << 16 | ctx.opad.h[4] >> 16; break; - case 15: otp_code = ctx.opad.h[3] << 24 | ctx.opad.h[4] >> 8; break; + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + u32 otp_code0; + + _totp_calculate (&otp_code0, tmp.i, tmp.pw_len, s, 8); + + COMPARE_S_SCALAR (otp_code0, 0, 0, 0); } + } + else if (count == 2) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; - // take only the lower 31 bits - otp_code &= 0x7fffffff; - // we want to generate only 6 digits of code - otp_code %= 1000000; + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); - COMPARE_S_SCALAR (otp_code, 0, 0, 0); + u32 otp_code0, otp_code1; + + _totp_calculate (&otp_code0, tmp.i, tmp.pw_len, s, 8); + + if (otp_code0 == search[0]) + { + _totp_calculate (&otp_code1, tmp.i, tmp.pw_len, s + 16, 8); + + COMPARE_S_SCALAR (otp_code0, otp_code1, 0, 0); + } + } + } + else if (count == 3) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + u32 otp_code0, otp_code1, otp_code2; + + _totp_calculate (&otp_code0, tmp.i, tmp.pw_len, s, 8); + + if (otp_code0 == search[0]) + { + _totp_calculate (&otp_code1, tmp.i, tmp.pw_len, s + 16, 8); + + if (otp_code1 == search[1]) + { + _totp_calculate (&otp_code2, tmp.i, tmp.pw_len, s + 32, 8); + + COMPARE_S_SCALAR (otp_code0, otp_code1, otp_code2, 0); + } + } + } + } + else if (count == 4) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + u32 otp_code0, otp_code1, otp_code2, otp_code3; + + _totp_calculate (&otp_code0, tmp.i, tmp.pw_len, s, 8); + + if (otp_code0 == search[0]) + { + _totp_calculate (&otp_code1, tmp.i, tmp.pw_len, s + 16, 8); + + if (otp_code1 == search[1]) + { + _totp_calculate (&otp_code2, tmp.i, tmp.pw_len, s + 32, 8); + + if (otp_code2 == search[2]) + { + _totp_calculate (&otp_code3, tmp.i, tmp.pw_len, s + 48, 8); + + COMPARE_S_SCALAR (otp_code0, otp_code1, otp_code2, otp_code3); + } + } + } + } } } diff --git a/OpenCL/m18100_a1-pure.cl b/OpenCL/m18100_a1-pure.cl index a596894ca..4eefd1fdc 100644 --- a/OpenCL/m18100_a1-pure.cl +++ b/OpenCL/m18100_a1-pure.cl @@ -14,6 +14,47 @@ #include M2S(INCLUDE_PATH/inc_hash_sha1.cl) #endif +DECLSPEC void _totp_calculate (PRIVATE_AS u32 *code, PRIVATE_AS const u32 *w, const u32 pw_len, PRIVATE_AS const u32 *s, const u32 salt_len) +{ + sha1_hmac_ctx_t ctx; + + sha1_hmac_init (&ctx, w, pw_len); + + sha1_hmac_update (&ctx, s, salt_len); + + sha1_hmac_final (&ctx); + + // initialize a buffer for the otp code + u32 otp_code = 0; + + // grab 4 consecutive bytes of the hash, starting at offset + switch (ctx.opad.h[4] & 15) + { + case 0: otp_code = ctx.opad.h[0]; break; + case 1: otp_code = ctx.opad.h[0] << 8 | ctx.opad.h[1] >> 24; break; + case 2: otp_code = ctx.opad.h[0] << 16 | ctx.opad.h[1] >> 16; break; + case 3: otp_code = ctx.opad.h[0] << 24 | ctx.opad.h[1] >> 8; break; + case 4: otp_code = ctx.opad.h[1]; break; + case 5: otp_code = ctx.opad.h[1] << 8 | ctx.opad.h[2] >> 24; break; + case 6: otp_code = ctx.opad.h[1] << 16 | ctx.opad.h[2] >> 16; break; + case 7: otp_code = ctx.opad.h[1] << 24 | ctx.opad.h[2] >> 8; break; + case 8: otp_code = ctx.opad.h[2]; break; + case 9: otp_code = ctx.opad.h[2] << 8 | ctx.opad.h[3] >> 24; break; + case 10: otp_code = ctx.opad.h[2] << 16 | ctx.opad.h[3] >> 16; break; + case 11: otp_code = ctx.opad.h[2] << 24 | ctx.opad.h[3] >> 8; break; + case 12: otp_code = ctx.opad.h[3]; break; + case 13: otp_code = ctx.opad.h[3] << 8 | ctx.opad.h[4] >> 24; break; + case 14: otp_code = ctx.opad.h[3] << 16 | ctx.opad.h[4] >> 16; break; + case 15: otp_code = ctx.opad.h[3] << 24 | ctx.opad.h[4] >> 8; break; + } + + // take only the lower 31 bits + otp_code &= 0x7fffffff; + + // we want to generate only 6 digits of code + *code = otp_code % 1000000; +} + KERNEL_FQ void m18100_mxx (KERN_ATTR_BASIC ()) { /** @@ -38,81 +79,157 @@ KERNEL_FQ void m18100_mxx (KERN_ATTR_BASIC ()) w[idx] = hc_swap32_S (pws[gid].i[idx]); } - const u32 salt_len = 8; + const u32 count = salt_bufs[SALT_POS_HOST].salt_len / 16; u32 s[64] = { 0 }; - for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + for (u32 i = 0; i < count; i += 1) { - s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + s[16 * i + 0] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 0]); + s[16 * i + 1] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 1]); } /** * loop */ - for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + if (count == 1) { - const u32 comb_len = combs_buf[il_pos].pw_len; - - u32 c[64]; - - #ifdef _unroll - #pragma unroll - #endif - for (int idx = 0; idx < 64; idx++) + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) { - c[idx] = hc_swap32_S (combs_buf[il_pos].i[idx]); + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = hc_swap32_S (combs_buf[il_pos].i[idx]); + } + + switch_buffer_by_offset_1x64_be_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + u32 otp_code0; + + _totp_calculate (&otp_code0, c, pw_len + comb_len, s, 8); + + COMPARE_M_SCALAR (otp_code0, 0, 0, 0); } - - switch_buffer_by_offset_1x64_be_S (c, pw_len); - - #ifdef _unroll - #pragma unroll - #endif - for (int i = 0; i < 64; i++) + } + else if (count == 2) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) { - c[i] |= w[i]; + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = hc_swap32_S (combs_buf[il_pos].i[idx]); + } + + switch_buffer_by_offset_1x64_be_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + u32 otp_code0, otp_code1; + + _totp_calculate (&otp_code0, c, pw_len + comb_len, s + 0, 8); + _totp_calculate (&otp_code1, c, pw_len + comb_len, s + 16, 8); + + COMPARE_M_SCALAR (otp_code0, otp_code1, 0, 0); } - - sha1_hmac_ctx_t ctx; - - sha1_hmac_init (&ctx, c, pw_len + comb_len); - - sha1_hmac_update (&ctx, s, salt_len); - - sha1_hmac_final (&ctx); - - // initialize a buffer for the otp code - u32 otp_code = 0; - - // grab 4 consecutive bytes of the hash, starting at offset - switch (ctx.opad.h[4] & 15) + } + else if (count == 3) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) { - case 0: otp_code = ctx.opad.h[0]; break; - case 1: otp_code = ctx.opad.h[0] << 8 | ctx.opad.h[1] >> 24; break; - case 2: otp_code = ctx.opad.h[0] << 16 | ctx.opad.h[1] >> 16; break; - case 3: otp_code = ctx.opad.h[0] << 24 | ctx.opad.h[1] >> 8; break; - case 4: otp_code = ctx.opad.h[1]; break; - case 5: otp_code = ctx.opad.h[1] << 8 | ctx.opad.h[2] >> 24; break; - case 6: otp_code = ctx.opad.h[1] << 16 | ctx.opad.h[2] >> 16; break; - case 7: otp_code = ctx.opad.h[1] << 24 | ctx.opad.h[2] >> 8; break; - case 8: otp_code = ctx.opad.h[2]; break; - case 9: otp_code = ctx.opad.h[2] << 8 | ctx.opad.h[3] >> 24; break; - case 10: otp_code = ctx.opad.h[2] << 16 | ctx.opad.h[3] >> 16; break; - case 11: otp_code = ctx.opad.h[2] << 24 | ctx.opad.h[3] >> 8; break; - case 12: otp_code = ctx.opad.h[3]; break; - case 13: otp_code = ctx.opad.h[3] << 8 | ctx.opad.h[4] >> 24; break; - case 14: otp_code = ctx.opad.h[3] << 16 | ctx.opad.h[4] >> 16; break; - case 15: otp_code = ctx.opad.h[3] << 24 | ctx.opad.h[4] >> 8; break; + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = hc_swap32_S (combs_buf[il_pos].i[idx]); + } + + switch_buffer_by_offset_1x64_be_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + u32 otp_code0, otp_code1, otp_code2; + + _totp_calculate (&otp_code0, c, pw_len + comb_len, s + 0, 8); + _totp_calculate (&otp_code1, c, pw_len + comb_len, s + 16, 8); + _totp_calculate (&otp_code2, c, pw_len + comb_len, s + 32, 8); + + COMPARE_M_SCALAR (otp_code0, otp_code1, otp_code2, 0); } + } + else if (count == 4) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; - // take only the lower 31 bits - otp_code &= 0x7fffffff; - // we want to generate only 6 digits of code - otp_code %= 1000000; + u32 c[64]; - COMPARE_M_SCALAR (otp_code, 0, 0, 0); + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = hc_swap32_S (combs_buf[il_pos].i[idx]); + } + + switch_buffer_by_offset_1x64_be_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + u32 otp_code0, otp_code1, otp_code2, otp_code3; + + _totp_calculate (&otp_code0, c, pw_len + comb_len, s + 0, 8); + _totp_calculate (&otp_code1, c, pw_len + comb_len, s + 16, 8); + _totp_calculate (&otp_code2, c, pw_len + comb_len, s + 32, 8); + _totp_calculate (&otp_code3, c, pw_len + comb_len, s + 48, 8); + + COMPARE_M_SCALAR (otp_code0, otp_code1, otp_code2, otp_code3); + } } } @@ -152,80 +269,180 @@ KERNEL_FQ void m18100_sxx (KERN_ATTR_BASIC ()) w[idx] = hc_swap32_S (pws[gid].i[idx]); } - const u32 salt_len = 8; + const u32 count = salt_bufs[SALT_POS_HOST].salt_len / 16; u32 s[64] = { 0 }; - for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + for (u32 i = 0; i < count; i += 1) { - s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + s[16 * i + 0] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 0]); + s[16 * i + 1] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 1]); } /** * loop */ - for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + if (count == 1) { - const u32 comb_len = combs_buf[il_pos].pw_len; - - u32 c[64]; - - #ifdef _unroll - #pragma unroll - #endif - for (int idx = 0; idx < 64; idx++) + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) { - c[idx] = hc_swap32_S (combs_buf[il_pos].i[idx]); + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = hc_swap32_S (combs_buf[il_pos].i[idx]); + } + + switch_buffer_by_offset_1x64_be_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + u32 otp_code0; + + _totp_calculate (&otp_code0, c, pw_len + comb_len, s, 8); + + COMPARE_S_SCALAR (otp_code0, 0, 0, 0); } - - switch_buffer_by_offset_1x64_be_S (c, pw_len); - - #ifdef _unroll - #pragma unroll - #endif - for (int i = 0; i < 64; i++) + } + else if (count == 2) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) { - c[i] |= w[i]; + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = hc_swap32_S (combs_buf[il_pos].i[idx]); + } + + switch_buffer_by_offset_1x64_be_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + u32 otp_code0, otp_code1; + + _totp_calculate (&otp_code0, c, pw_len + comb_len, s, 8); + + if (otp_code0 == search[0]) + { + _totp_calculate (&otp_code1, c, pw_len + comb_len, s + 16, 8); + + COMPARE_S_SCALAR (otp_code0, otp_code1, 0, 0); + } } - - sha1_hmac_ctx_t ctx; - - sha1_hmac_init (&ctx, c, pw_len + comb_len); - - sha1_hmac_update (&ctx, s, salt_len); - - sha1_hmac_final (&ctx); - - // initialize a buffer for the otp code - u32 otp_code = 0; - - // grab 4 consecutive bytes of the hash, starting at offset - switch (ctx.opad.h[4] & 15) + } + else if (count == 3) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) { - case 0: otp_code = ctx.opad.h[0]; break; - case 1: otp_code = ctx.opad.h[0] << 8 | ctx.opad.h[1] >> 24; break; - case 2: otp_code = ctx.opad.h[0] << 16 | ctx.opad.h[1] >> 16; break; - case 3: otp_code = ctx.opad.h[0] << 24 | ctx.opad.h[1] >> 8; break; - case 4: otp_code = ctx.opad.h[1]; break; - case 5: otp_code = ctx.opad.h[1] << 8 | ctx.opad.h[2] >> 24; break; - case 6: otp_code = ctx.opad.h[1] << 16 | ctx.opad.h[2] >> 16; break; - case 7: otp_code = ctx.opad.h[1] << 24 | ctx.opad.h[2] >> 8; break; - case 8: otp_code = ctx.opad.h[2]; break; - case 9: otp_code = ctx.opad.h[2] << 8 | ctx.opad.h[3] >> 24; break; - case 10: otp_code = ctx.opad.h[2] << 16 | ctx.opad.h[3] >> 16; break; - case 11: otp_code = ctx.opad.h[2] << 24 | ctx.opad.h[3] >> 8; break; - case 12: otp_code = ctx.opad.h[3]; break; - case 13: otp_code = ctx.opad.h[3] << 8 | ctx.opad.h[4] >> 24; break; - case 14: otp_code = ctx.opad.h[3] << 16 | ctx.opad.h[4] >> 16; break; - case 15: otp_code = ctx.opad.h[3] << 24 | ctx.opad.h[4] >> 8; break; + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = hc_swap32_S (combs_buf[il_pos].i[idx]); + } + + switch_buffer_by_offset_1x64_be_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + u32 otp_code0, otp_code1, otp_code2; + + _totp_calculate (&otp_code0, c, pw_len + comb_len, s, 8); + + if (otp_code0 == search[0]) + { + _totp_calculate (&otp_code1, c, pw_len + comb_len, s + 16, 8); + + if (otp_code1 == search[1]) + { + _totp_calculate (&otp_code2, c, pw_len + comb_len, s + 32, 8); + + COMPARE_S_SCALAR (otp_code0, otp_code1, otp_code2, 0); + } + } } + } + else if (count == 4) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; - // take only the lower 31 bits - otp_code &= 0x7fffffff; - // we want to generate only 6 digits of code - otp_code %= 1000000; + u32 c[64]; - COMPARE_S_SCALAR (otp_code, 0, 0, 0); + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = hc_swap32_S (combs_buf[il_pos].i[idx]); + } + + switch_buffer_by_offset_1x64_be_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + u32 otp_code0, otp_code1, otp_code2, otp_code3; + + _totp_calculate (&otp_code0, c, pw_len + comb_len, s, 8); + + if (otp_code0 == search[0]) + { + _totp_calculate (&otp_code1, c, pw_len + comb_len, s + 16, 8); + + if (otp_code1 == search[1]) + { + _totp_calculate (&otp_code2, c, pw_len + comb_len, s + 32, 8); + + if (otp_code2 == search[2]) + { + _totp_calculate (&otp_code3, c, pw_len + comb_len, s + 48, 8); + + COMPARE_S_SCALAR (otp_code0, otp_code1, otp_code2, otp_code3); + } + } + } + } } } diff --git a/OpenCL/m18100_a3-pure.cl b/OpenCL/m18100_a3-pure.cl index 70235ce95..2dd68ffdf 100644 --- a/OpenCL/m18100_a3-pure.cl +++ b/OpenCL/m18100_a3-pure.cl @@ -1,205 +1,324 @@ -/** - * Author......: See docs/credits.txt - * License.....: MIT - */ - -//#define NEW_SIMD_CODE - -#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_simd.cl) -#include M2S(INCLUDE_PATH/inc_hash_sha1.cl) -#endif - -KERNEL_FQ void m18100_mxx (KERN_ATTR_VECTOR ()) -{ - /** - * modifier - */ - - const u64 lid = get_local_id (0); - const u64 gid = get_global_id (0); - - if (gid >= GID_CNT) return; - - /** - * base - */ - - const u32 pw_len = pws[gid].pw_len; - - u32x w[64] = { 0 }; - - for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) - { - w[idx] = pws[gid].i[idx]; - } - - const u32 salt_len = 8; - - u32x s[64] = { 0 }; - - for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) - { - s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); - } - - /** - * loop - */ - - u32x w0l = w[0]; - - for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) - { - const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; - - const u32x w0 = w0l | w0r; - - w[0] = w0; - - sha1_hmac_ctx_vector_t ctx; - - sha1_hmac_init_vector (&ctx, w, pw_len); - - sha1_hmac_update_vector (&ctx, s, salt_len); - - sha1_hmac_final_vector (&ctx); - - // initialize a buffer for the otp code - u32 otp_code = 0; - - // grab 4 consecutive bytes of the hash, starting at offset - switch (ctx.opad.h[4] & 15) - { - case 0: otp_code = ctx.opad.h[0]; break; - case 1: otp_code = ctx.opad.h[0] << 8 | ctx.opad.h[1] >> 24; break; - case 2: otp_code = ctx.opad.h[0] << 16 | ctx.opad.h[1] >> 16; break; - case 3: otp_code = ctx.opad.h[0] << 24 | ctx.opad.h[1] >> 8; break; - case 4: otp_code = ctx.opad.h[1]; break; - case 5: otp_code = ctx.opad.h[1] << 8 | ctx.opad.h[2] >> 24; break; - case 6: otp_code = ctx.opad.h[1] << 16 | ctx.opad.h[2] >> 16; break; - case 7: otp_code = ctx.opad.h[1] << 24 | ctx.opad.h[2] >> 8; break; - case 8: otp_code = ctx.opad.h[2]; break; - case 9: otp_code = ctx.opad.h[2] << 8 | ctx.opad.h[3] >> 24; break; - case 10: otp_code = ctx.opad.h[2] << 16 | ctx.opad.h[3] >> 16; break; - case 11: otp_code = ctx.opad.h[2] << 24 | ctx.opad.h[3] >> 8; break; - case 12: otp_code = ctx.opad.h[3]; break; - case 13: otp_code = ctx.opad.h[3] << 8 | ctx.opad.h[4] >> 24; break; - case 14: otp_code = ctx.opad.h[3] << 16 | ctx.opad.h[4] >> 16; break; - case 15: otp_code = ctx.opad.h[3] << 24 | ctx.opad.h[4] >> 8; break; - } - - // take only the lower 31 bits - otp_code &= 0x7fffffff; - - // we want to generate only 6 digits of code - otp_code %= 1000000; - - COMPARE_M_SIMD (otp_code, 0, 0, 0); - } -} - -KERNEL_FQ void m18100_sxx (KERN_ATTR_VECTOR ()) -{ - /** - * modifier - */ - - const u64 lid = get_local_id (0); - 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; - - u32x w[64] = { 0 }; - - for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) - { - w[idx] = pws[gid].i[idx]; - } - - const u32 salt_len = 8; - - u32x s[64] = { 0 }; - - for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) - { - s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); - } - - /** - * loop - */ - - u32x w0l = w[0]; - - for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) - { - const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; - - const u32x w0 = w0l | w0r; - - w[0] = w0; - - sha1_hmac_ctx_vector_t ctx; - - sha1_hmac_init_vector (&ctx, w, pw_len); - - sha1_hmac_update_vector (&ctx, s, salt_len); - - sha1_hmac_final_vector (&ctx); - - // initialize a buffer for the otp code - u32 otp_code = 0; - - // grab 4 consecutive bytes of the hash, starting at offset - switch (ctx.opad.h[4] & 15) - { - case 0: otp_code = ctx.opad.h[0]; break; - case 1: otp_code = ctx.opad.h[0] << 8 | ctx.opad.h[1] >> 24; break; - case 2: otp_code = ctx.opad.h[0] << 16 | ctx.opad.h[1] >> 16; break; - case 3: otp_code = ctx.opad.h[0] << 24 | ctx.opad.h[1] >> 8; break; - case 4: otp_code = ctx.opad.h[1]; break; - case 5: otp_code = ctx.opad.h[1] << 8 | ctx.opad.h[2] >> 24; break; - case 6: otp_code = ctx.opad.h[1] << 16 | ctx.opad.h[2] >> 16; break; - case 7: otp_code = ctx.opad.h[1] << 24 | ctx.opad.h[2] >> 8; break; - case 8: otp_code = ctx.opad.h[2]; break; - case 9: otp_code = ctx.opad.h[2] << 8 | ctx.opad.h[3] >> 24; break; - case 10: otp_code = ctx.opad.h[2] << 16 | ctx.opad.h[3] >> 16; break; - case 11: otp_code = ctx.opad.h[2] << 24 | ctx.opad.h[3] >> 8; break; - case 12: otp_code = ctx.opad.h[3]; break; - case 13: otp_code = ctx.opad.h[3] << 8 | ctx.opad.h[4] >> 24; break; - case 14: otp_code = ctx.opad.h[3] << 16 | ctx.opad.h[4] >> 16; break; - case 15: otp_code = ctx.opad.h[3] << 24 | ctx.opad.h[4] >> 8; break; - } - - // take only the lower 31 bits - otp_code &= 0x7fffffff; - - // we want to generate only 6 digits of code - otp_code %= 1000000; - - COMPARE_S_SIMD (otp_code, 0, 0, 0); - } -} +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#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_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha1.cl) +#endif + +DECLSPEC void _totp_calculate (PRIVATE_AS u32x *code, PRIVATE_AS const u32x *w, const u32 pw_len, PRIVATE_AS const u32x *s, const u32 salt_len) +{ + sha1_hmac_ctx_vector_t ctx; + + sha1_hmac_init_vector (&ctx, w, pw_len); + + sha1_hmac_update_vector (&ctx, s, salt_len); + + sha1_hmac_final_vector (&ctx); + + // initialize a buffer for the otp code + u32x otp_code = 0; + + // grab 4 consecutive bytes of the hash, starting at offset + switch (ctx.opad.h[4] & 15) + { + case 0: otp_code = ctx.opad.h[0]; break; + case 1: otp_code = ctx.opad.h[0] << 8 | ctx.opad.h[1] >> 24; break; + case 2: otp_code = ctx.opad.h[0] << 16 | ctx.opad.h[1] >> 16; break; + case 3: otp_code = ctx.opad.h[0] << 24 | ctx.opad.h[1] >> 8; break; + case 4: otp_code = ctx.opad.h[1]; break; + case 5: otp_code = ctx.opad.h[1] << 8 | ctx.opad.h[2] >> 24; break; + case 6: otp_code = ctx.opad.h[1] << 16 | ctx.opad.h[2] >> 16; break; + case 7: otp_code = ctx.opad.h[1] << 24 | ctx.opad.h[2] >> 8; break; + case 8: otp_code = ctx.opad.h[2]; break; + case 9: otp_code = ctx.opad.h[2] << 8 | ctx.opad.h[3] >> 24; break; + case 10: otp_code = ctx.opad.h[2] << 16 | ctx.opad.h[3] >> 16; break; + case 11: otp_code = ctx.opad.h[2] << 24 | ctx.opad.h[3] >> 8; break; + case 12: otp_code = ctx.opad.h[3]; break; + case 13: otp_code = ctx.opad.h[3] << 8 | ctx.opad.h[4] >> 24; break; + case 14: otp_code = ctx.opad.h[3] << 16 | ctx.opad.h[4] >> 16; break; + case 15: otp_code = ctx.opad.h[3] << 24 | ctx.opad.h[4] >> 8; break; + } + + // take only the lower 31 bits + otp_code &= 0x7fffffff; + + // we want to generate only 6 digits of code + *code = otp_code % 1000000; +} + +KERNEL_FQ void m18100_mxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 count = salt_bufs[SALT_POS_HOST].salt_len / 16; + + u32x s[64] = { 0 }; + + for (u32 i = 0; i < count; i += 1) + { + s[16 * i + 0] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 0]); + s[16 * i + 1] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 1]); + } + + /** + * loop + */ + + u32x w0l = w[0]; + + if (count == 1) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + u32x otp_code0; + + _totp_calculate (&otp_code0, w, pw_len, s, 8); + + COMPARE_M_SIMD (otp_code0, 0, 0, 0); + } + } + else if (count == 2) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + u32x otp_code0, otp_code1; + + _totp_calculate (&otp_code0, w, pw_len, s + 0, 8); + _totp_calculate (&otp_code1, w, pw_len, s + 16, 8); + + COMPARE_M_SIMD (otp_code0, otp_code1, 0, 0); + } + } + else if (count == 3) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + u32x otp_code0, otp_code1, otp_code2; + + _totp_calculate (&otp_code0, w, pw_len, s + 0, 8); + _totp_calculate (&otp_code1, w, pw_len, s + 16, 8); + _totp_calculate (&otp_code2, w, pw_len, s + 32, 8); + + COMPARE_M_SIMD (otp_code0, otp_code1, otp_code2, 0); + } + } + else if (count == 4) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + u32x otp_code0, otp_code1, otp_code2, otp_code3; + + _totp_calculate (&otp_code0, w, pw_len, s + 0, 8); + _totp_calculate (&otp_code1, w, pw_len, s + 16, 8); + _totp_calculate (&otp_code2, w, pw_len, s + 32, 8); + _totp_calculate (&otp_code3, w, pw_len, s + 48, 8); + + COMPARE_M_SIMD (otp_code0, otp_code1, otp_code2, otp_code3); + } + } +} + +KERNEL_FQ void m18100_sxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + 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; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 count = salt_bufs[SALT_POS_HOST].salt_len / 16; + + u32x s[64] = { 0 }; + + for (u32 i = 0; i < count; i += 1) + { + s[16 * i + 0] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 0]); + s[16 * i + 1] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[4 * i + 1]); + } + + /** + * loop + */ + + u32x w0l = w[0]; + + if (count == 1) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + u32x otp_code0; + + _totp_calculate (&otp_code0, w, pw_len, s, 8); + + COMPARE_S_SIMD (otp_code0, 0, 0, 0); + } + } + else if (count == 2) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + u32x otp_code0, otp_code1; + + _totp_calculate (&otp_code0, w, pw_len, s, 8); + + if (MATCHES_ONE_VS(otp_code0, search[0])) + { + _totp_calculate (&otp_code1, w, pw_len, s + 16, 8); + + COMPARE_S_SIMD (otp_code0, otp_code1, 0, 0); + } + } + } + else if (count == 3) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + u32x otp_code0, otp_code1, otp_code2; + + _totp_calculate (&otp_code0, w, pw_len, s, 8); + + if (MATCHES_ONE_VS(otp_code0, search[0])) + { + _totp_calculate (&otp_code1, w, pw_len, s + 16, 8); + + if (MATCHES_ONE_VS(otp_code1, search[1])) + { + _totp_calculate (&otp_code2, w, pw_len, s + 32, 8); + + COMPARE_S_SIMD (otp_code0, otp_code1, otp_code2, 0); + } + } + } + } + else if (count == 4) + { + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + u32x otp_code0, otp_code1, otp_code2, otp_code3; + + _totp_calculate (&otp_code0, w, pw_len, s, 8); + + if (MATCHES_ONE_VS(otp_code0, search[0])) + { + _totp_calculate (&otp_code1, w, pw_len, s + 16, 8); + + if (MATCHES_ONE_VS(otp_code1, search[1])) + { + _totp_calculate (&otp_code2, w, pw_len, s + 32, 8); + + if (MATCHES_ONE_VS(otp_code2, search[2])) + { + _totp_calculate (&otp_code3, w, pw_len, s + 48, 8); + + COMPARE_S_SIMD (otp_code0, otp_code1, otp_code2, otp_code3); + } + } + } + } + } +} diff --git a/src/modules/module_18100.c b/src/modules/module_18100.c index 37a8ef2e7..54b12a68e 100644 --- a/src/modules/module_18100.c +++ b/src/modules/module_18100.c @@ -29,7 +29,7 @@ static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE | OPTS_TYPE_SUGGEST_KG; static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat"; -static const char *ST_HASH = "597056:3600"; +static const char *ST_HASH = "597056:3600:613004:1234567890:322664:9876543210"; 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; } @@ -57,54 +57,92 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE hc_token_t token; - memset (&token, 0, sizeof (hc_token_t)); - - token.token_cnt = 2; - - token.sep[0] = hashconfig->separator; - token.len[0] = 6; - token.attr[0] = TOKEN_ATTR_FIXED_LENGTH - | TOKEN_ATTR_VERIFY_HEX; - - token.len_min[1] = SALT_MIN; - token.len_max[1] = SALT_MAX; - token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH; - - if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) + // 1 to 4 TOTP codes + // 597056:3600 + // 597056:3600:613004:1234567890 + // 597056:3600:613004:1234567890:322664:9876543210 + // 597056:3600:613004:1234567890:322664:9876543210:068798:111222333 + int count; + for (count = 8; count > 0; count -= 2) { - token.len_min[1] *= 2; - token.len_max[1] *= 2; + memset (&token, 0, sizeof (hc_token_t)); - token.attr[1] |= TOKEN_ATTR_VERIFY_DIGIT; + token.token_cnt = count; + + for (int i = 0; i < count; i += 2) + { + token.sep[i + 0] = hashconfig->separator; + token.len[i + 0] = 6; + token.attr[i + 0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_DIGIT; + + // 0 to 18446744073709551616 + token.sep[i + 1] = hashconfig->separator; + token.len_min[i + 1] = 1; + token.len_max[i + 1] = 20; + token.attr[i + 1] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_DIGIT; + + if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) + { + token.len_min[i + 1] *= 2; + token.len_max[i + 1] *= 2; + token.attr[i + 1] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_HEX; + } + } + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer == PARSER_OK) break; + + // failed all tokenizers + if (count == 2) return (rc_tokenizer); + } + count /= 2; + + for (int i = 0; i < count; i += 1) + { + // now we need to reduce our hash into a token + int otp_code = hc_strtoul ((const char *) token.buf[2 * i + 0], NULL, 10); + + digest[i] = otp_code; + + const u8 *salt_pos = token.buf[2 * i + 1]; + + // convert ascii timestamp to ulong timestamp + u64 timestamp = hc_strtoull ((const char *) salt_pos, NULL, 10); + + // store the original salt value. Step division will destroy granularity for output + salt->salt_buf[4 * i + 3] = ((u32) (timestamp >> 0)); + salt->salt_buf[4 * i + 2] = ((u32) (timestamp >> 32)); + + // divide our timestamp by our step. We will use the RFC 6238 default of 30 for now + timestamp /= 30; + + // convert counter to 8-byte salt + salt->salt_buf[4 * i + 1] = byte_swap_32 ((u32) (timestamp >> 0)); + salt->salt_buf[4 * i + 0] = byte_swap_32 ((u32) (timestamp >> 32)); } - const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + // verify unique salts + for (int i = 0; i < count; i += 1) + { + u32 s0 = salt->salt_buf[4 * i + 0]; + u32 s1 = salt->salt_buf[4 * i + 1]; - if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); - - // now we need to reduce our hash into a token - int otp_code = hc_strtoul (line_buf, NULL, 10); - - digest[0] = otp_code; - - const u8 *salt_pos = token.buf[1]; - - // convert ascii timestamp to ulong timestamp - u64 timestamp = hc_strtoull ((const char *) salt_pos, NULL, 10); - - // store the original salt value. Step division will destroy granularity for output - salt->salt_buf[3] = ((u32) (timestamp >> 0)); - salt->salt_buf[2] = ((u32) (timestamp >> 32)); - - // divide our timestamp by our step. We will use the RFC 6238 default of 30 for now - timestamp /= 30; - - // convert counter to 8-byte salt - salt->salt_buf[1] = byte_swap_32 ((u32) (timestamp >> 0)); - salt->salt_buf[0] = byte_swap_32 ((u32) (timestamp >> 32)); + for (int j = i + 1; j < count; j += 1) + { + if (salt->salt_buf[4 * j + 0] == s0 && + salt->salt_buf[4 * j + 1] == s1) + { + return (PARSER_SALT_VALUE); + } + } + } // our salt will always be 8 bytes, but we are going to cheat and store it twice, so... - salt->salt_len = 16; + salt->salt_len = 16 * count; return (PARSER_OK); } @@ -113,13 +151,37 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE { const u32 *digest = (const u32 *) digest_buf; - // salt_buf[1] holds our 32 bit value. salt_buf[0] and salt_buf[1] would be 64 bits. + // salt_buf[4 * i + 1] holds our 32 bit value. salt_buf[4 * i + 0] and salt_buf[4 * i + 1] would be 64 bits. // we also need to multiply salt by our step to see the floor of our original timestamp range. // again, we will use the default RFC 6238 step of 30. - const u64 tmp_salt_buf = (((u64) (salt->salt_buf[2])) << 32) | ((u64) (salt->salt_buf[3])); + int count = salt->salt_len / 16; - const int line_len = snprintf (line_buf, line_size, "%06d%c%" PRIu64, digest[0], hashconfig->separator, tmp_salt_buf); + // all but the last TOTP code + int i = 0, line_len = 0; + for (; i < count - 1; i += 1) + { + const u64 tmp_salt_buf = (((u64) (salt->salt_buf[4 * i + 2])) << 32) | ((u64) (salt->salt_buf[4 * i + 3])); + const int ret = snprintf (line_buf + line_len, line_size - line_len, "%06d%c%" PRIu64 "%c", digest[i], hashconfig->separator, tmp_salt_buf, hashconfig->separator); + line_len += ret; + + // error + if (ret < 0) + { + return ret; + } + } + + // the last TOTP code + const u64 tmp_salt_buf = (((u64) (salt->salt_buf[4 * i + 2])) << 32) | ((u64) (salt->salt_buf[4 * i + 3])); + const int ret = snprintf (line_buf + line_len, line_size - line_len, "%06d%c%" PRIu64, digest[i], hashconfig->separator, tmp_salt_buf); + line_len += ret; + + // error + if (ret < 0) + { + return ret; + } return line_len; } From 08514edd22c10d21ba329317b0985753a695396f Mon Sep 17 00:00:00 2001 From: unix-ninja Date: Sat, 15 Feb 2025 22:29:38 -0500 Subject: [PATCH 042/252] Ignore .DS_Store files. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index d8ff600bb..f7d1967e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.DS_Store +*/.DS_Store *.exe *.bin *.app From faa680fbab803723d77449b7107c1c985a6b7981 Mon Sep 17 00:00:00 2001 From: unix-ninja Date: Sat, 15 Feb 2025 22:30:05 -0500 Subject: [PATCH 043/252] Add gitea2hashcat.py --- tools/gitea2hashcat.py | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 tools/gitea2hashcat.py diff --git a/tools/gitea2hashcat.py b/tools/gitea2hashcat.py new file mode 100755 index 000000000..ac1c539d2 --- /dev/null +++ b/tools/gitea2hashcat.py @@ -0,0 +1,75 @@ +#!/usr/bin/python3 +# Converts gitea PBKDF2-HMAC-SHA256 hashes into a format hashcat can use +# written by unix-ninja + +import argparse +import base64 +import sys + +def convert_hash(hash_string): + """Converts a SALT+HASH string to a hashcat compatible format, + ensuring the smaller input is treated as the salt. + Use : or | as delimeters. + """ + hash_string = hash_string.replace('|', ':') + try: + part1, part2 = hash_string.split(":") + except ValueError: + print(f"[-] Invalid input format: {hash_string}") + return None + + try: + bytes1 = bytes.fromhex(part1) + bytes2 = bytes.fromhex(part2) + except ValueError: + print(f"[-] Invalid hex input: {hash_string}") + return None + + # If lengths are equal, we will maintain the original order + if len(bytes1) > len(bytes2): + salt_bytes = bytes2 + hash_bytes = bytes1 + else: + salt_bytes = bytes1 + hash_bytes = bytes2 + + + salt_b64 = base64.b64encode(salt_bytes).decode('utf-8') + hash_b64 = base64.b64encode(hash_bytes).decode('utf-8') + + return f"sha256:50000:{salt_b64}:{hash_b64}" + + +def main(): + parser = argparse.ArgumentParser(description="Convert Gitea SALT+HASH strings to a hashcat-compatible format.", + formatter_class=argparse.RawTextHelpFormatter, + epilog="""Example: + gitea2hashcat.py : | ... or pipe input from stdin. + + You can also dump output straight from sqlite into this script: + sqlite3 gitea.db 'select salt,passwd from user;' | gitea2hashcat.py""") + parser.add_argument('hashes', nargs='*', help='SALT+HASH strings to convert') + args = parser.parse_args() + + # ... (rest of the main function remains the same) + print("[+] Run the output hashes through hashcat mode 10900 (PBKDF2-HMAC-SHA256)") + print() + + if args.hashes: + # Process command-line arguments + for hash_string in args.hashes: + converted_hash = convert_hash(hash_string) + if converted_hash: + print(converted_hash) + + else: + # Process input from stdin + for line in sys.stdin: + hash_string = line.strip() # Remove leading/trailing whitespace + converted_hash = convert_hash(hash_string) + if converted_hash: + print(converted_hash) + + +if __name__ == "__main__": + main() From 7509c6f70abcbf55fa35e17e8608ae2779fd9760 Mon Sep 17 00:00:00 2001 From: holly-o <128481388+holly-o@users.noreply.github.com> Date: Fri, 21 Feb 2025 16:03:42 +0000 Subject: [PATCH 044/252] Add apfs2hashcat.py --- tools/apfs2hashcat.py | 434 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 434 insertions(+) create mode 100644 tools/apfs2hashcat.py diff --git a/tools/apfs2hashcat.py b/tools/apfs2hashcat.py new file mode 100644 index 000000000..d310dd43e --- /dev/null +++ b/tools/apfs2hashcat.py @@ -0,0 +1,434 @@ +#!/usr/bin/env python3 + +# For extracting APFS hashes to be cracked by hashcat modes 18300 ($fvde$2$) or 16700 ($fvde$1$). +# Usage: `python3 apfs2hashcat.py -o <_apfs_container_offset>` +# The argument -o is optional. The script will attempt to read the partition table to find the location of APFS container(s). In the case that the partition table is missing or you want to specify a particular APFS container, use -o to provide the offset to the start of the container. + +import argparse +from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes + +# KNOWN_RECOVERY_HASHES = ['ebc6c064000011aaaa1100306543ecac', 'ec1c2ad9b6184ed6bd8d50f361c27507'] +KNOWN_RECOVERY_HASHES = ['64C0C6EB-0000-AA11-AA11-00306543ECAC', 'D92A1CEC-18B6-D64E-BD8D-50F361C27507'] +TAG_DICT = {'unk_80' : {'tag' : b'\x80', 'expected_len' : 1}, + 'uuid' : {'tag' : b'\x81', 'expected_len' : 0x10}, + 'unk_82' : {'tag' : b'\x82'}, + 'wrapped_kek' : {'tag' : b'\x83', 'expected_len' : 0x28}, + 'iterations' : {'tag' : b'\x84'}, + 'salt' : {'tag' : b'\x85', 'expected_len' : 0x10}} +# HEX_APFS_CONTAINER_GUID = 'ef57347c0000aa11aa1100306543ecac' +HEX_APFS_CONTAINER_GUID = '7C3457EF-0000-11AA-AA11-00306543ECAC' +AES_XTS_SECTOR_SIZE = 512 +EFI_PARTITION_HEADER = b'EFI PART' + +def uint_to_int(b): + return int(b[::-1].hex(), 16) + + +def findall(p, s): + i = s.find(p) + while i != -1: + yield i + i = s.find(p, i+1) + + +def hex_to_guid(hex_str): + + guid_parts = [0] * 5 + guid_parts[0] = hex_str[0:8] + guid_parts[1] = hex_str[8:12] + guid_parts[2] = hex_str[12:16] + guid_parts[3] = hex_str[16:20] + guid_parts[4] = hex_str[20:] + + guid = ''.join([guid_parts[0][i:i+2] for i in range(0, len(guid_parts[0]), 2)][::-1]) + guid += '-' + guid += ''.join([guid_parts[1][i:i+2] for i in range(0, len(guid_parts[1]), 2)][::-1]) + guid += '-' + guid += ''.join([guid_parts[2][i:i+2] for i in range(0, len(guid_parts[2]), 2)][::-1]) + guid += '-' + guid += guid_parts[3] + guid += '-' + guid += guid_parts[4] + + return guid.upper() + + +def parse_partition_entry(partition_entry): + type_GUID = partition_entry[0:0x10] + part_GUID = partition_entry[0x10:0x20] + start_LBA = partition_entry[0x20:0x28] + # end_LBA = partition_entry[0x28:0x30] + return part_GUID, type_GUID, start_LBA + + +# get main_start by multiplying apfs partition start lba by block size +def parse_partition_table(fp): + + # determine whether sector size is 0x200 or 0x1000 + sector_size = 0x0 + + # look for EFI PART at start of sector 1 + fp.seek(0x200) + signature = fp.read(0x8) + if signature == EFI_PARTITION_HEADER: + sector_size = 0x200 + + else: + fp.seek(0x1000) + signature = fp.read(0x8) + if signature == EFI_PARTITION_HEADER: + sector_size = 0x1000 + + print("[+] Identified sector size:", sector_size) + + if not sector_size: + print(f"[!] Invalid sector size {sector_size} (not 512 or 4096 bytes). Exiting.") + + fp.seek(2 * sector_size) # go to sector 2 + partitions = [] + partition_entry = b'1' + while any(partition_entry): + partition_entry = fp.read(0x80) + if any(partition_entry): + partitions.append(partition_entry) + + partition_dict = {} + for p in partitions: + part_GUID, type_GUID, start = parse_partition_entry(p) + starting_pos = uint_to_int(start) * sector_size + partition_dict[part_GUID.hex()] = {'start':starting_pos, 'partition_type':type_GUID.hex()} + + return partition_dict + + +def AES_XTS_decrypt_sector(uuid, tweak, ct): + + decryptor = Cipher( + algorithms.AES(key=uuid+uuid), + modes.XTS(tweak=tweak), + ).decryptor() + pt = decryptor.update(ct) + decryptor.finalize() + + return pt + + +def AES_decrypt(data, start_offset, block_size, uuid): + cs_factor = block_size // 0x200 # = 8 for block_size=4096 + uno = start_offset * cs_factor + pt = b'' + for offset in range(0, block_size, AES_XTS_SECTOR_SIZE): + ct = data[offset:offset + AES_XTS_SECTOR_SIZE] + tweak = hex(uno)[2:].zfill(32) # 32 so that the key is the correct length (16 bytes) + tweak = bytearray.fromhex(tweak)[::-1] + pt += AES_XTS_decrypt_sector(uuid, tweak, ct) + uno += 1 + + return pt + + +def TLV(full_kek_blob, tag, starting_index): + # expected tag should follow if this is the correct TLV) + if full_kek_blob[starting_index:starting_index+1] != TAG_DICT[tag]['tag']: + return -1, starting_index + # check for expected len for further confirmation + length = uint_to_int(full_kek_blob[starting_index+1:starting_index+2]) + expected_len = TAG_DICT[tag].get('expected_len') # use .get() since not all tags have an expected len + if expected_len: + if length != expected_len: + return -1, starting_index + next_starting_index = starting_index+2+length + value = full_kek_blob[starting_index+2:next_starting_index] + + return value, next_starting_index + + +def TLV_iterate(starting_index, pt, hash_set, volume_uuid): + for tag in TAG_DICT: + value, starting_index = TLV(pt, tag, starting_index) + + # i.e. if fails length check + if value == -1: + return starting_index + 1, hash_set + TAG_DICT[tag]['value'] = value + + aes_type = TAG_DICT['unk_82']['value'] + wrapped_kek = TAG_DICT['wrapped_kek']['value'] + iterations = TAG_DICT['iterations']['value'] + salt = TAG_DICT['salt']['value'] + + aes_type = uint_to_int(aes_type[0:4]) + + # FVDE - AES128 + if aes_type == 2: + aes_hash_value = 1 + wrapped_kek = wrapped_kek[:0x18] # shorter kek value, this removes zeros + + # APFS - AES256 + elif aes_type == 16 or aes_type == 0: + aes_hash_value = 2 + + else: + print("[!] AES type not recognised, continuing...") + return + + password_hash = f"$fvde${aes_hash_value}${len(salt)}${salt.hex()}${int(iterations.hex(),16)}${wrapped_kek.hex()}" + hash_set.add(password_hash) + print(f"\nFound password hash: {password_hash} (vol uuid: {volume_uuid.hex()})") + + kek_uuid = hex_to_guid(TAG_DICT['uuid']['value'].hex()) + if kek_uuid in KNOWN_RECOVERY_HASHES: + print(f"[!] Warning! Recognised UUID {kek_uuid}... possible recovery hash\n") + + return starting_index, hash_set + + +def parse_block(block): + nx_xid = uint_to_int(block[16:24]) + obj_type = uint_to_int(block[24:26]) + magic = block[0x20:0x24] + + return nx_xid, obj_type, magic + + +def parse_apsb_block(block): + obj_type = uint_to_int(block[24:26]) + magic = block[0x20:0x24] + uuid = block[240:256] + encryption = uint_to_int(block[264:272]) + name = block[704:960] + + return obj_type, magic, uuid, encryption, name + + +def parse_keybag_entry(uuid, pt): + uuid_iterator = findall(uuid, pt) + for starting_pos in uuid_iterator: + ke_uuid, ke_tag, ke_keylen = pt[starting_pos:starting_pos+16], uint_to_int(pt[starting_pos + 16:starting_pos + 18]), uint_to_int(pt[starting_pos + 18:starting_pos + 20]) + padding = pt[starting_pos + 20:starting_pos + 24] + keydata = pt[starting_pos + 24: starting_pos + 24 + ke_keylen] + + # only tag 3 is needed for constructing the hash + if ke_tag == 3: + assert padding == b'\x00\x00\x00\x00' + volume_unlock_record = keydata + return volume_unlock_record + + return None + + +def get_fs_oids(csb_body): + max_file_systems = uint_to_int(csb_body[0x94:0x98]) + fs_oids = set() + for fs_entry in range(max_file_systems): + oid_start = 0x98 + 8 * fs_entry + fs_oid = uint_to_int(csb_body[oid_start:oid_start + 8]) + if not fs_oid: + continue + fs_oids.add(fs_oid) + + return fs_oids + + +def parse_csb(csb): + csb_body = csb[0x20:0x568] + + header = csb_body[:4] # 'NXSB' + assert header == b'NXSB' + block_size = uint_to_int(csb_body[4:8]) # default is 4096 + uuid = csb_body[0x28:0x38] # used as key for unwrapping + omap_oid = uint_to_int(csb_body[0x80:0x88]) # omap_oid to locate the omap to find volume offsets + fs_oids = get_fs_oids(csb_body) + + # locate container's keybag using nx_keylocker field + keylocker_paddr = uint_to_int(csb_body[0x4f0:0x4f8]) + + # block info for iterating to find most recent csb + xp_desc_blocks = uint_to_int(csb_body[0x48:0x4b]) + xp_desc_base = uint_to_int(csb_body[0x50:0x54]) + + return block_size, uuid, keylocker_paddr, omap_oid, fs_oids, xp_desc_base, xp_desc_blocks + + +def get_offset_from_oid(oid, apfs_start, block_size): + return apfs_start + oid * block_size + + +def parse_tree(tree, fs_oids, block_size): + + volume_addresses = [] + + # get key data from TOC: + table_space_offset = uint_to_int(tree[0x28:0x2a]) + table_space_len = uint_to_int(tree[0x2a:0x2c]) + start_of_key_area = table_space_offset + table_space_len + 0x38 # 0x38 = header + entries + + # b-tree structure is header (0x20 bytes) -> ToC -> keys -> free space -> values -> btree_info (0x28 bytes) + end_of_value_area = block_size - 0x28 + + tree_data = tree[0x38:] + for m in range(len(fs_oids)): + data_start = m * 4 + key_offset = uint_to_int(tree_data[data_start:data_start + 2]) # key offset is from the start of the key area downwards + data_offset = uint_to_int(tree_data[data_start + 2:data_start + 4]) # data offset is from the end of the data area upwards + + # get to key area + key_start = key_offset + start_of_key_area + key_oid = uint_to_int(tree[key_start:key_start + 0x8]) + + if key_oid not in fs_oids: + print(f"Found key_oid {key_oid} in omap but not present in fs map. Skipping this volume") + + else: + val_end = end_of_value_area - data_offset + data_paddr = uint_to_int(tree[val_end + 0x8:val_end + 0x10]) + volume_addresses.append(data_paddr) + + return volume_addresses + + +def get_volumes(fp, block_size, apfs_start, tree, fs_oids): + volume_addresses = parse_tree(tree, fs_oids, block_size) + volumes_dict = dict() + for v in volume_addresses: + fp.seek(apfs_start + block_size * v) + block_start = fp.read(block_size) + obj_type, magic, uuid, encryption, name = parse_apsb_block(block_start) + if obj_type == 13 and magic == b'APSB': + volumes_dict[uuid] = {'start':v, 'name':name} + print() + print("[+] The following volumes are present:") + for u in volumes_dict: + print(f"{u.hex()} ({volumes_dict[u]['name'].decode()}) at {hex(volumes_dict[u]['start'] * block_size + apfs_start)}") + + return volumes_dict + + +def decrypt_volume_keybag(fp, volume_keybag_addr, block_size, apfs_struct_start, volume_uuid): + volume_keybag_addr = volume_keybag_addr[:4].hex().zfill(8) + volume_keybag_addr = bytearray.fromhex(volume_keybag_addr)[::-1] + volume_keybag_addr = int(volume_keybag_addr.hex(),16) + + offset = block_size * volume_keybag_addr + apfs_struct_start + fp.seek(offset) + encrypted_keybag = fp.read(block_size) + pt = AES_decrypt(encrypted_keybag, volume_keybag_addr, block_size, volume_uuid) + + return pt + + +def get_apfs_containers(fp): + partition_dict = parse_partition_table(fp) + apfs_containers = [] + for d in partition_dict: + if hex_to_guid(partition_dict[d]['partition_type']) == HEX_APFS_CONTAINER_GUID: + apfs_containers.append(partition_dict[d]['start']) + + return apfs_containers + + +def get_tree(fp, omap_oid, apfs_struct_start, block_size): + omap_offset = get_offset_from_oid(omap_oid, apfs_struct_start, block_size) + fp.seek(omap_offset + 0x30) # location for tree_oid + tree_oid = fp.read(0x10) + tree_oid = uint_to_int(tree_oid) + tree_offset = get_offset_from_oid(tree_oid, apfs_struct_start, block_size) + + fp.seek(tree_offset) + tree = fp.read(0x1000) + + return tree + + +def get_container_keybag(fp, apfs_struct_start, block_size, keylocker_paddr): + # calculate offset to read from + offs = block_size * keylocker_paddr + apfs_struct_start + fp.seek(offs) + data = fp.read(block_size) + + return data + + +def find_valid_csb(fp, block_size, xp_desc_base, xp_desc_blocks, apfs_start): + max_xid = 0 + max_xid_paddr = 0 + + for paddr in range(xp_desc_base, xp_desc_base + xp_desc_blocks): + offs = block_size * paddr + apfs_start + fp.seek(offs + 0x10) + csb_xid = uint_to_int(fp.read(0x8)) + if csb_xid >= max_xid: + max_xid = csb_xid + max_xid_paddr = paddr + + print(f"[+] Found valid csb with xid {max_xid} at {hex(max_xid_paddr)}") + return max_xid_paddr + + +def main(): + + p = argparse.ArgumentParser() + p.add_argument('filename') + p.add_argument('-o', '--offset', help='[OPTIONAL] offset for APFS volume - may be necessary if partition table is not present') + args = p.parse_args() + + filename = args.filename + with open(filename, 'rb') as fp: + + if args.offset: + apfs_offset = int(args.offset) + apfs_containers = [apfs_offset] + + else: + apfs_containers = get_apfs_containers(fp) + + if apfs_containers == []: + print("[!] APFS volume GUID not found, exiting.") + exit() + + for apfs_struct_start in apfs_containers: + print(f"[+] APFS container starts at {hex(apfs_struct_start)}") + fp.seek(apfs_struct_start) + csb = fp.read(0x568) + + # read the first csb for initial info - then use this to iterate through all csbs and find the most recent one + block_size, uuid, keylocker_paddr, omap_oid, fs_oids, xp_desc_base, xp_desc_blocks = parse_csb(csb) + valid_csb_paddr = find_valid_csb(fp, block_size, xp_desc_base, xp_desc_blocks, apfs_struct_start) + + fp.seek(valid_csb_paddr * block_size + apfs_struct_start) + valid_csb = fp.read(block_size) + block_size, uuid, keylocker_paddr, omap_oid, fs_oids, xp_desc_base, xp_desc_blocks = parse_csb(valid_csb) + + encrypted_keybag = get_container_keybag(fp, apfs_struct_start, block_size, keylocker_paddr) + # Unwrap container keybag using AES-XTS with container UUID as key + starting_pt = AES_decrypt(encrypted_keybag, keylocker_paddr, block_size, uuid) + + # find all volumes to iterate through + tree = get_tree(fp, omap_oid, apfs_struct_start, block_size) + + volumes_dict = get_volumes(fp, block_size, apfs_struct_start, tree, fs_oids) + + hash_set = set() + for volume_uuid in volumes_dict: + + # find entry in container's keybag matching volume UUID and has KB_TAG_VOLUME_UNLOCK_RECORDS = 3. Its keydata is location of volume keybag. + volume_keybag_addr = parse_keybag_entry(volume_uuid, starting_pt) + + # continue if encrypted keybag not found + if not volume_keybag_addr: + continue + + # unwrap volume keybag using volume uuid AES-XTS + pt = decrypt_volume_keybag(fp, volume_keybag_addr, block_size, apfs_struct_start, volume_uuid) + + # parse TLV for 80 first + index_iterator = findall(TAG_DICT['unk_80']['tag'], pt) + for starting_index in index_iterator: + starting_index, hash_set = TLV_iterate(starting_index, pt, hash_set, volume_uuid) + + print() + print("[+] All hashes found.") + + return + +if __name__ == "__main__": + main() From a8e0c8b213aea5211aa459d90af6922f40831428 Mon Sep 17 00:00:00 2001 From: holly-o <128481388+holly-o@users.noreply.github.com> Date: Fri, 21 Feb 2025 16:06:29 +0000 Subject: [PATCH 045/252] Update apfs2hashcat.py Remove hex version of known UUIDs --- tools/apfs2hashcat.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/apfs2hashcat.py b/tools/apfs2hashcat.py index d310dd43e..a0cc6a5da 100644 --- a/tools/apfs2hashcat.py +++ b/tools/apfs2hashcat.py @@ -7,7 +7,6 @@ import argparse from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes -# KNOWN_RECOVERY_HASHES = ['ebc6c064000011aaaa1100306543ecac', 'ec1c2ad9b6184ed6bd8d50f361c27507'] KNOWN_RECOVERY_HASHES = ['64C0C6EB-0000-AA11-AA11-00306543ECAC', 'D92A1CEC-18B6-D64E-BD8D-50F361C27507'] TAG_DICT = {'unk_80' : {'tag' : b'\x80', 'expected_len' : 1}, 'uuid' : {'tag' : b'\x81', 'expected_len' : 0x10}, @@ -15,7 +14,6 @@ TAG_DICT = {'unk_80' : {'tag' : b'\x80', 'expected_len' : 1}, 'wrapped_kek' : {'tag' : b'\x83', 'expected_len' : 0x28}, 'iterations' : {'tag' : b'\x84'}, 'salt' : {'tag' : b'\x85', 'expected_len' : 0x10}} -# HEX_APFS_CONTAINER_GUID = 'ef57347c0000aa11aa1100306543ecac' HEX_APFS_CONTAINER_GUID = '7C3457EF-0000-11AA-AA11-00306543ECAC' AES_XTS_SECTOR_SIZE = 512 EFI_PARTITION_HEADER = b'EFI PART' From b2c846135dbc7cd0e5e226d9217f8716eb5f3a95 Mon Sep 17 00:00:00 2001 From: magnum Date: Tue, 25 Feb 2025 15:10:33 +0100 Subject: [PATCH 046/252] Recover from (rare) non-fatal file locking problems --- src/locking.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/locking.c b/src/locking.c index 8918101a2..492350bab 100644 --- a/src/locking.c +++ b/src/locking.c @@ -20,9 +20,18 @@ int hc_lockfile (HCFILE *fp) lock.l_type = F_WRLCK; - /* Needs this loop because a signal may interrupt a wait for lock */ while (fcntl (fp->fd, F_SETLKW, &lock)) { + // These shouldn't happen with F_SETLKW yet are (rarely) seen IRL. Recoverable! + if (errno == EAGAIN || errno == ENOLCK) + { + struct timeval tv = { .tv_sec = 0, .tv_usec = 10000 }; + select (0, NULL, NULL, NULL, &tv); + + continue; + } + + // A signal may interrupt a wait for lock with EINTR. Anything else is fatal if (errno != EINTR) return -1; } From 9b9a7a519a19fe56d5d53fba255f6cb879daee6a Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 Date: Sat, 5 Apr 2025 19:10:12 +0100 Subject: [PATCH 047/252] Recommend --keep-guessing on -m 20510 --- src/modules/module_20510.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/module_20510.c b/src/modules/module_20510.c index d96f57b6e..4172c1fda 100644 --- a/src/modules/module_20510.c +++ b/src/modules/module_20510.c @@ -81,7 +81,8 @@ static const u32 OPTI_TYPE = 0; static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE | OPTS_TYPE_COPY_TMPS | OPTS_TYPE_MAXIMUM_THREADS - | OPTS_TYPE_AUTODETECT_DISABLE; + | OPTS_TYPE_AUTODETECT_DISABLE + | OPTS_TYPE_SUGGEST_KG; static const u32 SALT_TYPE = SALT_TYPE_NONE; static const char *ST_PASS = "t"; // actually "hashcat" static const char *ST_HASH = "f1eff5c0368d10311dcfc419"; From d2e9eacca8fa540e4d18f34258a72307aca8c30c Mon Sep 17 00:00:00 2001 From: holly-o <128481388+holly-o@users.noreply.github.com> Date: Fri, 11 Apr 2025 16:11:20 +0100 Subject: [PATCH 048/252] Added OpenCL files for plugin 67890 --- OpenCL/inc_hash_blake2s.cl | 664 ++++++++++++++++++++++++++++++++++++- OpenCL/inc_hash_blake2s.h | 37 +++ OpenCL/m67890_a0-pure.cl | 135 ++++++++ OpenCL/m67890_a1-pure.cl | 183 ++++++++++ OpenCL/m67890_a3-pure.cl | 156 +++++++++ 5 files changed, 1172 insertions(+), 3 deletions(-) create mode 100644 OpenCL/m67890_a0-pure.cl create mode 100644 OpenCL/m67890_a1-pure.cl create mode 100644 OpenCL/m67890_a3-pure.cl diff --git a/OpenCL/inc_hash_blake2s.cl b/OpenCL/inc_hash_blake2s.cl index 5fb60f979..77ecc02fb 100644 --- a/OpenCL/inc_hash_blake2s.cl +++ b/OpenCL/inc_hash_blake2s.cl @@ -9,6 +9,7 @@ #include "inc_common.h" #include "inc_hash_blake2s.h" + DECLSPEC u32 blake2s_rot16_S (const u32 a) { vconv32_t in; @@ -217,7 +218,7 @@ DECLSPEC void blake2s_update_64 (PRIVATE_AS blake2s_ctx_t *ctx, PRIVATE_AS u32 * if (pos == 0) { - if (ctx->len > 0) // if new block (pos == 0) AND the (old) len is not zero => transform + if (ctx->len > 0) { blake2s_transform (ctx->h, ctx->m, ctx->len, BLAKE2S_UPDATE); } @@ -288,8 +289,6 @@ DECLSPEC void blake2s_update_64 (PRIVATE_AS blake2s_ctx_t *ctx, PRIVATE_AS u32 * ctx->m[14] |= w3[2]; ctx->m[15] |= w3[3]; - // len must be a multiple of 64 (not ctx->len) for BLAKE2S_UPDATE: - const u32 cur_len = ((ctx->len + len) / 64) * 64; blake2s_transform (ctx->h, ctx->m, cur_len, BLAKE2S_UPDATE); @@ -424,11 +423,520 @@ DECLSPEC void blake2s_update_global (PRIVATE_AS blake2s_ctx_t *ctx, GLOBAL_AS co blake2s_update_64 (ctx, w0, w1, w2, w3, len - (u32) pos1); } +DECLSPEC void blake2s_update_swap (PRIVATE_AS blake2s_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + blake2s_update_64 (ctx, w0, w1, w2, w3, 64); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + blake2s_update_64 (ctx, w0, w1, w2, w3, len - pos1); +} + +DECLSPEC void blake2s_update_global_swap (PRIVATE_AS blake2s_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + const int limit = (const int) len - 64; // int type needed, could be negative + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < limit; pos1 += 64, pos4 += 16) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + blake2s_update_64 (ctx, w0, w1, w2, w3, 64); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + blake2s_update_64 (ctx, w0, w1, w2, w3, len - (u32) pos1); +} + + DECLSPEC void blake2s_final (PRIVATE_AS blake2s_ctx_t *ctx) { blake2s_transform (ctx->h, ctx->m, ctx->len, BLAKE2S_FINAL); } + +DECLSPEC void blake2s_hmac_init_64 (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w0, PRIVATE_AS const u32 *w1, PRIVATE_AS const u32 *w2, PRIVATE_AS const u32 *w3) +{ + u32 a0[4]; + u32 a1[4]; + u32 a2[4]; + u32 a3[4]; + + // ipad + + a0[0] = w0[0] ^ 0x36363636; + a0[1] = w0[1] ^ 0x36363636; + a0[2] = w0[2] ^ 0x36363636; + a0[3] = w0[3] ^ 0x36363636; + a1[0] = w1[0] ^ 0x36363636; + a1[1] = w1[1] ^ 0x36363636; + a1[2] = w1[2] ^ 0x36363636; + a1[3] = w1[3] ^ 0x36363636; + a2[0] = w2[0] ^ 0x36363636; + a2[1] = w2[1] ^ 0x36363636; + a2[2] = w2[2] ^ 0x36363636; + a2[3] = w2[3] ^ 0x36363636; + a3[0] = w3[0] ^ 0x36363636; + a3[1] = w3[1] ^ 0x36363636; + a3[2] = w3[2] ^ 0x36363636; + a3[3] = w3[3] ^ 0x36363636; + + blake2s_init (&ctx->ipad); + + blake2s_update_64 (&ctx->ipad, a0, a1, a2, a3, 64); + + // opad + + u32 b0[4]; + u32 b1[4]; + u32 b2[4]; + u32 b3[4]; + + b0[0] = w0[0] ^ 0x5c5c5c5c; + b0[1] = w0[1] ^ 0x5c5c5c5c; + b0[2] = w0[2] ^ 0x5c5c5c5c; + b0[3] = w0[3] ^ 0x5c5c5c5c; + b1[0] = w1[0] ^ 0x5c5c5c5c; + b1[1] = w1[1] ^ 0x5c5c5c5c; + b1[2] = w1[2] ^ 0x5c5c5c5c; + b1[3] = w1[3] ^ 0x5c5c5c5c; + b2[0] = w2[0] ^ 0x5c5c5c5c; + b2[1] = w2[1] ^ 0x5c5c5c5c; + b2[2] = w2[2] ^ 0x5c5c5c5c; + b2[3] = w2[3] ^ 0x5c5c5c5c; + b3[0] = w3[0] ^ 0x5c5c5c5c; + b3[1] = w3[1] ^ 0x5c5c5c5c; + b3[2] = w3[2] ^ 0x5c5c5c5c; + b3[3] = w3[3] ^ 0x5c5c5c5c; + + blake2s_init (&ctx->opad); + + blake2s_update_64 (&ctx->opad, b0, b1, b2, b3, 64); +} + +DECLSPEC void blake2s_hmac_init (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + if (len > 64) + { + blake2s_ctx_t tmp; + + blake2s_init (&tmp); + + blake2s_update (&tmp, w, len); + + blake2s_final (&tmp); + + w0[0] = tmp.h[0]; + w0[1] = tmp.h[1]; + w0[2] = tmp.h[2]; + w0[3] = tmp.h[3]; + w1[0] = tmp.h[4]; + w1[1] = tmp.h[5]; + w1[2] = tmp.h[6]; + w1[3] = tmp.h[7]; + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + } + else + { + w0[0] = w[ 0]; + w0[1] = w[ 1]; + w0[2] = w[ 2]; + w0[3] = w[ 3]; + w1[0] = w[ 4]; + w1[1] = w[ 5]; + w1[2] = w[ 6]; + w1[3] = w[ 7]; + w2[0] = w[ 8]; + w2[1] = w[ 9]; + w2[2] = w[10]; + w2[3] = w[11]; + w3[0] = w[12]; + w3[1] = w[13]; + w3[2] = w[14]; + w3[3] = w[15]; + } + + blake2s_hmac_init_64 (ctx, w0, w1, w2, w3); +} + +DECLSPEC void blake2s_hmac_init_swap (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + if (len > 64) + { + blake2s_ctx_t tmp; + + blake2s_init (&tmp); + + blake2s_update_swap (&tmp, w, len); + + blake2s_final (&tmp); + + w0[0] = tmp.h[0]; + w0[1] = tmp.h[1]; + w0[2] = tmp.h[2]; + w0[3] = tmp.h[3]; + w1[0] = tmp.h[4]; + w1[1] = tmp.h[5]; + w1[2] = tmp.h[6]; + w1[3] = tmp.h[7]; + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + } + else + { + w0[0] = hc_swap32_S (w[ 0]); + w0[1] = hc_swap32_S (w[ 1]); + w0[2] = hc_swap32_S (w[ 2]); + w0[3] = hc_swap32_S (w[ 3]); + w1[0] = hc_swap32_S (w[ 4]); + w1[1] = hc_swap32_S (w[ 5]); + w1[2] = hc_swap32_S (w[ 6]); + w1[3] = hc_swap32_S (w[ 7]); + w2[0] = hc_swap32_S (w[ 8]); + w2[1] = hc_swap32_S (w[ 9]); + w2[2] = hc_swap32_S (w[10]); + w2[3] = hc_swap32_S (w[11]); + w3[0] = hc_swap32_S (w[12]); + w3[1] = hc_swap32_S (w[13]); + w3[2] = hc_swap32_S (w[14]); + w3[3] = hc_swap32_S (w[15]); + } + + blake2s_hmac_init_64 (ctx, w0, w1, w2, w3); +} + +DECLSPEC void blake2s_hmac_init_global (PRIVATE_AS blake2s_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + if (len > 64) + { + blake2s_ctx_t tmp; + + blake2s_init (&tmp); + + blake2s_update_global (&tmp, w, len); + + blake2s_final (&tmp); + + w0[0] = tmp.h[0]; + w0[1] = tmp.h[1]; + w0[2] = tmp.h[2]; + w0[3] = tmp.h[3]; + w1[0] = tmp.h[4]; + w1[1] = tmp.h[5]; + w1[2] = tmp.h[6]; + w1[3] = tmp.h[7]; + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + } + else + { + w0[0] = w[ 0]; + w0[1] = w[ 1]; + w0[2] = w[ 2]; + w0[3] = w[ 3]; + w1[0] = w[ 4]; + w1[1] = w[ 5]; + w1[2] = w[ 6]; + w1[3] = w[ 7]; + w2[0] = w[ 8]; + w2[1] = w[ 9]; + w2[2] = w[10]; + w2[3] = w[11]; + w3[0] = w[12]; + w3[1] = w[13]; + w3[2] = w[14]; + w3[3] = w[15]; + } + + blake2s_hmac_init_64 (ctx, w0, w1, w2, w3); +} + +DECLSPEC void blake2s_hmac_init_global_swap (PRIVATE_AS blake2s_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + if (len > 64) + { + blake2s_ctx_t tmp; + + blake2s_init (&tmp); + + blake2s_update_global_swap (&tmp, w, len); + + blake2s_final (&tmp); + + w0[0] = tmp.h[0]; + w0[1] = tmp.h[1]; + w0[2] = tmp.h[2]; + w0[3] = tmp.h[3]; + w1[0] = tmp.h[4]; + w1[1] = tmp.h[5]; + w1[2] = tmp.h[6]; + w1[3] = tmp.h[7]; + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + } + else + { + w0[0] = hc_swap32_S (w[ 0]); + w0[1] = hc_swap32_S (w[ 1]); + w0[2] = hc_swap32_S (w[ 2]); + w0[3] = hc_swap32_S (w[ 3]); + w1[0] = hc_swap32_S (w[ 4]); + w1[1] = hc_swap32_S (w[ 5]); + w1[2] = hc_swap32_S (w[ 6]); + w1[3] = hc_swap32_S (w[ 7]); + w2[0] = hc_swap32_S (w[ 8]); + w2[1] = hc_swap32_S (w[ 9]); + w2[2] = hc_swap32_S (w[10]); + w2[3] = hc_swap32_S (w[11]); + w3[0] = hc_swap32_S (w[12]); + w3[1] = hc_swap32_S (w[13]); + w3[2] = hc_swap32_S (w[14]); + w3[3] = hc_swap32_S (w[15]); + } + + blake2s_hmac_init_64 (ctx, w0, w1, w2, w3); +} + +DECLSPEC void blake2s_hmac_update_64 (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS u32 *w0, PRIVATE_AS u32 *w1, PRIVATE_AS u32 *w2, PRIVATE_AS u32 *w3, const int len) +{ + blake2s_update_64 (&ctx->ipad, w0, w1, w2, w3, len); +} + +DECLSPEC void blake2s_hmac_update (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + blake2s_update (&ctx->ipad, w, len); +} + +DECLSPEC void blake2s_hmac_update_swap (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + blake2s_update_swap (&ctx->ipad, w, len); +} + +DECLSPEC void blake2s_hmac_update_global (PRIVATE_AS blake2s_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + blake2s_update_global (&ctx->ipad, w, len); +} + +DECLSPEC void blake2s_hmac_update_global_swap (PRIVATE_AS blake2s_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + blake2s_update_global_swap (&ctx->ipad, w, len); +} + +DECLSPEC void blake2s_hmac_final (PRIVATE_AS blake2s_hmac_ctx_t *ctx) +{ + blake2s_final (&ctx->ipad); + + for (int n = 0; n < 8; n += 1) + { + blake2s_update(&ctx->opad, &ctx->ipad.h[n], 4); + } + + ctx->opad.m[8] = 0; + ctx->opad.m[9] = 0; + ctx->opad.m[10]= 0; + ctx->opad.m[11]= 0; + ctx->opad.m[12]= 0; + ctx->opad.m[13]= 0; + ctx->opad.m[14]= 0; + ctx->opad.m[15]= 0; + + blake2s_final (&ctx->opad); +} + DECLSPEC void blake2s_transform_vector (PRIVATE_AS u32x *h, PRIVATE_AS const u32x *m, const u32x len, const u32 f0) { const u32x t0 = len; @@ -452,6 +960,7 @@ DECLSPEC void blake2s_transform_vector (PRIVATE_AS u32x *h, PRIVATE_AS const u32 v[14] = BLAKE2S_IV_06 ^ f0; v[15] = BLAKE2S_IV_07; // ^ f1; + BLAKE2S_ROUND_VECTOR ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); BLAKE2S_ROUND_VECTOR (14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3); BLAKE2S_ROUND_VECTOR (11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4); @@ -700,3 +1209,152 @@ DECLSPEC void blake2s_final_vector (PRIVATE_AS blake2s_ctx_vector_t *ctx) { blake2s_transform_vector (ctx->h, ctx->m, (u32x) ctx->len, BLAKE2S_FINAL); } + +DECLSPEC void blake2s_hmac_init_vector_64 (PRIVATE_AS blake2s_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w0, PRIVATE_AS const u32x *w1, PRIVATE_AS const u32x *w2, PRIVATE_AS const u32x *w3) +{ + u32x a0[4]; + u32x a1[4]; + u32x a2[4]; + u32x a3[4]; + + // ipad + + a0[0] = w0[0] ^ 0x36363636; + a0[1] = w0[1] ^ 0x36363636; + a0[2] = w0[2] ^ 0x36363636; + a0[3] = w0[3] ^ 0x36363636; + a1[0] = w1[0] ^ 0x36363636; + a1[1] = w1[1] ^ 0x36363636; + a1[2] = w1[2] ^ 0x36363636; + a1[3] = w1[3] ^ 0x36363636; + a2[0] = w2[0] ^ 0x36363636; + a2[1] = w2[1] ^ 0x36363636; + a2[2] = w2[2] ^ 0x36363636; + a2[3] = w2[3] ^ 0x36363636; + a3[0] = w3[0] ^ 0x36363636; + a3[1] = w3[1] ^ 0x36363636; + a3[2] = w3[2] ^ 0x36363636; + a3[3] = w3[3] ^ 0x36363636; + + blake2s_init_vector (&ctx->ipad); + + blake2s_update_vector_64 (&ctx->ipad, a0, a1, a2, a3, 64); + + // opad + + u32x b0[4]; + u32x b1[4]; + u32x b2[4]; + u32x b3[4]; + + b0[0] = w0[0] ^ 0x5c5c5c5c; + b0[1] = w0[1] ^ 0x5c5c5c5c; + b0[2] = w0[2] ^ 0x5c5c5c5c; + b0[3] = w0[3] ^ 0x5c5c5c5c; + b1[0] = w1[0] ^ 0x5c5c5c5c; + b1[1] = w1[1] ^ 0x5c5c5c5c; + b1[2] = w1[2] ^ 0x5c5c5c5c; + b1[3] = w1[3] ^ 0x5c5c5c5c; + b2[0] = w2[0] ^ 0x5c5c5c5c; + b2[1] = w2[1] ^ 0x5c5c5c5c; + b2[2] = w2[2] ^ 0x5c5c5c5c; + b2[3] = w2[3] ^ 0x5c5c5c5c; + b3[0] = w3[0] ^ 0x5c5c5c5c; + b3[1] = w3[1] ^ 0x5c5c5c5c; + b3[2] = w3[2] ^ 0x5c5c5c5c; + b3[3] = w3[3] ^ 0x5c5c5c5c; + + blake2s_init_vector (&ctx->opad); + + blake2s_update_vector_64 (&ctx->opad, b0, b1, b2, b3, 64); +} + + +DECLSPEC void blake2s_hmac_init_vector (PRIVATE_AS blake2s_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len) +{ + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + if (len > 64) + { + blake2s_ctx_vector_t tmp; + + blake2s_init_vector (&tmp); + + blake2s_update_vector (&tmp, w, len); + + blake2s_final_vector (&tmp); + + w0[0] = tmp.h[0]; + w0[1] = tmp.h[1]; + w0[2] = tmp.h[2]; + w0[3] = tmp.h[3]; + w1[0] = tmp.h[4]; + w1[1] = tmp.h[5]; + w1[2] = tmp.h[6]; + w1[3] = tmp.h[7]; + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + } + else + { + w0[0] = w[ 0]; + w0[1] = w[ 1]; + w0[2] = w[ 2]; + w0[3] = w[ 3]; + w1[0] = w[ 4]; + w1[1] = w[ 5]; + w1[2] = w[ 6]; + w1[3] = w[ 7]; + w2[0] = w[ 8]; + w2[1] = w[ 9]; + w2[2] = w[10]; + w2[3] = w[11]; + w3[0] = w[12]; + w3[1] = w[13]; + w3[2] = w[14]; + w3[3] = w[15]; + } + + blake2s_hmac_init_vector_64 (ctx, w0, w1, w2, w3); +} + +DECLSPEC void blake2s_hmac_update_vector_64 (PRIVATE_AS blake2s_hmac_ctx_vector_t *ctx, PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, const int len) +{ + blake2s_update_vector_64 (&ctx->ipad, w0, w1, w2, w3, len); +} + +DECLSPEC void blake2s_hmac_update_vector (PRIVATE_AS blake2s_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len) +{ + blake2s_update_vector (&ctx->ipad, w, len); +} + +DECLSPEC void blake2s_hmac_final_vector (PRIVATE_AS blake2s_hmac_ctx_vector_t *ctx) +{ + + blake2s_final_vector (&ctx->ipad); + + for (int n = 0; n < 8; n += 1) + { + blake2s_update_vector(&ctx->opad, &ctx->ipad.h[n], 4); + } + + ctx->opad.m[8] = 0; + ctx->opad.m[9] = 0; + ctx->opad.m[10]= 0; + ctx->opad.m[11]= 0; + ctx->opad.m[12]= 0; + ctx->opad.m[13]= 0; + ctx->opad.m[14]= 0; + ctx->opad.m[15]= 0; + + blake2s_final_vector (&ctx->opad); +} diff --git a/OpenCL/inc_hash_blake2s.h b/OpenCL/inc_hash_blake2s.h index 63f2942f1..9a13a59c7 100644 --- a/OpenCL/inc_hash_blake2s.h +++ b/OpenCL/inc_hash_blake2s.h @@ -72,6 +72,14 @@ typedef struct blake2s_ctx } blake2s_ctx_t; +typedef struct blake2s_hmac_ctx +{ + blake2s_ctx_t ipad; + blake2s_ctx_t opad; + +} blake2s_hmac_ctx_t; + + typedef struct blake2s_ctx_vector { u32x m[16]; // buffer @@ -81,16 +89,45 @@ typedef struct blake2s_ctx_vector } blake2s_ctx_vector_t; +typedef struct blake2s_hmac_ctx_vector +{ + blake2s_ctx_vector_t ipad; + blake2s_ctx_vector_t opad; + +} blake2s_hmac_ctx_vector_t; + + + + DECLSPEC void blake2s_transform (PRIVATE_AS u32 *h, PRIVATE_AS const u32 *m, const int len, const u32 f0); DECLSPEC void blake2s_init (PRIVATE_AS blake2s_ctx_t *ctx); DECLSPEC void blake2s_update (PRIVATE_AS blake2s_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); DECLSPEC void blake2s_update_global (PRIVATE_AS blake2s_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void blake2s_update_global_swap (PRIVATE_AS blake2s_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); DECLSPEC void blake2s_final (PRIVATE_AS blake2s_ctx_t *ctx); +DECLSPEC void blake2s_hmac_init_64 (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w0, PRIVATE_AS const u32 *w1, PRIVATE_AS const u32 *w2, PRIVATE_AS const u32 *w3); +DECLSPEC void blake2s_hmac_init (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void blake2s_hmac_init_swap (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void blake2s_hmac_init_global (PRIVATE_AS blake2s_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void blake2s_hmac_init_global_swap (PRIVATE_AS blake2s_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void blake2s_hmac_update_64 (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS u32 *w0, PRIVATE_AS u32 *w1, PRIVATE_AS u32 *w2, PRIVATE_AS u32 *w3, const int len); +DECLSPEC void blake2s_hmac_update (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void blake2s_hmac_update_swap (PRIVATE_AS blake2s_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void blake2s_hmac_update_global (PRIVATE_AS blake2s_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void blake2s_hmac_update_global_swap (PRIVATE_AS blake2s_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void blake2s_hmac_final (PRIVATE_AS blake2s_hmac_ctx_t *ctx); + DECLSPEC void blake2s_transform_vector (PRIVATE_AS u32x *h, PRIVATE_AS const u32x *m, const u32x len, const u32 f0); DECLSPEC void blake2s_init_vector (PRIVATE_AS blake2s_ctx_vector_t *ctx); DECLSPEC void blake2s_init_vector_from_scalar (PRIVATE_AS blake2s_ctx_vector_t *ctx, PRIVATE_AS blake2s_ctx_t *ctx0); DECLSPEC void blake2s_update_vector (PRIVATE_AS blake2s_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len); DECLSPEC void blake2s_final_vector (PRIVATE_AS blake2s_ctx_vector_t *ctx); +DECLSPEC void blake2s_hmac_init_vector_64 (PRIVATE_AS blake2s_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w0, PRIVATE_AS const u32x *w1, PRIVATE_AS const u32x *w2, PRIVATE_AS const u32x *w3); +DECLSPEC void blake2s_hmac_init_vector (PRIVATE_AS blake2s_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len); +DECLSPEC void blake2s_hmac_update_vector_64 (PRIVATE_AS blake2s_hmac_ctx_vector_t *ctx, PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, const int len); +DECLSPEC void blake2s_hmac_update_vector (PRIVATE_AS blake2s_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len); +DECLSPEC void blake2s_hmac_final_vector (PRIVATE_AS blake2s_hmac_ctx_vector_t *ctx); + #endif // INC_HASH_BLAKE2S_H diff --git a/OpenCL/m67890_a0-pure.cl b/OpenCL/m67890_a0-pure.cl new file mode 100644 index 000000000..b32d7a7cf --- /dev/null +++ b/OpenCL/m67890_a0-pure.cl @@ -0,0 +1,135 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#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_blake2s.cl) +#endif + +KERNEL_FQ void m67890_mxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + blake2s_hmac_ctx_t ctx; + + blake2s_hmac_init (&ctx, tmp.i, tmp.pw_len); + + blake2s_hmac_update (&ctx, s, salt_len); + + blake2s_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m67890_sxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + 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 + */ + + COPY_PW (pws[gid]); + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + blake2s_hmac_ctx_t ctx; + + blake2s_hmac_init (&ctx, tmp.i, tmp.pw_len); + + blake2s_hmac_update (&ctx, s, salt_len); + + blake2s_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m67890_a1-pure.cl b/OpenCL/m67890_a1-pure.cl new file mode 100644 index 000000000..04f023d61 --- /dev/null +++ b/OpenCL/m67890_a1-pure.cl @@ -0,0 +1,183 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#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_blake2s.cl) +#endif + +KERNEL_FQ void m67890_mxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32 w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = combs_buf[il_pos].i[idx]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + blake2s_hmac_ctx_t ctx; + + blake2s_hmac_init (&ctx, c, pw_len + comb_len); + + blake2s_hmac_update (&ctx, s, salt_len); + + blake2s_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m67890_sxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + 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; + + u32 w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = combs_buf[il_pos].i[idx]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + blake2s_hmac_ctx_t ctx; + + blake2s_hmac_init (&ctx, c, pw_len + comb_len); + + blake2s_hmac_update (&ctx, s, salt_len); + + blake2s_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m67890_a3-pure.cl b/OpenCL/m67890_a3-pure.cl new file mode 100644 index 000000000..8e39f0a60 --- /dev/null +++ b/OpenCL/m67890_a3-pure.cl @@ -0,0 +1,156 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#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_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_blake2s.cl) +#endif + +KERNEL_FQ void m67890_mxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32x s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + blake2s_hmac_ctx_vector_t ctx; + + blake2s_hmac_init_vector (&ctx, w, pw_len); + + blake2s_hmac_update_vector (&ctx, s, salt_len); + + blake2s_hmac_final_vector (&ctx); + + const u32x r0 = ctx.opad.h[DGST_R0]; + const u32x r1 = ctx.opad.h[DGST_R1]; + const u32x r2 = ctx.opad.h[DGST_R2]; + const u32x r3 = ctx.opad.h[DGST_R3]; + + COMPARE_M_SIMD (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m67890_sxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + 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; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32x s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + blake2s_hmac_ctx_vector_t ctx; + + blake2s_hmac_init_vector (&ctx, w, pw_len); + + blake2s_hmac_update_vector (&ctx, s, salt_len); + + blake2s_hmac_final_vector (&ctx); + + const u32x r0 = ctx.opad.h[DGST_R0]; + const u32x r1 = ctx.opad.h[DGST_R1]; + const u32x r2 = ctx.opad.h[DGST_R2]; + const u32x r3 = ctx.opad.h[DGST_R3]; + + COMPARE_S_SIMD (r0, r1, r2, r3); + } + +} From 3268b58e2417b1e240743f47bc355a91b8e2b562 Mon Sep 17 00:00:00 2001 From: Andreas Vikerup Date: Tue, 15 Apr 2025 16:25:53 +0200 Subject: [PATCH 049/252] add module 20713 - sha256(sha256(pass+salt)) --- OpenCL/m20713_a0-pure.cl | 253 +++++++++++++++++++++++++++++++++ OpenCL/m20713_a1-pure.cl | 257 +++++++++++++++++++++++++++++++++ OpenCL/m20713_a3-pure.cl | 283 +++++++++++++++++++++++++++++++++++++ src/modules/module_20713.c | 260 ++++++++++++++++++++++++++++++++++ 4 files changed, 1053 insertions(+) create mode 100644 OpenCL/m20713_a0-pure.cl create mode 100644 OpenCL/m20713_a1-pure.cl create mode 100644 OpenCL/m20713_a3-pure.cl create mode 100644 src/modules/module_20713.c diff --git a/OpenCL/m20713_a0-pure.cl b/OpenCL/m20713_a0-pure.cl new file mode 100644 index 000000000..f0929bc49 --- /dev/null +++ b/OpenCL/m20713_a0-pure.cl @@ -0,0 +1,253 @@ +/** + * Author......: Andreas Vikerup @ Shelltrail + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#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) +#endif + +#if VECT_SIZE == 1 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i)]) +#elif VECT_SIZE == 2 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1]) +#elif VECT_SIZE == 4 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3]) +#elif VECT_SIZE == 8 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7]) +#elif VECT_SIZE == 16 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7], l_bin2asc[(i).s8], l_bin2asc[(i).s9], l_bin2asc[(i).sa], l_bin2asc[(i).sb], l_bin2asc[(i).sc], l_bin2asc[(i).sd], l_bin2asc[(i).se], l_bin2asc[(i).sf]) +#endif + +KERNEL_FQ void m20713_mxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /** + * bin2asc table + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 0 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 8; + } + + SYNC_THREADS (); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + COPY_PW (pws[gid]); + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (int i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + sha256_ctx_t ctx0; + sha256_init (&ctx0); + sha256_update_swap (&ctx0, tmp.i, tmp.pw_len); + sha256_update (&ctx0, s, salt_len); + sha256_final (&ctx0); + + const u32 a = ctx0.h[0]; + const u32 b = ctx0.h[1]; + const u32 c = ctx0.h[2]; + const u32 d = ctx0.h[3]; + const u32 e = ctx0.h[4]; + const u32 f = ctx0.h[5]; + const u32 g = ctx0.h[6]; + const u32 h = ctx0.h[7]; + + sha256_ctx_t ctx; + sha256_init (&ctx); + + w0[0] = uint_to_hex_lower8_le ((a >> 16) & 255) << 0 | uint_to_hex_lower8_le ((a >> 24) & 255) << 16; + w0[1] = uint_to_hex_lower8_le ((a >> 0) & 255) << 0 | uint_to_hex_lower8_le ((a >> 8) & 255) << 16; + w0[2] = uint_to_hex_lower8_le ((b >> 16) & 255) << 0 | uint_to_hex_lower8_le ((b >> 24) & 255) << 16; + w0[3] = uint_to_hex_lower8_le ((b >> 0) & 255) << 0 | uint_to_hex_lower8_le ((b >> 8) & 255) << 16; + w1[0] = uint_to_hex_lower8_le ((c >> 16) & 255) << 0 | uint_to_hex_lower8_le ((c >> 24) & 255) << 16; + w1[1] = uint_to_hex_lower8_le ((c >> 0) & 255) << 0 | uint_to_hex_lower8_le ((c >> 8) & 255) << 16; + w1[2] = uint_to_hex_lower8_le ((d >> 16) & 255) << 0 | uint_to_hex_lower8_le ((d >> 24) & 255) << 16; + w1[3] = uint_to_hex_lower8_le ((d >> 0) & 255) << 0 | uint_to_hex_lower8_le ((d >> 8) & 255) << 16; + w2[0] = uint_to_hex_lower8_le ((e >> 16) & 255) << 0 | uint_to_hex_lower8_le ((e >> 24) & 255) << 16; + w2[1] = uint_to_hex_lower8_le ((e >> 0) & 255) << 0 | uint_to_hex_lower8_le ((e >> 8) & 255) << 16; + w2[2] = uint_to_hex_lower8_le ((f >> 16) & 255) << 0 | uint_to_hex_lower8_le ((f >> 24) & 255) << 16; + w2[3] = uint_to_hex_lower8_le ((f >> 0) & 255) << 0 | uint_to_hex_lower8_le ((f >> 8) & 255) << 16; + w3[0] = uint_to_hex_lower8_le ((g >> 16) & 255) << 0 | uint_to_hex_lower8_le ((g >> 24) & 255) << 16; + w3[1] = uint_to_hex_lower8_le ((g >> 0) & 255) << 0 | uint_to_hex_lower8_le ((g >> 8) & 255) << 16; + w3[2] = uint_to_hex_lower8_le ((h >> 16) & 255) << 0 | uint_to_hex_lower8_le ((h >> 24) & 255) << 16; + w3[3] = uint_to_hex_lower8_le ((h >> 0) & 255) << 0 | uint_to_hex_lower8_le ((h >> 8) & 255) << 16; + + sha256_update_64 (&ctx, w0, w1, w2, w3, 64); + sha256_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m20713_sxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /** + * bin2asc table + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 0 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 8; + } + + SYNC_THREADS (); + + 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 + */ + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + COPY_PW (pws[gid]); + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (int i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + sha256_ctx_t ctx0; + sha256_init (&ctx0); + sha256_update_swap (&ctx0, tmp.i, tmp.pw_len); + sha256_update (&ctx0, s, salt_len); + sha256_final (&ctx0); + + const u32 a = ctx0.h[0]; + const u32 b = ctx0.h[1]; + const u32 c = ctx0.h[2]; + const u32 d = ctx0.h[3]; + const u32 e = ctx0.h[4]; + const u32 f = ctx0.h[5]; + const u32 g = ctx0.h[6]; + const u32 h = ctx0.h[7]; + + sha256_ctx_t ctx; + sha256_init (&ctx); + + w0[0] = uint_to_hex_lower8_le ((a >> 16) & 255) << 0 | uint_to_hex_lower8_le ((a >> 24) & 255) << 16; + w0[1] = uint_to_hex_lower8_le ((a >> 0) & 255) << 0 | uint_to_hex_lower8_le ((a >> 8) & 255) << 16; + w0[2] = uint_to_hex_lower8_le ((b >> 16) & 255) << 0 | uint_to_hex_lower8_le ((b >> 24) & 255) << 16; + w0[3] = uint_to_hex_lower8_le ((b >> 0) & 255) << 0 | uint_to_hex_lower8_le ((b >> 8) & 255) << 16; + w1[0] = uint_to_hex_lower8_le ((c >> 16) & 255) << 0 | uint_to_hex_lower8_le ((c >> 24) & 255) << 16; + w1[1] = uint_to_hex_lower8_le ((c >> 0) & 255) << 0 | uint_to_hex_lower8_le ((c >> 8) & 255) << 16; + w1[2] = uint_to_hex_lower8_le ((d >> 16) & 255) << 0 | uint_to_hex_lower8_le ((d >> 24) & 255) << 16; + w1[3] = uint_to_hex_lower8_le ((d >> 0) & 255) << 0 | uint_to_hex_lower8_le ((d >> 8) & 255) << 16; + w2[0] = uint_to_hex_lower8_le ((e >> 16) & 255) << 0 | uint_to_hex_lower8_le ((e >> 24) & 255) << 16; + w2[1] = uint_to_hex_lower8_le ((e >> 0) & 255) << 0 | uint_to_hex_lower8_le ((e >> 8) & 255) << 16; + w2[2] = uint_to_hex_lower8_le ((f >> 16) & 255) << 0 | uint_to_hex_lower8_le ((f >> 24) & 255) << 16; + w2[3] = uint_to_hex_lower8_le ((f >> 0) & 255) << 0 | uint_to_hex_lower8_le ((f >> 8) & 255) << 16; + w3[0] = uint_to_hex_lower8_le ((g >> 16) & 255) << 0 | uint_to_hex_lower8_le ((g >> 24) & 255) << 16; + w3[1] = uint_to_hex_lower8_le ((g >> 0) & 255) << 0 | uint_to_hex_lower8_le ((g >> 8) & 255) << 16; + w3[2] = uint_to_hex_lower8_le ((h >> 16) & 255) << 0 | uint_to_hex_lower8_le ((h >> 24) & 255) << 16; + w3[3] = uint_to_hex_lower8_le ((h >> 0) & 255) << 0 | uint_to_hex_lower8_le ((h >> 8) & 255) << 16; + + sha256_update_64 (&ctx, w0, w1, w2, w3, 64); + sha256_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m20713_a1-pure.cl b/OpenCL/m20713_a1-pure.cl new file mode 100644 index 000000000..97482e3f9 --- /dev/null +++ b/OpenCL/m20713_a1-pure.cl @@ -0,0 +1,257 @@ +/** + * Author......: Andreas Vikerup @ Shelltrail + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#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) +#endif + +#if VECT_SIZE == 1 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i)]) +#elif VECT_SIZE == 2 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1]) +#elif VECT_SIZE == 4 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3]) +#elif VECT_SIZE == 8 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7]) +#elif VECT_SIZE == 16 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7], l_bin2asc[(i).s8], l_bin2asc[(i).s9], l_bin2asc[(i).sa], l_bin2asc[(i).sb], l_bin2asc[(i).sc], l_bin2asc[(i).sd], l_bin2asc[(i).se], l_bin2asc[(i).sf]) +#endif + +KERNEL_FQ void m20713_mxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + /** + * bin2asc table + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 0 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 8; + } + + SYNC_THREADS (); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + u32 s[64] = { 0 }; + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + for (int i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + } + + sha256_ctx_t ctx1; + + sha256_init (&ctx1); + + sha256_update_global_swap (&ctx1, pws[gid].i, pws[gid].pw_len); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + sha256_ctx_t ctx0 = ctx1; + + sha256_update_global_swap (&ctx0, combs_buf[il_pos].i, combs_buf[il_pos].pw_len); + sha256_update (&ctx0, s, salt_len); + + sha256_final (&ctx0); + + const u32 a = ctx0.h[0]; + const u32 b = ctx0.h[1]; + const u32 c = ctx0.h[2]; + const u32 d = ctx0.h[3]; + const u32 e = ctx0.h[4]; + const u32 f = ctx0.h[5]; + const u32 g = ctx0.h[6]; + const u32 h = ctx0.h[7]; + + sha256_ctx_t ctx; + + sha256_init (&ctx); + + w0[0] = uint_to_hex_lower8_le ((a >> 16) & 255) << 0 | uint_to_hex_lower8_le ((a >> 24) & 255) << 16; + w0[1] = uint_to_hex_lower8_le ((a >> 0) & 255) << 0 | uint_to_hex_lower8_le ((a >> 8) & 255) << 16; + w0[2] = uint_to_hex_lower8_le ((b >> 16) & 255) << 0 | uint_to_hex_lower8_le ((b >> 24) & 255) << 16; + w0[3] = uint_to_hex_lower8_le ((b >> 0) & 255) << 0 | uint_to_hex_lower8_le ((b >> 8) & 255) << 16; + w1[0] = uint_to_hex_lower8_le ((c >> 16) & 255) << 0 | uint_to_hex_lower8_le ((c >> 24) & 255) << 16; + w1[1] = uint_to_hex_lower8_le ((c >> 0) & 255) << 0 | uint_to_hex_lower8_le ((c >> 8) & 255) << 16; + w1[2] = uint_to_hex_lower8_le ((d >> 16) & 255) << 0 | uint_to_hex_lower8_le ((d >> 24) & 255) << 16; + w1[3] = uint_to_hex_lower8_le ((d >> 0) & 255) << 0 | uint_to_hex_lower8_le ((d >> 8) & 255) << 16; + w2[0] = uint_to_hex_lower8_le ((e >> 16) & 255) << 0 | uint_to_hex_lower8_le ((e >> 24) & 255) << 16; + w2[1] = uint_to_hex_lower8_le ((e >> 0) & 255) << 0 | uint_to_hex_lower8_le ((e >> 8) & 255) << 16; + w2[2] = uint_to_hex_lower8_le ((f >> 16) & 255) << 0 | uint_to_hex_lower8_le ((f >> 24) & 255) << 16; + w2[3] = uint_to_hex_lower8_le ((f >> 0) & 255) << 0 | uint_to_hex_lower8_le ((f >> 8) & 255) << 16; + w3[0] = uint_to_hex_lower8_le ((g >> 16) & 255) << 0 | uint_to_hex_lower8_le ((g >> 24) & 255) << 16; + w3[1] = uint_to_hex_lower8_le ((g >> 0) & 255) << 0 | uint_to_hex_lower8_le ((g >> 8) & 255) << 16; + w3[2] = uint_to_hex_lower8_le ((h >> 16) & 255) << 0 | uint_to_hex_lower8_le ((h >> 24) & 255) << 16; + w3[3] = uint_to_hex_lower8_le ((h >> 0) & 255) << 0 | uint_to_hex_lower8_le ((h >> 8) & 255) << 16; + + sha256_update_64 (&ctx, w0, w1, w2, w3, 64); + + sha256_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m20713_sxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + /** + * bin2asc table + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 0 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 8; + } + + SYNC_THREADS (); + + 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 + */ + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (int i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + } + + sha256_ctx_t ctx1; + + sha256_init (&ctx1); + + sha256_update_global_swap (&ctx1, pws[gid].i, pws[gid].pw_len); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + sha256_ctx_t ctx0 = ctx1; + + sha256_update_global_swap (&ctx0, combs_buf[il_pos].i, combs_buf[il_pos].pw_len); + sha256_update (&ctx0, s, salt_len); + + sha256_final (&ctx0); + + const u32 a = ctx0.h[0]; + const u32 b = ctx0.h[1]; + const u32 c = ctx0.h[2]; + const u32 d = ctx0.h[3]; + const u32 e = ctx0.h[4]; + const u32 f = ctx0.h[5]; + const u32 g = ctx0.h[6]; + const u32 h = ctx0.h[7]; + + sha256_ctx_t ctx; + + sha256_init (&ctx); + + w0[0] = uint_to_hex_lower8_le ((a >> 16) & 255) << 0 | uint_to_hex_lower8_le ((a >> 24) & 255) << 16; + w0[1] = uint_to_hex_lower8_le ((a >> 0) & 255) << 0 | uint_to_hex_lower8_le ((a >> 8) & 255) << 16; + w0[2] = uint_to_hex_lower8_le ((b >> 16) & 255) << 0 | uint_to_hex_lower8_le ((b >> 24) & 255) << 16; + w0[3] = uint_to_hex_lower8_le ((b >> 0) & 255) << 0 | uint_to_hex_lower8_le ((b >> 8) & 255) << 16; + w1[0] = uint_to_hex_lower8_le ((c >> 16) & 255) << 0 | uint_to_hex_lower8_le ((c >> 24) & 255) << 16; + w1[1] = uint_to_hex_lower8_le ((c >> 0) & 255) << 0 | uint_to_hex_lower8_le ((c >> 8) & 255) << 16; + w1[2] = uint_to_hex_lower8_le ((d >> 16) & 255) << 0 | uint_to_hex_lower8_le ((d >> 24) & 255) << 16; + w1[3] = uint_to_hex_lower8_le ((d >> 0) & 255) << 0 | uint_to_hex_lower8_le ((d >> 8) & 255) << 16; + w2[0] = uint_to_hex_lower8_le ((e >> 16) & 255) << 0 | uint_to_hex_lower8_le ((e >> 24) & 255) << 16; + w2[1] = uint_to_hex_lower8_le ((e >> 0) & 255) << 0 | uint_to_hex_lower8_le ((e >> 8) & 255) << 16; + w2[2] = uint_to_hex_lower8_le ((f >> 16) & 255) << 0 | uint_to_hex_lower8_le ((f >> 24) & 255) << 16; + w2[3] = uint_to_hex_lower8_le ((f >> 0) & 255) << 0 | uint_to_hex_lower8_le ((f >> 8) & 255) << 16; + w3[0] = uint_to_hex_lower8_le ((g >> 16) & 255) << 0 | uint_to_hex_lower8_le ((g >> 24) & 255) << 16; + w3[1] = uint_to_hex_lower8_le ((g >> 0) & 255) << 0 | uint_to_hex_lower8_le ((g >> 8) & 255) << 16; + w3[2] = uint_to_hex_lower8_le ((h >> 16) & 255) << 0 | uint_to_hex_lower8_le ((h >> 24) & 255) << 16; + w3[3] = uint_to_hex_lower8_le ((h >> 0) & 255) << 0 | uint_to_hex_lower8_le ((h >> 8) & 255) << 16; + + sha256_update_64 (&ctx, w0, w1, w2, w3, 64); + + sha256_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m20713_a3-pure.cl b/OpenCL/m20713_a3-pure.cl new file mode 100644 index 000000000..988d063cd --- /dev/null +++ b/OpenCL/m20713_a3-pure.cl @@ -0,0 +1,283 @@ +/** + * Author......: Andreas Vikerup @ Shelltrail + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#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_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_sha256.cl) +#endif + +#if VECT_SIZE == 1 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i)]) +#elif VECT_SIZE == 2 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1]) +#elif VECT_SIZE == 4 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3]) +#elif VECT_SIZE == 8 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7]) +#elif VECT_SIZE == 16 +#define uint_to_hex_lower8_le(i) make_u32x (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3], l_bin2asc[(i).s4], l_bin2asc[(i).s5], l_bin2asc[(i).s6], l_bin2asc[(i).s7], l_bin2asc[(i).s8], l_bin2asc[(i).s9], l_bin2asc[(i).sa], l_bin2asc[(i).sb], l_bin2asc[(i).sc], l_bin2asc[(i).sd], l_bin2asc[(i).se], l_bin2asc[(i).sf]) +#endif + +KERNEL_FQ void m20713_mxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /** + * bin2asc table + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 0 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 8; + } + + SYNC_THREADS (); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + u32x _w0[4]; + u32x _w1[4]; + u32x _w2[4]; + u32x _w3[4]; + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32x s[64] = { 0 }; + + for (int i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + sha256_ctx_vector_t ctx0; + + sha256_init_vector (&ctx0); + + sha256_update_vector (&ctx0, w, pw_len); + sha256_update_vector (&ctx0, s, salt_len); + + sha256_final_vector (&ctx0); + + const u32x a = ctx0.h[0]; + const u32x b = ctx0.h[1]; + const u32x c = ctx0.h[2]; + const u32x d = ctx0.h[3]; + const u32x e = ctx0.h[4]; + const u32x f = ctx0.h[5]; + const u32x g = ctx0.h[6]; + const u32x h = ctx0.h[7]; + + sha256_ctx_vector_t ctx; + + sha256_init_vector (&ctx); + + _w0[0] = uint_to_hex_lower8_le ((a >> 16) & 255) << 0 | uint_to_hex_lower8_le ((a >> 24) & 255) << 16; + _w0[1] = uint_to_hex_lower8_le ((a >> 0) & 255) << 0 | uint_to_hex_lower8_le ((a >> 8) & 255) << 16; + _w0[2] = uint_to_hex_lower8_le ((b >> 16) & 255) << 0 | uint_to_hex_lower8_le ((b >> 24) & 255) << 16; + _w0[3] = uint_to_hex_lower8_le ((b >> 0) & 255) << 0 | uint_to_hex_lower8_le ((b >> 8) & 255) << 16; + _w1[0] = uint_to_hex_lower8_le ((c >> 16) & 255) << 0 | uint_to_hex_lower8_le ((c >> 24) & 255) << 16; + _w1[1] = uint_to_hex_lower8_le ((c >> 0) & 255) << 0 | uint_to_hex_lower8_le ((c >> 8) & 255) << 16; + _w1[2] = uint_to_hex_lower8_le ((d >> 16) & 255) << 0 | uint_to_hex_lower8_le ((d >> 24) & 255) << 16; + _w1[3] = uint_to_hex_lower8_le ((d >> 0) & 255) << 0 | uint_to_hex_lower8_le ((d >> 8) & 255) << 16; + _w2[0] = uint_to_hex_lower8_le ((e >> 16) & 255) << 0 | uint_to_hex_lower8_le ((e >> 24) & 255) << 16; + _w2[1] = uint_to_hex_lower8_le ((e >> 0) & 255) << 0 | uint_to_hex_lower8_le ((e >> 8) & 255) << 16; + _w2[2] = uint_to_hex_lower8_le ((f >> 16) & 255) << 0 | uint_to_hex_lower8_le ((f >> 24) & 255) << 16; + _w2[3] = uint_to_hex_lower8_le ((f >> 0) & 255) << 0 | uint_to_hex_lower8_le ((f >> 8) & 255) << 16; + _w3[0] = uint_to_hex_lower8_le ((g >> 16) & 255) << 0 | uint_to_hex_lower8_le ((g >> 24) & 255) << 16; + _w3[1] = uint_to_hex_lower8_le ((g >> 0) & 255) << 0 | uint_to_hex_lower8_le ((g >> 8) & 255) << 16; + _w3[2] = uint_to_hex_lower8_le ((h >> 16) & 255) << 0 | uint_to_hex_lower8_le ((h >> 24) & 255) << 16; + _w3[3] = uint_to_hex_lower8_le ((h >> 0) & 255) << 0 | uint_to_hex_lower8_le ((h >> 8) & 255) << 16; + + sha256_update_vector_64 (&ctx, _w0, _w1, _w2, _w3, 64); + + sha256_final_vector (&ctx); + + const u32x r0 = ctx.h[DGST_R0]; + const u32x r1 = ctx.h[DGST_R1]; + const u32x r2 = ctx.h[DGST_R2]; + const u32x r3 = ctx.h[DGST_R3]; + + COMPARE_M_SIMD (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m20713_sxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); + + /** + * bin2asc table + */ + + LOCAL_VK u32 l_bin2asc[256]; + + for (u32 i = lid; i < 256; i += lsz) + { + const u32 i0 = (i >> 0) & 15; + const u32 i1 = (i >> 4) & 15; + + l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'a' - 10 + i0) << 0 + | ((i1 < 10) ? '0' + i1 : 'a' - 10 + i1) << 8; + } + + SYNC_THREADS (); + + 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 + */ + + u32x _w0[4]; + u32x _w1[4]; + u32x _w2[4]; + u32x _w3[4]; + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32x s[64] = { 0 }; + + for (int i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = hc_swap32_S (salt_bufs[SALT_POS_HOST].salt_buf[idx]); + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + sha256_ctx_vector_t ctx0; + + sha256_init_vector (&ctx0); + + sha256_update_vector (&ctx0, w, pw_len); + sha256_update_vector (&ctx0, s, salt_len); + + sha256_final_vector (&ctx0); + + const u32x a = ctx0.h[0]; + const u32x b = ctx0.h[1]; + const u32x c = ctx0.h[2]; + const u32x d = ctx0.h[3]; + const u32x e = ctx0.h[4]; + const u32x f = ctx0.h[5]; + const u32x g = ctx0.h[6]; + const u32x h = ctx0.h[7]; + + sha256_ctx_vector_t ctx; + + sha256_init_vector (&ctx); + + _w0[0] = uint_to_hex_lower8_le ((a >> 16) & 255) << 0 | uint_to_hex_lower8_le ((a >> 24) & 255) << 16; + _w0[1] = uint_to_hex_lower8_le ((a >> 0) & 255) << 0 | uint_to_hex_lower8_le ((a >> 8) & 255) << 16; + _w0[2] = uint_to_hex_lower8_le ((b >> 16) & 255) << 0 | uint_to_hex_lower8_le ((b >> 24) & 255) << 16; + _w0[3] = uint_to_hex_lower8_le ((b >> 0) & 255) << 0 | uint_to_hex_lower8_le ((b >> 8) & 255) << 16; + _w1[0] = uint_to_hex_lower8_le ((c >> 16) & 255) << 0 | uint_to_hex_lower8_le ((c >> 24) & 255) << 16; + _w1[1] = uint_to_hex_lower8_le ((c >> 0) & 255) << 0 | uint_to_hex_lower8_le ((c >> 8) & 255) << 16; + _w1[2] = uint_to_hex_lower8_le ((d >> 16) & 255) << 0 | uint_to_hex_lower8_le ((d >> 24) & 255) << 16; + _w1[3] = uint_to_hex_lower8_le ((d >> 0) & 255) << 0 | uint_to_hex_lower8_le ((d >> 8) & 255) << 16; + _w2[0] = uint_to_hex_lower8_le ((e >> 16) & 255) << 0 | uint_to_hex_lower8_le ((e >> 24) & 255) << 16; + _w2[1] = uint_to_hex_lower8_le ((e >> 0) & 255) << 0 | uint_to_hex_lower8_le ((e >> 8) & 255) << 16; + _w2[2] = uint_to_hex_lower8_le ((f >> 16) & 255) << 0 | uint_to_hex_lower8_le ((f >> 24) & 255) << 16; + _w2[3] = uint_to_hex_lower8_le ((f >> 0) & 255) << 0 | uint_to_hex_lower8_le ((f >> 8) & 255) << 16; + _w3[0] = uint_to_hex_lower8_le ((g >> 16) & 255) << 0 | uint_to_hex_lower8_le ((g >> 24) & 255) << 16; + _w3[1] = uint_to_hex_lower8_le ((g >> 0) & 255) << 0 | uint_to_hex_lower8_le ((g >> 8) & 255) << 16; + _w3[2] = uint_to_hex_lower8_le ((h >> 16) & 255) << 0 | uint_to_hex_lower8_le ((h >> 24) & 255) << 16; + _w3[3] = uint_to_hex_lower8_le ((h >> 0) & 255) << 0 | uint_to_hex_lower8_le ((h >> 8) & 255) << 16; + + sha256_update_vector_64 (&ctx, _w0, _w1, _w2, _w3, 64); + + sha256_final_vector (&ctx); + + const u32x r0 = ctx.h[DGST_R0]; + const u32x r1 = ctx.h[DGST_R1]; + const u32x r2 = ctx.h[DGST_R2]; + const u32x r3 = ctx.h[DGST_R3]; + + COMPARE_S_SIMD (r0, r1, r2, r3); + } +} diff --git a/src/modules/module_20713.c b/src/modules/module_20713.c new file mode 100644 index 000000000..f3ce41883 --- /dev/null +++ b/src/modules/module_20713.c @@ -0,0 +1,260 @@ +/** + * Author......: Andreas Vikerup @ Shelltrail + * 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 = 3; +static const u32 DGST_POS1 = 7; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 6; +static const u32 DGST_SIZE = DGST_SIZE_4_8; +static const u32 HASH_CATEGORY = HASH_CATEGORY_RAW_HASH_SALTED; +static const char *HASH_NAME = "sha256(sha256($pass.$salt))"; +static const u64 KERN_TYPE = 20713; +static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE + | OPTI_TYPE_PRECOMPUTE_INIT + | OPTI_TYPE_EARLY_SKIP + | OPTI_TYPE_NOT_ITERATED + | OPTI_TYPE_RAW_HASH; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_BE + | OPTS_TYPE_PT_ADD80 + | OPTS_TYPE_PT_ADDBITS15; +static const u32 SALT_TYPE = SALT_TYPE_GENERIC; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "ad66bdc0841d7e08d96c03de271ce14e77de078746b535adbf9d4b6ccbf2a517:7218532375810603"; + +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; } + +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; + + memset (&token, 0, sizeof (hc_token_t)); + + token.token_cnt = 2; + + token.sep[0] = hashconfig->separator; + token.len[0] = 64; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_HEX; + + token.len_min[1] = SALT_MIN; + token.len_max[1] = SALT_MAX; + token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH; + + if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) + { + token.len_min[1] *= 2; + token.len_max[1] *= 2; + + token.attr[1] |= TOKEN_ATTR_VERIFY_HEX; + } + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + const u8 *hash_pos = token.buf[0]; + + digest[0] = hex_to_u32 (hash_pos + 0); + digest[1] = hex_to_u32 (hash_pos + 8); + digest[2] = hex_to_u32 (hash_pos + 16); + digest[3] = hex_to_u32 (hash_pos + 24); + digest[4] = hex_to_u32 (hash_pos + 32); + digest[5] = hex_to_u32 (hash_pos + 40); + digest[6] = hex_to_u32 (hash_pos + 48); + digest[7] = hex_to_u32 (hash_pos + 56); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + digest[6] = byte_swap_32 (digest[6]); + digest[7] = byte_swap_32 (digest[7]); + + if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL) + { + digest[0] -= SHA256M_A; + digest[1] -= SHA256M_B; + digest[2] -= SHA256M_C; + digest[3] -= SHA256M_D; + digest[4] -= SHA256M_E; + digest[5] -= SHA256M_F; + digest[6] -= SHA256M_G; + digest[7] -= SHA256M_H; + } + + const u8 *salt_pos = token.buf[1]; + const int salt_len = token.len[1]; + + const bool parse_rc = generic_salt_decode (hashconfig, salt_pos, salt_len, (u8 *) salt->salt_buf, (int *) &salt->salt_len); + + if (parse_rc == false) return (PARSER_SALT_LENGTH); + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + u32 tmp[8]; + + tmp[0] = digest[0]; + tmp[1] = digest[1]; + tmp[2] = digest[2]; + tmp[3] = digest[3]; + tmp[4] = digest[4]; + tmp[5] = digest[5]; + tmp[6] = digest[6]; + tmp[7] = digest[7]; + + if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL) + { + tmp[0] += SHA256M_A; + tmp[1] += SHA256M_B; + tmp[2] += SHA256M_C; + tmp[3] += SHA256M_D; + tmp[4] += SHA256M_E; + tmp[5] += SHA256M_F; + tmp[6] += SHA256M_G; + tmp[7] += SHA256M_H; + } + + tmp[0] = byte_swap_32 (tmp[0]); + tmp[1] = byte_swap_32 (tmp[1]); + tmp[2] = byte_swap_32 (tmp[2]); + tmp[3] = byte_swap_32 (tmp[3]); + tmp[4] = byte_swap_32 (tmp[4]); + tmp[5] = byte_swap_32 (tmp[5]); + tmp[6] = byte_swap_32 (tmp[6]); + tmp[7] = byte_swap_32 (tmp[7]); + + u8 *out_buf = (u8 *) line_buf; + + int out_len = 0; + + u32_to_hex (tmp[0], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[1], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[2], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[3], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[4], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[5], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[6], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[7], out_buf + out_len); out_len += 8; + + out_buf[out_len] = hashconfig->separator; + + out_len += 1; + + out_len += generic_salt_encode (hashconfig, (const u8 *) salt->salt_buf, (const int) salt->salt_len, out_buf + out_len); + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_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_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = MODULE_DEFAULT; + module_ctx->module_pw_min = MODULE_DEFAULT; + module_ctx->module_salt_max = MODULE_DEFAULT; + module_ctx->module_salt_min = MODULE_DEFAULT; + module_ctx->module_salt_type = module_salt_type; + module_ctx->module_separator = MODULE_DEFAULT; + module_ctx->module_st_hash = module_st_hash; + module_ctx->module_st_pass = module_st_pass; + module_ctx->module_tmp_size = MODULE_DEFAULT; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} From 6568c5988b9aef2c60fb3e87afc96c7de1c96d9f Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Fri, 18 Apr 2025 14:17:21 +0200 Subject: [PATCH 050/252] fix #3914 --- src/backend.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/backend.c b/src/backend.c index f7c916e1d..28361cca2 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1462,11 +1462,15 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, device_param->kernel_param.loop_pos = loops_pos; device_param->kernel_param.loop_cnt = loops_cnt; + int aux_cnt = 0; + if (hashconfig->opts_type & OPTS_TYPE_AUX1) { if (run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX1, pws_pos, pws_cnt, false, 0) == -1) return -1; if (status_ctx->run_thread_level2 == false) break; + + aux_cnt++; } if (hashconfig->opts_type & OPTS_TYPE_AUX2) @@ -1474,6 +1478,8 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, if (run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX2, pws_pos, pws_cnt, false, 0) == -1) return -1; if (status_ctx->run_thread_level2 == false) break; + + aux_cnt++; } if (hashconfig->opts_type & OPTS_TYPE_AUX3) @@ -1481,6 +1487,8 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, if (run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX3, pws_pos, pws_cnt, false, 0) == -1) return -1; if (status_ctx->run_thread_level2 == false) break; + + aux_cnt++; } if (hashconfig->opts_type & OPTS_TYPE_AUX4) @@ -1488,6 +1496,15 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, if (run_kernel (hashcat_ctx, device_param, KERN_RUN_AUX4, pws_pos, pws_cnt, false, 0) == -1) return -1; if (status_ctx->run_thread_level2 == false) break; + + aux_cnt++; + } + + if (aux_cnt == 0) + { + if (run_kernel (hashcat_ctx, device_param, KERN_RUN_3, pws_pos, pws_cnt, false, 0) == -1) return -1; + + if (status_ctx->run_thread_level2 == false) break; } } } From 16d117d47080b83b553a4575eadaa2a554bd9a7f Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Fri, 18 Apr 2025 14:53:52 +0200 Subject: [PATCH 051/252] update zlib to 1.3.1, commit 5a82f71 --- deps/zlib/.cmake-format.yaml | 245 + deps/zlib/.github/workflows/c-std.yml | 230 + deps/zlib/.github/workflows/cmake.yml | 112 + deps/zlib/.github/workflows/configure.yml | 136 + deps/zlib/.github/workflows/fuzz.yml | 25 + deps/zlib/.github/workflows/msys-cygwin.yml | 77 + deps/zlib/.gitignore | 51 + deps/zlib/BUILD.bazel | 134 + deps/zlib/CMakeLists.txt | 443 +- deps/zlib/ChangeLog | 218 +- deps/zlib/FAQ | 7 +- deps/zlib/LICENSE | 22 + deps/zlib/MODULE.bazel | 9 + deps/zlib/Makefile.in | 89 +- deps/zlib/README | 26 +- deps/zlib/README-cmake.md | 83 + deps/zlib/adler32.c | 32 +- deps/zlib/compress.c | 21 +- deps/zlib/configure | 227 +- deps/zlib/contrib/README.contrib | 23 +- deps/zlib/contrib/ada/readme.txt | 6 +- deps/zlib/contrib/ada/test.adb | 4 +- deps/zlib/contrib/ada/zlib-streams.ads | 2 +- deps/zlib/contrib/ada/zlib-thin.adb | 3 +- deps/zlib/contrib/ada/zlib.adb | 2 +- deps/zlib/contrib/ada/zlib.ads | 2 +- deps/zlib/contrib/amd64/amd64-match.S | 452 - deps/zlib/contrib/asm686/README.686 | 51 - deps/zlib/contrib/asm686/match.S | 357 - deps/zlib/contrib/blast/blast.h | 2 +- deps/zlib/contrib/delphi/ZLib.pas | 2 +- .../contrib/dotzlib/DotZLib/ChecksumImpl.cs | 4 +- .../zlib/contrib/dotzlib/DotZLib/CodecBase.cs | 4 +- .../contrib/dotzlib/DotZLib/GZipStream.cs | 6 +- .../zlib/contrib/dotzlib/DotZLib/UnitTests.cs | 2 +- deps/zlib/contrib/dotzlib/readme.txt | 2 +- deps/zlib/contrib/gcc_gvmat64/gvmat64.S | 1148 +- deps/zlib/contrib/infback9/infback9.c | 48 +- deps/zlib/contrib/infback9/infback9.h | 16 +- deps/zlib/contrib/infback9/inftree9.c | 17 +- deps/zlib/contrib/infback9/inftree9.h | 12 +- deps/zlib/contrib/inflate86/inffas86.c | 1157 -- deps/zlib/contrib/inflate86/inffast.S | 1368 --- deps/zlib/contrib/iostream3/zfstream.h | 4 +- deps/zlib/contrib/masmx64/bld_ml64.bat | 2 - deps/zlib/contrib/masmx64/gvmat64.asm | 553 - deps/zlib/contrib/masmx64/inffas8664.c | 186 - deps/zlib/contrib/masmx64/inffasx64.asm | 396 - deps/zlib/contrib/masmx64/readme.txt | 31 - deps/zlib/contrib/masmx86/bld_ml32.bat | 2 - deps/zlib/contrib/masmx86/inffas32.asm | 1080 -- deps/zlib/contrib/masmx86/match686.asm | 479 - deps/zlib/contrib/masmx86/readme.txt | 27 - deps/zlib/contrib/minizip/CMakeLists.txt | 380 + deps/zlib/contrib/minizip/Makefile | 28 +- .../contrib/minizip/MiniZip64_Changes.txt | 2 +- deps/zlib/contrib/minizip/configure.ac | 4 +- deps/zlib/contrib/minizip/crypt.h | 29 +- deps/zlib/contrib/minizip/ints.h | 57 + deps/zlib/contrib/minizip/ioapi.c | 80 +- deps/zlib/contrib/minizip/ioapi.h | 81 +- deps/zlib/contrib/minizip/iowin32.c | 88 +- deps/zlib/contrib/minizip/iowin32.h | 8 +- deps/zlib/contrib/minizip/make_vms.com | 2 +- deps/zlib/contrib/minizip/miniunz.c | 117 +- deps/zlib/contrib/minizip/minizip.c | 98 +- deps/zlib/contrib/minizip/minizip.pc.in | 2 +- deps/zlib/contrib/minizip/minizip.pc.txt | 13 + .../contrib/minizip/minizipConfig.cmake.in | 35 + deps/zlib/contrib/minizip/mztools.c | 73 +- deps/zlib/contrib/minizip/skipset.h | 361 + deps/zlib/contrib/minizip/test/CMakeLists.txt | 121 + .../add_subdirectory_exclude_test.cmake.in | 29 + .../test/add_subdirectory_test.cmake.in | 28 + .../minizip/test/find_package_test.cmake.in | 25 + deps/zlib/contrib/minizip/test/test_helper.cm | 32 + deps/zlib/contrib/minizip/unzip.c | 580 +- deps/zlib/contrib/minizip/unzip.h | 152 +- deps/zlib/contrib/minizip/zip.c | 690 +- deps/zlib/contrib/minizip/zip.h | 322 +- deps/zlib/contrib/nuget/nuget.csproj | 43 + deps/zlib/contrib/nuget/nuget.sln | 22 + deps/zlib/contrib/pascal/zlibpas.pas | 2 +- deps/zlib/contrib/puff/README | 2 +- deps/zlib/contrib/puff/puff.c | 12 +- deps/zlib/contrib/puff/pufftest.c | 6 +- deps/zlib/contrib/testzlib/testzlib.c | 2 +- deps/zlib/contrib/untgz/untgz.c | 63 +- deps/zlib/contrib/vstudio/readme.txt | 159 +- .../vstudio/vc10/miniunz.vcxproj.filters | 2 +- .../vstudio/vc10/minizip.vcxproj.filters | 2 +- .../contrib/vstudio/vc10/testzlib.vcxproj | 24 +- .../vstudio/vc10/testzlib.vcxproj.filters | 5 +- .../vstudio/vc10/testzlibdll.vcxproj.filters | 2 +- deps/zlib/contrib/vstudio/vc10/zlib.rc | 8 +- .../contrib/vstudio/vc10/zlibstat.vcxproj | 50 +- .../vstudio/vc10/zlibstat.vcxproj.filters | 3 - deps/zlib/contrib/vstudio/vc10/zlibvc.def | 10 +- deps/zlib/contrib/vstudio/vc10/zlibvc.vcxproj | 58 +- .../vstudio/vc10/zlibvc.vcxproj.filters | 3 - .../contrib/vstudio/vc11/testzlib.vcxproj | 24 +- deps/zlib/contrib/vstudio/vc11/zlib.rc | 8 +- .../contrib/vstudio/vc11/zlibstat.vcxproj | 34 +- deps/zlib/contrib/vstudio/vc11/zlibvc.def | 10 +- deps/zlib/contrib/vstudio/vc11/zlibvc.vcxproj | 58 +- .../contrib/vstudio/vc12/testzlib.vcxproj | 24 +- deps/zlib/contrib/vstudio/vc12/zlib.rc | 8 +- .../contrib/vstudio/vc12/zlibstat.vcxproj | 34 +- deps/zlib/contrib/vstudio/vc12/zlibvc.def | 10 +- deps/zlib/contrib/vstudio/vc12/zlibvc.vcxproj | 58 +- .../contrib/vstudio/vc14/testzlib.vcxproj | 24 +- deps/zlib/contrib/vstudio/vc14/zlib.rc | 8 +- .../contrib/vstudio/vc14/zlibstat.vcxproj | 34 +- deps/zlib/contrib/vstudio/vc14/zlibvc.def | 10 +- deps/zlib/contrib/vstudio/vc14/zlibvc.vcxproj | 58 +- .../zlib/contrib/vstudio/vc17/miniunz.vcxproj | 409 + .../zlib/contrib/vstudio/vc17/minizip.vcxproj | 405 + .../contrib/vstudio/vc17/testzlib.vcxproj | 473 + .../contrib/vstudio/vc17/testzlibdll.vcxproj | 409 + deps/zlib/contrib/vstudio/vc17/zlib.rc | 32 + .../contrib/vstudio/vc17/zlibstat.vcxproj | 602 + deps/zlib/contrib/vstudio/vc17/zlibvc.def | 161 + deps/zlib/contrib/vstudio/vc17/zlibvc.sln | 179 + deps/zlib/contrib/vstudio/vc17/zlibvc.vcxproj | 875 ++ deps/zlib/contrib/vstudio/vc9/miniunz.vcproj | 2 +- deps/zlib/contrib/vstudio/vc9/minizip.vcproj | 2 +- deps/zlib/contrib/vstudio/vc9/testzlib.vcproj | 66 +- .../contrib/vstudio/vc9/testzlibdll.vcproj | 2 +- deps/zlib/contrib/vstudio/vc9/zlib.rc | 8 +- deps/zlib/contrib/vstudio/vc9/zlibstat.vcproj | 76 +- deps/zlib/contrib/vstudio/vc9/zlibvc.def | 10 +- deps/zlib/contrib/vstudio/vc9/zlibvc.vcproj | 82 +- deps/zlib/crc32.c | 1283 ++- deps/zlib/crc32.h | 9877 ++++++++++++++++- deps/zlib/deflate.c | 909 +- deps/zlib/deflate.h | 77 +- deps/zlib/doc/algorithm.txt | 2 +- deps/zlib/doc/crc-doc.1.0.pdf | Bin 0 -> 776142 bytes deps/zlib/doc/txtvsbin.txt | 12 +- deps/zlib/examples/README.examples | 5 + deps/zlib/examples/enough.c | 735 +- deps/zlib/examples/fitblk.c | 6 +- deps/zlib/examples/gun.c | 20 +- deps/zlib/examples/gzappend.c | 6 +- deps/zlib/examples/gzlog.c | 13 +- deps/zlib/examples/gzlog.h | 2 +- deps/zlib/examples/gznorm.c | 474 + deps/zlib/examples/zlib_how.html | 26 +- deps/zlib/examples/zpipe.c | 4 + deps/zlib/examples/zran.c | 775 +- deps/zlib/examples/zran.h | 53 + deps/zlib/gzclose.c | 4 +- deps/zlib/gzguts.h | 91 +- deps/zlib/gzlib.c | 146 +- deps/zlib/gzread.c | 109 +- deps/zlib/gzwrite.c | 118 +- deps/zlib/infback.c | 76 +- deps/zlib/inffast.c | 41 +- deps/zlib/inffast.h | 2 +- deps/zlib/inflate.c | 229 +- deps/zlib/inflate.h | 7 +- deps/zlib/inftrees.c | 17 +- deps/zlib/inftrees.h | 12 +- deps/zlib/make_vms.com | 4 +- deps/zlib/msdos/Makefile.dj2 | 2 +- deps/zlib/old/Makefile.riscos | 2 +- deps/zlib/old/visual-basic.txt | 2 +- deps/zlib/os400/README400 | 6 +- deps/zlib/os400/bndsrc | 14 + deps/zlib/os400/zlib.inc | 14 +- deps/zlib/qnx/package.qpg | 12 +- deps/zlib/test/CMakeLists.txt | 265 + .../add_subdirectory_exclude_test.cmake.in | 29 + deps/zlib/test/add_subdirectory_test.cmake.in | 28 + deps/zlib/test/example.c | 120 +- deps/zlib/test/find_package_test.cmake.in | 26 + deps/zlib/test/infcover.c | 15 +- deps/zlib/test/minigzip.c | 253 +- deps/zlib/treebuild.xml | 4 +- deps/zlib/trees.c | 678 +- deps/zlib/uncompr.c | 16 +- deps/zlib/win32/DLL_FAQ.txt | 22 +- deps/zlib/win32/Makefile.bor | 1 - deps/zlib/win32/Makefile.gcc | 7 +- deps/zlib/win32/Makefile.msc | 4 - deps/zlib/win32/README-WIN32.txt | 8 +- deps/zlib/win32/zlib.def | 4 + deps/zlib/win32/zlib1.rc | 7 +- deps/zlib/zconf.h | 60 +- deps/zlib/zconf.h.cmakein | 536 - deps/zlib/zconf.h.in | 60 +- deps/zlib/zlib.3 | 8 +- deps/zlib/zlib.3.pdf | Bin 19318 -> 25523 bytes deps/zlib/zlib.h | 641 +- deps/zlib/zlib.map | 198 +- deps/zlib/zlib.pc.cmakein | 8 +- deps/zlib/zlib2ansi | 152 - deps/zlib/zlibConfig.cmake.in | 26 + deps/zlib/zutil.c | 66 +- deps/zlib/zutil.h | 76 +- 200 files changed, 22714 insertions(+), 13538 deletions(-) create mode 100644 deps/zlib/.cmake-format.yaml create mode 100644 deps/zlib/.github/workflows/c-std.yml create mode 100644 deps/zlib/.github/workflows/cmake.yml create mode 100644 deps/zlib/.github/workflows/configure.yml create mode 100644 deps/zlib/.github/workflows/fuzz.yml create mode 100644 deps/zlib/.github/workflows/msys-cygwin.yml create mode 100644 deps/zlib/.gitignore create mode 100644 deps/zlib/BUILD.bazel create mode 100644 deps/zlib/LICENSE create mode 100644 deps/zlib/MODULE.bazel create mode 100644 deps/zlib/README-cmake.md delete mode 100644 deps/zlib/contrib/amd64/amd64-match.S delete mode 100644 deps/zlib/contrib/asm686/README.686 delete mode 100644 deps/zlib/contrib/asm686/match.S delete mode 100644 deps/zlib/contrib/inflate86/inffas86.c delete mode 100644 deps/zlib/contrib/inflate86/inffast.S delete mode 100644 deps/zlib/contrib/masmx64/bld_ml64.bat delete mode 100644 deps/zlib/contrib/masmx64/gvmat64.asm delete mode 100644 deps/zlib/contrib/masmx64/inffas8664.c delete mode 100644 deps/zlib/contrib/masmx64/inffasx64.asm delete mode 100644 deps/zlib/contrib/masmx64/readme.txt delete mode 100644 deps/zlib/contrib/masmx86/bld_ml32.bat delete mode 100644 deps/zlib/contrib/masmx86/inffas32.asm delete mode 100644 deps/zlib/contrib/masmx86/match686.asm delete mode 100644 deps/zlib/contrib/masmx86/readme.txt create mode 100644 deps/zlib/contrib/minizip/CMakeLists.txt create mode 100644 deps/zlib/contrib/minizip/ints.h create mode 100644 deps/zlib/contrib/minizip/minizip.pc.txt create mode 100644 deps/zlib/contrib/minizip/minizipConfig.cmake.in create mode 100644 deps/zlib/contrib/minizip/skipset.h create mode 100644 deps/zlib/contrib/minizip/test/CMakeLists.txt create mode 100644 deps/zlib/contrib/minizip/test/add_subdirectory_exclude_test.cmake.in create mode 100644 deps/zlib/contrib/minizip/test/add_subdirectory_test.cmake.in create mode 100644 deps/zlib/contrib/minizip/test/find_package_test.cmake.in create mode 100644 deps/zlib/contrib/minizip/test/test_helper.cm create mode 100644 deps/zlib/contrib/nuget/nuget.csproj create mode 100644 deps/zlib/contrib/nuget/nuget.sln create mode 100644 deps/zlib/contrib/vstudio/vc17/miniunz.vcxproj create mode 100644 deps/zlib/contrib/vstudio/vc17/minizip.vcxproj create mode 100644 deps/zlib/contrib/vstudio/vc17/testzlib.vcxproj create mode 100644 deps/zlib/contrib/vstudio/vc17/testzlibdll.vcxproj create mode 100644 deps/zlib/contrib/vstudio/vc17/zlib.rc create mode 100644 deps/zlib/contrib/vstudio/vc17/zlibstat.vcxproj create mode 100644 deps/zlib/contrib/vstudio/vc17/zlibvc.def create mode 100644 deps/zlib/contrib/vstudio/vc17/zlibvc.sln create mode 100644 deps/zlib/contrib/vstudio/vc17/zlibvc.vcxproj create mode 100644 deps/zlib/doc/crc-doc.1.0.pdf create mode 100644 deps/zlib/examples/gznorm.c create mode 100644 deps/zlib/examples/zran.h create mode 100644 deps/zlib/test/CMakeLists.txt create mode 100644 deps/zlib/test/add_subdirectory_exclude_test.cmake.in create mode 100644 deps/zlib/test/add_subdirectory_test.cmake.in create mode 100644 deps/zlib/test/find_package_test.cmake.in delete mode 100644 deps/zlib/zconf.h.cmakein delete mode 100755 deps/zlib/zlib2ansi create mode 100644 deps/zlib/zlibConfig.cmake.in diff --git a/deps/zlib/.cmake-format.yaml b/deps/zlib/.cmake-format.yaml new file mode 100644 index 000000000..9c554da15 --- /dev/null +++ b/deps/zlib/.cmake-format.yaml @@ -0,0 +1,245 @@ +_help_parse: Options affecting listfile parsing +parse: + _help_additional_commands: + - Specify structure for custom cmake functions + additional_commands: + foo: + flags: + - BAR + - BAZ + kwargs: + HEADERS: '*' + SOURCES: '*' + DEPENDS: '*' + _help_override_spec: + - Override configurations per-command where available + override_spec: {} + _help_vartags: + - Specify variable tags. + vartags: [] + _help_proptags: + - Specify property tags. + proptags: [] +_help_format: Options affecting formatting. +format: + _help_disable: + - Disable formatting entirely, making cmake-format a no-op + disable: false + _help_line_width: + - How wide to allow formatted cmake files + line_width: 80 + _help_tab_size: + - How many spaces to tab for indent + tab_size: 4 + _help_use_tabchars: + - If true, lines are indented using tab characters (utf-8 + - 0x09) instead of space characters (utf-8 0x20). + - In cases where the layout would require a fractional tab + - character, the behavior of the fractional indentation is + - governed by + use_tabchars: false + _help_fractional_tab_policy: + - If is True, then the value of this variable + - indicates how fractional indentions are handled during + - whitespace replacement. If set to 'use-space', fractional + - indentation is left as spaces (utf-8 0x20). If set to + - '`round-up` fractional indentation is replaced with a single' + - tab character (utf-8 0x09) effectively shifting the column + - to the next tabstop + fractional_tab_policy: use-space + _help_max_subgroups_hwrap: + - If an argument group contains more than this many sub-groups + - (parg or kwarg groups) then force it to a vertical layout. + max_subgroups_hwrap: 2 + _help_max_pargs_hwrap: + - If a positional argument group contains more than this many + - arguments, then force it to a vertical layout. + max_pargs_hwrap: 6 + _help_max_rows_cmdline: + - If a cmdline positional group consumes more than this many + - lines without nesting, then invalidate the layout (and nest) + max_rows_cmdline: 2 + _help_separate_ctrl_name_with_space: + - If true, separate flow control names from their parentheses + - with a space + separate_ctrl_name_with_space: false + _help_separate_fn_name_with_space: + - If true, separate function names from parentheses with a + - space + separate_fn_name_with_space: false + _help_dangle_parens: + - If a statement is wrapped to more than one line, than dangle + - the closing parenthesis on its own line. + dangle_parens: false + _help_dangle_align: + - If the trailing parenthesis must be 'dangled' on its on + - 'line, then align it to this reference: `prefix`: the start' + - 'of the statement, `prefix-indent`: the start of the' + - 'statement, plus one indentation level, `child`: align to' + - the column of the arguments + dangle_align: prefix + _help_min_prefix_chars: + - If the statement spelling length (including space and + - parenthesis) is smaller than this amount, then force reject + - nested layouts. + min_prefix_chars: 4 + _help_max_prefix_chars: + - If the statement spelling length (including space and + - parenthesis) is larger than the tab width by more than this + - amount, then force reject un-nested layouts. + max_prefix_chars: 10 + _help_max_lines_hwrap: + - If a candidate layout is wrapped horizontally but it exceeds + - this many lines, then reject the layout. + max_lines_hwrap: 2 + _help_line_ending: + - What style line endings to use in the output. + line_ending: unix + _help_command_case: + - Format command names consistently as 'lower' or 'upper' case + command_case: canonical + _help_keyword_case: + - Format keywords consistently as 'lower' or 'upper' case + keyword_case: unchanged + _help_always_wrap: + - A list of command names which should always be wrapped + always_wrap: [] + _help_enable_sort: + - If true, the argument lists which are known to be sortable + - will be sorted lexicographicall + enable_sort: true + _help_autosort: + - If true, the parsers may infer whether or not an argument + - list is sortable (without annotation). + autosort: false + _help_require_valid_layout: + - By default, if cmake-format cannot successfully fit + - everything into the desired linewidth it will apply the + - last, most aggressive attempt that it made. If this flag is + - True, however, cmake-format will print error, exit with non- + - zero status code, and write-out nothing + require_valid_layout: false + _help_layout_passes: + - A dictionary mapping layout nodes to a list of wrap + - decisions. See the documentation for more information. + layout_passes: {} +_help_markup: Options affecting comment reflow and formatting. +markup: + _help_bullet_char: + - What character to use for bulleted lists + bullet_char: '*' + _help_enum_char: + - What character to use as punctuation after numerals in an + - enumerated list + enum_char: . + _help_first_comment_is_literal: + - If comment markup is enabled, don't reflow the first comment + - block in each listfile. Use this to preserve formatting of + - your copyright/license statements. + first_comment_is_literal: false + _help_literal_comment_pattern: + - If comment markup is enabled, don't reflow any comment block + - which matches this (regex) pattern. Default is `None` + - (disabled). + literal_comment_pattern: null + _help_fence_pattern: + - Regular expression to match preformat fences in comments + - default= ``r'^\s*([`~]{3}[`~]*)(.*)$'`` + fence_pattern: ^\s*([`~]{3}[`~]*)(.*)$ + _help_ruler_pattern: + - Regular expression to match rulers in comments default= + - '``r''^\s*[^\w\s]{3}.*[^\w\s]{3}$''``' + ruler_pattern: ^\s*[^\w\s]{3}.*[^\w\s]{3}$ + _help_explicit_trailing_pattern: + - If a comment line matches starts with this pattern then it + - is explicitly a trailing comment for the preceding argument. + - Default is '#<' + explicit_trailing_pattern: '#<' + _help_hashruler_min_length: + - If a comment line starts with at least this many consecutive + - hash characters, then don't lstrip() them off. This allows + - for lazy hash rulers where the first hash char is not + - separated by space + hashruler_min_length: 10 + _help_canonicalize_hashrulers: + - If true, then insert a space between the first hash char and + - remaining hash chars in a hash ruler, and normalize its + - length to fill the column + canonicalize_hashrulers: true + _help_enable_markup: + - enable comment markup parsing and reflow + enable_markup: true +_help_lint: Options affecting the linter +lint: + _help_disabled_codes: + - a list of lint codes to disable + disabled_codes: [] + _help_function_pattern: + - regular expression pattern describing valid function names + function_pattern: '[0-9a-z_]+' + _help_macro_pattern: + - regular expression pattern describing valid macro names + macro_pattern: '[0-9A-Z_]+' + _help_global_var_pattern: + - regular expression pattern describing valid names for + - variables with global (cache) scope + global_var_pattern: '[A-Z][0-9A-Z_]+' + _help_internal_var_pattern: + - regular expression pattern describing valid names for + - variables with global scope (but internal semantic) + internal_var_pattern: _[A-Z][0-9A-Z_]+ + _help_local_var_pattern: + - regular expression pattern describing valid names for + - variables with local scope + local_var_pattern: '[a-z][a-z0-9_]+' + _help_private_var_pattern: + - regular expression pattern describing valid names for + - privatedirectory variables + private_var_pattern: _[0-9a-z_]+ + _help_public_var_pattern: + - regular expression pattern describing valid names for public + - directory variables + public_var_pattern: '[A-Z][0-9A-Z_]+' + _help_argument_var_pattern: + - regular expression pattern describing valid names for + - function/macro arguments and loop variables. + argument_var_pattern: '[a-z][a-z0-9_]+' + _help_keyword_pattern: + - regular expression pattern describing valid names for + - keywords used in functions or macros + keyword_pattern: '[A-Z][0-9A-Z_]+' + _help_max_conditionals_custom_parser: + - In the heuristic for C0201, how many conditionals to match + - within a loop in before considering the loop a parser. + max_conditionals_custom_parser: 2 + _help_min_statement_spacing: + - Require at least this many newlines between statements + min_statement_spacing: 1 + _help_max_statement_spacing: + - Require no more than this many newlines between statements + max_statement_spacing: 2 + max_returns: 6 + max_branches: 12 + max_arguments: 5 + max_localvars: 15 + max_statements: 50 +_help_encode: Options affecting file encoding +encode: + _help_emit_byteorder_mark: + - If true, emit the unicode byte-order mark (BOM) at the start + - of the file + emit_byteorder_mark: false + _help_input_encoding: + - Specify the encoding of the input file. Defaults to utf-8 + input_encoding: utf-8 + _help_output_encoding: + - Specify the encoding of the output file. Defaults to utf-8. + - Note that cmake only claims to support utf-8 so be careful + - when using anything else + output_encoding: utf-8 +_help_misc: Miscellaneous configurations options. +misc: + _help_per_command: + - A dictionary containing any per-command configuration + - overrides. Currently only `command_case` is supported. + per_command: {} diff --git a/deps/zlib/.github/workflows/c-std.yml b/deps/zlib/.github/workflows/c-std.yml new file mode 100644 index 000000000..a99cdb569 --- /dev/null +++ b/deps/zlib/.github/workflows/c-std.yml @@ -0,0 +1,230 @@ +name: C Standard + +# Compile with as many C standards as possible. +# The worflow is setup to fail on any compilation warnings. + +on: + workflow_dispatch: + push: + pull_request: + +jobs: + + main: + name: ${{ matrix.os.name }} ${{ matrix.compiler }} ${{ matrix.arch.name }} ${{ matrix.std.name }} ${{ matrix.builder }} + runs-on: ${{ matrix.os.value }} + strategy: + fail-fast: false + matrix: + os: + - name: Linux + value: ubuntu-latest + + - name: MacOS + value: macos-latest + + - name: Windows + value: windows-latest + cmake-opt: -G Ninja + + compiler: + - gcc + - clang + + arch: + - name: 64-bit + tag: amd64 + compiler-opt: -m64 + cmake-opt: -A x64 + + - name: 32-bit + tag: i386 + compiler-opt: -m32 + cmake-opt: -A Win32 + + + builder: + - configure + - cmake + + std: + - name: c89 + value: c89 + + - name: gnu89 + value: gnu89 + + - name: c94 + value: iso9899:199409 + + - name: c99 + value: c99 + + - name: gnu99 + value: gnu99 + + - name: c11 + value: c11 + + - name: gnu11 + value: gnu11 + + - name: c17 + value: c17 + + - name: gnu17 + value: gnu17 + + - name: c2x + value: c2x + + - name: gnu2x + value: gnu2x + + exclude: + # Don't run 32-bit on MacOS + - { os: { name: MacOS }, + arch: { tag: i386 } } + + # Don't run configure on Windows + - { os: { name: Windows }, + builder: configure } + + # Don't run gcc 32-bit on Windows + - { os: { name: Windows }, + arch: { tag: i386 } } + + steps: + + - name: Checkout repository + uses: actions/checkout@v4 + with: + show-progress: 'false' + + - name: Install packages (Linux) + if: runner.os == 'Linux' && matrix.arch.tag == 'i386' + run: | + sudo apt-get update + sudo apt install gcc-multilib libc6-dev-i386-cross + + - name: Install packages (Windows) + if: runner.os == 'Windows' + run: | + choco install --no-progress ninja + + - name: Generate project files (configure) + if: matrix.builder == 'configure' + run: | + ./configure + env: + CC: ${{ matrix.compiler }} + CFLAGS: -std=${{ matrix.std.value }} ${{ matrix.arch.compiler-opt }} -Werror -Wall -Wextra + + - name: Compile source code (configure) + if: matrix.builder == 'configure' + run: make -j2 + + - name: Run test cases (configure) + if: matrix.builder == 'configure' + run: | + make test + make cover + + - name: Generate project files (cmake) + if: matrix.builder == 'cmake' + run: | + cmake -S . -B ./build1 -D CMAKE_BUILD_TYPE=Release ${{ matrix.os.cmake-opt }} -DZLIB_BUILD_TESTING=OFF + env: + CC: ${{ matrix.compiler }} + CFLAGS: -std=${{ matrix.std.value }} ${{ matrix.arch.compiler-opt }} -Werror -Wall -Wextra + + - name: Generate project files with tests (cmake) + if: matrix.builder == 'cmake' + run: | + cmake -S . -B ./build2 -D CMAKE_BUILD_TYPE=Release ${{ matrix.os.cmake-opt }} -DZLIB_BUILD_MINIZIP=ON -DMINIZIP_ENABLE_BZIP2=OFF + env: + CC: ${{ matrix.compiler }} + CFLAGS: -std=${{ matrix.std.value }} ${{ matrix.arch.compiler-opt }} -Wall -Wextra + + - name: Compile source code (cmake) + if: matrix.builder == 'cmake' + run: cmake --build ./build1 --config Release + + - name: Compile source code with tests (cmake) + if: matrix.builder == 'cmake' + run: cmake --build ./build2 --config Release + + - name: Run test cases (cmake) + if: matrix.builder == 'cmake' + run: ctest ./build2 -C Release --output-on-failure --max-width 120 + + + msvc: + name: ${{ matrix.os.name }} ${{ matrix.compiler }} ${{ matrix.arch.name }} ${{ matrix.std.name }} ${{ matrix.builder }} + runs-on: ${{ matrix.os.value }} + strategy: + fail-fast: false + matrix: + os: + - name: Windows + value: windows-latest + + compiler: + - cl + + arch: + - name: 32-bit + value: -A Win32 + + - name: 64-bit + value: -A x64 + + builder: + - cmake + + std: + - name: default + value: "" + + - name: C11 + value: /std:c11 + + - name: C17 + value: /std:c17 + + # not available on the runner yet + # - name: C20 + # value: /std:c20 + + - name: latest + value: /std:clatest + + steps: + + - name: Checkout repository + uses: actions/checkout@v4 + with: + show-progress: 'false' + + - name: Generate project files (cmake) + run: | + cmake -S . -B ./build1 ${{ matrix.arch.value }} -D CMAKE_BUILD_TYPE=Release -DZLIB_BUILD_TESTING=OFF + env: + CC: ${{ matrix.compiler }} + CFLAGS: /WX ${{ matrix.std.value }} + + - name: Generate project files with tests (cmake) + run: | + cmake -S . -B ./build2 ${{ matrix.arch.value }} -D CMAKE_BUILD_TYPE=Release -DZLIB_BUILD_MINIZIP=ON -DMINIZIP_ENABLE_BZIP2=OFF + env: + CC: ${{ matrix.compiler }} + CFLAGS: ${{ matrix.std.value }} + + - name: Compile source code (cmake) + run: cmake --build ./build1 --config Release -v + + - name: Compile source code with tests(cmake) + run: cmake --build ./build2 --config Release -v + + - name: Run test cases (cmake) + run: ctest ./build2 -C Release --output-on-failure --max-width 120 diff --git a/deps/zlib/.github/workflows/cmake.yml b/deps/zlib/.github/workflows/cmake.yml new file mode 100644 index 000000000..25a3b8124 --- /dev/null +++ b/deps/zlib/.github/workflows/cmake.yml @@ -0,0 +1,112 @@ +name: CMake +on: [push, pull_request] +jobs: + ci-cmake: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: Ubuntu GCC + os: ubuntu-latest + compiler: gcc + cflags: -Wall -Wextra + pkgtgt: package package_source + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON + + - name: Ubuntu GCC -O3 + os: ubuntu-latest + compiler: gcc + cflags: -O3 -Wall -Wextra + pkgtgt: package package_source + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON + + - name: Ubuntu Clang + os: ubuntu-latest + compiler: clang + cflags: -Wall -Wextra + pkgtgt: package package_source + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON + + - name: Ubuntu Clang Debug + os: ubuntu-latest + compiler: clang + cflags: -Wall -Wextra + build-config: Debug + pkgtgt: package package_source + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON + + - name: Windows MSVC Win32 + os: windows-latest + compiler: cl + cflags: /W3 + cmake-args: -A Win32 + pkgtgt: PACKAGE + + - name: Windows MSVC Win64 + os: windows-latest + compiler: cl + cflags: /W3 + cmake-args: -A x64 -DMINIZIP_ENABLE_BZIP2=OFF + pkgtgt: PACKAGE + + - name: Windows GCC + os: windows-latest + compiler: gcc + cflags: -Wall -Wextra + cmake-args: -G Ninja -DMINIZIP_ENABLE_BZIP2=OFF + pkgtgt: package + + - name: macOS Clang + os: macos-latest + compiler: clang + cflags: -Wall -Wextra + pkgtgt: package + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON + + - name: macOS GCC + os: macos-latest + compiler: gcc-12 + cflags: -Wall -Wextra + pkgtgt: package + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install packages (Windows) + if: runner.os == 'Windows' + run: | + choco install --no-progress ninja + + - name: Install packages (Linux) + if: runner.os == 'Linux' + run: | + sudo apt install libbz2-dev + - name: Generate project files + run: cmake -S . -B ../build ${{ matrix.cmake-args }} -D CMAKE_BUILD_TYPE=${{ matrix.build-config || 'Release' }} -DZLIB_BUILD_MINIZIP=ON + env: + CC: ${{ matrix.compiler }} + CFLAGS: ${{ matrix.cflags }} + + - name: Compile source code + run: cmake --build ../build --config ${{ matrix.build-config || 'Release' }} + + - name: Run test cases + run: ctest -C Release --output-on-failure --max-width 120 + working-directory: ../build + + - name: create packages + run: cmake --build ../build --config ${{ matrix.build-config || 'Release' }} -t ${{ matrix.pkgtgt }} + + - name: Upload build errors + uses: actions/upload-artifact@v4 + if: failure() + with: + name: ${{ matrix.name }} (cmake) + path: | + ../build/CMakeFiles/CMakeOutput.log + ../build/CMakeFiles/CMakeError.log + retention-days: 7 diff --git a/deps/zlib/.github/workflows/configure.yml b/deps/zlib/.github/workflows/configure.yml new file mode 100644 index 000000000..f19272c72 --- /dev/null +++ b/deps/zlib/.github/workflows/configure.yml @@ -0,0 +1,136 @@ +name: Configure +on: [push, pull_request] +jobs: + ci-configure: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: Ubuntu GCC + os: ubuntu-latest + compiler: gcc + configure-args: --warn + + # Test out of source builds + - name: Ubuntu GCC OSB + os: ubuntu-latest + compiler: gcc + configure-args: --warn + build-dir: ../build + src-dir: ../zlib + + - name: Ubuntu GCC ARM SF + os: ubuntu-latest + compiler: arm-linux-gnueabi-gcc + configure-args: --warn + chost: arm-linux-gnueabi + packages: qemu-system qemu-user gcc-arm-linux-gnueabi libc-dev-armel-cross + qemu-run: qemu-arm -L /usr/arm-linux-gnueabi + + - name: Ubuntu GCC ARM HF + os: ubuntu-latest + compiler: arm-linux-gnueabihf-gcc + configure-args: --warn + chost: arm-linux-gnueabihf + packages: qemu-system qemu-user gcc-arm-linux-gnueabihf libc-dev-armhf-cross + qemu-run: qemu-arm -L /usr/arm-linux-gnueabihf + + - name: Ubuntu GCC AARCH64 + os: ubuntu-latest + compiler: aarch64-linux-gnu-gcc + configure-args: --warn + chost: aarch64-linux-gnu + packages: qemu-system qemu-user gcc-aarch64-linux-gnu libc-dev-arm64-cross + qemu-run: qemu-aarch64 -L /usr/aarch64-linux-gnu + + - name: Ubuntu GCC PPC + os: ubuntu-latest + compiler: powerpc-linux-gnu-gcc + configure-args: --warn --static + chost: powerpc-linux-gnu + packages: qemu-system qemu-user gcc-powerpc-linux-gnu libc-dev-powerpc-cross + qemu-run: qemu-ppc -L /usr/powerpc-linux-gnu + cflags: -static + ldflags: -static + + - name: Ubuntu GCC PPC64 + os: ubuntu-latest + compiler: powerpc64-linux-gnu-gcc + configure-args: --warn --static + chost: powerpc-linux-gnu + packages: qemu-system qemu-user gcc-powerpc64-linux-gnu libc-dev-ppc64-cross + qemu-run: qemu-ppc64 -L /usr/powerpc64-linux-gnu + cflags: -static + ldflags: -static + + - name: Ubuntu GCC PPC64LE + os: ubuntu-latest + compiler: powerpc64le-linux-gnu-gcc + configure-args: --warn + chost: powerpc64le-linux-gnu + packages: qemu-system qemu-user gcc-powerpc64le-linux-gnu libc-dev-ppc64el-cross + qemu-run: qemu-ppc64le -L /usr/powerpc64le-linux-gnu + + - name: Ubuntu GCC S390X + os: ubuntu-latest + compiler: s390x-linux-gnu-gcc + configure-args: --warn --static + chost: s390x-linux-gnu + packages: qemu-system qemu-user gcc-s390x-linux-gnu libc-dev-s390x-cross + qemu-run: qemu-s390x -L /usr/s390x-linux-gnu + cflags: -static + ldflags: -static + + - name: macOS GCC + os: macos-latest + compiler: gcc-12 + configure-args: --warn + + - name: macOS Clang + os: macos-latest + compiler: clang + configure-args: --warn + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install packages (Ubuntu) + if: runner.os == 'Linux' && matrix.packages + run: | + sudo apt-get update + sudo apt-get install -y ${{ matrix.packages }} + + - name: Generate project files + run: | + [ -d ${{ matrix.build-dir || '.' }} ] || mkdir ${{ matrix.build-dir || '.' }} + cd ${{ matrix.build-dir || '.' }} + ${{ matrix.src-dir || '.' }}/configure ${{ matrix.configure-args }} + env: + CC: ${{ matrix.compiler }} + CFLAGS: ${{ matrix.cflags }} + LDFLAGS: ${{ matrix.ldflags }} + CHOST: ${{ matrix.chost }} + + - name: Compile source code + run: make -j2 + working-directory: ${{ matrix.build-dir }} + + - name: Run test cases + run: | + make test + make cover + working-directory: ${{ matrix.build-dir }} + env: + QEMU_RUN: ${{ matrix.qemu-run }} + + - name: Upload build errors + uses: actions/upload-artifact@v4 + if: failure() + with: + name: ${{ matrix.name }} (configure) + path: | + ${{ matrix.build-dir || '.' }}/configure.log + retention-days: 7 diff --git a/deps/zlib/.github/workflows/fuzz.yml b/deps/zlib/.github/workflows/fuzz.yml new file mode 100644 index 000000000..ddca83c37 --- /dev/null +++ b/deps/zlib/.github/workflows/fuzz.yml @@ -0,0 +1,25 @@ +name: OSS-Fuzz +on: [pull_request] +jobs: + Fuzzing: + runs-on: ubuntu-latest + steps: + - name: Build Fuzzers + uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master + with: + oss-fuzz-project-name: 'zlib' + dry-run: false + + - name: Run Fuzzers + uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master + with: + oss-fuzz-project-name: 'zlib' + fuzz-seconds: 300 + dry-run: false + + - name: Upload Crash + uses: actions/upload-artifact@v4 + if: failure() + with: + name: artifacts + path: ./out/artifacts diff --git a/deps/zlib/.github/workflows/msys-cygwin.yml b/deps/zlib/.github/workflows/msys-cygwin.yml new file mode 100644 index 000000000..e76be9f0d --- /dev/null +++ b/deps/zlib/.github/workflows/msys-cygwin.yml @@ -0,0 +1,77 @@ +name: mingw/cygwin + +on: [push, pull_request] + +jobs: + MSys: + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + sys: [mingw32, mingw64, ucrt64, clang64] + name: MSys - ${{ matrix.sys }} + defaults: + run: + shell: msys2 {0} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup MSYS2 + uses: msys2/setup-msys2@v2 + with: + msystem: ${{ matrix.sys }} + update: true + install: >- + make + pacboy: >- + toolchain:p + cmake:p + - name: Configure + run: | + cmake -G"Unix Makefiles" \ + -S . \ + -B build \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DMINIZIP_ENABLE_BZIP2=ON + - name: Build + run: cmake --build build --config Release + - name: Run tests + run: ctest --output-on-failure --test-dir build -C Release + + cygwin: + strategy: + fail-fast: false + runs-on: windows-latest + defaults: + run: + shell: C:\cygwin\bin\bash.exe --login -o igncr '{0}' + name: Cygwin + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup cygwin + uses: cygwin/cygwin-install-action@master + with: + packages: >- + cmake + cygwin-devel + gcc-core + gcc-g++ + ninja + - name: Configure + run: | + cmake /cygdrive/d/a/zlib/zlib \ + -B build \ + -DCMAKE_BUILD_TYPE=Release \ + -DZLIB_BUILD_MINIZIP=ON \ + -DMINIZIP_ENABLE_BZIP2=OFF \ + -G Ninja + - name: Build + run: cmake --build build --config Release -v -j1 + - name: Run tests + run: ctest --output-on-failure --test-dir build -C Release diff --git a/deps/zlib/.gitignore b/deps/zlib/.gitignore new file mode 100644 index 000000000..8d069ed38 --- /dev/null +++ b/deps/zlib/.gitignore @@ -0,0 +1,51 @@ +*.diff +*.patch +*.orig +*.rej + +*~ +*.a +*.lo +*.o +*.dylib + +*.gcda +*.gcno +*.gcov + +/zconf.h +/Makefile +/example +/example64 +/examplesh +**/libz.so* +/minigzip +/minigzip64 +/minigzipsh +/zlib.pc +/configure.log +/build + +.DS_Store +.vs +*.user +*.nupkg +contrib/vstudio/vc143/x86 +contrib/vstudio/vc143/x64 +contrib/vstudio/vc143/arm +contrib/vstudio/vc143/arm64 +contrib/nuget/bin +contrib/nuget/obj +*.included + +# Bazel directories +/bazel-* +/bazel-bin +/bazel-genfiles +/bazel-out +/bazel-testlogs +user.bazelrc + +# MODULE.bazel.lock is ignored for now as per this recommendation: +# https://github.com/bazelbuild/bazel/issues/20369 +MODULE.bazel.lock diff --git a/deps/zlib/BUILD.bazel b/deps/zlib/BUILD.bazel new file mode 100644 index 000000000..9a294f2f2 --- /dev/null +++ b/deps/zlib/BUILD.bazel @@ -0,0 +1,134 @@ +# Copied from https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/zlib/1.3.1.bcr.4/patches +# Adapted from https://github.com/protocolbuffers/protobuf/blob/master/third_party/zlib.BUILD + +# Copyright 2008 Google Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Code generated by the Protocol Buffer compiler is owned by the owner +# of the input file used when generating it. This code is not +# standalone and requires a support library to be linked with it. This +# support library is itself covered by the above license. + +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_license//rules:license.bzl", "license") + +package( + default_applicable_licenses = [":license"], +) + +license( + name = "license", + license_kinds = ["@rules_license//licenses/spdx:Zlib"], + license_text = "LICENSE", +) + +exports_files([ + "LICENSE", +]) + +_ZLIB_HEADERS = [ + "crc32.h", + "deflate.h", + "gzguts.h", + "inffast.h", + "inffixed.h", + "inflate.h", + "inftrees.h", + "trees.h", + "zconf.h", + "zlib.h", + "zutil.h", +] + +_ZLIB_PREFIXED_HEADERS = ["zlib/include/" + hdr for hdr in _ZLIB_HEADERS] + +# In order to limit the damage from the `includes` propagation +# via `:zlib`, copy the public headers to a subdirectory and +# expose those. +genrule( + name = "copy_public_headers", + srcs = _ZLIB_HEADERS, + outs = _ZLIB_PREFIXED_HEADERS, + cmd_bash = "cp $(SRCS) $(@D)/zlib/include/", + cmd_bat = " && ".join( + ["@copy /Y \"$(location %s)\" \"$(@D)\\zlib\\include\\\" >NUL" % + s for s in _ZLIB_HEADERS], + ), +) + +config_setting( + name = "mingw_gcc_compiler", + flag_values = { + "@bazel_tools//tools/cpp:compiler": "mingw-gcc", + }, + visibility = [":__subpackages__"], +) + +cc_library( + name = "z", + srcs = [ + "adler32.c", + "compress.c", + "crc32.c", + "deflate.c", + "gzclose.c", + "gzlib.c", + "gzread.c", + "gzwrite.c", + "infback.c", + "inffast.c", + "inflate.c", + "inftrees.c", + "trees.c", + "uncompr.c", + "zutil.c", + # Include the un-prefixed headers in srcs to work + # around the fact that zlib isn't consistent in its + # choice of <> or "" delimiter when including itself. + ] + _ZLIB_HEADERS, + hdrs = _ZLIB_PREFIXED_HEADERS, + copts = select({ + ":mingw_gcc_compiler": [ + "-fpermissive", + ], + "@platforms//os:windows": [], + "//conditions:default": [ + "-Wno-deprecated-non-prototype", + "-Wno-unused-variable", + "-Wno-implicit-function-declaration", + ], + }), + includes = ["zlib/include/"], + visibility = ["//visibility:public"], +) + +alias( + name = "zlib", + actual = ":z", + visibility = ["//visibility:public"], +) diff --git a/deps/zlib/CMakeLists.txt b/deps/zlib/CMakeLists.txt index 0fe939df6..aa7359121 100644 --- a/deps/zlib/CMakeLists.txt +++ b/deps/zlib/CMakeLists.txt @@ -1,99 +1,131 @@ -cmake_minimum_required(VERSION 2.4.4) -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) +cmake_minimum_required(VERSION 3.12...3.31) -project(zlib C) +project( + zlib + LANGUAGES C + VERSION 1.4.1.1 + HOMEPAGE_URL "https://zlib.net/" + DESCRIPTION "a general-purpose lossless data-compression library") -set(VERSION "1.2.11") +# ============================================================================ +# CPack +# ============================================================================ +set(CPACK_PACKAGE_VENDOR "zlib-Project") +set(CPACK_PACKAGE_DESCRIPTION_FILE ${zlib_SOURCE_DIR}/README) +set(CPACK_RESOURCE_FILE_LICENSE ${zlib_SOURCE_DIR}/LICENSE) +set(CPACK_RESOURCE_FILE_README ${zlib_SOURCE_DIR}/README) -option(ASM686 "Enable building i686 assembly implementation") -option(AMD64 "Enable building amd64 assembly implementation") +# ============================================================================ +# configuration +# ============================================================================ -set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") -set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") -set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") -set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages") -set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") +option(ZLIB_BUILD_TESTING "Enable Zlib Examples as tests" ON) +option(ZLIB_BUILD_SHARED "Enable building zlib shared library" ON) +option(ZLIB_BUILD_STATIC "Enable building zlib static library" ON) +option(ZLIB_BUILD_MINIZIP "Enable building libminizip contrib library" OFF) +option(ZLIB_INSTALL "Enable installation of zlib" ON) +option(ZLIB_PREFIX "prefix for all types and library functions, see zconf.h.in" + OFF) +mark_as_advanced(ZLIB_PREFIX) -include(CheckTypeSize) +if(WIN32) + option(ZLIB_INSTALL_COMPAT_DLL "Install a copy as zlib1.dll" ON) +endif(WIN32) + +get_property(IS_MULTI GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + +if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT IS_MULTI) + message(STATUS "No CMAKE_BUILD_TYPE set -- using Release") + set(CMAKE_BUILD_TYPE Release) +endif(NOT DEFINED CMAKE_BUILD_TYPE AND NOT IS_MULTI) + +include(CheckCSourceCompiles) include(CheckFunctionExists) include(CheckIncludeFile) -include(CheckCSourceCompiles) -enable_testing() +include(CMakePackageConfigHelpers) +include(CheckTypeSize) +include(CPack) +include(GNUInstallDirs) -check_include_file(sys/types.h HAVE_SYS_TYPES_H) -check_include_file(stdint.h HAVE_STDINT_H) -check_include_file(stddef.h HAVE_STDDEF_H) +set(CPACK_INCLUDED TRUE) + +if(NOT ZLIB_CONF_WRITTEN) + set(Z_PREFIX ${ZLIB_PREFIX}) + set(CONF_OUT_FILE ${zlib_BINARY_DIR}/zconf.h.cmakein) + file(READ ${zlib_SOURCE_DIR}/zconf.h ZCONF_CONTENT LIMIT 245) + file(WRITE ${CONF_OUT_FILE} ${ZCONF_CONTENT}) + file(APPEND ${CONF_OUT_FILE} "#cmakedefine Z_PREFIX 1\n") + file(APPEND ${CONF_OUT_FILE} "#cmakedefine HAVE_STDARG_H 1\n") + file(APPEND ${CONF_OUT_FILE} "#cmakedefine HAVE_UNISTD_H 1\n") + file(READ ${zlib_SOURCE_DIR}/zconf.h ZCONF_CONTENT OFFSET 244) + set(FIRST_ITEM TRUE) + + foreach(item IN LISTS ZCONF_CONTENT) + if(FIRST_ITEM) + string(APPEND OUT_CONTENT ${item}) + set(FIRST_ITEM FALSE) + else(FIRST_ITEM) + string(APPEND OUT_CONTENT "\;" ${item}) + endif(FIRST_ITEM) + endforeach(item IN LISTS ${ZCONF_CONTENT}) + + file(APPEND ${CONF_OUT_FILE} ${OUT_CONTENT}) + set(ZLIB_CONF_WRITTEN + TRUE + CACHE BOOL "zconf.h.cmakein was created") + mark_as_advanced(ZLIB_CONF_WRITTEN) +endif(NOT ZLIB_CONF_WRITTEN) # # Check to see if we have large file support # set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1) -# We add these other definitions here because CheckTypeSize.cmake -# in CMake 2.4.x does not automatically do so and we want -# compatibility with CMake 2.4.x. -if(HAVE_SYS_TYPES_H) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) -endif() -if(HAVE_STDINT_H) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) -endif() -if(HAVE_STDDEF_H) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) -endif() check_type_size(off64_t OFF64_T) -if(HAVE_OFF64_T) - add_definitions(-D_LARGEFILE64_SOURCE=1) -endif() -set(CMAKE_REQUIRED_DEFINITIONS) # clear variable +unset(CMAKE_REQUIRED_DEFINITIONS) # clear variable # # Check for fseeko # check_function_exists(fseeko HAVE_FSEEKO) -if(NOT HAVE_FSEEKO) - add_definitions(-DNO_FSEEKO) -endif() + +# +# Check for stdarg.h +# +check_include_file(stdarg.h HAVE_STDARG_H) # # Check for unistd.h # -check_include_file(unistd.h Z_HAVE_UNISTD_H) +check_include_file(unistd.h HAVE_UNISTD_H) +# +# Check visibility attribute is supported +# if(MSVC) - set(CMAKE_DEBUG_POSTFIX "d") - add_definitions(-D_CRT_SECURE_NO_DEPRECATE) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -endif() + set(CMAKE_REQUIRED_FLAGS "-WX") +else(MSVC) + set(CMAKE_REQUIRED_FLAGS "-WError") +endif(MSVC) -if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) - # If we're doing an out of source build and the user has a zconf.h - # in their source tree... - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h) - message(STATUS "Renaming") - message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h") - message(STATUS "to 'zconf.h.included' because this file is included with zlib") - message(STATUS "but CMake generates it automatically in the build directory.") - file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included) - endif() -endif() +check_c_source_compiles( + " + #include + static void f(void) __attribute__ ((visibility(\"hidden\"))); + int main(void) {return 0;} + " + HAVE___ATTR__VIS_HIDDEN) -set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein - ${ZLIB_PC} @ONLY) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein - ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) +unset(CMAKE_COMPILE_FLAGS) +set(ZLIB_PC ${zlib_BINARY_DIR}/zlib.pc) +configure_file(${zlib_SOURCE_DIR}/zlib.pc.cmakein ${ZLIB_PC} @ONLY) +configure_file(${zlib_BINARY_DIR}/zconf.h.cmakein ${zlib_BINARY_DIR}/zconf.h) - -#============================================================================ +# ============================================================================ # zlib -#============================================================================ +# ============================================================================ + +set(ZLIB_PUBLIC_HDRS ${zlib_BINARY_DIR}/zconf.h zlib.h) -set(ZLIB_PUBLIC_HDRS - ${CMAKE_CURRENT_BINARY_DIR}/zconf.h - zlib.h -) set(ZLIB_PRIVATE_HDRS crc32.h deflate.h @@ -103,8 +135,8 @@ set(ZLIB_PRIVATE_HDRS inflate.h inftrees.h trees.h - zutil.h -) + zutil.h) + set(ZLIB_SRCS adler32.c compress.c @@ -120,130 +152,179 @@ set(ZLIB_SRCS inffast.c trees.c uncompr.c - zutil.c -) + zutil.c) -if(NOT MINGW) - set(ZLIB_DLL_SRCS - win32/zlib1.rc # If present will override custom build rule below. - ) -endif() +if(WIN32) + set(zlib_static_suffix "s") + set(CMAKE_DEBUG_POSTFIX "d") +endif(WIN32) -if(CMAKE_COMPILER_IS_GNUCC) - if(ASM686) - set(ZLIB_ASMS contrib/asm686/match.S) - elseif (AMD64) - set(ZLIB_ASMS contrib/amd64/amd64-match.S) - endif () +if(ZLIB_BUILD_SHARED) + add_library( + zlib SHARED ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS} + $<$,$>:win32/zlib1.rc>) + add_library(ZLIB::ZLIB ALIAS zlib) + target_include_directories( + zlib + PUBLIC $ + $ + $) + target_compile_definitions( + zlib + PRIVATE ZLIB_BUILD + $<$:NO_FSEEKO> + $<$:HAVE_HIDDEN> + $<$:_CRT_SECURE_NO_DEPRECATE> + $<$:_CRT_NONSTDC_NO_DEPRECATE> + PUBLIC $<$:_LARGEFILE64_SOURCE=1>) + set(INSTALL_VERSION ${zlib_VERSION}) - if(ZLIB_ASMS) - add_definitions(-DASMV) - set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE) - endif() -endif() + if(NOT CYGWIN) + set_target_properties(zlib PROPERTIES SOVERSION ${zlib_VERSION_MAJOR} + VERSION ${INSTALL_VERSION}) + endif(NOT CYGWIN) -if(MSVC) - if(ASM686) - ENABLE_LANGUAGE(ASM_MASM) - set(ZLIB_ASMS - contrib/masmx86/inffas32.asm - contrib/masmx86/match686.asm - ) - elseif (AMD64) - ENABLE_LANGUAGE(ASM_MASM) - set(ZLIB_ASMS - contrib/masmx64/gvmat64.asm - contrib/masmx64/inffasx64.asm - ) - endif() + set_target_properties( + zlib + PROPERTIES DEFINE_SYMBOL ZLIB_DLL + EXPORT_NAME ZLIB + OUTPUT_NAME z) + if(UNIX + AND NOT APPLE + AND NOT (CMAKE_SYSTEM_NAME STREQUAL AIX)) + # On unix-like platforms the library is almost always called libz + set_target_properties( + zlib + PROPERTIES LINK_FLAGS + "-Wl,--version-script,\"${zlib_SOURCE_DIR}/zlib.map\"") + endif( + UNIX + AND NOT APPLE + AND NOT (CMAKE_SYSTEM_NAME STREQUAL AIX)) +endif(ZLIB_BUILD_SHARED) - if(ZLIB_ASMS) - add_definitions(-DASMV -DASMINF) - endif() -endif() +if(ZLIB_BUILD_STATIC) + add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} + ${ZLIB_PRIVATE_HDRS}) + add_library(ZLIB::ZLIBSTATIC ALIAS zlibstatic) + target_include_directories( + zlibstatic + PUBLIC $ + $ + $) + target_compile_definitions( + zlibstatic + PRIVATE ZLIB_BUILD + $<$:NO_FSEEKO> + $<$:HAVE_HIDDEN> + $<$:_CRT_SECURE_NO_DEPRECATE> + $<$:_CRT_NONSTDC_NO_DEPRECATE> + PUBLIC $<$:_LARGEFILE64_SOURCE=1>) + set_target_properties( + zlibstatic PROPERTIES EXPORT_NAME ZLIBSTATIC OUTPUT_NAME + z${zlib_static_suffix}) +endif(ZLIB_BUILD_STATIC) -# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION -file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents) -string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*" - "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents}) +if(ZLIB_INSTALL) + if(ZLIB_BUILD_SHARED) + install( + TARGETS zlib + COMPONENT Runtime + EXPORT zlibSharedExport + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + install( + EXPORT zlibSharedExport + FILE ZLIB-shared.cmake + NAMESPACE ZLIB:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib) + if(ZLIB_INSTALL_COMPAT_DLL) + install( + FILES $ + COMPONENT Runtime + RENAME zlib1.dll + DESTINATION "${CMAKE_INSTALL_BINDIR}") + endif(ZLIB_INSTALL_COMPAT_DLL) -if(MINGW) - # This gets us DLL resource information when compiling on MinGW. - if(NOT CMAKE_RC_COMPILER) - set(CMAKE_RC_COMPILER windres.exe) - endif() + if(MSVC) + install( + FILES $ + COMPONENT Runtime + DESTINATION ${CMAKE_INSTALL_BINDIR} + CONFIGURATIONS Debug OR RelWithDebInfo + OPTIONAL) + endif(MSVC) + endif(ZLIB_BUILD_SHARED) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj - COMMAND ${CMAKE_RC_COMPILER} - -D GCC_WINDRES - -I ${CMAKE_CURRENT_SOURCE_DIR} - -I ${CMAKE_CURRENT_BINARY_DIR} - -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj - -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc) - set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) -endif(MINGW) + if(ZLIB_BUILD_STATIC) + install( + TARGETS zlibstatic + COMPONENT Development + EXPORT zlibStaticExport + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + install( + EXPORT zlibStaticExport + FILE ZLIB-static.cmake + NAMESPACE ZLIB:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib) -add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) -add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) -set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) -set_target_properties(zlib PROPERTIES SOVERSION 1) + if(ZLIB_INSTALL_COMPAT_DLL AND MINGW) + install( + FILES $ + COMPONENT Development + RENAME libz.dll.a + DESTINATION "${CMAKE_INSTALL_LIBDIR}") + endif(ZLIB_INSTALL_COMPAT_DLL AND MINGW) + endif(ZLIB_BUILD_STATIC) -if(NOT CYGWIN) - # This property causes shared libraries on Linux to have the full version - # encoded into their final filename. We disable this on Cygwin because - # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll - # seems to be the default. - # - # This has no effect with MSVC, on that platform the version info for - # the DLL comes from the resource file win32/zlib1.rc - set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) -endif() + configure_package_config_file( + ${zlib_SOURCE_DIR}/zlibConfig.cmake.in + ${zlib_BINARY_DIR}/ZLIBConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib) -if(UNIX) - # On unix-like platforms the library is almost always called libz - set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) - if(NOT APPLE) - set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") - endif() -elseif(BUILD_SHARED_LIBS AND WIN32) - # Creates zlib1.dll when building shared library version - set_target_properties(zlib PROPERTIES SUFFIX "1.dll") -endif() + write_basic_package_version_file( + "${zlib_BINARY_DIR}/ZLIBConfigVersion.cmake" + VERSION "${zlib_VERSION}" + COMPATIBILITY AnyNewerVersion) -if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) - install(TARGETS zlib zlibstatic - RUNTIME DESTINATION "${INSTALL_BIN_DIR}" - ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" - LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) -endif() -if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) - install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}") -endif() -if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) - install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3") -endif() -if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) - install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") -endif() + install(FILES ${zlib_BINARY_DIR}/ZLIBConfig.cmake + ${zlib_BINARY_DIR}/ZLIBConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib) + install( + FILES ${ZLIB_PUBLIC_HDRS} + COMPONENT Development + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + install( + FILES zlib.3 + COMPONENT Docs + DESTINATION "${CMAKE_INSTALL_MANDIR}/man3") + install( + FILES LICENSE + doc/algorithm.txt + doc/crc-doc.1.0.pdf + doc/rfc1950.txt + doc/rfc1951.txt + doc/rfc1952.txt + doc/txtvsbin.txt + COMPONENT Docs + DESTINATION "${CMAKE_INSTALL_DOCDIR}/zlib") + install( + FILES ${ZLIB_PC} + COMPONENT Development + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +endif(ZLIB_INSTALL) -#============================================================================ -# Example binaries -#============================================================================ +# ============================================================================ +# Tests +# ============================================================================ +if(ZLIB_BUILD_TESTING) + enable_testing() + add_subdirectory(test) +endif(ZLIB_BUILD_TESTING) -add_executable(example test/example.c) -target_link_libraries(example zlib) -add_test(example example) - -add_executable(minigzip test/minigzip.c) -target_link_libraries(minigzip zlib) - -if(HAVE_OFF64_T) - add_executable(example64 test/example.c) - target_link_libraries(example64 zlib) - set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") - add_test(example64 example64) - - add_executable(minigzip64 test/minigzip.c) - target_link_libraries(minigzip64 zlib) - set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") -endif() +if(ZLIB_BUILD_MINIZIP) + add_subdirectory(contrib/minizip/) +endif(ZLIB_BUILD_MINIZIP) diff --git a/deps/zlib/ChangeLog b/deps/zlib/ChangeLog index 30199a65a..1f83ab05c 100644 --- a/deps/zlib/ChangeLog +++ b/deps/zlib/ChangeLog @@ -1,6 +1,112 @@ ChangeLog file for zlib +Changes in 1.3.1.1 (xx Jan 2024) +- + +Changes in 1.3.1 (22 Jan 2024) +- Reject overflows of zip header fields in minizip +- Fix bug in inflateSync() for data held in bit buffer +- Add LIT_MEM define to use more memory for a small deflate speedup +- Fix decision on the emission of Zip64 end records in minizip +- Add bounds checking to ERR_MSG() macro, used by zError() +- Neutralize zip file traversal attacks in miniunz +- Fix a bug in ZLIB_DEBUG compiles in check_match() +- Various portability and appearance improvements + +Changes in 1.3 (18 Aug 2023) +- Remove K&R function definitions and zlib2ansi +- Fix bug in deflateBound() for level 0 and memLevel 9 +- Fix bug when gzungetc() is used immediately after gzopen() +- Fix bug when using gzflush() with a very small buffer +- Fix crash when gzsetparams() attempted for transparent write +- Fix test/example.c to work with FORCE_STORED +- Rewrite of zran in examples (see zran.c version history) +- Fix minizip to allow it to open an empty zip file +- Fix reading disk number start on zip64 files in minizip +- Fix logic error in minizip argument processing +- Add minizip testing to Makefile +- Read multiple bytes instead of byte-by-byte in minizip unzip.c +- Add memory sanitizer to configure (--memory) +- Various portability improvements +- Various documentation improvements +- Various spelling and typo corrections + +Changes in 1.2.13 (13 Oct 2022) +- Fix configure issue that discarded provided CC definition +- Correct incorrect inputs provided to the CRC functions +- Repair prototypes and exporting of new CRC functions +- Fix inflateBack to detect invalid input with distances too far +- Have infback() deliver all of the available output up to any error +- Fix a bug when getting a gzip header extra field with inflate() +- Fix bug in block type selection when Z_FIXED used +- Tighten deflateBound bounds +- Remove deleted assembler code references +- Various portability and appearance improvements + +Changes in 1.2.12 (27 Mar 2022) +- Cygwin does not have _wopen(), so do not create gzopen_w() there +- Permit a deflateParams() parameter change as soon as possible +- Limit hash table inserts after switch from stored deflate +- Fix bug when window full in deflate_stored() +- Fix CLEAR_HASH macro to be usable as a single statement +- Avoid a conversion error in gzseek when off_t type too small +- Have Makefile return non-zero error code on test failure +- Avoid some conversion warnings in gzread.c and gzwrite.c +- Update use of errno for newer Windows CE versions +- Small speedup to inflate [psumbera] +- Return an error if the gzputs string length can't fit in an int +- Add address checking in clang to -w option of configure +- Don't compute check value for raw inflate if asked to validate +- Handle case where inflateSync used when header never processed +- Avoid the use of ptrdiff_t +- Avoid an undefined behavior of memcpy() in gzappend() +- Avoid undefined behaviors of memcpy() in gz*printf() +- Avoid an undefined behavior of memcpy() in _tr_stored_block() +- Make the names in functions declarations identical to definitions +- Remove old assembler code in which bugs have manifested +- Fix deflateEnd() to not report an error at start of raw deflate +- Add legal disclaimer to README +- Emphasize the need to continue decompressing gzip members +- Correct the initialization requirements for deflateInit2() +- Fix a bug that can crash deflate on some input when using Z_FIXED +- Assure that the number of bits for deflatePrime() is valid +- Use a structure to make globals in enough.c evident +- Use a macro for the printf format of big_t in enough.c +- Clean up code style in enough.c, update version +- Use inline function instead of macro for index in enough.c +- Clarify that prefix codes are counted in enough.c +- Show all the codes for the maximum tables size in enough.c +- Add gznorm.c example, which normalizes gzip files +- Fix the zran.c example to work on a multiple-member gzip file +- Add tables for crc32_combine(), to speed it up by a factor of 200 +- Add crc32_combine_gen() and crc32_combine_op() for fast combines +- Speed up software CRC-32 computation by a factor of 1.5 to 3 +- Use atomic test and set, if available, for dynamic CRC tables +- Don't bother computing check value after successful inflateSync() +- Correct comment in crc32.c +- Add use of the ARMv8 crc32 instructions when requested +- Use ARM crc32 instructions if the ARM architecture has them +- Explicitly note that the 32-bit check values are 32 bits +- Avoid adding empty gzip member after gzflush with Z_FINISH +- Fix memory leak on error in gzlog.c +- Fix error in comment on the polynomial representation of a byte +- Clarify gz* function interfaces, referring to parameter names +- Change macro name in inflate.c to avoid collision in VxWorks +- Correct typo in blast.c +- Improve portability of contrib/minizip +- Fix indentation in minizip's zip.c +- Replace black/white with allow/block. (theresa-m) +- minizip warning fix if MAXU32 already defined. (gvollant) +- Fix unztell64() in minizip to work past 4GB. (Daniël Hörchner) +- Clean up minizip to reduce warnings for testing +- Add fallthrough comments for gcc +- Eliminate use of ULL constants +- Separate out address sanitizing from warnings in configure +- Remove destructive aspects of make distclean +- Check for cc masquerading as gcc or clang in configure +- Fix crc32.c to compile local functions only if used + Changes in 1.2.11 (15 Jan 2017) - Fix deflate stored bug when pulling last block from window - Permit immediate deflateParams changes before any deflate input @@ -96,7 +202,7 @@ Changes in 1.2.7.1 (24 Mar 2013) - Fix types in contrib/minizip to match result of get_crc_table() - Simplify contrib/vstudio/vc10 with 'd' suffix - Add TOP support to win32/Makefile.msc -- Suport i686 and amd64 assembler builds in CMakeLists.txt +- Support i686 and amd64 assembler builds in CMakeLists.txt - Fix typos in the use of _LARGEFILE64_SOURCE in zconf.h - Add vc11 and vc12 build files to contrib/vstudio - Add gzvprintf() as an undocumented function in zlib @@ -296,14 +402,14 @@ Changes in 1.2.5.1 (10 Sep 2011) - Use u4 type for crc_table to avoid conversion warnings - Apply casts in zlib.h to avoid conversion warnings - Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller] -- Improve inflateSync() documentation to note indeterminancy +- Improve inflateSync() documentation to note indeterminacy - Add deflatePending() function to return the amount of pending output - Correct the spelling of "specification" in FAQ [Randers-Pehrson] - Add a check in configure for stdarg.h, use for gzprintf() - Check that pointers fit in ints when gzprint() compiled old style - Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler] - Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt] -- Add debug records in assmebler code [Londer] +- Add debug records in assembler code [Londer] - Update RFC references to use http://tools.ietf.org/html/... [Li] - Add --archs option, use of libtool to configure for Mac OS X [Borstel] @@ -511,7 +617,7 @@ Changes in 1.2.3.5 (8 Jan 2010) - Don't use _vsnprintf on later versions of MSVC [Lowman] - Add CMake build script and input file [Lowman] - Update contrib/minizip to 1.1 [Svensson, Vollant] -- Moved nintendods directory from contrib to . +- Moved nintendods directory from contrib to root - Replace gzio.c with a new set of routines with the same functionality - Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above - Update contrib/minizip to 1.1b @@ -685,7 +791,7 @@ Changes in 1.2.2.4 (11 July 2005) - Be more strict on incomplete code sets in inflate_table() and increase ENOUGH and MAXD -- this repairs a possible security vulnerability for invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for - discovering the vulnerability and providing test cases. + discovering the vulnerability and providing test cases - Add ia64 support to configure for HP-UX [Smith] - Add error return to gzread() for format or i/o error [Levin] - Use malloc.h for OS/2 [Necasek] @@ -721,7 +827,7 @@ Changes in 1.2.2.2 (30 December 2004) - Add Z_FIXED strategy option to deflateInit2() to force fixed trees - Add updated make_vms.com [Coghlan], update README - Create a new "examples" directory, move gzappend.c there, add zpipe.c, - fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html. + fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html - Add FAQ entry and comments in deflate.c on uninitialized memory access - Add Solaris 9 make options in configure [Gilbert] - Allow strerror() usage in gzio.c for STDC @@ -792,7 +898,7 @@ Changes in 1.2.1.1 (9 January 2004) - Fix a big fat bug in inftrees.c that prevented decoding valid dynamic blocks with only literals and no distance codes -- Thanks to "Hot Emu" for the bug report and sample file -- Add a note to puff.c on no distance codes case. +- Add a note to puff.c on no distance codes case Changes in 1.2.1 (17 November 2003) - Remove a tab in contrib/gzappend/gzappend.c @@ -970,7 +1076,7 @@ Changes in 1.2.0.1 (17 March 2003) - Include additional header file on VMS for off_t typedef - Try to use _vsnprintf where it supplants vsprintf [Vollant] - Add some casts in inffast.c -- Enchance comments in zlib.h on what happens if gzprintf() tries to +- Enhance comments in zlib.h on what happens if gzprintf() tries to write more than 4095 bytes before compression - Remove unused state from inflateBackEnd() - Remove exit(0) from minigzip.c, example.c @@ -1036,14 +1142,14 @@ Changes in 1.2.0 (9 March 2003) - Add contrib/puff/ simple inflate for deflate format description Changes in 1.1.4 (11 March 2002) -- ZFREE was repeated on same allocation on some error conditions. +- ZFREE was repeated on same allocation on some error conditions This creates a security problem described in http://www.zlib.org/advisory-2002-03-11.txt - Returned incorrect error (Z_MEM_ERROR) on some invalid data - Avoid accesses before window for invalid distances with inflate window - less than 32K. + less than 32K - force windowBits > 8 to avoid a bug in the encoder for a window size - of 256 bytes. (A complete fix will be available in 1.1.5). + of 256 bytes. (A complete fix will be available in 1.1.5) Changes in 1.1.3 (9 July 1998) - fix "an inflate input buffer bug that shows up on rare but persistent @@ -1117,7 +1223,7 @@ Changes in 1.1.1 (27 Feb 98) - remove block truncation heuristic which had very marginal effect for zlib (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the compression ratio on some files. This also allows inlining _tr_tally for - matches in deflate_slow. + matches in deflate_slow - added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier) Changes in 1.1.0 (24 Feb 98) @@ -1148,7 +1254,7 @@ Changes in 1.0.9 (17 Feb 1998) - Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8 - in inftrees.c, avoid cc -O bug on HP (Farshid Elahi) - in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with - the declaration of FAR (Gilles VOllant) + the declaration of FAR (Gilles Vollant) - install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann) - read_buf buf parameter of type Bytef* instead of charf* - zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout) @@ -1162,7 +1268,7 @@ Changes in 1.0.8 (27 Jan 1998) - include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong) - use constant arrays for the static trees in trees.c instead of computing them at run time (thanks to Ken Raeburn for this suggestion). To create - trees.h, compile with GEN_TREES_H and run "make test". + trees.h, compile with GEN_TREES_H and run "make test" - check return code of example in "make test" and display result - pass minigzip command line options to file_compress - simplifying code of inflateSync to avoid gcc 2.8 bug @@ -1201,12 +1307,12 @@ Changes in 1.0.6 (19 Jan 1998) - add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code) - Fix a deflate bug occurring only with compression level 0 (thanks to - Andy Buckler for finding this one). -- In minigzip, pass transparently also the first byte for .Z files. + Andy Buckler for finding this one) +- In minigzip, pass transparently also the first byte for .Z files - return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress() - check Z_FINISH in inflate (thanks to Marc Schluper) - Implement deflateCopy (thanks to Adam Costello) -- make static libraries by default in configure, add --shared option. +- make static libraries by default in configure, add --shared option - move MSDOS or Windows specific files to directory msdos - suppress the notion of partial flush to simplify the interface (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4) @@ -1218,7 +1324,7 @@ Changes in 1.0.6 (19 Jan 1998) - added Makefile.nt (thanks to Stephen Williams) - added the unsupported "contrib" directory: contrib/asm386/ by Gilles Vollant - 386 asm code replacing longest_match(). + 386 asm code replacing longest_match() contrib/iostream/ by Kevin Ruland A C++ I/O streams interface to the zlib gz* functions contrib/iostream2/ by Tyge Løvset @@ -1226,7 +1332,7 @@ Changes in 1.0.6 (19 Jan 1998) contrib/untgz/ by "Pedro A. Aranda Guti\irrez" A very simple tar.gz file extractor using zlib contrib/visual-basic.txt by Carlos Rios - How to use compress(), uncompress() and the gz* functions from VB. + How to use compress(), uncompress() and the gz* functions from VB - pass params -f (filtered data), -h (huffman only), -1 to -9 (compression level) in minigzip (thanks to Tom Lane) @@ -1235,8 +1341,8 @@ Changes in 1.0.6 (19 Jan 1998) - add undocumented function inflateSyncPoint() (hack for Paul Mackerras) - add undocumented function zError to convert error code to string (for Tim Smithers) -- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code. -- Use default memcpy for Symantec MSDOS compiler. +- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code +- Use default memcpy for Symantec MSDOS compiler - Add EXPORT keyword for check_func (needed for Windows DLL) - add current directory to LD_LIBRARY_PATH for "make test" - create also a link for libz.so.1 @@ -1249,7 +1355,7 @@ Changes in 1.0.6 (19 Jan 1998) - allow compilation with ANSI keywords only enabled for TurboC in large model - avoid "versionString"[0] (Borland bug) - add NEED_DUMMY_RETURN for Borland -- use variable z_verbose for tracing in debug mode (L. Peter Deutsch). +- use variable z_verbose for tracing in debug mode (L. Peter Deutsch) - allow compilation with CC - defined STDC for OS/2 (David Charlap) - limit external names to 8 chars for MVS (Thomas Lund) @@ -1259,7 +1365,7 @@ Changes in 1.0.6 (19 Jan 1998) - use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau) - added makelcc.bat for lcc-win32 (Tom St Denis) - in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe) -- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion. +- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion - check for unistd.h in configure (for off_t) - remove useless check parameter in inflate_blocks_free - avoid useless assignment of s->check to itself in inflate_blocks_new @@ -1280,7 +1386,7 @@ Changes in 1.0.5 (3 Jan 98) Changes in 1.0.4 (24 Jul 96) - In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF bit, so the decompressor could decompress all the correct data but went - on to attempt decompressing extra garbage data. This affected minigzip too. + on to attempt decompressing extra garbage data. This affected minigzip too - zlibVersion and gzerror return const char* (needed for DLL) - port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno) - use z_error only for DEBUG (avoid problem with DLLs) @@ -1310,7 +1416,7 @@ Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion] - fix array overlay in deflate.c which sometimes caused bad compressed data - fix inflate bug with empty stored block - fix MSDOS medium model which was broken in 0.99 -- fix deflateParams() which could generate bad compressed data. +- fix deflateParams() which could generate bad compressed data - Bytef is define'd instead of typedef'ed (work around Borland bug) - added an INDEX file - new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32), @@ -1331,7 +1437,7 @@ Changes in 0.99 (27 Jan 96) - allow preset dictionary shared between compressor and decompressor - allow compression level 0 (no compression) - add deflateParams in zlib.h: allow dynamic change of compression level - and compression strategy. + and compression strategy - test large buffers and deflateParams in example.c - add optional "configure" to build zlib as a shared library - suppress Makefile.qnx, use configure instead @@ -1370,33 +1476,33 @@ Changes in 0.99 (27 Jan 96) - fix typo in Make_vms.com (f$trnlnm -> f$getsyi) - in fcalloc, normalize pointer if size > 65520 bytes - don't use special fcalloc for 32 bit Borland C++ -- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... +- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc. - use Z_BINARY instead of BINARY - document that gzclose after gzdopen will close the file -- allow "a" as mode in gzopen. +- allow "a" as mode in gzopen - fix error checking in gzread - allow skipping .gz extra-field on pipes - added reference to Perl interface in README - put the crc table in FAR data (I dislike more and more the medium model :) - added get_crc_table -- added a dimension to all arrays (Borland C can't count). +- added a dimension to all arrays (Borland C can't count) - workaround Borland C bug in declaration of inflate_codes_new & inflate_fast - guard against multiple inclusion of *.h (for precompiled header on Mac) -- Watcom C pretends to be Microsoft C small model even in 32 bit mode. +- Watcom C pretends to be Microsoft C small model even in 32 bit mode - don't use unsized arrays to avoid silly warnings by Visual C++: warning C4746: 'inflate_mask' : unsized array treated as '__far' - (what's wrong with far data in far model?). + (what's wrong with far data in far model?) - define enum out of inflate_blocks_state to allow compilation with C++ Changes in 0.95 (16 Aug 95) - fix MSDOS small and medium model (now easier to adapt to any compiler) - inlined send_bits - fix the final (:-) bug for deflate with flush (output was correct but - not completely flushed in rare occasions). + not completely flushed in rare occasions) - default window size is same for compression and decompression - (it's now sufficient to set MAX_WBITS in zconf.h). + (it's now sufficient to set MAX_WBITS in zconf.h) - voidp -> voidpf and voidnp -> voidp (for consistency with other - typedefs and because voidnp was not near in large model). + typedefs and because voidnp was not near in large model) Changes in 0.94 (13 Aug 95) - support MSDOS medium model @@ -1405,12 +1511,12 @@ Changes in 0.94 (13 Aug 95) - added support for VMS - allow a compression level in gzopen() - gzflush now calls fflush -- For deflate with flush, flush even if no more input is provided. +- For deflate with flush, flush even if no more input is provided - rename libgz.a as libz.a - avoid complex expression in infcodes.c triggering Turbo C bug - work around a problem with gcc on Alpha (in INSERT_STRING) - don't use inline functions (problem with some gcc versions) -- allow renaming of Byte, uInt, etc... with #define. +- allow renaming of Byte, uInt, etc... with #define - avoid warning about (unused) pointer before start of array in deflate.c - avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c - avoid reserved word 'new' in trees.c @@ -1429,7 +1535,7 @@ Changes in 0.92 (3 May 95) - no memcpy on Pyramid - suppressed inftest.c - optimized fill_window, put longest_match inline for gcc -- optimized inflate on stored blocks. +- optimized inflate on stored blocks - untabify all sources to simplify patches Changes in 0.91 (2 May 95) @@ -1447,7 +1553,7 @@ Changes in 0.9 (1 May 95) - let again gzread copy uncompressed data unchanged (was working in 0.71) - deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented - added a test of inflateSync in example.c -- moved MAX_WBITS to zconf.h because users might want to change that. +- moved MAX_WBITS to zconf.h because users might want to change that - document explicitly that zalloc(64K) on MSDOS must return a normalized pointer (zero offset) - added Makefiles for Microsoft C, Turbo C, Borland C++ @@ -1456,7 +1562,7 @@ Changes in 0.9 (1 May 95) Changes in 0.8 (29 April 95) - added fast inflate (inffast.c) - deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this - is incompatible with previous versions of zlib which returned Z_OK. + is incompatible with previous versions of zlib which returned Z_OK - work around a TurboC compiler bug (bad code for b << 0, see infutil.h) (actually that was not a compiler bug, see 0.81 above) - gzread no longer reads one extra byte in certain cases @@ -1466,50 +1572,50 @@ Changes in 0.8 (29 April 95) Changes in 0.71 (14 April 95) - Fixed more MSDOS compilation problems :( There is still a bug with - TurboC large model. + TurboC large model Changes in 0.7 (14 April 95) -- Added full inflate support. +- Added full inflate support - Simplified the crc32() interface. The pre- and post-conditioning (one's complement) is now done inside crc32(). WARNING: this is - incompatible with previous versions; see zlib.h for the new usage. + incompatible with previous versions; see zlib.h for the new usage Changes in 0.61 (12 April 95) -- workaround for a bug in TurboC. example and minigzip now work on MSDOS. +- workaround for a bug in TurboC. example and minigzip now work on MSDOS Changes in 0.6 (11 April 95) - added minigzip.c - added gzdopen to reopen a file descriptor as gzFile -- added transparent reading of non-gziped files in gzread. +- added transparent reading of non-gziped files in gzread - fixed bug in gzread (don't read crc as data) -- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose). +- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose) - don't allocate big arrays in the stack (for MSDOS) - fix some MSDOS compilation problems Changes in 0.5: - do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but - not yet Z_FULL_FLUSH. + not yet Z_FULL_FLUSH - support decompression but only in a single step (forced Z_FINISH) -- added opaque object for zalloc and zfree. +- added opaque object for zalloc and zfree - added deflateReset and inflateReset -- added a variable zlib_version for consistency checking. -- renamed the 'filter' parameter of deflateInit2 as 'strategy'. - Added Z_FILTERED and Z_HUFFMAN_ONLY constants. +- added a variable zlib_version for consistency checking +- renamed the 'filter' parameter of deflateInit2 as 'strategy' + Added Z_FILTERED and Z_HUFFMAN_ONLY constants Changes in 0.4: -- avoid "zip" everywhere, use zlib instead of ziplib. +- avoid "zip" everywhere, use zlib instead of ziplib - suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush - if compression method == 8. + if compression method == 8 - added adler32 and crc32 - renamed deflateOptions as deflateInit2, call one or the other but not both -- added the method parameter for deflateInit2. +- added the method parameter for deflateInit2 - added inflateInit2 -- simplied considerably deflateInit and inflateInit by not supporting +- simplified considerably deflateInit and inflateInit by not supporting user-provided history buffer. This is supported only in deflateInit2 - and inflateInit2. + and inflateInit2 Changes in 0.3: - prefix all macro names with Z_ -- use Z_FINISH instead of deflateEnd to finish compression. +- use Z_FINISH instead of deflateEnd to finish compression - added Z_HUFFMAN_ONLY - added gzerror() diff --git a/deps/zlib/FAQ b/deps/zlib/FAQ index 99b7cf92e..f72cac63c 100644 --- a/deps/zlib/FAQ +++ b/deps/zlib/FAQ @@ -4,7 +4,7 @@ If your question is not there, please check the zlib home page http://zlib.net/ which may have more recent information. -The lastest zlib FAQ is at http://zlib.net/zlib_faq.html +The latest zlib FAQ is at http://zlib.net/zlib_faq.html 1. Is zlib Y2K-compliant? @@ -14,13 +14,12 @@ The lastest zlib FAQ is at http://zlib.net/zlib_faq.html 2. Where can I get a Windows DLL version? The zlib sources can be compiled without change to produce a DLL. See the - file win32/DLL_FAQ.txt in the zlib distribution. Pointers to the - precompiled DLL are found in the zlib web site at http://zlib.net/ . + file win32/DLL_FAQ.txt in the zlib distribution. 3. Where can I get a Visual Basic interface to zlib? See - * http://marknelson.us/1997/01/01/zlib-engine/ + * https://marknelson.us/posts/1997/01/01/zlib-engine.html * win32/DLL_FAQ.txt in the zlib distribution 4. compress() returns Z_BUF_ERROR. diff --git a/deps/zlib/LICENSE b/deps/zlib/LICENSE new file mode 100644 index 000000000..b517acd57 --- /dev/null +++ b/deps/zlib/LICENSE @@ -0,0 +1,22 @@ +Copyright notice: + + (C) 1995-2024 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu diff --git a/deps/zlib/MODULE.bazel b/deps/zlib/MODULE.bazel new file mode 100644 index 000000000..cb4c13ef3 --- /dev/null +++ b/deps/zlib/MODULE.bazel @@ -0,0 +1,9 @@ +module( + name = "zlib", + version = "0.0.0", + compatibility_level = 1, +) + +bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "rules_cc", version = "0.0.16") +bazel_dep(name = "rules_license", version = "1.0.0") diff --git a/deps/zlib/Makefile.in b/deps/zlib/Makefile.in index 5a77949ff..7010b25c5 100644 --- a/deps/zlib/Makefile.in +++ b/deps/zlib/Makefile.in @@ -1,5 +1,5 @@ # Makefile for zlib -# Copyright (C) 1995-2017 Jean-loup Gailly, Mark Adler +# Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler # For conditions of distribution and use, see copyright notice in zlib.h # To compile and test, type: @@ -7,16 +7,14 @@ # Normally configure builds both a static and a shared library. # If you want to build just a static library, use: ./configure --static -# To use the asm code, type: -# cp contrib/asm?86/match.S ./match.S -# make LOC=-DASMV OBJA=match.o - # To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type: # make install # To install in $HOME instead of /usr/local, use: # make install prefix=$HOME CC=cc +GCOV=GCOV +LLVM_GCOV_FLAG=LLMV_GCOV_FLAG CFLAGS=-O #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 @@ -26,13 +24,13 @@ CFLAGS=-O SFLAGS=-O LDFLAGS= -TEST_LDFLAGS=-L. libz.a +TEST_LIBS=-L. libz.a LDSHARED=$(CC) CPP=$(CC) -E STATICLIB=libz.a SHAREDLIB=libz.so -SHAREDLIBV=libz.so.1.2.11 +SHAREDLIBV=libz.so.1.3.1.1 SHAREDLIBM=libz.so.1 LIBS=$(STATICLIB) $(SHAREDLIBV) @@ -87,12 +85,12 @@ test: all teststatic testshared teststatic: static @TMPST=tmpst_$$; \ - if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \ + if echo hello world | ${QEMU_RUN} ./minigzip | ${QEMU_RUN} ./minigzip -d && ${QEMU_RUN} ./example $$TMPST ; then \ echo ' *** zlib test OK ***'; \ else \ echo ' *** zlib test FAILED ***'; false; \ - fi; \ - rm -f $$TMPST + fi + @rm -f tmpst_$$ testshared: shared @LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ @@ -100,32 +98,36 @@ testshared: shared DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \ SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \ TMPSH=tmpsh_$$; \ - if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \ + if echo hello world | ${QEMU_RUN} ./minigzipsh | ${QEMU_RUN} ./minigzipsh -d && ${QEMU_RUN} ./examplesh $$TMPSH; then \ echo ' *** zlib shared test OK ***'; \ else \ echo ' *** zlib shared test FAILED ***'; false; \ - fi; \ - rm -f $$TMPSH + fi + @rm -f tmpsh_$$ test64: all64 @TMP64=tmp64_$$; \ - if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \ + if echo hello world | ${QEMU_RUN} ./minigzip64 | ${QEMU_RUN} ./minigzip64 -d && ${QEMU_RUN} ./example64 $$TMP64; then \ echo ' *** zlib 64-bit test OK ***'; \ else \ echo ' *** zlib 64-bit test FAILED ***'; false; \ - fi; \ - rm -f $$TMP64 + fi + @rm -f tmp64_$$ infcover.o: $(SRCDIR)test/infcover.c $(SRCDIR)zlib.h zconf.h - $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/infcover.c + $(CC) $(CFLAGS) $(ZINCOUT) -c -coverage -o $@ $(SRCDIR)test/infcover.c infcover: infcover.o libz.a - $(CC) $(CFLAGS) -o $@ infcover.o libz.a + $(CC) $(CFLAGS) -coverage -o $@ infcover.o libz.a cover: infcover +ifdef $(GCOV) rm -f *.gcda - ./infcover - gcov inf*.c + ${QEMU_RUN} ./infcover + ${GCOV} ${LLVM_GCOV_FLAG} inf*.c -o ./infcover.gcda +else + @echo 'cover disabled as no suitable gcov was found' +endif libz.a: $(OBJS) $(AR) $(ARFLAGS) $@ $(OBJS) @@ -180,7 +182,7 @@ inftrees.o: $(SRCDIR)inftrees.c trees.o: $(SRCDIR)trees.c $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)trees.c -zutil.o: $(SRCDIR)zutil.c +zutil.o: $(SRCDIR)zutil.c $(SRCDIR)gzguts.h $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)zutil.c compress.o: $(SRCDIR)compress.c @@ -242,7 +244,7 @@ trees.lo: $(SRCDIR)trees.c $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/trees.o $(SRCDIR)trees.c -@mv objs/trees.o $@ -zutil.lo: $(SRCDIR)zutil.c +zutil.lo: $(SRCDIR)zutil.c $(SRCDIR)gzguts.h -@mkdir objs 2>/dev/null || test -d objs $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/zutil.o $(SRCDIR)zutil.c -@mv objs/zutil.o $@ @@ -286,22 +288,22 @@ placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a -@rmdir objs example$(EXE): example.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ example.o $(TEST_LIBS) minigzip$(EXE): minigzip.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip.o $(TEST_LIBS) examplesh$(EXE): example.o $(SHAREDLIBV) - $(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV) + $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) -L. $(SHAREDLIBV) minigzipsh$(EXE): minigzip.o $(SHAREDLIBV) - $(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV) + $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) -L. $(SHAREDLIBV) example64$(EXE): example64.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ example64.o $(TEST_LIBS) minigzip64$(EXE): minigzip64.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip64.o $(TEST_LIBS) install-libs: $(LIBS) -@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi @@ -353,18 +355,25 @@ docs: zlib.3.pdf zlib.3.pdf: $(SRCDIR)zlib.3 groff -mandoc -f H -T ps $(SRCDIR)zlib.3 | ps2pdf - $@ -zconf.h.cmakein: $(SRCDIR)zconf.h.in - -@ TEMPFILE=zconfh_$$; \ - echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\ - sed -f $$TEMPFILE $(SRCDIR)zconf.h.in > $@ &&\ - touch -r $(SRCDIR)zconf.h.in $@ &&\ - rm $$TEMPFILE +# zconf.h.cmakein: $(SRCDIR)zconf.h.in +# -@ TEMPFILE=zconfh_$$; \ +# echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\ +# sed -f $$TEMPFILE $(SRCDIR)zconf.h.in > $@ &&\ +# touch -r $(SRCDIR)zconf.h.in $@ &&\ +# rm $$TEMPFILE +# zconf: $(SRCDIR)zconf.h.in cp -p $(SRCDIR)zconf.h.in zconf.h +minizip-test: static + cd contrib/minizip && { CC="$(CC)" CFLAGS="$(CFLAGS)" $(MAKE) test ; cd ../.. ; } + +minizip-clean: + cd contrib/minizip && { $(MAKE) clean ; cd ../.. ; } + mostlyclean: clean -clean: +clean: minizip-clean rm -f *.o *.lo *~ \ example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \ example64$(EXE) minigzip64$(EXE) \ @@ -376,20 +385,19 @@ clean: rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov maintainer-clean: distclean -distclean: clean zconf zconf.h.cmakein docs +distclean: clean zconf # zconf.h.cmakein rm -f Makefile zlib.pc configure.log -@rm -f .DS_Store @if [ -f Makefile.in ]; then \ printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile ; \ printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile ; \ touch -r $(SRCDIR)Makefile.in Makefile ; fi - @if [ ! -f zconf.h.in ]; then rm -f zconf.h zconf.h.cmakein ; fi - @if [ ! -f zlib.3 ]; then rm -f zlib.3.pdf ; fi tags: etags $(SRCDIR)*.[ch] -adler32.o zutil.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h +adler32.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h +zutil.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h gzclose.o gzlib.o gzread.o gzwrite.o: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h compress.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h crc32.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h @@ -399,7 +407,8 @@ inffast.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR inftrees.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h trees.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)trees.h -adler32.lo zutil.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h +adler32.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h +zutil.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h gzclose.lo gzlib.lo gzread.lo gzwrite.lo: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h compress.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h crc32.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h diff --git a/deps/zlib/README b/deps/zlib/README index 51106de47..75da52058 100644 --- a/deps/zlib/README +++ b/deps/zlib/README @@ -1,6 +1,6 @@ ZLIB DATA COMPRESSION LIBRARY -zlib 1.2.11 is a general purpose data compression library. All the code is +zlib 1.3.1.1 is a general purpose data compression library. All the code is thread safe. The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and @@ -29,18 +29,17 @@ PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help. Mark Nelson wrote an article about zlib for the Jan. 1997 issue of Dr. Dobb's Journal; a copy of the article is available at -http://marknelson.us/1997/01/01/zlib-engine/ . +https://marknelson.us/posts/1997/01/01/zlib-engine.html . -The changes made in version 1.2.11 are documented in the file ChangeLog. +The changes made in version 1.3.1.1 are documented in the file ChangeLog. Unsupported third party contributions are provided in directory contrib/ . -zlib is available in Java using the java.util.zip package, documented at -http://java.sun.com/developer/technicalArticles/Programming/compression/ . +zlib is available in Java using the java.util.zip package. Follow the API +Documentation link at: https://docs.oracle.com/search/?q=java.util.zip . -A Perl interface to zlib written by Paul Marquess is available -at CPAN (Comprehensive Perl Archive Network) sites, including -http://search.cpan.org/~pmqs/IO-Compress-Zlib/ . +A Perl interface to zlib and bzip2 written by Paul Marquess +can be found at https://github.com/pmqs/IO-Compress . A Python interface to zlib written by A.M. Kuchling is available in Python 1.5 and later versions, see @@ -64,14 +63,12 @@ Notes for some targets: - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works when compiled with cc. -- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is +- On Digital Unix 4.0D (formerly OSF/1) on AlphaServer, the cc option -std1 is necessary to get gzprintf working correctly. This is done by configure. - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with other compilers. Use "make test" to check your compiler. -- gzdopen is not supported on RISCOS or BEOS. - - For PalmOs, see http://palmzlib.sourceforge.net/ @@ -84,7 +81,7 @@ Acknowledgments: Copyright notice: - (C) 1995-2017 Jean-loup Gailly and Mark Adler + (C) 1995-2024 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -108,7 +105,10 @@ Copyright notice: If you use the zlib library in a product, we would appreciate *not* receiving lengthy legal documents to sign. The sources are provided for free but without warranty of any kind. The library has been entirely written by Jean-loup -Gailly and Mark Adler; it does not include third-party code. +Gailly and Mark Adler; it does not include third-party code. We make all +contributions to and distributions of this project solely in our personal +capacity, and are not conveying any rights to any intellectual property of +any third parties. If you redistribute modified sources, we would appreciate that you include in the file ChangeLog history information documenting your changes. Please read diff --git a/deps/zlib/README-cmake.md b/deps/zlib/README-cmake.md new file mode 100644 index 000000000..7258f9cad --- /dev/null +++ b/deps/zlib/README-cmake.md @@ -0,0 +1,83 @@ +# For building with cmake at least version 3.12 (minizip 3.12) is needed + +In most cases the usual + + cmake -S . -B build -D CMAKE_BUILD_TYPE=Release + +will create everything you need, however if you want something off default you can adjust several options fit your needs. +Every option is list below (excluding the cmake-standard options), they can be set via cmake-gui or on cmdline with + + -D