diff --git a/OpenCL/m06211-pure.cl b/OpenCL/m06211-pure.cl index 06f519632..11e5a5bf4 100644 --- a/OpenCL/m06211-pure.cl +++ b/OpenCL/m06211-pure.cl @@ -17,9 +17,11 @@ #include M2S(INCLUDE_PATH/inc_cipher_serpent.cl) #endif +#define TC_DATA_LEN (448) + typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; diff --git a/OpenCL/m06212-pure.cl b/OpenCL/m06212-pure.cl index 3dd97cda7..01dca38c8 100644 --- a/OpenCL/m06212-pure.cl +++ b/OpenCL/m06212-pure.cl @@ -17,9 +17,11 @@ #include M2S(INCLUDE_PATH/inc_cipher_serpent.cl) #endif +#define TC_DATA_LEN (448) + typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; diff --git a/OpenCL/m06213-pure.cl b/OpenCL/m06213-pure.cl index aeb9d64b3..dd51ac790 100644 --- a/OpenCL/m06213-pure.cl +++ b/OpenCL/m06213-pure.cl @@ -17,9 +17,11 @@ #include M2S(INCLUDE_PATH/inc_cipher_serpent.cl) #endif +#define TC_DATA_LEN (448) + typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; diff --git a/OpenCL/m06221-pure.cl b/OpenCL/m06221-pure.cl index 671459f2a..cf03af58b 100644 --- a/OpenCL/m06221-pure.cl +++ b/OpenCL/m06221-pure.cl @@ -17,9 +17,11 @@ #include M2S(INCLUDE_PATH/inc_cipher_serpent.cl) #endif +#define TC_DATA_LEN (448) + typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; diff --git a/OpenCL/m06222-pure.cl b/OpenCL/m06222-pure.cl index 348139296..6187ff2dd 100644 --- a/OpenCL/m06222-pure.cl +++ b/OpenCL/m06222-pure.cl @@ -17,9 +17,11 @@ #include M2S(INCLUDE_PATH/inc_cipher_serpent.cl) #endif +#define TC_DATA_LEN (448) + typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; diff --git a/OpenCL/m06223-pure.cl b/OpenCL/m06223-pure.cl index fd79c732d..5e64191df 100644 --- a/OpenCL/m06223-pure.cl +++ b/OpenCL/m06223-pure.cl @@ -17,9 +17,11 @@ #include M2S(INCLUDE_PATH/inc_cipher_serpent.cl) #endif +#define TC_DATA_LEN (448) + typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; diff --git a/OpenCL/m06231-pure.cl b/OpenCL/m06231-pure.cl index dba51becc..85880b268 100644 --- a/OpenCL/m06231-pure.cl +++ b/OpenCL/m06231-pure.cl @@ -17,9 +17,11 @@ #include M2S(INCLUDE_PATH/inc_cipher_serpent.cl) #endif +#define TC_DATA_LEN (448) + typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; diff --git a/OpenCL/m06232-pure.cl b/OpenCL/m06232-pure.cl index 0241ba0f9..702a1719e 100644 --- a/OpenCL/m06232-pure.cl +++ b/OpenCL/m06232-pure.cl @@ -17,9 +17,11 @@ #include M2S(INCLUDE_PATH/inc_cipher_serpent.cl) #endif +#define TC_DATA_LEN (448) + typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; diff --git a/OpenCL/m06233-pure.cl b/OpenCL/m06233-pure.cl index d2add150c..446c58327 100644 --- a/OpenCL/m06233-pure.cl +++ b/OpenCL/m06233-pure.cl @@ -17,9 +17,11 @@ #include M2S(INCLUDE_PATH/inc_cipher_serpent.cl) #endif +#define TC_DATA_LEN (448) + typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; diff --git a/src/modules/module_06211.c b/src/modules/module_06211.c index 724c294f2..c6c9fd9d1 100644 --- a/src/modules/module_06211.c +++ b/src/modules/module_06211.c @@ -46,9 +46,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc_tmp { @@ -62,7 +63,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -130,20 +131,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -247,7 +239,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06212.c b/src/modules/module_06212.c index 867e0b6cc..3310e88be 100644 --- a/src/modules/module_06212.c +++ b/src/modules/module_06212.c @@ -46,9 +46,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc_tmp { @@ -62,7 +63,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -130,20 +131,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -247,7 +239,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06213.c b/src/modules/module_06213.c index 0a6b6dcab..627b34820 100644 --- a/src/modules/module_06213.c +++ b/src/modules/module_06213.c @@ -46,9 +46,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc_tmp { @@ -62,7 +63,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -130,20 +131,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -247,7 +239,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06221.c b/src/modules/module_06221.c index 2c50e0551..db2870643 100644 --- a/src/modules/module_06221.c +++ b/src/modules/module_06221.c @@ -48,9 +48,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc64_tmp { @@ -64,7 +65,7 @@ typedef struct tc64_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -132,20 +133,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -251,7 +243,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06222.c b/src/modules/module_06222.c index d73e1b312..c3655e6bc 100644 --- a/src/modules/module_06222.c +++ b/src/modules/module_06222.c @@ -48,9 +48,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc64_tmp { @@ -64,7 +65,7 @@ typedef struct tc64_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -132,20 +133,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -251,7 +243,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06223.c b/src/modules/module_06223.c index 93ac513dd..f8e0a0ef8 100644 --- a/src/modules/module_06223.c +++ b/src/modules/module_06223.c @@ -48,9 +48,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc64_tmp { @@ -64,7 +65,7 @@ typedef struct tc64_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -132,20 +133,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -251,7 +243,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06231.c b/src/modules/module_06231.c index 6087089be..c70fe5c3b 100644 --- a/src/modules/module_06231.c +++ b/src/modules/module_06231.c @@ -47,9 +47,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc_tmp { @@ -63,7 +64,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -140,20 +141,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -259,7 +251,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06232.c b/src/modules/module_06232.c index 57745d7f3..7320f817c 100644 --- a/src/modules/module_06232.c +++ b/src/modules/module_06232.c @@ -47,9 +47,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc_tmp { @@ -63,7 +64,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -140,20 +141,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -259,7 +251,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06233.c b/src/modules/module_06233.c index 0ae9948b9..350e383ec 100644 --- a/src/modules/module_06233.c +++ b/src/modules/module_06233.c @@ -47,9 +47,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc_tmp { @@ -63,7 +64,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -136,20 +137,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -255,7 +247,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06241.c b/src/modules/module_06241.c index 1c12bf870..e709fd118 100644 --- a/src/modules/module_06241.c +++ b/src/modules/module_06241.c @@ -47,9 +47,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc_tmp { @@ -63,7 +64,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -143,20 +144,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -262,7 +254,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06242.c b/src/modules/module_06242.c index 02bf12884..5d95cbb07 100644 --- a/src/modules/module_06242.c +++ b/src/modules/module_06242.c @@ -47,9 +47,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc_tmp { @@ -63,7 +64,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -143,20 +144,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -262,7 +254,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_06243.c b/src/modules/module_06243.c index f25baa720..bcc4f937f 100644 --- a/src/modules/module_06243.c +++ b/src/modules/module_06243.c @@ -47,9 +47,10 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 -#define TC_HEADER_LEN 512 +#define TC_SALT_LEN ( 64) +#define TC_DATA_LEN ( 448) +#define TC_HEADER_LEN ( 512) +#define TC_HEADER_HEX_LEN (TC_HEADER_LEN * 2) typedef struct tc_tmp { @@ -63,7 +64,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -143,20 +144,11 @@ u32 module_pw_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED con int module_hash_init_selftest (MAYBE_UNUSED const hashconfig_t *hashconfig, hash_t *hash) { - const size_t st_hash_len = strlen (hashconfig->st_hash); + char header[TC_HEADER_LEN + 1] = { 0 }; - char *tmpdata = (char *) hcmalloc (st_hash_len / 2); + hex_decode ((const u8 *) hashconfig->st_hash, TC_HEADER_HEX_LEN, (u8 *) header); - for (size_t i = 0, j = 0; j < st_hash_len; i += 1, j += 2) - { - const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + j); - - tmpdata[i] = c; - } - - const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, tmpdata, st_hash_len / 2); - - hcfree (tmpdata); + const int parser_status = module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, header, TC_HEADER_LEN); return parser_status; } @@ -262,7 +254,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } diff --git a/src/modules/module_29311.c b/src/modules/module_29311.c index 166e834d0..78bc26ca6 100644 --- a/src/modules/module_29311.c +++ b/src/modules/module_29311.c @@ -46,8 +46,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc_tmp { @@ -61,7 +64,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -132,14 +135,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -151,12 +154,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -166,10 +164,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -183,7 +178,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -237,25 +232,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29312.c b/src/modules/module_29312.c index 041c58aa4..1ee66f9a7 100644 --- a/src/modules/module_29312.c +++ b/src/modules/module_29312.c @@ -46,8 +46,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc_tmp { @@ -61,7 +64,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -132,14 +135,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -151,12 +154,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -166,10 +164,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -183,7 +178,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -237,25 +232,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29313.c b/src/modules/module_29313.c index 26b1fbc00..a0f8032f8 100644 --- a/src/modules/module_29313.c +++ b/src/modules/module_29313.c @@ -46,8 +46,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc_tmp { @@ -61,7 +64,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -132,14 +135,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -151,12 +154,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -166,10 +164,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -183,7 +178,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -237,25 +232,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29321.c b/src/modules/module_29321.c index 5ca063dec..d6ef9fe04 100644 --- a/src/modules/module_29321.c +++ b/src/modules/module_29321.c @@ -48,8 +48,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc64_tmp { @@ -63,7 +66,7 @@ typedef struct tc64_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -134,14 +137,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -153,12 +156,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -168,10 +166,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -185,7 +180,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -239,25 +234,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29322.c b/src/modules/module_29322.c index f241b10a9..6a20cfb10 100644 --- a/src/modules/module_29322.c +++ b/src/modules/module_29322.c @@ -48,8 +48,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc64_tmp { @@ -63,7 +66,7 @@ typedef struct tc64_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -134,14 +137,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -153,12 +156,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -168,10 +166,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -185,7 +180,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -239,25 +234,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29323.c b/src/modules/module_29323.c index 5b66f010d..3642f2add 100644 --- a/src/modules/module_29323.c +++ b/src/modules/module_29323.c @@ -48,8 +48,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc64_tmp { @@ -63,7 +66,7 @@ typedef struct tc64_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -134,14 +137,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -153,12 +156,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -168,10 +166,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -185,7 +180,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -239,25 +234,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29331.c b/src/modules/module_29331.c index b26e7f852..45d9fdc51 100644 --- a/src/modules/module_29331.c +++ b/src/modules/module_29331.c @@ -47,8 +47,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc_tmp { @@ -62,7 +65,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -142,14 +145,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -161,12 +164,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -176,10 +174,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -193,7 +188,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -247,25 +242,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29332.c b/src/modules/module_29332.c index a1c89da59..2c0e5dd6e 100644 --- a/src/modules/module_29332.c +++ b/src/modules/module_29332.c @@ -47,8 +47,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc_tmp { @@ -62,7 +65,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -142,14 +145,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -161,12 +164,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -176,10 +174,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -193,7 +188,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -247,25 +242,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29333.c b/src/modules/module_29333.c index 104a7a54f..8557776fc 100644 --- a/src/modules/module_29333.c +++ b/src/modules/module_29333.c @@ -47,8 +47,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc_tmp { @@ -62,7 +65,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -138,14 +141,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -157,12 +160,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -172,10 +170,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -189,7 +184,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -243,25 +238,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29341.c b/src/modules/module_29341.c index 30d20e5f9..873c646c2 100644 --- a/src/modules/module_29341.c +++ b/src/modules/module_29341.c @@ -47,8 +47,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc_tmp { @@ -62,7 +65,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -145,14 +148,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -164,12 +167,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -179,10 +177,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -196,7 +191,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -250,25 +245,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29342.c b/src/modules/module_29342.c index ce78a34f0..465e3a52a 100644 --- a/src/modules/module_29342.c +++ b/src/modules/module_29342.c @@ -47,8 +47,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc_tmp { @@ -62,7 +65,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -145,14 +148,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -164,12 +167,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -179,10 +177,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -196,7 +191,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -250,25 +245,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/src/modules/module_29343.c b/src/modules/module_29343.c index ceb0233e2..2eb1dbbf0 100644 --- a/src/modules/module_29343.c +++ b/src/modules/module_29343.c @@ -47,8 +47,11 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } -#define TC_SALT_LEN 64 -#define TC_DATA_LEN 448 +#define TC_SALT_LEN ( 64) +#define TC_SALT_HEX_LEN (TC_SALT_LEN * 2) + +#define TC_DATA_LEN ( 448) +#define TC_DATA_HEX_LEN (TC_DATA_LEN * 2) typedef struct tc_tmp { @@ -62,7 +65,7 @@ typedef struct tc_tmp typedef struct tc { - u32 data_buf[112]; + u32 data_buf[TC_DATA_LEN / 4]; u32 keyfile_buf16[16]; u32 keyfile_buf32[32]; u32 keyfile_enabled; @@ -145,14 +148,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE | TOKEN_ATTR_VERIFY_SIGNATURE; token.sep[1] = '$'; - token.len_min[1] = 128; - token.len_max[1] = 128; + token.len_min[1] = TC_SALT_HEX_LEN; + token.len_max[1] = TC_SALT_HEX_LEN; token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; token.sep[2] = '$'; - token.len_min[2] = 896; - token.len_max[2] = 896; + token.len_min[2] = TC_DATA_HEX_LEN; + token.len_max[2] = TC_DATA_HEX_LEN; token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH | TOKEN_ATTR_VERIFY_HEX; @@ -164,12 +167,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *salt_pos = token.buf[1]; - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - salt->salt_buf[i] = hex_to_u32 (salt_pos + j); - } - - salt->salt_len = TC_SALT_LEN; + salt->salt_len = hex_decode (salt_pos, TC_SALT_HEX_LEN, (u8 *) salt->salt_buf); // iter @@ -179,10 +177,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u8 *data_pos = token.buf[2]; - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - tc->data_buf[i] = hex_to_u32 (data_pos + j); - } + hex_decode (data_pos, TC_DATA_HEX_LEN, (u8 *) tc->data_buf); // entropy @@ -196,7 +191,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // fake digest - memcpy (digest, tc->data_buf, 112); + memcpy (digest, tc->data_buf, TC_DATA_LEN / 4); return (PARSER_OK); } @@ -250,25 +245,15 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // salt - #define TC_SALT_HEX_LEN TC_SALT_LEN * 2 + 1 + char salt_buf[TC_SALT_HEX_LEN + 1] = { 0 }; - char salt_buf[TC_SALT_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_SALT_LEN / 4; i += 1, j += 8) - { - snprintf (salt_buf + j, TC_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i])); - } + hex_encode ((const u8 *) salt->salt_buf, TC_SALT_LEN, (u8 *) salt_buf); // data - #define TC_DATA_HEX_LEN TC_DATA_LEN * 2 + 1 + char data_buf[TC_DATA_HEX_LEN + 1] = { 0 }; - char data_buf[TC_DATA_HEX_LEN] = { 0 }; - - for (u32 i = 0, j = 0; i < TC_DATA_LEN / 4; i += 1, j += 8) - { - snprintf (data_buf + j, TC_DATA_HEX_LEN - j, "%08x", byte_swap_32 (tc->data_buf[i])); - } + hex_encode ((const u8 *) tc->data_buf, TC_DATA_LEN, (u8 *) data_buf); // output diff --git a/tools/truecrypt2hashcat.py b/tools/truecrypt2hashcat.py index 89571b404..e96d61551 100755 --- a/tools/truecrypt2hashcat.py +++ b/tools/truecrypt2hashcat.py @@ -1,5 +1,10 @@ #!/usr/bin/env python3 +# +# Author......: See docs/credits.txt +# License.....: MIT +# + from argparse import ArgumentParser, ArgumentTypeError @@ -23,9 +28,10 @@ def validate_offset(offset): offset = BOOTABLE_OFFSET + HIDDEN_OFFSET try: offset = int(offset) - assert offset >= 0 - except (AssertionError, ValueError): - raise ArgumentTypeError("offset is nether non-negative number nor bootable, hidden or bootable+hidden value") + except ValueError as e: + raise ArgumentTypeError("value is nether number nor allowed string") from e + if offset < 0: + raise ArgumentTypeError("value cannot be less than zero") return offset @@ -42,14 +48,18 @@ if __name__ == "__main__": args = parser.parse_args() - with open(args.path, "rb") as file: - file.seek(args.offset) + try: + with open(args.path, "rb") as file: + file.seek(args.offset) - header = file.read(HEADER_LENGTH) + header = file.read(HEADER_LENGTH) - assert len(header) == HEADER_LENGTH, "less data than needed" + if len(header) < HEADER_LENGTH: + parser.error("file contains less data than needed") - salt, data = header[:SALT_LENGTH], header[SALT_LENGTH:] + salt, data = header[:SALT_LENGTH], header[SALT_LENGTH:] - hash = SIGNATURE + salt.hex() + "$" + data.hex() - print(hash) + hash = SIGNATURE + salt.hex() + "$" + data.hex() + print(hash) + except IOError as e: + parser.error(e.strerror.lower())