2 * @file diffie_hellman.h
4 * @brief Interface of diffie_hellman_t.
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
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>.
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
24 #ifndef DIFFIE_HELLMAN_H_
25 #define DIFFIE_HELLMAN_H_
27 typedef enum diffie_hellman_group_t diffie_hellman_group_t
;
28 typedef struct diffie_hellman_t diffie_hellman_t
;
33 * @brief Diffie-Hellman group.
35 * The modulus (or group) to use for a Diffie-Hellman calculation.
37 * See IKEv2 RFC 3.3.2 and RFC 3526.
41 enum diffie_hellman_group_t
{
54 * enum name for diffie_hellman_group_t.
56 extern enum_name_t
*diffie_hellman_group_names
;
59 * @brief Implementation of the widely used Diffie-Hellman algorithm.
62 * - diffie_hellman_create()
66 struct diffie_hellman_t
{
69 * @brief Returns the shared secret of this diffie hellman exchange.
71 * @warning Space for returned secret is allocated and must be
72 * freed by the caller.
74 * @param this calling diffie_hellman_t object
75 * @param[out] secret shared secret will be written into this chunk
78 * - FAILED if not both DH values are set
80 status_t (*get_shared_secret
) (diffie_hellman_t
*this, chunk_t
*secret
);
83 * @brief Sets the public value of partner.
85 * chunk gets cloned and can be destroyed afterwards.
87 * @param this calling diffie_hellman_t object
88 * @param public_value public value of partner
90 void (*set_other_public_value
) (diffie_hellman_t
*this, chunk_t public_value
);
93 * @brief Gets the public value of partner.
95 * @warning Space for returned chunk is allocated and must be
96 * freed by the caller.
98 * @param this calling diffie_hellman_t object
99 * @param[out] public_value public value of partner is stored at this location
102 * - FAILED if other public value not set
104 status_t (*get_other_public_value
) (diffie_hellman_t
*this, chunk_t
*public_value
);
107 * @brief Gets the public value of caller
109 * @warning Space for returned chunk is allocated and must be
110 * freed by the caller.
112 * @param this calling diffie_hellman_t object
113 * @param[out] public_value public value of caller is stored at this location
115 void (*get_my_public_value
) (diffie_hellman_t
*this, chunk_t
*public_value
);
118 * @brief Get the DH group used.
120 * @param this calling diffie_hellman_t object
121 * @return DH group set in construction
123 diffie_hellman_group_t (*get_dh_group
) (diffie_hellman_t
*this);
126 * @brief Destroys an diffie_hellman_t object.
128 * @param this diffie_hellman_t object to destroy
130 void (*destroy
) (diffie_hellman_t
*this);
134 * @brief Creates a new diffie_hellman_t object.
136 * The first diffie hellman public value gets automatically created.
138 * @param dh_group_number Diffie Hellman group number to use
140 * - diffie_hellman_t object
141 * - NULL if dh group not supported
143 * @ingroup transforms
145 diffie_hellman_t
*diffie_hellman_create(diffie_hellman_group_t dh_group_number
);
147 #endif /*DIFFIE_HELLMAN_H_*/