added ECDH with OpenSSL (see RFC 4753)
[strongswan.git] / src / libstrongswan / crypto / diffie_hellman.h
1 /*
2 * Copyright (C) 2005-2007 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 * $Id$
17 */
18
19 /**
20 * @defgroup diffie_hellman diffie_hellman
21 * @{ @ingroup crypto
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 * 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.
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
54 };
55
56 /**
57 * enum name for diffie_hellman_group_t.
58 */
59 extern enum_name_t *diffie_hellman_group_names;
60
61 /**
62 * Implementation of the Diffie-Hellman algorithm, as in RFC2631.
63 */
64 struct diffie_hellman_t {
65
66 /**
67 * Returns the shared secret of this diffie hellman exchange.
68 *
69 * Space for returned secret is allocated and must be
70 * freed by the caller.
71 *
72 * @param secret shared secret will be written into this chunk
73 * @return SUCCESS, FAILED if not both DH values are set
74 */
75 status_t (*get_shared_secret) (diffie_hellman_t *this, chunk_t *secret);
76
77 /**
78 * Sets the public value of partner.
79 *
80 * Chunk gets cloned and can be destroyed afterwards.
81 *
82 * @param value public value of partner
83 */
84 void (*set_other_public_value) (diffie_hellman_t *this, chunk_t value);
85
86 /**
87 * Gets the public value of partner.
88 *
89 * Space for returned chunk is allocated and must be freed by the caller.
90 *
91 * @param value public value of partner is stored at this location
92 * @return SUCCESS, FAILED if other public value not set
93 */
94 status_t (*get_other_public_value) (diffie_hellman_t *this, chunk_t *value);
95
96 /**
97 * Gets the own public value to transmit.
98 *
99 * Space for returned chunk is allocated and must be freed by the caller.
100 *
101 * @param value public value of caller is stored at this location
102 */
103 void (*get_my_public_value) (diffie_hellman_t *this, chunk_t *value);
104
105 /**
106 * Get the DH group used.
107 *
108 * @return DH group set in construction
109 */
110 diffie_hellman_group_t (*get_dh_group) (diffie_hellman_t *this);
111
112 /**
113 * Destroys an diffie_hellman_t object.
114 */
115 void (*destroy) (diffie_hellman_t *this);
116 };
117
118 #endif /*DIFFIE_HELLMAN_H_ @} */