14cec6818a37b0ab98618c921f3ce8bd5c7c1695
[strongswan.git] / Source / charon / transforms / hmac.h
1 /**
2 * @file hmac.h
3 *
4 * @brief Implementation of message authentication
5 * using cryptographic hash functions (HMAC). See RFC2104.
6 *
7 */
8
9 /*
10 * Copyright (C) 2005 Jan Hutter, Martin Willi
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #ifndef HMAC_H_
25 #define HMAC_H_
26
27
28 #include "hashers/hasher.h"
29
30
31 /**
32 * Object representing a hmac
33 */
34 typedef struct hmac_s hmac_t;
35
36 struct hmac_s {
37 /**
38 * @brief Generate message authentication code.
39 *
40 * @param this calling hmac
41 * @param data chunk of data to authenticate
42 * @param [out]buffer pointer where the generated bytes will be written
43 * @return
44 * - SUCCESS in any case
45 */
46 status_t (*get_mac) (hmac_t *this, chunk_t data, u_int8_t *buffer);
47
48 /**
49 * @brief Generates message authentication code and
50 * allocate space for them.
51 *
52 * @param this calling hmac
53 * @param data chunk of data to authenticate
54 * @param [out]chunk chunk which will hold generated bytes
55 * @return
56 * - SUCCESS in any case
57 * - OUT_OF_RES if space could not be allocated
58 */
59 status_t (*allocate_mac) (hmac_t *this, chunk_t data, chunk_t *chunk);
60
61 /**
62 * @brief get the block size of this hmac
63 *
64 * @param this calling hmac
65 * @return block size in bytes
66 */
67 size_t (*get_block_size) (hmac_t *this);
68
69 /**
70 * @brief set the key for this hmac
71 *
72 * Any key length is accepted.
73 *
74 * @param this calling hmac
75 * @param key key to set
76 * @return block size in bytes
77 */
78 size_t (*set_key) (hmac_t *this, chunk_t key);
79
80 /**
81 * @brief Destroys a hmac object.
82 *
83 * @param this hmac_t object to destroy
84 * @return
85 * SUCCESS in any case
86 */
87 status_t (*destroy) (hmac_t *this);
88 };
89
90 /**
91 * Creates a new hmac_t object
92 *
93 * @param hash_algorithm hash algorithm to use
94 * @return
95 * - hmac_t if successfully
96 * - NULL if out of ressources or hash not supported
97 */
98 hmac_t *hmac_create(hash_algorithm_t hash_algorithm);
99
100 #endif /*HMAC_H_*/