1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-26 09:58:16 +00:00

Get rid of bin_to_hex_lower(), add u8_to_hex_lower(), u32_to_hex_lower() and u64_to_hex_lower()

This commit is contained in:
jsteube 2016-12-26 12:52:06 +01:00
parent 45479978c4
commit f0b287e838
3 changed files with 70 additions and 38 deletions

View File

@ -20,7 +20,9 @@ u8 hex_to_u8 (const u8 hex[2]);
u32 hex_to_u32 (const u8 hex[8]);
u64 hex_to_u64 (const u8 hex[16]);
void bin_to_hex_lower (const u32 v, u8 hex[8]);
void u8_to_hex_lower (const u8 v, u8 hex[2]);
void u32_to_hex_lower (const u32 v, u8 hex[8]);
void u64_to_hex_lower (const u64 v, u8 hex[16]);
u8 int_to_base32 (const u8 c);
u8 base32_to_int (const u8 c);

View File

@ -216,27 +216,60 @@ u64 hex_to_u64 (const u8 hex[16])
return (v);
}
void bin_to_hex_lower (const u32 v, u8 hex[8])
void u8_to_hex_lower (const u8 v, u8 hex[2])
{
hex[0] = v >> 28 & 15;
hex[1] = v >> 24 & 15;
hex[2] = v >> 20 & 15;
hex[3] = v >> 16 & 15;
hex[4] = v >> 12 & 15;
hex[5] = v >> 8 & 15;
hex[6] = v >> 4 & 15;
hex[7] = v >> 0 & 15;
const u8 tbl[0x10] =
{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f',
};
u32 add;
hex[1] = tbl[v >> 0 & 15];
hex[0] = tbl[v >> 4 & 15];
}
hex[0] += 6; add = ((hex[0] & 0x10u) >> 4) * 39; hex[0] += 42 + add;
hex[1] += 6; add = ((hex[1] & 0x10u) >> 4) * 39; hex[1] += 42 + add;
hex[2] += 6; add = ((hex[2] & 0x10u) >> 4) * 39; hex[2] += 42 + add;
hex[3] += 6; add = ((hex[3] & 0x10u) >> 4) * 39; hex[3] += 42 + add;
hex[4] += 6; add = ((hex[4] & 0x10u) >> 4) * 39; hex[4] += 42 + add;
hex[5] += 6; add = ((hex[5] & 0x10u) >> 4) * 39; hex[5] += 42 + add;
hex[6] += 6; add = ((hex[6] & 0x10u) >> 4) * 39; hex[6] += 42 + add;
hex[7] += 6; add = ((hex[7] & 0x10u) >> 4) * 39; hex[7] += 42 + add;
void u32_to_hex_lower (const u32 v, u8 hex[8])
{
const u8 tbl[0x10] =
{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f',
};
hex[1] = tbl[v >> 0 & 15];
hex[0] = tbl[v >> 4 & 15];
hex[3] = tbl[v >> 8 & 15];
hex[2] = tbl[v >> 12 & 15];
hex[5] = tbl[v >> 16 & 15];
hex[4] = tbl[v >> 20 & 15];
hex[7] = tbl[v >> 24 & 15];
hex[6] = tbl[v >> 28 & 15];
}
void u64_to_hex_lower (const u64 v, u8 hex[16])
{
const u8 tbl[0x10] =
{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f',
};
hex[ 1] = tbl[v >> 0 & 15];
hex[ 0] = tbl[v >> 4 & 15];
hex[ 3] = tbl[v >> 8 & 15];
hex[ 2] = tbl[v >> 12 & 15];
hex[ 5] = tbl[v >> 16 & 15];
hex[ 4] = tbl[v >> 20 & 15];
hex[ 7] = tbl[v >> 24 & 15];
hex[ 6] = tbl[v >> 28 & 15];
hex[ 9] = tbl[v >> 32 & 15];
hex[ 8] = tbl[v >> 36 & 15];
hex[11] = tbl[v >> 40 & 15];
hex[10] = tbl[v >> 44 & 15];
hex[13] = tbl[v >> 48 & 15];
hex[12] = tbl[v >> 52 & 15];
hex[15] = tbl[v >> 56 & 15];
hex[14] = tbl[v >> 60 & 15];
}
u8 int_to_base32 (const u8 c)

View File

@ -4046,15 +4046,23 @@ int ipb2_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSE
u32 salt_len = input_len - 32 - 1;
u8 *salt_buf = (u8 *) input_buf + 32 + 1;
u8 *salt_buf = input_buf + 32 + 1;
u8 *salt_buf_ptr = (u8 *) salt->salt_buf;
salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len, hashconfig);
if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH);
salt->salt_len = salt_len;
// precomput first md5
u32 salt_pc_block[16] = { 0 };
u8 *salt_pc_block_ptr = (u8 *) salt_pc_block;
salt_len = parse_and_store_salt (salt_pc_block_ptr, salt_buf, salt_len, hashconfig);
if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH);
memcpy (salt_pc_block_ptr, salt_buf_ptr, salt_len);
salt_pc_block_ptr[salt_len] = 0x80;
@ -4064,23 +4072,12 @@ int ipb2_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSE
md5_64 (salt_pc_block, salt_pc_digest);
salt_pc_digest[0] = byte_swap_32 (salt_pc_digest[0]);
salt_pc_digest[1] = byte_swap_32 (salt_pc_digest[1]);
salt_pc_digest[2] = byte_swap_32 (salt_pc_digest[2]);
salt_pc_digest[3] = byte_swap_32 (salt_pc_digest[3]);
u8 *salt_buf_ptr = (u8 *) salt->salt_buf;
memcpy (salt_buf_ptr, salt_buf, salt_len);
u8 *salt_buf_pc_ptr = (u8 *) salt->salt_buf_pc;
bin_to_hex_lower (salt_pc_digest[0], salt_buf_pc_ptr + 0);
bin_to_hex_lower (salt_pc_digest[1], salt_buf_pc_ptr + 8);
bin_to_hex_lower (salt_pc_digest[2], salt_buf_pc_ptr + 16);
bin_to_hex_lower (salt_pc_digest[3], salt_buf_pc_ptr + 24);
salt->salt_len = 32; // changed, was salt_len before -- was a bug? 32 should be correct
u32_to_hex_lower (salt_pc_digest[0], salt_buf_pc_ptr + 0);
u32_to_hex_lower (salt_pc_digest[1], salt_buf_pc_ptr + 8);
u32_to_hex_lower (salt_pc_digest[2], salt_buf_pc_ptr + 16);
u32_to_hex_lower (salt_pc_digest[3], salt_buf_pc_ptr + 24);
return (PARSER_OK);
}