f374b14f8163381c1c03a1cf6ced80a64af26b1a
[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 Destroys a hmac object.
71 *
72 * @param this hmac_t object to destroy
73 * @return
74 * SUCCESS in any case
75 */
76 status_t (*destroy) (hmac_t *this);
77 };
78
79 /**
80 * Creates a new hmac_t object
81 *
82 * @param hash_algorithm hash algorithm to use
83 * @param key A chunk containing the key
84 * @return
85 * - hmac_t if successfully
86 * - NULL if out of ressources or hash not supported
87 */
88 hmac_t *hmac_create(hash_algorithm_t hash_algorithm, chunk_t key);
89
90 #endif /*HMAC_H_*/