Add a return value to hasher_t.get_hash()
[strongswan.git] / src / libstrongswan / crypto / mac.h
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2005-2008 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup mac mac
20 * @{ @ingroup crypto
21 */
22
23 #ifndef MAC_H_
24 #define MAC_H_
25
26 typedef struct mac_t mac_t;
27
28 #include <library.h>
29
30 /**
31 * Generic interface for message authentication codes.
32 *
33 * Classes implementing this interface can use the PRF and signer wrappers.
34 */
35 struct mac_t {
36
37 /**
38 * Generate message authentication code.
39 *
40 * If out is NULL, no result is given back. A next call will
41 * append the data to already supplied data. If out is not NULL,
42 * the mac of all apended data is calculated, written to out and the
43 * internal state is reset.
44 *
45 * @param data chunk of data to authenticate
46 * @param out pointer where the generated bytes will be written
47 * @return TRUE if mac generated successfully
48 */
49 __attribute__((warn_unused_result))
50 bool (*get_mac)(mac_t *this, chunk_t data, u_int8_t *out);
51
52 /**
53 * Get the size of the resulting MAC.
54 *
55 * @return block size in bytes
56 */
57 size_t (*get_mac_size)(mac_t *this);
58
59 /**
60 * Set the key to be used for the MAC.
61 *
62 * Any key length must be accepted.
63 *
64 * @param key key to set
65 * @return TRUE if key set successfully
66 */
67 __attribute__((warn_unused_result))
68 bool (*set_key) (mac_t *this, chunk_t key);
69
70 /**
71 * Destroys a mac_t object.
72 */
73 void (*destroy) (mac_t *this);
74 };
75
76 #endif /** MAC_H_ @}*/