fixed typo
[strongswan.git] / src / libstrongswan / crypto / hmac.h
1 /**
2 * @file hmac.h
3 *
4 * @brief Interface of hmac_t.
5 */
6
7 /*
8 * Copyright (C) 2005-2006 Martin Willi
9 * Copyright (C) 2005 Jan Hutter
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 HMAC_H_
24 #define HMAC_H_
25
26 typedef struct hmac_t hmac_t;
27
28 #include <crypto/hashers/hasher.h>
29
30 /**
31 * @brief Message authentication using hash functions.
32 *
33 * This class implements the message authenticaion algorithm
34 * described in RFC2104. It uses a hash function, wich must
35 * be implemented as a hasher_t class.
36 *
37 * See http://www.faqs.org/rfcs/rfc2104.html for RFC.
38 * @see
39 * - hasher_t
40 * - prf_hmac_t
41 *
42 * @b Constructors:
43 * - hmac_create()
44 *
45 * @ingroup transforms
46 */
47 struct hmac_t {
48 /**
49 * @brief Generate message authentication code.
50 *
51 * If buffer is NULL, no result is given back. A next call will
52 * append the data to already supplied data. If buffer is not NULL,
53 * the mac of all apended data is calculated, returned and the
54 * state of the hmac_t is reseted.
55 *
56 * @param this calling object
57 * @param data chunk of data to authenticate
58 * @param[out] buffer pointer where the generated bytes will be written
59 */
60 void (*get_mac) (hmac_t *this, chunk_t data, u_int8_t *buffer);
61
62 /**
63 * @brief Generates message authentication code and
64 * allocate space for them.
65 *
66 * If chunk is NULL, no result is given back. A next call will
67 * append the data to already supplied. If chunk is not NULL,
68 * the mac of all apended data is calculated, returned and the
69 * state of the hmac_t reset;
70 *
71 * @param this calling object
72 * @param data chunk of data to authenticate
73 * @param[out] chunk chunk which will hold generated bytes
74 */
75 void (*allocate_mac) (hmac_t *this, chunk_t data, chunk_t *chunk);
76
77 /**
78 * @brief Get the block size of this hmac_t object.
79 *
80 * @param this calling object
81 * @return block size in bytes
82 */
83 size_t (*get_block_size) (hmac_t *this);
84
85 /**
86 * @brief Set the key for this hmac_t object.
87 *
88 * Any key length is accepted.
89 *
90 * @param this calling object
91 * @param key key to set
92 */
93 void (*set_key) (hmac_t *this, chunk_t key);
94
95 /**
96 * @brief Destroys a hmac_t object.
97 *
98 * @param this calling object
99 */
100 void (*destroy) (hmac_t *this);
101 };
102
103 /**
104 * @brief Creates a new hmac_t object.
105 *
106 * Creates a hasher_t object internally.
107 *
108 * @param hash_algorithm hash algorithm to use
109 * @return
110 * - hmac_t object
111 * - NULL if hash algorithm is not supported
112 *
113 * @ingroup transforms
114 */
115 hmac_t *hmac_create(hash_algorithm_t hash_algorithm);
116
117 #endif /*HMAC_H_*/