From 9aeb4f602e3b64e7b3a11c2abcf1ae0fb720f833 Mon Sep 17 00:00:00 2001 From: mhasbini Date: Mon, 21 Jan 2019 20:44:28 +0200 Subject: [PATCH] Migrate correct parsing function --- include/interface_migrate.h | 2 ++ src/interface_migrate.c | 49 +++++++++++++++++++++++++++++++++++++ src/modules/module_17300.c | 26 ++++++-------------- 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/include/interface_migrate.h b/include/interface_migrate.h index ff571ff15..d8ce78f66 100644 --- a/include/interface_migrate.h +++ b/include/interface_migrate.h @@ -822,6 +822,7 @@ typedef enum hash_type HASH_TYPE_MD4 = 1, HASH_TYPE_MD5 = 2, HASH_TYPE_SHA1 = 4, + HASH_TYPE_SHA224 = 5, HASH_TYPE_SHA256 = 6, HASH_TYPE_SHA384 = 7, HASH_TYPE_SHA512 = 8, @@ -1182,6 +1183,7 @@ int sha1_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_bu int sha1b64_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig); int sha1b64s_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig); int sha1s_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig); +int sha224_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig); int sha256_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig); int sha256s_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig); int sha384_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig); diff --git a/src/interface_migrate.c b/src/interface_migrate.c index f3ca3548f..6bfce1da5 100644 --- a/src/interface_migrate.c +++ b/src/interface_migrate.c @@ -5155,6 +5155,55 @@ int oraclet_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UN return (PARSER_OK); } +int sha224_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig) +{ + u32 *digest = (u32 *) hash_buf->digest; + + token_t token; + + token.token_cnt = 1; + + token.len_min[0] = 56; + token.len_max[0] = 56; + token.attr[0] = TOKEN_ATTR_VERIFY_LENGTH + | TOKEN_ATTR_VERIFY_HEX; + + const int rc_tokenizer = input_tokenizer (input_buf, input_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + const u8 *hash_pos = token.buf[0]; + + digest[0] = hex_to_u32 (hash_pos + 0); + digest[1] = hex_to_u32 (hash_pos + 8); + digest[2] = hex_to_u32 (hash_pos + 16); + digest[3] = hex_to_u32 (hash_pos + 24); + digest[4] = hex_to_u32 (hash_pos + 32); + digest[5] = hex_to_u32 (hash_pos + 40); + digest[6] = hex_to_u32 (hash_pos + 48); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + digest[6] = byte_swap_32 (digest[6]); + + if (hashconfig->opti_type & OPTI_TYPE_PRECOMPUTE_MERKLE) + { + digest[0] -= SHA224M_A; + digest[1] -= SHA224M_B; + digest[2] -= SHA224M_C; + digest[3] -= SHA224M_D; + digest[4] -= SHA224M_E; + digest[5] -= SHA224M_F; + digest[6] -= SHA224M_G; + } + + return (PARSER_OK); +} + int sha256_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig) { u32 *digest = (u32 *) hash_buf->digest; diff --git a/src/modules/module_17300.c b/src/modules/module_17300.c index 00494af3b..0e7d81e3f 100644 --- a/src/modules/module_17300.c +++ b/src/modules/module_17300.c @@ -9,7 +9,6 @@ #include "bitops.h" #include "convert.h" #include "shared.h" -#include "inc_hash_constants.h" static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; static const u32 DGST_POS0 = 6; @@ -18,7 +17,7 @@ static const u32 DGST_POS2 = 4; static const u32 DGST_POS3 = 5; static const u32 DGST_SIZE = DGST_SIZE_8_25; static const u32 HASH_CATEGORY = HASH_CATEGORY_RAW_HASH; -static const char *HASH_NAME = "SHA3-224 "; +static const char *HASH_NAME = "SHA3-224"; static const u32 HASH_TYPE = HASH_TYPE_GENERIC; static const u64 KERN_TYPE = 17300; static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE @@ -52,18 +51,20 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE token_t token; - token.token_cnt = 1; + token.token_cnt = 1; - token.len_min[0] = 56; - token.len_max[0] = 56; - token.attr[0] = TOKEN_ATTR_VERIFY_LENGTH - | TOKEN_ATTR_VERIFY_HEX; + token.len[0] = 56; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_HEX; const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); const u8 *hash_pos = token.buf[0]; + const int hash_len = token.len[0]; + + if (hash_len != 56) return (PARSER_GLOBAL_LENGTH); digest[0] = hex_to_u32 (hash_pos + 0); digest[1] = hex_to_u32 (hash_pos + 8); @@ -73,17 +74,6 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE digest[5] = hex_to_u32 (hash_pos + 40); digest[6] = hex_to_u32 (hash_pos + 48); - if (hashconfig->opti_type & OPTI_TYPE_PRECOMPUTE_MERKLE) - { - digest[0] -= SHA224M_A; - digest[1] -= SHA224M_B; - digest[2] -= SHA224M_C; - digest[3] -= SHA224M_D; - digest[4] -= SHA224M_E; - digest[5] -= SHA224M_F; - digest[6] -= SHA224M_G; - } - return (PARSER_OK); }