]> the.earth.li Git - onak.git/blob - hash-helper.h
0.6.3 release
[onak.git] / hash-helper.h
1 /*
2  * hash-helper.h - Helper functions for calculating hashes
3  *
4  * Copyright Jonathan McDowell <noodles@earth.li>
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program.  If not, see <https://www.gnu.org/licenses/>.
17  */
18
19 #ifndef __HASH_HELPER_H__
20 #define __HASH_HELPER_H__
21
22 #include <stdint.h>
23
24 #include "build-config.h"
25
26 #ifdef HAVE_NETTLE
27 #include <nettle/md5.h>
28 #include <nettle/ripemd160.h>
29 #include <nettle/sha.h>
30 #else
31 #include "md5.h"
32 #include "sha1.h"
33 #endif
34
35 #include "onak.h"
36 #include "sha1x.h"
37
38 #define MAX_HASH_CHUNKS         8
39
40 struct onak_hash_ctx {
41         uint8_t type;
42         union {
43                 struct sha1_ctx sha1;
44                 struct sha1x_ctx sha1x;
45                 struct md5_ctx md5;
46 #ifdef HAVE_NETTLE
47                 struct ripemd160_ctx ripemd160;
48                 struct sha224_ctx sha224;
49                 struct sha256_ctx sha256;
50                 struct sha384_ctx sha384;
51                 struct sha512_ctx sha512;
52 #endif
53         };
54 };
55
56 struct onak_hash_data {
57         uint8_t hashtype;
58         uint8_t chunks;
59         size_t len[MAX_HASH_CHUNKS];
60         uint8_t *data[MAX_HASH_CHUNKS];
61 };
62
63 onak_status_t onak_hash(struct onak_hash_data *data, uint8_t *hash);
64
65 #endif /* __HASH_HELPER_H__ */