1 /*
2 * AIDE (Advanced Intrusion Detection Environment)
3 *
4 * Copyright (C) 2020 Hannes von Haugwitz
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include "config.h"
22 #include "hashsum.h"
23
24 #ifdef WITH_MHASH
25 #include <mhash.h>
26 #endif
27 #ifdef WITH_GCRYPT
28 #include <gcrypt.h>
29 #endif
30
31 hashsum_t hashsums[] = {
32 { attr_md5, 16 },
33 { attr_sha1, 20 },
34 { attr_sha256, 32 },
35 { attr_sha512, 64 },
36 { attr_rmd160, 20 },
37 { attr_tiger, 24 },
38 { attr_crc32, 4 },
39 { attr_crc32b, 4 },
40 { attr_haval, 32 },
41 { attr_whirlpool, 64 },
42 { attr_gostr3411_94, 32 },
43 { attr_stribog256, 32 },
44 { attr_stribog512, 64 },
45 };
46
47 #ifdef WITH_MHASH
48 int algorithms[] = { /* order must match hashsums array */
49 MHASH_MD5,
50 MHASH_SHA1,
51 MHASH_SHA256,
52 MHASH_SHA512,
53 MHASH_RIPEMD160,
54 MHASH_TIGER,
55 MHASH_CRC32,
56 MHASH_CRC32B,
57 MHASH_HAVAL,
58 #ifdef HAVE_MHASH_WHIRLPOOL
59 MHASH_WHIRLPOOL,
60 #else
61 -1,
62 #endif
63 MHASH_GOST,
64 -1, /* stribog256 not available */
65 -1, /* stribog512 not available */
66 };
67 #endif
68
69 #ifdef WITH_GCRYPT
70 int algorithms[] = { /* order must match hashsums array */
71 GCRY_MD_MD5,
72 GCRY_MD_SHA1,
73 GCRY_MD_SHA256,
74 GCRY_MD_SHA512,
75 GCRY_MD_RMD160,
76 GCRY_MD_TIGER,
77 GCRY_MD_CRC32,
78 -1, /* CRC32B is not available */
79 -1, /* GCRY_MD_HAVAL is not (yet) implemented */
80 GCRY_MD_WHIRLPOOL,
81 GCRY_MD_GOSTR3411_94,
82 GCRY_MD_STRIBOG256,
83 GCRY_MD_STRIBOG512,
84 };
85 #endif
86
get_hashes(bool include_unsupported)87 DB_ATTR_TYPE get_hashes(bool include_unsupported) {
88 DB_ATTR_TYPE attr = 0LLU;
89 for (int i = 0; i < num_hashes; ++i) {
90 if (include_unsupported || algorithms[i] >= 0) {
91 attr |= ATTR(hashsums[i].attribute);
92 }
93 }
94 return attr;
95 };
96