4 * @brief Interface of hmac_t.
8 * Copyright (C) 2005 Jan Hutter, Martin Willi
9 * Hochschule fuer Technik Rapperswil
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 #include <crypto/hashers/hasher.h>
26 #include <definitions.h>
29 typedef struct hmac_t hmac_t
;
32 * @brief Message authentication using hash functions.
34 * This class implements the message authenticaion algorithm
35 * described in RFC2104. It uses a hash function, wich must
36 * be implemented as a hasher_t class.
38 * See http://www.faqs.org/rfcs/rfc2104.html for RFC.
50 * @brief Generate message authentication code.
52 * If buffer is NULL, no result is given back. A next call will
53 * append the data to already supplied data. If buffer is not NULL,
54 * the mac of all apended data is calculated, returned and the
55 * state of the hmac_t is reseted.
57 * @param this calling object
58 * @param data chunk of data to authenticate
59 * @param[out] buffer pointer where the generated bytes will be written
61 void (*get_mac
) (hmac_t
*this, chunk_t data
, u_int8_t
*buffer
);
64 * @brief Generates message authentication code and
65 * allocate space for them.
67 * If chunk is NULL, no result is given back. A next call will
68 * append the data to already supplied. If chunk is not NULL,
69 * the mac of all apended data is calculated, returned and the
70 * state of the hmac_t reset;
72 * @param this calling object
73 * @param data chunk of data to authenticate
74 * @param[out] chunk chunk which will hold generated bytes
76 void (*allocate_mac
) (hmac_t
*this, chunk_t data
, chunk_t
*chunk
);
79 * @brief Get the block size of this hmac_t object.
81 * @param this calling object
82 * @return block size in bytes
84 size_t (*get_block_size
) (hmac_t
*this);
87 * @brief Set the key for this hmac_t object.
89 * Any key length is accepted.
91 * @param this calling object
92 * @param key key to set
94 void (*set_key
) (hmac_t
*this, chunk_t key
);
97 * @brief Destroys a hmac_t object.
99 * @param this calling object
101 void (*destroy
) (hmac_t
*this);
105 * @brief Creates a new hmac_t object.
107 * Creates a hasher_t object internally.
109 * @param hash_algorithm hash algorithm to use
112 * - NULL if hash algorithm is not supported
114 * @ingroup transforms
116 hmac_t
*hmac_create(hash_algorithm_t hash_algorithm
);