2b6aab46e3f5acd397355cde1f32f0767c3d4d6f
[strongswan.git] / Source / charon / transforms / prfs / prf.h
1 /**
2 * @file prf.h
3 *
4 * @brief Generic interface for pseudo-random-functions
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 <encoding/payloads/transform_substructure.h>
27
28
29 typedef struct prf_t prf_t;
30
31 /**
32 * Object representing a diffie hellman exchange
33 *
34 * @ingroup prfs
35 */
36 struct prf_t {
37 /**
38 * @brief generates pseudo random bytes and writes them
39 * in the buffer
40 *
41 * @param this calling prf
42 * @param seed a chunk containing the seed for the next bytes
43 * @param [out]buffer pointer where the generated bytes will be written
44 * @return
45 * - SUCCESS in any case
46 */
47 status_t (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
48
49 /**
50 * @brief generates pseudo random bytes and allocate space for them
51 *
52 * @param this calling prf
53 * @param seed a chunk containing the seed for the next bytes
54 * @param [out]chunk chunk which will hold generated bytes
55 * @return
56 * - SUCCESS in any case
57 * - OUT_OF_RES if space could not be allocated
58 */
59 status_t (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
60
61 /**
62 * @brief get the block size of this prf
63 *
64 * @param this calling prf
65 * @return block size in bytes
66 */
67 size_t (*get_block_size) (prf_t *this);
68
69 /**
70 * @brief Set the key for this prf
71 *
72 * @param this calling prf
73 * @return block size in bytes
74 */
75 status_t (*set_key) (prf_t *this, chunk_t key);
76
77 /**
78 * @brief Destroys a prf object.
79 *
80 * @param this prf_t object to destroy
81 * @return
82 * SUCCESS in any case
83 */
84 status_t (*destroy) (prf_t *this);
85 };
86
87 /**
88 * Creates a new prf_t object
89 *
90 * @param pseudo_random_function Algorithm to use
91 * @return
92 * - prf_t if successfully
93 * - NULL if out of ressources or prf not supported
94 *
95 * @ingroup prfs
96 */
97 prf_t *prf_create(pseudo_random_function_t pseudo_random_function);
98
99 #endif /*PRF_H_*/