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