diff --git a/include/hashes.h b/include/hashes.h index 9d4aec4fa..d726540b1 100644 --- a/include/hashes.h +++ b/include/hashes.h @@ -26,7 +26,8 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx); int hashes_init_stage3 (hashcat_ctx_t *hashcat_ctx); int hashes_init_stage4 (hashcat_ctx_t *hashcat_ctx); -int hashes_init_selftest (hashcat_ctx_t *hashcat_ctx); +int hashes_init_selftest (hashcat_ctx_t *hashcat_ctx); +int hashes_init_benchmark (hashcat_ctx_t *hashcat_ctx); void hashes_destroy (hashcat_ctx_t *hashcat_ctx); diff --git a/include/interface.h b/include/interface.h index f0412bafd..4c1ee4f30 100644 --- a/include/interface.h +++ b/include/interface.h @@ -45,10 +45,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx); void hashconfig_destroy (hashcat_ctx_t *hashcat_ctx); u32 default_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); -void *default_benchmark_esalt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra); -void *default_benchmark_hook_salt (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 char *default_benchmark_mask (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra); -salt_t *default_benchmark_salt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra); bool default_dictstat_disable (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra); u32 default_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); u32 default_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); diff --git a/include/types.h b/include/types.h index ffd8ef2f1..c2459bcf2 100644 --- a/include/types.h +++ b/include/types.h @@ -947,12 +947,6 @@ struct hashconfig const char *hash_name; const char *benchmark_mask; - u32 benchmark_salt_len; - u32 benchmark_salt_iter; - - salt_t *benchmark_salt; - void *benchmark_esalt; - void *benchmark_hook_salt; u32 kernel_accel_min; u32 kernel_accel_max; diff --git a/src/hashcat.c b/src/hashcat.c index 708fdb352..28d723542 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -604,6 +604,14 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) if (rc_hashes_init_selftest == -1) return -1; + /** + * load hashes, benchmark + */ + + const int rc_hashes_init_benchmark = hashes_init_benchmark (hashcat_ctx); + + if (rc_hashes_init_benchmark == -1) return -1; + /** * Done loading hashes, log results */ diff --git a/src/hashes.c b/src/hashes.c index 7b6ab865e..bc0e7ae85 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -739,22 +739,13 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) hashes->hook_salts_buf = hook_salts_buf; /** - * load hashes, part III: parse hashes or generate them if benchmark + * load hashes, part III: parse hashes */ u32 hashes_cnt = 0; if (user_options->benchmark == true) { - if (hashconfig->is_salted == true) - { - memcpy (hashes_buf[0].salt, hashconfig->benchmark_salt, sizeof (salt_t)); - - memcpy (hashes_buf[0].esalt, hashconfig->benchmark_esalt, hashconfig->esalt_size); - - memcpy (hashes_buf[0].hook_salt, hashconfig->benchmark_hook_salt, hashconfig->hook_salt_size); - } - hashes->hashfile = "-"; hashes_cnt = 1; @@ -1704,6 +1695,68 @@ int hashes_init_selftest (hashcat_ctx_t *hashcat_ctx) return 0; } +int hashes_init_benchmark (hashcat_ctx_t *hashcat_ctx) +{ + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + hashes_t *hashes = hashcat_ctx->hashes; + const module_ctx_t *module_ctx = hashcat_ctx->module_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + if (user_options->benchmark == false) return 0; + + if (hashconfig->is_salted == false) return 0; + + hash_t *hashes_buf = hashes->hashes_buf; + + if (module_ctx->module_benchmark_salt != MODULE_DEFAULT) + { + salt_t *ptr = module_ctx->module_benchmark_salt (hashconfig, user_options, user_options_extra); + + memcpy (hashes->salts_buf, ptr, sizeof (salt_t)); + + hcfree (ptr); + } + else + { + memcpy (hashes->salts_buf, hashes->st_salts_buf, sizeof (salt_t)); + } + + if (hashconfig->esalt_size > 0) + { + if (module_ctx->module_benchmark_esalt != MODULE_DEFAULT) + { + void *ptr = module_ctx->module_benchmark_esalt (hashconfig, user_options, user_options_extra); + + memcpy (hashes->esalts_buf, ptr, hashconfig->esalt_size); + + hcfree (ptr); + } + else + { + memcpy (hashes->esalts_buf, hashes->st_esalts_buf, hashconfig->esalt_size); + } + } + + if (hashconfig->hook_salt_size > 0) + { + if (module_ctx->module_benchmark_hook_salt != MODULE_DEFAULT) + { + void *ptr = module_ctx->module_benchmark_hook_salt (hashconfig, user_options, user_options_extra); + + memcpy (hashes->hook_salts_buf, ptr, hashconfig->hook_salt_size); + + hcfree (ptr); + } + else + { + memcpy (hashes->hook_salts_buf, hashes->st_hook_salts_buf, hashconfig->hook_salt_size); + } + } + + return 0; +} + void hashes_destroy (hashcat_ctx_t *hashcat_ctx) { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; diff --git a/src/interface.c b/src/interface.c index 00b8d853a..263a273de 100644 --- a/src/interface.c +++ b/src/interface.c @@ -706,6 +706,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx) // set some boring defaults hashconfig->attack_exec = default_attack_exec (hashconfig, user_options, user_options_extra); + hashconfig->benchmark_mask = default_benchmark_mask (hashconfig, user_options, user_options_extra); hashconfig->dgst_pos0 = default_dgst_pos0 (hashconfig, user_options, user_options_extra); hashconfig->dgst_pos1 = default_dgst_pos1 (hashconfig, user_options, user_options_extra); hashconfig->dgst_pos2 = default_dgst_pos2 (hashconfig, user_options, user_options_extra); @@ -759,6 +760,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx) } if (module_ctx->module_attack_exec != MODULE_DEFAULT) hashconfig->attack_exec = module_ctx->module_attack_exec (hashconfig, user_options, user_options_extra); + if (module_ctx->module_benchmark_mask != MODULE_DEFAULT) hashconfig->benchmark_mask = module_ctx->module_benchmark_mask (hashconfig, user_options, user_options_extra); if (module_ctx->module_dgst_pos0 != MODULE_DEFAULT) hashconfig->dgst_pos0 = module_ctx->module_dgst_pos0 (hashconfig, user_options, user_options_extra); if (module_ctx->module_dgst_pos1 != MODULE_DEFAULT) hashconfig->dgst_pos1 = module_ctx->module_dgst_pos1 (hashconfig, user_options, user_options_extra); if (module_ctx->module_dgst_pos2 != MODULE_DEFAULT) hashconfig->dgst_pos2 = module_ctx->module_dgst_pos2 (hashconfig, user_options, user_options_extra); @@ -909,16 +911,6 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx) // those depend on some previously defined values - hashconfig->benchmark_esalt = default_benchmark_esalt (hashconfig, user_options, user_options_extra); - hashconfig->benchmark_hook_salt = default_benchmark_hook_salt (hashconfig, user_options, user_options_extra); - hashconfig->benchmark_mask = default_benchmark_mask (hashconfig, user_options, user_options_extra); - hashconfig->benchmark_salt = default_benchmark_salt (hashconfig, user_options, user_options_extra); - - if (module_ctx->module_benchmark_esalt != MODULE_DEFAULT) hashconfig->benchmark_esalt = module_ctx->module_benchmark_esalt (hashconfig, user_options, user_options_extra); - if (module_ctx->module_benchmark_hook_salt != MODULE_DEFAULT) hashconfig->benchmark_hook_salt = module_ctx->module_benchmark_hook_salt (hashconfig, user_options, user_options_extra); - if (module_ctx->module_benchmark_mask != MODULE_DEFAULT) hashconfig->benchmark_mask = module_ctx->module_benchmark_mask (hashconfig, user_options, user_options_extra); - if (module_ctx->module_benchmark_salt != MODULE_DEFAULT) hashconfig->benchmark_salt = module_ctx->module_benchmark_salt (hashconfig, user_options, user_options_extra); - hashconfig->pw_max = default_pw_max (hashconfig, user_options, user_options_extra); hashconfig->pw_min = default_pw_min (hashconfig, user_options, user_options_extra); hashconfig->salt_max = default_salt_max (hashconfig, user_options, user_options_extra); @@ -1149,20 +1141,6 @@ u32 default_salt_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED return salt_max; } -void *default_benchmark_esalt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) -{ - void *esalt = (void *) hcmalloc (hashconfig->esalt_size); - - return esalt; -} - -void *default_benchmark_hook_salt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) -{ - void *hook_salt = (void *) hcmalloc (hashconfig->hook_salt_size); - - return hook_salt; -} - const char *default_benchmark_mask (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { const char *mask = "?b?b?b?b?b?b?b"; @@ -1170,16 +1148,6 @@ const char *default_benchmark_mask (MAYBE_UNUSED const hashconfig_t *hashconfig, return mask; } -salt_t *default_benchmark_salt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) -{ - salt_t *salt = (salt_t *) hcmalloc (sizeof (salt_t)); - - salt->salt_len = 8; - salt->salt_iter = 1; - - return salt; -} - u32 default_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) { const u32 opti_type = 0;