updated prf identifiers
[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 /** RFC2104 */
39 PRF_HMAC_MD5 = 1,
40 /** RFC2104 */
41 PRF_HMAC_SHA1 = 2,
42 /** RFC2104 */
43 PRF_HMAC_TIGER = 3,
44 /** RFC4434 */
45 PRF_AES128_XCBC = 4,
46 /** RFC4868 */
47 PRF_HMAC_SHA2_256 = 5,
48 /** RFC4868. */
49 PRF_HMAC_SHA2_384 = 6,
50 /** RFC4868 */
51 PRF_HMAC_SHA2_512 = 7,
52 /** RFC4615 */
53 PRF_AES128_CMAC = 8,
54 /** FIPS 186-2-change1 */
55 PRF_FIPS_SHA1_160 = 1025,
56 /** FIPS 186-2-change1, uses fixed output size of 160bit */
57 PRF_FIPS_DES = 1026,
58 /**
59 * Keyed hash algorithm using SHA1, used in EAP-AKA:
60 * This PRF uses SHA1, but XORs the key into the IV. No "Final()" operation
61 * is applied to the SHA1 state. */
62 PRF_KEYED_SHA1 = 1027,
63 };
64
65 /**
66 * enum name for encryption_algorithm_t.
67 */
68 extern enum_name_t *pseudo_random_function_names;
69
70 /**
71 * Generic interface for pseudo-random-functions.
72 */
73 struct prf_t {
74 /**
75 * Generates pseudo random bytes and writes them in the buffer.
76 *
77 * @param seed a chunk containing the seed for the next bytes
78 * @param buffer pointer where the generated bytes will be written
79 */
80 void (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
81
82 /**
83 * Generates pseudo random bytes and allocate space for them.
84 *
85 * @param seed a chunk containing the seed for the next bytes
86 * @param chunk chunk which will hold generated bytes
87 */
88 void (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
89
90 /**
91 * Get the block size of this prf_t object.
92 *
93 * @return block size in bytes
94 */
95 size_t (*get_block_size) (prf_t *this);
96
97 /**
98 * Get the key size of this prf_t object.
99 *
100 * This is a suggestion only, all implemented PRFs accept variable key
101 * length.
102 *
103 * @return key size in bytes
104 */
105 size_t (*get_key_size) (prf_t *this);
106
107 /**
108 * Set the key for this prf_t object.
109 *
110 * @param key key to set
111 */
112 void (*set_key) (prf_t *this, chunk_t key);
113
114 /**
115 * Destroys a prf object.
116 */
117 void (*destroy) (prf_t *this);
118 };
119
120 #endif /** PRF_H_ @}*/