implemented an optional DH public value test
[strongswan.git] / src / libstrongswan / crypto / diffie_hellman.h
1 /**
2 * @file diffie_hellman.h
3 *
4 * @brief Interface of diffie_hellman_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2007 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #ifndef DIFFIE_HELLMAN_H_
25 #define DIFFIE_HELLMAN_H_
26
27 typedef enum diffie_hellman_group_t diffie_hellman_group_t;
28 typedef struct diffie_hellman_t diffie_hellman_t;
29
30 #include <library.h>
31
32 /**
33 * @brief Diffie-Hellman group.
34 *
35 * The modulus (or group) to use for a Diffie-Hellman calculation.
36 *
37 * See IKEv2 RFC 3.3.2 and RFC 3526.
38 *
39 * @ingroup crypto
40 */
41 enum diffie_hellman_group_t {
42 MODP_NONE = 0,
43 MODP_768_BIT = 1,
44 MODP_1024_BIT = 2,
45 MODP_1536_BIT = 5,
46 MODP_2048_BIT = 14,
47 MODP_3072_BIT = 15,
48 MODP_4096_BIT = 16,
49 MODP_6144_BIT = 17,
50 MODP_8192_BIT = 18
51 };
52
53 /**
54 * enum name for diffie_hellman_group_t.
55 */
56 extern enum_name_t *diffie_hellman_group_names;
57
58 /**
59 * @brief Implementation of the Diffie-Hellman algorithm, as in RFC2631.
60 *
61 * @b Constructors:
62 * - diffie_hellman_create()
63 *
64 * @ingroup crypto
65 */
66 struct diffie_hellman_t {
67
68 /**
69 * @brief Returns the shared secret of this diffie hellman exchange.
70 *
71 * Space for returned secret is allocated and must be
72 * freed by the caller.
73 *
74 * @param this calling object
75 * @param secret shared secret will be written into this chunk
76 * @return
77 * - SUCCESS
78 * - FAILED if not both DH values are set
79 */
80 status_t (*get_shared_secret) (diffie_hellman_t *this, chunk_t *secret);
81
82 /**
83 * @brief Sets the public value of partner.
84 *
85 * Chunk gets cloned and can be destroyed afterwards.
86 *
87 * @param this calling object
88 * @param value public value of partner
89 */
90 void (*set_other_public_value) (diffie_hellman_t *this, chunk_t value);
91
92 /**
93 * @brief Gets the public value of partner.
94 *
95 * Space for returned chunk is allocated and must be freed by the caller.
96 *
97 * @param this calling object
98 * @param value public value of partner is stored at this location
99 * @return
100 * - SUCCESS
101 * - FAILED if other public value not set
102 */
103 status_t (*get_other_public_value) (diffie_hellman_t *this, chunk_t *value);
104
105 /**
106 * @brief Gets the own public value to transmit.
107 *
108 * Space for returned chunk is allocated and must be freed by the caller.
109 *
110 * @param this calling object
111 * @param value public value of caller is stored at this location
112 */
113 void (*get_my_public_value) (diffie_hellman_t *this, chunk_t *value);
114
115 /**
116 * @brief Get the DH group used.
117 *
118 * @param this calling object
119 * @return DH group set in construction
120 */
121 diffie_hellman_group_t (*get_dh_group) (diffie_hellman_t *this);
122
123 /**
124 * @brief Destroys an diffie_hellman_t object.
125 *
126 * @param this diffie_hellman_t object to destroy
127 */
128 void (*destroy) (diffie_hellman_t *this);
129 };
130
131 /**
132 * @brief Creates a new diffie_hellman_t object.
133 *
134 * @param group Diffie Hellman group number to use
135 * @return
136 * - diffie_hellman_t object
137 * - NULL if dh group not supported
138 *
139 * @ingroup crypto
140 */
141 diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t group);
142
143 #endif /*DIFFIE_HELLMAN_H_*/
144