implemented sha2_hasher which supports SHA-256, SHA-384 and SHA-512
[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:
35 * - PRF_HMAC_MD5
36 * - PRF_HMAC_SHA1
37 *
38 * @ingroup prfs
39 */
40 enum pseudo_random_function_t {
41 PRF_UNDEFINED = 1024,
42 /** Implemented via hmac_prf_t. */
43 PRF_HMAC_MD5 = 1,
44 /** Implemented via hmac_prf_t. */
45 PRF_HMAC_SHA1 = 2,
46 PRF_HMAC_TIGER = 3,
47 PRF_AES128_CBC = 4,
48 };
49
50 /**
51 * String mappings for encryption_algorithm_t.
52 */
53 extern mapping_t pseudo_random_function_m[];
54
55
56 typedef struct prf_t prf_t;
57
58 /**
59 * @brief Generic interface for pseudo-random-functions.
60 *
61 * @b Constructors:
62 * - prf_create()
63 * - hmac_prf_create()
64 *
65 * @todo Implement more prf algorithms
66 *
67 * @ingroup prfs
68 */
69 struct prf_t {
70 /**
71 * @brief Generates pseudo random bytes and writes them in the buffer.
72 *
73 * @param this calling object
74 * @param seed a chunk containing the seed for the next bytes
75 * @param[out] buffer pointer where the generated bytes will be written
76 */
77 void (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
78
79 /**
80 * @brief Generates pseudo random bytes and allocate space for them.
81 *
82 * @param this calling object
83 * @param seed a chunk containing the seed for the next bytes
84 * @param[out] chunk chunk which will hold generated bytes
85 */
86 void (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
87
88 /**
89 * @brief Get the block size of this prf_t object.
90 *
91 * @param this calling object
92 * @return block size in bytes
93 */
94 size_t (*get_block_size) (prf_t *this);
95
96 /**
97 * @brief Get the key size of this prf_t object.
98 *
99 * @param this calling object
100 * @return key size in bytes
101 */
102 size_t (*get_key_size) (prf_t *this);
103
104 /**
105 * @brief Set the key for this prf_t object.
106 *
107 * @param this calling object
108 * @param key key to set
109 */
110 void (*set_key) (prf_t *this, chunk_t key);
111
112 /**
113 * @brief Destroys a prf object.
114 *
115 * @param this calling object
116 */
117 void (*destroy) (prf_t *this);
118 };
119
120 /**
121 * @brief Generic constructor for a prf_t oject.
122 *
123 * @param pseudo_random_function Algorithm to use
124 * @return
125 * - prf_t object
126 * - NULL if prf algorithm not supported
127 *
128 * @ingroup prfs
129 */
130 prf_t *prf_create(pseudo_random_function_t pseudo_random_function);
131
132 #endif /*PRF_H_*/