/** * \brief Store a hash into the hash table * * \param hash_table hash table that will hold the hash * \param string hexadecimal string representing the hash * \param filename file name from where the string was read * \param line_no file line number from where the string was read * \param type the hash algorithm * * \retval -1 failed to load the hash into the hash table * \retval 1 successfully loaded the has into the hash table */ int LoadHashTable(ROHashTable *hash_table, char *string, char *filename, int line_no, uint32_t type) { /* allocate the maximum size a hash can have (in this case is SHA256, 32 bytes) */ uint8_t hash[32]; /* specify the actual size that should be read depending on the hash algorithm */ uint16_t size = 32; if (type == DETECT_FILEMD5) { size = 16; } else if (type == DETECT_FILESHA1) { size = 20; } /* every byte represented with hexadecimal digits is two characters */ uint16_t expected_len = (size * 2); if (ReadHashString(hash, string, filename, line_no, expected_len) == 1) { if (ROHashInitQueueValue(hash_table, &hash, size) != 1) return -1; } return 1; }
static int MD5LoadHash(ROHashTable *hash, char *string) { uint8_t md5[16]; if (Md5ReadString(md5, string) == 1) { if (ROHashInitQueueValue(hash, &md5, (uint16_t)sizeof(md5)) != 1) return -1; } return 1; }