diff --git a/include/hash_management.h b/include/hash_management.h index 30d958662..ab19df474 100644 --- a/include/hash_management.h +++ b/include/hash_management.h @@ -8,6 +8,11 @@ #define USERNAME 0 +int sort_by_digest_p0p1 (const void *v1, const void *v2); +int sort_by_salt (const void *v1, const void *v2); +int sort_by_hash (const void *v1, const void *v2); +int sort_by_hash_no_salt (const void *v1, const void *v2); + void save_hash (); void check_hash (hc_device_param_t *device_param, plain_t *plain); diff --git a/src/hash_management.c b/src/hash_management.c index 774eafc73..00e4acfce 100644 --- a/src/hash_management.c +++ b/src/hash_management.c @@ -35,6 +35,94 @@ extern hc_global_data_t data; extern hc_thread_mutex_t mux_display; +int sort_by_digest_p0p1 (const void *v1, const void *v2) +{ + const u32 *d1 = (const u32 *) v1; + const u32 *d2 = (const u32 *) v2; + + const uint dgst_pos0 = data.hashconfig->dgst_pos0; + const uint dgst_pos1 = data.hashconfig->dgst_pos1; + const uint dgst_pos2 = data.hashconfig->dgst_pos2; + const uint dgst_pos3 = data.hashconfig->dgst_pos3; + + if (d1[dgst_pos3] > d2[dgst_pos3]) return 1; + if (d1[dgst_pos3] < d2[dgst_pos3]) return -1; + if (d1[dgst_pos2] > d2[dgst_pos2]) return 1; + if (d1[dgst_pos2] < d2[dgst_pos2]) return -1; + if (d1[dgst_pos1] > d2[dgst_pos1]) return 1; + if (d1[dgst_pos1] < d2[dgst_pos1]) return -1; + if (d1[dgst_pos0] > d2[dgst_pos0]) return 1; + if (d1[dgst_pos0] < d2[dgst_pos0]) return -1; + + return 0; +} + +int sort_by_salt (const void *v1, const void *v2) +{ + const salt_t *s1 = (const salt_t *) v1; + const salt_t *s2 = (const salt_t *) v2; + + const int res1 = s1->salt_len - s2->salt_len; + + if (res1 != 0) return (res1); + + const int res2 = s1->salt_iter - s2->salt_iter; + + if (res2 != 0) return (res2); + + uint n; + + n = 16; + + while (n--) + { + if (s1->salt_buf[n] > s2->salt_buf[n]) return 1; + if (s1->salt_buf[n] < s2->salt_buf[n]) return -1; + } + + n = 8; + + while (n--) + { + if (s1->salt_buf_pc[n] > s2->salt_buf_pc[n]) return 1; + if (s1->salt_buf_pc[n] < s2->salt_buf_pc[n]) return -1; + } + + return 0; +} + +int sort_by_hash (const void *v1, const void *v2) +{ + const hash_t *h1 = (const hash_t *) v1; + const hash_t *h2 = (const hash_t *) v2; + + if (data.hashconfig->is_salted) + { + const salt_t *s1 = h1->salt; + const salt_t *s2 = h2->salt; + + int res = sort_by_salt (s1, s2); + + if (res != 0) return (res); + } + + const void *d1 = h1->digest; + const void *d2 = h2->digest; + + return sort_by_digest_p0p1 (d1, d2); +} + +int sort_by_hash_no_salt (const void *v1, const void *v2) +{ + const hash_t *h1 = (const hash_t *) v1; + const hash_t *h2 = (const hash_t *) v2; + + const void *d1 = h1->digest; + const void *d2 = h2->digest; + + return sort_by_digest_p0p1 (d1, d2); +} + void save_hash () { hashconfig_t *hashconfig = data.hashconfig; diff --git a/src/hashcat.c b/src/hashcat.c index 4e4b5d8a8..1e0eafb2e 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -109,95 +109,6 @@ const int comptime = COMPTIME; - -// hash_management - -int sort_by_digest_p0p1 (const void *v1, const void *v2) -{ - const u32 *d1 = (const u32 *) v1; - const u32 *d2 = (const u32 *) v2; - - const uint dgst_pos0 = data.hashconfig->dgst_pos0; - const uint dgst_pos1 = data.hashconfig->dgst_pos1; - const uint dgst_pos2 = data.hashconfig->dgst_pos2; - const uint dgst_pos3 = data.hashconfig->dgst_pos3; - - if (d1[dgst_pos3] > d2[dgst_pos3]) return ( 1); - if (d1[dgst_pos3] < d2[dgst_pos3]) return -1; - if (d1[dgst_pos2] > d2[dgst_pos2]) return ( 1); - if (d1[dgst_pos2] < d2[dgst_pos2]) return -1; - if (d1[dgst_pos1] > d2[dgst_pos1]) return ( 1); - if (d1[dgst_pos1] < d2[dgst_pos1]) return -1; - if (d1[dgst_pos0] > d2[dgst_pos0]) return ( 1); - if (d1[dgst_pos0] < d2[dgst_pos0]) return -1; - - return 0; -} -int sort_by_salt (const void *v1, const void *v2) -{ - const salt_t *s1 = (const salt_t *) v1; - const salt_t *s2 = (const salt_t *) v2; - - const int res1 = s1->salt_len - s2->salt_len; - - if (res1 != 0) return (res1); - - const int res2 = s1->salt_iter - s2->salt_iter; - - if (res2 != 0) return (res2); - - uint n; - - n = 16; - - while (n--) - { - if (s1->salt_buf[n] > s2->salt_buf[n]) return ( 1); - if (s1->salt_buf[n] < s2->salt_buf[n]) return -1; - } - - n = 8; - - while (n--) - { - if (s1->salt_buf_pc[n] > s2->salt_buf_pc[n]) return ( 1); - if (s1->salt_buf_pc[n] < s2->salt_buf_pc[n]) return -1; - } - - return 0; -} -int sort_by_hash (const void *v1, const void *v2) -{ - const hash_t *h1 = (const hash_t *) v1; - const hash_t *h2 = (const hash_t *) v2; - - if (data.hashconfig->is_salted) - { - const salt_t *s1 = h1->salt; - const salt_t *s2 = h2->salt; - - int res = sort_by_salt (s1, s2); - - if (res != 0) return (res); - } - - const void *d1 = h1->digest; - const void *d2 = h2->digest; - - return sort_by_digest_p0p1 (d1, d2); -} -int sort_by_hash_no_salt (const void *v1, const void *v2) -{ - const hash_t *h1 = (const hash_t *) v1; - const hash_t *h2 = (const hash_t *) v2; - - const void *d1 = h1->digest; - const void *d2 = h2->digest; - - return sort_by_digest_p0p1 (d1, d2); -} - - // remove #define REMOVE 0 #define REMOVE_TIMER 60