]>
Commit | Line | Data |
---|---|---|
99400f97 | 1 | /* |
908d5717 | 2 | * Copyright (C) 2010 Tobias Brunner |
c96aefe2 | 3 | * Copyright (C) 2005-2007 Martin Willi |
c71d53ba | 4 | * Copyright (C) 2005 Jan Hutter |
99400f97 JH |
5 | * Hochschule fuer Technik Rapperswil |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2 of the License, or (at your | |
10 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | * for more details. | |
552cc11b | 16 | */ |
7daf5226 | 17 | |
552cc11b MW |
18 | /** |
19 | * @defgroup diffie_hellman diffie_hellman | |
20 | * @{ @ingroup crypto | |
99400f97 JH |
21 | */ |
22 | ||
23 | #ifndef DIFFIE_HELLMAN_H_ | |
24 | #define DIFFIE_HELLMAN_H_ | |
25 | ||
8277be60 | 26 | typedef enum diffie_hellman_group_t diffie_hellman_group_t; |
382b4817 | 27 | typedef struct diffie_hellman_t diffie_hellman_t; |
908d5717 | 28 | typedef struct diffie_hellman_params_t diffie_hellman_params_t; |
8277be60 | 29 | |
db7ef624 | 30 | #include <library.h> |
382b4817 MW |
31 | |
32 | /** | |
552cc11b | 33 | * Diffie-Hellman group. |
382b4817 | 34 | * |
8277be60 | 35 | * The modulus (or group) to use for a Diffie-Hellman calculation. |
8a491129 | 36 | * See IKEv2 RFC 3.3.2 and RFC 3526. |
7daf5226 | 37 | * |
346e9c57 | 38 | * ECP groups are defined in RFC 4753 and RFC 5114. |
8277be60 MW |
39 | */ |
40 | enum diffie_hellman_group_t { | |
0caf2b93 AS |
41 | MODP_NONE = 0, |
42 | MODP_768_BIT = 1, | |
43 | MODP_1024_BIT = 2, | |
44 | MODP_1536_BIT = 5, | |
8277be60 MW |
45 | MODP_2048_BIT = 14, |
46 | MODP_3072_BIT = 15, | |
47 | MODP_4096_BIT = 16, | |
48 | MODP_6144_BIT = 17, | |
fc1a31d5 | 49 | MODP_8192_BIT = 18, |
0caf2b93 AS |
50 | ECP_256_BIT = 19, |
51 | ECP_384_BIT = 20, | |
52 | ECP_521_BIT = 21, | |
4590260b MW |
53 | MODP_1024_160 = 22, |
54 | MODP_2048_224 = 23, | |
55 | MODP_2048_256 = 24, | |
0caf2b93 AS |
56 | ECP_192_BIT = 25, |
57 | ECP_224_BIT = 26, | |
a20abb81 MW |
58 | /** insecure NULL diffie hellman group for testing, in PRIVATE USE */ |
59 | MODP_NULL = 1024, | |
8277be60 MW |
60 | }; |
61 | ||
60356f33 MW |
62 | /** |
63 | * enum name for diffie_hellman_group_t. | |
8277be60 | 64 | */ |
60356f33 | 65 | extern enum_name_t *diffie_hellman_group_names; |
8277be60 | 66 | |
99400f97 | 67 | /** |
552cc11b | 68 | * Implementation of the Diffie-Hellman algorithm, as in RFC2631. |
99400f97 | 69 | */ |
5796aa16 | 70 | struct diffie_hellman_t { |
7daf5226 | 71 | |
99400f97 | 72 | /** |
552cc11b | 73 | * Returns the shared secret of this diffie hellman exchange. |
7daf5226 MW |
74 | * |
75 | * Space for returned secret is allocated and must be | |
8277be60 | 76 | * freed by the caller. |
7daf5226 | 77 | * |
908d5717 TB |
78 | * @param secret shared secret will be written into this chunk |
79 | * @return SUCCESS, FAILED if not both DH values are set | |
99400f97 JH |
80 | */ |
81 | status_t (*get_shared_secret) (diffie_hellman_t *this, chunk_t *secret); | |
7daf5226 | 82 | |
99400f97 | 83 | /** |
552cc11b | 84 | * Sets the public value of partner. |
7daf5226 | 85 | * |
c96aefe2 | 86 | * Chunk gets cloned and can be destroyed afterwards. |
7daf5226 | 87 | * |
908d5717 | 88 | * @param value public value of partner |
99400f97 | 89 | */ |
c96aefe2 | 90 | void (*set_other_public_value) (diffie_hellman_t *this, chunk_t value); |
7daf5226 | 91 | |
99400f97 | 92 | /** |
552cc11b | 93 | * Gets the own public value to transmit. |
7daf5226 | 94 | * |
c96aefe2 | 95 | * Space for returned chunk is allocated and must be freed by the caller. |
7daf5226 | 96 | * |
c96aefe2 | 97 | * @param value public value of caller is stored at this location |
99400f97 | 98 | */ |
c96aefe2 | 99 | void (*get_my_public_value) (diffie_hellman_t *this, chunk_t *value); |
7daf5226 | 100 | |
ce461bbd | 101 | /** |
552cc11b | 102 | * Get the DH group used. |
7daf5226 | 103 | * |
c96aefe2 | 104 | * @return DH group set in construction |
ce461bbd MW |
105 | */ |
106 | diffie_hellman_group_t (*get_dh_group) (diffie_hellman_t *this); | |
99400f97 JH |
107 | |
108 | /** | |
552cc11b | 109 | * Destroys an diffie_hellman_t object. |
99400f97 | 110 | */ |
d048df5c | 111 | void (*destroy) (diffie_hellman_t *this); |
99400f97 JH |
112 | }; |
113 | ||
908d5717 TB |
114 | /** |
115 | * Parameters for a specific diffie hellman group. | |
116 | */ | |
117 | struct diffie_hellman_params_t { | |
908d5717 TB |
118 | |
119 | /** | |
b34b93db | 120 | * The prime of the group |
908d5717 | 121 | */ |
b34b93db | 122 | const chunk_t prime; |
908d5717 TB |
123 | |
124 | /** | |
b34b93db | 125 | * Generator of the group |
908d5717 | 126 | */ |
b34b93db | 127 | const chunk_t generator; |
908d5717 TB |
128 | |
129 | /** | |
b34b93db | 130 | * Exponent length to use |
908d5717 TB |
131 | */ |
132 | size_t exp_len; | |
4590260b MW |
133 | |
134 | /** | |
135 | * Prime order subgroup; for MODP Groups 22-24 | |
136 | */ | |
137 | const chunk_t subgroup; | |
908d5717 TB |
138 | }; |
139 | ||
140 | /** | |
141 | * Get the parameters associated with the specified diffie hellman group. | |
142 | * | |
143 | * @param group DH group | |
144 | * @return The parameters or NULL, if the group is not supported | |
145 | */ | |
146 | diffie_hellman_params_t *diffie_hellman_get_params(diffie_hellman_group_t group); | |
147 | ||
1490ff4d | 148 | #endif /** DIFFIE_HELLMAN_H_ @}*/ |