758e7367193dab2aedc808f7b541541e78256085
[strongswan.git] / src / libstrongswan / crypto / prfs / prf.h
1 /**
2 * @file prf.h
3 *
4 * @brief Interface prf_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
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 PRF_H_
25 #define PRF_H_
26
27 #include <types.h>
28
29 typedef enum pseudo_random_function_t pseudo_random_function_t;
30
31 /**
32 * @brief Pseudo random function, as in IKEv2 RFC 3.3.2.
33 *
34 * Currently only the following algorithms are implemented and therefore supported:
35 * - PRF_HMAC_MD5
36 * - PRF_HMAC_SHA1
37 *
38 * @ingroup prfs
39 */
40 enum pseudo_random_function_t {
41 PRF_UNDEFINED = 1024,
42 /**
43 * Implemented in class hmac_prf_t.
44 */
45 PRF_HMAC_MD5 = 1,
46 /**
47 * Implemented in class hmac_prf_t.
48 */
49 PRF_HMAC_SHA1 = 2,
50 PRF_HMAC_TIGER = 3,
51 PRF_AES128_CBC = 4
52 };
53
54 /**
55 * String mappings for encryption_algorithm_t.
56 */
57 extern mapping_t pseudo_random_function_m[];
58
59
60 typedef struct prf_t prf_t;
61
62 /**
63 * @brief Generic interface for pseudo-random-functions.
64 *
65 * @b Constructors:
66 * - prf_create()
67 * - hmac_prf_create()
68 *
69 * @todo Implement more prf algorithms
70 *
71 * @ingroup prfs
72 */
73 struct prf_t {
74 /**
75 * @brief Generates pseudo random bytes and writes them
76 * in the buffer.
77 *
78 * @param this calling object
79 * @param seed a chunk containing the seed for the next bytes
80 * @param[out] buffer pointer where the generated bytes will be written
81 */
82 void (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
83
84 /**
85 * @brief Generates pseudo random bytes and allocate space for them.
86 *
87 * @param this calling object
88 * @param seed a chunk containing the seed for the next bytes
89 * @param[out] chunk chunk which will hold generated bytes
90 */
91 void (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
92
93 /**
94 * @brief Get the block size of this prf_t object.
95 *
96 * @param this calling object
97 * @return block size in bytes
98 */
99 size_t (*get_block_size) (prf_t *this);
100
101 /**
102 * @brief Get the key size of this prf_t object.
103 *
104 * @param this calling object
105 * @return key size in bytes
106 */
107 size_t (*get_key_size) (prf_t *this);
108
109 /**
110 * @brief Set the key for this prf_t object.
111 *
112 * @param this calling object
113 * @param key key to set
114 */
115 void (*set_key) (prf_t *this, chunk_t key);
116
117 /**
118 * @brief Destroys a prf object.
119 *
120 * @param this calling object
121 */
122 void (*destroy) (prf_t *this);
123 };
124
125 /**
126 * @brief Generic constructor for a prf_t oject.
127 *
128 * @param pseudo_random_function Algorithm to use
129 * @return
130 * - prf_t object
131 * - NULL if prf algorithm not supported
132 *
133 * @ingroup prfs
134 */
135 prf_t *prf_create(pseudo_random_function_t pseudo_random_function);
136
137 #endif /*PRF_H_*/