4 * @brief Interface hasher_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
30 typedef enum hash_algorithm_t hash_algorithm_t
;
33 * @brief Algorithms to use for hashing.
35 * Currently only the following algorithms are implemented and therefore supported:
42 enum hash_algorithm_t
{
45 * Implemented in class md5_hasher_t.
49 * Implemented in class sha1_hasher_t.
58 * String mappings for hash_algorithm_t.
60 extern mapping_t hash_algorithm_m
[];
63 typedef struct hasher_t hasher_t
;
66 * @brief Generic interface for all hash functions.
70 * - md5_hasher_create()
71 * - sha1_hasher_create()
77 * @todo Implement more hash algorithms
83 * @brief Hash data and write it in the buffer.
85 * If the parameter hash is NULL, no result is written back
86 * an more data can be appended to already hashed data.
87 * If not, the result is written back and the hasher is reseted.
89 * @warning: the hash output parameter must hold at least
90 * hash_t.get_block_size bytes.
92 * @param this calling object
93 * @param data data to hash
94 * @param[out] hash pointer where the hash will be written
96 void (*get_hash
) (hasher_t
*this, chunk_t data
, u_int8_t
*hash
);
99 * @brief Hash data and allocate space for the hash.
101 * If the parameter hash is NULL, no result is written back
102 * an more data can be appended to already hashed data.
103 * If not, the result is written back and the hasher is reseted.
105 * @param this calling object
106 * @param data chunk with data to hash
107 * @param[out] hash chunk which will hold allocated hash
109 void (*allocate_hash
) (hasher_t
*this, chunk_t data
, chunk_t
*hash
);
112 * @brief Get the size of the resulting hash.
114 * @param this calling object
115 * @return hash size in bytes
117 size_t (*get_hash_size
) (hasher_t
*this);
120 * @brief Resets the hashers state, which allows
121 * computation of a completely new hash.
123 * @param this calling object
125 void (*reset
) (hasher_t
*this);
128 * @brief Destroys a hasher object.
130 * @param this calling object
132 void (*destroy
) (hasher_t
*this);
136 * @brief Generic interface to create a hasher_t.
138 * @param hash_algorithm Algorithm to use for hashing
141 * - NULL if algorithm not supported
145 hasher_t
*hasher_create(hash_algorithm_t hash_algorithm
);