mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-25 09:28:20 +00:00
Use special type for hashlist sorting in brain_compute_session()
This commit is contained in:
parent
f9e4dc0db1
commit
ff37264c36
@ -24,7 +24,8 @@
|
||||
#include <sys/select.h>
|
||||
#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);
|
||||
|
@ -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
|
||||
{
|
||||
|
24
src/brain.c
24
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);
|
||||
|
12
src/shared.c
12
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;
|
||||
|
Loading…
Reference in New Issue
Block a user