b412ed588d6dc3a22dc29ac71b145d52c780ff91
[strongswan.git] / src / libstrongswan / crypto / prfs / prf.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 prf
21 * @{ @ingroup crypto
22 */
23
24 #ifndef PRF_H_
25 #define PRF_H_
26
27 typedef enum pseudo_random_function_t pseudo_random_function_t;
28 typedef struct prf_t prf_t;
29
30 #include <library.h>
31
32 /**
33 * Pseudo random function, as in IKEv2 RFC 3.3.2.
34 *
35 * PRF algorithms not defined in IKEv2 are allocated in "private use"
36 * space.
37 */
38 enum pseudo_random_function_t {
39 PRF_UNDEFINED = 1024,
40 /** Implemented via hmac_prf_t. */
41 PRF_HMAC_MD5 = 1,
42 /** Implemented via hmac_prf_t. */
43 PRF_HMAC_SHA1 = 2,
44 PRF_HMAC_TIGER = 3,
45 PRF_AES128_XCBC = 4,
46 /** Implemented via hmac_prf_t. */
47 PRF_HMAC_SHA2_256 = 5,
48 /** Implemented via hmac_prf_t. */
49 PRF_HMAC_SHA2_384 = 6,
50 /** Implemented via hmac_prf_t. */
51 PRF_HMAC_SHA2_512 = 7,
52 /** Implemented via fips_prf_t, other output sizes would be possible */
53 PRF_FIPS_SHA1_160 = 1025,
54 /** Could be implemented via fips_prf_t, uses fixed output size of 160bit */
55 PRF_FIPS_DES = 1026,
56 /**
57 * Keyed hash algorithm using SHA1, used in EAP-AKA:
58 * This PRF uses SHA1, but XORs the key into the IV. No "Final()" operation
59 * is applied to the SHA1 state. */
60 PRF_KEYED_SHA1 = 1027,
61 };
62
63 /**
64 * enum name for encryption_algorithm_t.
65 */
66 extern enum_name_t *pseudo_random_function_names;
67
68 /**
69 * Generic interface for pseudo-random-functions.
70 */
71 struct prf_t {
72 /**
73 * Generates pseudo random bytes and writes them in the buffer.
74 *
75 * @param seed a chunk containing the seed for the next bytes
76 * @param buffer pointer where the generated bytes will be written
77 */
78 void (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
79
80 /**
81 * Generates pseudo random bytes and allocate space for them.
82 *
83 * @param seed a chunk containing the seed for the next bytes
84 * @param chunk chunk which will hold generated bytes
85 */
86 void (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
87
88 /**
89 * Get the block size of this prf_t object.
90 *
91 * @return block size in bytes
92 */
93 size_t (*get_block_size) (prf_t *this);
94
95 /**
96 * Get the key size of this prf_t object.
97 *
98 * This is a suggestion only, all implemented PRFs accept variable key
99 * length.
100 *
101 * @return key size in bytes
102 */
103 size_t (*get_key_size) (prf_t *this);
104
105 /**
106 * Set the key for this prf_t object.
107 *
108 * @param key key to set
109 */
110 void (*set_key) (prf_t *this, chunk_t key);
111
112 /**
113 * Destroys a prf object.
114 */
115 void (*destroy) (prf_t *this);
116 };
117
118 #endif /*PRF_H_ @} */