1 /* 2 * Copyright (C) 2013-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved. 3 * Copyright (C) 2010-2013 Sourcefire, Inc. 4 * 5 * Authors: aCaB 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #ifndef __MATCHER_HASH_H 23 #define __MATCHER_HASH_H 24 25 #if HAVE_CONFIG_H 26 #include "clamav-config.h" 27 #endif 28 29 #include "clamav-types.h" 30 #include "hashtab.h" 31 32 enum CLI_HASH_TYPE { 33 CLI_HASH_MD5 = 0, 34 CLI_HASH_SHA1, 35 CLI_HASH_SHA256, 36 37 /* new hash types go above this line */ 38 CLI_HASH_AVAIL_TYPES 39 }; 40 41 #define CLI_HASHLEN_MD5 16 42 #define CLI_HASHLEN_SHA1 20 43 #define CLI_HASHLEN_SHA256 32 44 #define CLI_HASHLEN_MAX 32 45 46 struct cli_sz_hash { 47 uint8_t *hash_array; 48 const char **virusnames; 49 uint32_t items; 50 }; 51 52 struct cli_hash_patt { 53 struct cli_htu32 sizehashes[CLI_HASH_AVAIL_TYPES]; 54 }; 55 56 struct cli_hash_wild { 57 struct cli_sz_hash hashes[CLI_HASH_AVAIL_TYPES]; 58 }; 59 60 int hm_addhash_str(struct cli_matcher *root, const char *strhash, uint32_t size, const char *virusname); 61 int hm_addhash_bin(struct cli_matcher *root, const void *binhash, enum CLI_HASH_TYPE type, uint32_t size, const char *virusname); 62 void hm_flush(struct cli_matcher *root); 63 int cli_hm_scan(const unsigned char *digest, uint32_t size, const char **virname, const struct cli_matcher *root, enum CLI_HASH_TYPE type); 64 int cli_hm_scan_wild(const unsigned char *digest, const char **virname, const struct cli_matcher *root, enum CLI_HASH_TYPE type); 65 int cli_hm_have_size(const struct cli_matcher *root, enum CLI_HASH_TYPE type, uint32_t size); 66 int cli_hm_have_wild(const struct cli_matcher *root, enum CLI_HASH_TYPE type); 67 int cli_hm_have_any(const struct cli_matcher *root, enum CLI_HASH_TYPE type); 68 void hm_free(struct cli_matcher *root); 69 70 #endif 71