- moved algorithm definitions from payloads to corresponding transforms
[strongswan.git] / Source / charon / transforms / prfs / prf.h
1 /**
2 * @file prf.h
3 *
4 * @brief Interface of 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 draft 3.3.2.
32 */
33 enum pseudo_random_function_t {
34 PRF_UNDEFINED = 1024,
35 PRF_HMAC_MD5 = 1,
36 PRF_HMAC_SHA1 = 2,
37 PRF_HMAC_TIGER = 3,
38 PRF_AES128_CBC = 4
39 };
40
41 /**
42 * string mappings for encryption_algorithm_t
43 */
44 extern mapping_t pseudo_random_function_m[];
45
46
47 typedef struct prf_t prf_t;
48
49 /**
50 * @brief Generic interface for pseudo-random-functions.
51 *
52 * @ingroup prfs
53 */
54 struct prf_t {
55 /**
56 * @brief generates pseudo random bytes and writes them
57 * in the buffer.
58 *
59 * @param this calling prf
60 * @param seed a chunk containing the seed for the next bytes
61 * @param[out] buffer pointer where the generated bytes will be written
62 * @return
63 * - SUCCESS in any case
64 */
65 status_t (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
66
67 /**
68 * @brief generates pseudo random bytes and allocate space for them.
69 *
70 * @param this calling prf
71 * @param seed a chunk containing the seed for the next bytes
72 * @param[out] chunk chunk which will hold generated bytes
73 * @return
74 * - SUCCESS in any case
75 * - OUT_OF_RES if space could not be allocated
76 */
77 status_t (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
78
79 /**
80 * @brief get the block size of this prf.
81 *
82 * @param this calling prf
83 * @return block size in bytes
84 */
85 size_t (*get_block_size) (prf_t *this);
86
87 /**
88 * @brief Set the key for this prf.
89 *
90 * @param this calling prf
91 * @param key key to set
92 * @return
93 * - SUCCESS in any case
94 */
95 status_t (*set_key) (prf_t *this, chunk_t key);
96
97 /**
98 * @brief Destroys a prf object..
99 *
100 * @param this prf_t object to destroy
101 * @return
102 * - SUCCESS in any case
103 */
104 status_t (*destroy) (prf_t *this);
105 };
106
107 /**
108 * @brief Generic constructor for a prf_t.
109 *
110 * @param pseudo_random_function Algorithm to use
111 * @return
112 * - prf_t if successfully
113 * - NULL if out of ressources or prf not supported
114 *
115 * @ingroup prfs
116 */
117 prf_t *prf_create(pseudo_random_function_t pseudo_random_function);
118
119 #endif /*PRF_H_*/