5f266e133e9a198ce9fe664523bdf6cedd300157
[strongswan.git] / src / libstrongswan / plugins / hmac / hmac.h
1 /*
2 * Copyright (C) 2005-2008 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup hmac hmac
19 * @{ @ingroup hmac_p
20 */
21
22 #ifndef HMAC_H_
23 #define HMAC_H_
24
25 typedef struct hmac_t hmac_t;
26
27 #include <crypto/hashers/hasher.h>
28
29 /**
30 * Message authentication using hash functions.
31 *
32 * This class implements the message authenticaion algorithm
33 * described in RFC2104. It uses a hash function, wich must
34 * be implemented as a hasher_t class.
35 */
36 struct hmac_t {
37 /**
38 * Generate message authentication code.
39 *
40 * If buffer is NULL, no result is given back. A next call will
41 * append the data to already supplied data. If buffer is not NULL,
42 * the mac of all apended data is calculated, returned and the
43 * state of the hmac_t is reseted.
44 *
45 * @param data chunk of data to authenticate
46 * @param buffer pointer where the generated bytes will be written
47 */
48 void (*get_mac) (hmac_t *this, chunk_t data, u_int8_t *buffer);
49
50 /**
51 * Generates message authentication code and allocate space for them.
52 *
53 * If chunk is NULL, no result is given back. A next call will
54 * append the data to already supplied. If chunk is not NULL,
55 * the mac of all apended data is calculated, returned and the
56 * state of the hmac_t reset;
57 *
58 * @param data chunk of data to authenticate
59 * @param chunk chunk which will hold generated bytes
60 */
61 void (*allocate_mac) (hmac_t *this, chunk_t data, chunk_t *chunk);
62
63 /**
64 * Get the block size of this hmac_t object.
65 *
66 * @return block size in bytes
67 */
68 size_t (*get_block_size) (hmac_t *this);
69
70 /**
71 * Set the key for this hmac_t object.
72 *
73 * Any key length is accepted.
74 *
75 * @param key key to set
76 */
77 void (*set_key) (hmac_t *this, chunk_t key);
78
79 /**
80 * Destroys a hmac_t object.
81 */
82 void (*destroy) (hmac_t *this);
83 };
84
85 /**
86 * Creates a new hmac_t object.
87 *
88 * @param hash_algorithm hash algorithm to use
89 * @return hmac_t object, NULL if not supported
90 */
91 hmac_t *hmac_create(hash_algorithm_t hash_algorithm);
92
93 #endif /*HMAC_H_ @}*/