1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-27 17:08:12 +00:00

Move more functions to hash_management.c

This commit is contained in:
jsteube 2016-09-14 19:50:53 +02:00
parent bd9e092ea3
commit 963cda3db6
3 changed files with 93 additions and 89 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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