]> git.ipfire.org Git - people/ms/strongswan.git/blob - Source/lib/crypto/prfs/prf.h
- renamed get_block_size of hasher
[people/ms/strongswan.git] / Source / lib / crypto / prfs / prf.h
1 /**
2 * @file prf.h
3 *
4 * @brief Interface prf_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef PRF_H_
24 #define PRF_H_
25
26 #include <types.h>
27
28 typedef enum pseudo_random_function_t pseudo_random_function_t;
29
30 /**
31 * @brief Pseudo random function, as in IKEv2 RFC 3.3.2.
32 *
33 * Currently only the following algorithms are implemented and therefore supported:
34 * - PRF_HMAC_MD5
35 * - PRF_HMAC_SHA1
36 *
37 * @ingroup prfs
38 */
39 enum pseudo_random_function_t {
40 PRF_UNDEFINED = 1024,
41 /**
42 * Implemented in class hmac_prf_t.
43 */
44 PRF_HMAC_MD5 = 1,
45 /**
46 * Implemented in class hmac_prf_t.
47 */
48 PRF_HMAC_SHA1 = 2,
49 PRF_HMAC_TIGER = 3,
50 PRF_AES128_CBC = 4
51 };
52
53 /**
54 * String mappings for encryption_algorithm_t.
55 */
56 extern mapping_t pseudo_random_function_m[];
57
58
59 typedef struct prf_t prf_t;
60
61 /**
62 * @brief Generic interface for pseudo-random-functions.
63 *
64 * @b Constructors:
65 * - prf_create()
66 * - hmac_prf_create()
67 *
68 * @todo Implement more prf algorithms
69 *
70 * @ingroup prfs
71 */
72 struct prf_t {
73 /**
74 * @brief Generates pseudo random bytes and writes them
75 * in the buffer.
76 *
77 * @param this calling object
78 * @param seed a chunk containing the seed for the next bytes
79 * @param[out] buffer pointer where the generated bytes will be written
80 */
81 void (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
82
83 /**
84 * @brief Generates pseudo random bytes and allocate space for them.
85 *
86 * @param this calling object
87 * @param seed a chunk containing the seed for the next bytes
88 * @param[out] chunk chunk which will hold generated bytes
89 */
90 void (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
91
92 /**
93 * @brief Get the block size of this prf_t object.
94 *
95 * @param this calling object
96 * @return block size in bytes
97 */
98 size_t (*get_block_size) (prf_t *this);
99
100 /**
101 * @brief Get the key size of this prf_t object.
102 *
103 * @param this calling object
104 * @return key size in bytes
105 */
106 size_t (*get_key_size) (prf_t *this);
107
108 /**
109 * @brief Set the key for this prf_t object.
110 *
111 * @param this calling object
112 * @param key key to set
113 */
114 void (*set_key) (prf_t *this, chunk_t key);
115
116 /**
117 * @brief Destroys a prf object.
118 *
119 * @param this calling object
120 */
121 void (*destroy) (prf_t *this);
122 };
123
124 /**
125 * @brief Generic constructor for a prf_t oject.
126 *
127 * @param pseudo_random_function Algorithm to use
128 * @return
129 * - prf_t object
130 * - NULL if prf algorithm not supported
131 *
132 * @ingroup prfs
133 */
134 prf_t *prf_create(pseudo_random_function_t pseudo_random_function);
135
136 #endif /*PRF_H_*/