4 * @brief Generic interface for hash functions
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
27 #include "../../types.h"
30 * algorithms to use for hashing
32 typedef enum hash_algorithm_e hash_algorithm_t
;
34 enum hash_algorithm_e
{
41 * Object representing a hasher
43 typedef struct hasher_s hasher_t
;
47 * @brief hash data and write it in the buffer
49 * @param this calling hasher
50 * @param data data to hash
51 * @param [out]buffer pointer where the hash will be written
53 * - SUCCESS in any case
55 status_t (*get_hash
) (hasher_t
*this, chunk_t data
, u_int8_t
*buffer
);
58 * @brief hash data and allocate space for the hash
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
64 * - SUCCESS in any case
65 * - OUT_OF_RES if space could not be allocated
67 status_t (*allocate_hash
) (hasher_t
*this, chunk_t data
, chunk_t
*hash
);
70 * @brief get the block size of this hashing function
72 * @param this calling hasher
73 * @return block size in bytes
75 size_t (*get_block_size
) (hasher_t
*this);
78 * @brief Destroys a hasher object.
80 * @param this hasher_t object to destroy
84 status_t (*destroy
) (hasher_t
*this);
88 * Creates a new hasher_t object
90 * @param hash_algorithm Algorithm to use for hashing
92 * - hasher_t if successfully
93 * - NULL if out of ressources
95 hasher_t
*hasher_create(hash_algorithm_t hash_algorithm
);