]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/crypto/diffie_hellman.h
Added support for DH groups 22, 23 and 24, patch contributed by Joy Latten
[thirdparty/strongswan.git] / src / libstrongswan / crypto / diffie_hellman.h
1 /*
2 * Copyright (C) 2010 Tobias Brunner
3 * Copyright (C) 2005-2007 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
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.
16 */
17
18 /**
19 * @defgroup diffie_hellman diffie_hellman
20 * @{ @ingroup crypto
21 */
22
23 #ifndef DIFFIE_HELLMAN_H_
24 #define DIFFIE_HELLMAN_H_
25
26 typedef enum diffie_hellman_group_t diffie_hellman_group_t;
27 typedef struct diffie_hellman_t diffie_hellman_t;
28 typedef struct diffie_hellman_params_t diffie_hellman_params_t;
29
30 #include <library.h>
31
32 /**
33 * Diffie-Hellman group.
34 *
35 * The modulus (or group) to use for a Diffie-Hellman calculation.
36 * See IKEv2 RFC 3.3.2 and RFC 3526.
37 *
38 * ECP groups are defined in RFC 4753 and RFC 5114.
39 */
40 enum diffie_hellman_group_t {
41 MODP_NONE = 0,
42 MODP_768_BIT = 1,
43 MODP_1024_BIT = 2,
44 MODP_1536_BIT = 5,
45 MODP_2048_BIT = 14,
46 MODP_3072_BIT = 15,
47 MODP_4096_BIT = 16,
48 MODP_6144_BIT = 17,
49 MODP_8192_BIT = 18,
50 ECP_256_BIT = 19,
51 ECP_384_BIT = 20,
52 ECP_521_BIT = 21,
53 MODP_1024_160 = 22,
54 MODP_2048_224 = 23,
55 MODP_2048_256 = 24,
56 ECP_192_BIT = 25,
57 ECP_224_BIT = 26,
58 /** insecure NULL diffie hellman group for testing, in PRIVATE USE */
59 MODP_NULL = 1024,
60 };
61
62 /**
63 * enum name for diffie_hellman_group_t.
64 */
65 extern enum_name_t *diffie_hellman_group_names;
66
67 /**
68 * Implementation of the Diffie-Hellman algorithm, as in RFC2631.
69 */
70 struct diffie_hellman_t {
71
72 /**
73 * Returns the shared secret of this diffie hellman exchange.
74 *
75 * Space for returned secret is allocated and must be
76 * freed by the caller.
77 *
78 * @param secret shared secret will be written into this chunk
79 * @return SUCCESS, FAILED if not both DH values are set
80 */
81 status_t (*get_shared_secret) (diffie_hellman_t *this, chunk_t *secret);
82
83 /**
84 * Sets the public value of partner.
85 *
86 * Chunk gets cloned and can be destroyed afterwards.
87 *
88 * @param value public value of partner
89 */
90 void (*set_other_public_value) (diffie_hellman_t *this, chunk_t value);
91
92 /**
93 * Gets the own public value to transmit.
94 *
95 * Space for returned chunk is allocated and must be freed by the caller.
96 *
97 * @param value public value of caller is stored at this location
98 */
99 void (*get_my_public_value) (diffie_hellman_t *this, chunk_t *value);
100
101 /**
102 * Get the DH group used.
103 *
104 * @return DH group set in construction
105 */
106 diffie_hellman_group_t (*get_dh_group) (diffie_hellman_t *this);
107
108 /**
109 * Destroys an diffie_hellman_t object.
110 */
111 void (*destroy) (diffie_hellman_t *this);
112 };
113
114 /**
115 * Parameters for a specific diffie hellman group.
116 */
117 struct diffie_hellman_params_t {
118
119 /**
120 * The prime of the group
121 */
122 const chunk_t prime;
123
124 /**
125 * Generator of the group
126 */
127 const chunk_t generator;
128
129 /**
130 * Exponent length to use
131 */
132 size_t exp_len;
133
134 /**
135 * Prime order subgroup; for MODP Groups 22-24
136 */
137 const chunk_t subgroup;
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
148 #endif /** DIFFIE_HELLMAN_H_ @}*/