9e074974cad9eb885e123510e2b3641ed8896f0b
[strongswan.git] / src / libstrongswan / crypto / prf_plus.h
1 /*
2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * $Id$
17 */
18
19 /**
20 * @defgroup prf_plus prf_plus
21 * @{ @ingroup crypto
22 */
23
24 #ifndef PRF_PLUS_H_
25 #define PRF_PLUS_H_
26
27 typedef struct prf_plus_t prf_plus_t;
28
29 #include <crypto/prfs/prf.h>
30
31 /**
32 * Implementation of the prf+ function described in IKEv2 RFC.
33 *
34 * This class implements the prf+ algorithm. Internally it uses a pseudo random
35 * function, which implements the prf_t interface.
36 * See IKEv2 RFC 2.13.
37 */
38 struct prf_plus_t {
39 /**
40 * Get pseudo random bytes.
41 *
42 * Get the next few bytes of the prf+ output. Space
43 * must be allocated by the caller.
44 *
45 * @param length number of bytes to get
46 * @param buffer pointer where the generated bytes will be written
47 */
48 void (*get_bytes) (prf_plus_t *this, size_t length, u_int8_t *buffer);
49
50 /**
51 * Allocate pseudo random bytes.
52 *
53 * Get the next few bytes of the prf+ output. This function
54 * will allocate the required space.
55 *
56 * @param length number of bytes to get
57 * @param chunk chunk which will hold generated bytes
58 */
59 void (*allocate_bytes) (prf_plus_t *this, size_t length, chunk_t *chunk);
60
61 /**
62 * Destroys a prf_plus_t object.
63 */
64 void (*destroy) (prf_plus_t *this);
65 };
66
67 /**
68 * Creates a new prf_plus_t object.
69 *
70 * Seed will be cloned. prf will
71 * not be cloned, must be destroyed outside after
72 * prf_plus_t usage.
73 *
74 * @param prf prf object to use
75 * @param seed input seed for prf
76 * @return prf_plus_t object
77 */
78 prf_plus_t *prf_plus_create(prf_t *prf, chunk_t seed);
79
80 #endif /*PRF_PLUS_H_ @} */