24286782d40b870ac8e473144bf78fc940edec3b
[strongswan.git] / Source / charon / transforms / hashers / hasher.h
1 /**
2 * @file hasher.h
3 *
4 * @brief Generic interface for hash functions
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef HASHER_H_
24 #define HASHER_H_
25
26
27 #include "../../types.h"
28
29 /**
30 * algorithms to use for hashing
31 */
32 typedef enum hash_algorithm_e hash_algorithm_t;
33
34 enum hash_algorithm_e {
35 SHA1,
36 MD5
37 };
38
39
40 /**
41 * Object representing a hasher
42 */
43 typedef struct hasher_s hasher_t;
44
45 struct hasher_s {
46 /**
47 * @brief hash data and write it in the buffer
48 *
49 * @param this calling hasher
50 * @param data data to hash
51 * @param [out]buffer pointer where the hash will be written
52 * @return
53 * - SUCCESS in any case
54 */
55 status_t (*get_hash) (hasher_t *this, chunk_t data, u_int8_t *buffer);
56
57 /**
58 * @brief hash data and allocate space for the hash
59 *
60 * @param this calling hasher
61 * @param seed a chunk containing the seed for the next bytes
62 * @param [out]hash chunk which will hold allocated hash
63 * @return
64 * - SUCCESS in any case
65 * - OUT_OF_RES if space could not be allocated
66 */
67 status_t (*allocate_hash) (hasher_t *this, chunk_t data, chunk_t *hash);
68
69 /**
70 * @brief get the block size of this hashing function
71 *
72 * @param this calling hasher
73 * @return block size in bytes
74 */
75 size_t (*get_block_size) (hasher_t *this);
76
77 /**
78 * @brief Destroys a hasher object.
79 *
80 * @param this hasher_t object to destroy
81 * @return
82 * SUCCESS in any case
83 */
84 status_t (*destroy) (hasher_t *this);
85 };
86
87 /**
88 * Creates a new hasher_t object
89 *
90 * @param hash_algorithm Algorithm to use for hashing
91 * @return
92 * - hasher_t if successfully
93 * - NULL if out of ressources
94 */
95 hasher_t *hasher_create(hash_algorithm_t hash_algorithm);
96
97 #endif /*HASHER_H_*/