]> git.ipfire.org Git - thirdparty/strongswan.git/blame - programs/charon/lib/crypto/hmac.h
- import of strongswan-2.7.0
[thirdparty/strongswan.git] / programs / charon / lib / crypto / hmac.h
CommitLineData
781fadcc
MW
1/**
2 * @file hmac.h
3 *
5796aa16 4 * @brief Interface of hmac_t.
781fadcc
MW
5 */
6
7/*
8 * Copyright (C) 2005 Jan Hutter, Martin Willi
9 * Hochschule fuer Technik Rapperswil
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 */
21
22#ifndef HMAC_H_
23#define HMAC_H_
24
68621281 25#include <crypto/hashers/hasher.h>
5796aa16
MW
26#include <definitions.h>
27
28
29typedef struct hmac_t hmac_t;
781fadcc 30
781fadcc 31/**
7a09fcea 32 * @brief Message authentication using hash functions.
5796aa16
MW
33 *
34 * This class implements the message authenticaion algorithm
35 * described in RFC2104. It uses a hash function, wich must
36 * be implemented as a hasher_t class.
37 *
1e7d52a6
JH
38 * See http://www.faqs.org/rfcs/rfc2104.html for RFC.
39 * @see
40 * - hasher_t
41 * - prf_hmac_t
42 *
43 * @b Constructors:
44 * - hmac_create()
5796aa16
MW
45 *
46 * @ingroup transforms
781fadcc 47 */
5796aa16 48struct hmac_t {
781fadcc
MW
49 /**
50 * @brief Generate message authentication code.
51 *
1318dd4e 52 * If buffer is NULL, no result is given back. A next call will
1e7d52a6 53 * append the data to already supplied data. If buffer is not NULL,
1318dd4e 54 * the mac of all apended data is calculated, returned and the
1e7d52a6 55 * state of the hmac_t is reseted.
1318dd4e 56 *
1e7d52a6 57 * @param this calling object
781fadcc 58 * @param data chunk of data to authenticate
8277be60 59 * @param[out] buffer pointer where the generated bytes will be written
781fadcc 60 */
d048df5c 61 void (*get_mac) (hmac_t *this, chunk_t data, u_int8_t *buffer);
781fadcc
MW
62
63 /**
64 * @brief Generates message authentication code and
65 * allocate space for them.
66 *
1318dd4e
MW
67 * If chunk is NULL, no result is given back. A next call will
68 * append the data to already supplied. If chunk is not NULL,
69 * the mac of all apended data is calculated, returned and the
70 * state of the hmac_t reset;
71 *
1e7d52a6 72 * @param this calling object
781fadcc 73 * @param data chunk of data to authenticate
8277be60 74 * @param[out] chunk chunk which will hold generated bytes
781fadcc 75 */
d048df5c 76 void (*allocate_mac) (hmac_t *this, chunk_t data, chunk_t *chunk);
781fadcc
MW
77
78 /**
1e7d52a6 79 * @brief Get the block size of this hmac_t object.
781fadcc 80 *
1e7d52a6 81 * @param this calling object
781fadcc
MW
82 * @return block size in bytes
83 */
a217b51d
MW
84 size_t (*get_block_size) (hmac_t *this);
85
86 /**
1e7d52a6 87 * @brief Set the key for this hmac_t object.
a217b51d
MW
88 *
89 * Any key length is accepted.
90 *
1e7d52a6 91 * @param this calling object
a217b51d 92 * @param key key to set
a217b51d 93 */
d048df5c 94 void (*set_key) (hmac_t *this, chunk_t key);
781fadcc
MW
95
96 /**
1e7d52a6 97 * @brief Destroys a hmac_t object.
781fadcc 98 *
1e7d52a6 99 * @param this calling object
781fadcc 100 */
d048df5c 101 void (*destroy) (hmac_t *this);
781fadcc
MW
102};
103
104/**
5796aa16
MW
105 * @brief Creates a new hmac_t object.
106 *
1e7d52a6 107 * Creates a hasher_t object internally.
781fadcc
MW
108 *
109 * @param hash_algorithm hash algorithm to use
781fadcc 110 * @return
1e7d52a6
JH
111 * - hmac_t object
112 * - NULL if hash algorithm is not supported
5796aa16
MW
113 *
114 * @ingroup transforms
781fadcc 115 */
a217b51d 116hmac_t *hmac_create(hash_algorithm_t hash_algorithm);
781fadcc
MW
117
118#endif /*HMAC_H_*/