04ed9eaeb6acf0d528df14b680260cf8fbe8c206
[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 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 ECP_192_BIT = 25,
54 ECP_224_BIT = 26,
55 /** insecure NULL diffie hellman group for testing, in PRIVATE USE */
56 MODP_NULL = 1024,
57 };
58
59 /**
60 * enum name for diffie_hellman_group_t.
61 */
62 extern enum_name_t *diffie_hellman_group_names;
63
64 /**
65 * Implementation of the Diffie-Hellman algorithm, as in RFC2631.
66 */
67 struct diffie_hellman_t {
68
69 /**
70 * Returns the shared secret of this diffie hellman exchange.
71 *
72 * Space for returned secret is allocated and must be
73 * freed by the caller.
74 *
75 * @param secret shared secret will be written into this chunk
76 * @return SUCCESS, FAILED if not both DH values are set
77 */
78 status_t (*get_shared_secret) (diffie_hellman_t *this, chunk_t *secret);
79
80 /**
81 * Sets the public value of partner.
82 *
83 * Chunk gets cloned and can be destroyed afterwards.
84 *
85 * @param value public value of partner
86 */
87 void (*set_other_public_value) (diffie_hellman_t *this, chunk_t value);
88
89 /**
90 * Gets the own public value to transmit.
91 *
92 * Space for returned chunk is allocated and must be freed by the caller.
93 *
94 * @param value public value of caller is stored at this location
95 */
96 void (*get_my_public_value) (diffie_hellman_t *this, chunk_t *value);
97
98 /**
99 * Get the DH group used.
100 *
101 * @return DH group set in construction
102 */
103 diffie_hellman_group_t (*get_dh_group) (diffie_hellman_t *this);
104
105 /**
106 * Destroys an diffie_hellman_t object.
107 */
108 void (*destroy) (diffie_hellman_t *this);
109 };
110
111 #endif /*DIFFIE_HELLMAN_H_ @} */