diff --git a/include/shared.h b/include/shared.h index 326aa5c41..fafc36ee0 100644 --- a/include/shared.h +++ b/include/shared.h @@ -24,7 +24,8 @@ #include #endif -int sort_by_stringptr (const void *p1, const void *p2); +int sort_by_string_sized (const void *p1, const void *p2); +int sort_by_stringptr (const void *p1, const void *p2); bool overflow_check_u32_add (const u32 a, const u32 b); bool overflow_check_u32_mul (const u32 a, const u32 b); diff --git a/include/types.h b/include/types.h index 7972d4821..fdc1285e5 100644 --- a/include/types.h +++ b/include/types.h @@ -1626,6 +1626,13 @@ typedef struct cpu_set } cpu_set_t; #endif +typedef struct +{ + char *buf; + int len; + +} string_sized_t; + /* AES context. */ typedef struct aes_context { diff --git a/src/brain.c b/src/brain.c index dacdb0f7d..b39c4f16d 100644 --- a/src/brain.c +++ b/src/brain.c @@ -98,10 +98,9 @@ u32 brain_compute_session (hashcat_ctx_t *hashcat_ctx) // like OPTI_TYPE_PRECOMPUTE_MERKLE which cause different hashes in digests_buf // in case -O is used - char **out_bufs = (char **) hccalloc (hashes->digests_cnt, sizeof (char *)); - int *out_lens = (int *) hccalloc (hashes->digests_cnt, sizeof (int)); + string_sized_t *string_sized_buf = (string_sized_t *) hccalloc (hashes->digests_cnt, sizeof (string_sized_t)); - int out_idx = 0; + int string_sized_cnt = 0; u8 *out_buf = (u8 *) hcmalloc (HCBUFSIZ_LARGE); @@ -115,28 +114,27 @@ u32 brain_compute_session (hashcat_ctx_t *hashcat_ctx) { const int out_len = hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salts_idx, digest_idx); - out_bufs[out_idx] = (char *) hcmalloc (out_len + 1); - out_lens[out_idx] = out_len; + string_sized_buf[string_sized_cnt].buf = (char *) hcmalloc (out_len + 1); + string_sized_buf[string_sized_cnt].len = out_len; - memcpy (out_bufs[out_idx], out_buf, out_len); + memcpy (string_sized_buf[string_sized_cnt].buf, out_buf, out_len); - out_idx++; + string_sized_cnt++; } } hcfree (out_buf); - qsort (out_bufs, out_idx, sizeof (char *), sort_by_stringptr); + qsort (string_sized_buf, string_sized_cnt, sizeof (string_sized_t), sort_by_string_sized); - for (int i = 0; i < out_idx; i++) + for (int i = 0; i < string_sized_cnt; i++) { - XXH64_update (state, out_bufs[i], out_lens[i]); + XXH64_update (state, string_sized_buf[i].buf, string_sized_buf[i].len); - hcfree (out_bufs[i]); + hcfree (string_sized_buf[i].buf); } - hcfree (out_bufs); - hcfree (out_lens); + hcfree (string_sized_buf); } const u32 session = (const u32) XXH64_digest (state); diff --git a/src/shared.c b/src/shared.c index b23a047b3..8b59d600f 100644 --- a/src/shared.c +++ b/src/shared.c @@ -97,6 +97,18 @@ static const char *HASH_CATEGORY_OTP_STR = "One-Time Password static const char *HASH_CATEGORY_PLAIN_STR = "Plaintext"; static const char *HASH_CATEGORY_FRAMEWORK_STR = "Framework"; +int sort_by_string_sized (const void *p1, const void *p2) +{ + string_sized_t *s1 = (string_sized_t *) p1; + string_sized_t *s2 = (string_sized_t *) p2; + + const int d = s1->len - s2->len; + + if (d != 0) return d; + + return memcmp (s1->buf, s2->buf, s1->len); +} + int sort_by_stringptr (const void *p1, const void *p2) { const char* const *s1 = (const char* const *) p1;