ab1672d327cbbaa3ffb15d30d74826e110427fe2
[strongswan.git] / Source / charon / transforms / diffie_hellman.h
1 /**
2 * @file diffie_hellman.h
3 *
4 * @brief Class to represent a diffie hellman exchange.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef DIFFIE_HELLMAN_H_
24 #define DIFFIE_HELLMAN_H_
25
26 #include <types.h>
27 #include <encoding/payloads/transform_substructure.h>
28
29 typedef struct diffie_hellman_t diffie_hellman_t;
30
31 /**
32 * Object representing a diffie hellman exchange
33 *
34 */
35 struct diffie_hellman_t {
36
37 /**
38 * @brief Returns the shared secret of this diffie hellman exchange
39 *
40 * @warning Space for returned secret is allocated and has to get freed by the caller
41 *
42 * @param this calling diffie_hellman_t object
43 * @param[out] secret shared secret will be written into this chunk
44 * @return
45 * - SUCCESS
46 * - FAILED if not both DH values are set
47 * - OUT_OF_RES if out of ressources
48 */
49 status_t (*get_shared_secret) (diffie_hellman_t *this, chunk_t *secret);
50
51 /**
52 * @brief Sets the public value of partner
53 *
54 * @warning chunk gets copied
55 *
56 * @param this calling diffie_hellman_t object
57 * @param public_value public value of partner
58 * @return
59 * - SUCCESS
60 * - OUT_OF_RES if out of ressources
61 */
62 status_t (*set_other_public_value) (diffie_hellman_t *this, chunk_t public_value);
63
64 /**
65 * @brief Gets the public value of partner
66 *
67 * @warning chunk gets copied
68 *
69 * @param this calling diffie_hellman_t object
70 * @param[out] public_value public value of partner is stored at this location
71 * @return
72 * - SUCCESS
73 * - OUT_OF_RES if out of ressources
74 * - FAILED if other public value not set
75 */
76 status_t (*get_other_public_value) (diffie_hellman_t *this, chunk_t *public_value);
77
78 /**
79 * @brief Gets the public value of caller
80 *
81 * @warning chunk gets copied
82 *
83 * @param this calling diffie_hellman_t object
84 * @param[out] public_value public value of caller is stored at this location
85 * @return
86 * - SUCCESS
87 * - OUT_OF_RES if out of ressources
88 */
89 status_t (*get_my_public_value) (diffie_hellman_t *this, chunk_t *public_value);
90
91 /**
92 * @brief Destroys an diffie_hellman_t object.
93 *
94 * @param this diffie_hellman_t object to destroy
95 * @return
96 * SUCCESS in any case
97 */
98 status_t (*destroy) (diffie_hellman_t *this);
99 };
100
101 /**
102 * Creates a new diffie_hellman_t object
103 *
104 * The first diffie hellman public value gets automatically created
105 *
106 * @param dh_group_number Diffie Hellman group number to use
107 * @return
108 * - diffie_hellman_t if successfully
109 * - NULL if out of ressources or dh_group not supported
110 */
111 diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t dh_group_number);
112
113 #endif /*DIFFIE_HELLMAN_H_*/