2 * @file diffie_hellman.h
4 * @brief Interface of diffie_hellman_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
23 #ifndef DIFFIE_HELLMAN_H_
24 #define DIFFIE_HELLMAN_H_
29 typedef enum diffie_hellman_group_t diffie_hellman_group_t
;
32 * @brief Diffie-Hellman group.
34 * The modulus (or group) to use for a Diffie-Hellman calculation.
36 * See IKEv2 RFC 3.3.2 and RFC 3526.
40 enum diffie_hellman_group_t
{
41 MODP_UNDEFINED
= 1024,
53 * String mappings for diffie_hellman_group_t.
55 extern mapping_t diffie_hellman_group_m
[];
58 typedef struct diffie_hellman_t diffie_hellman_t
;
61 * @brief Implementation of the widely used Diffie-Hellman algorithm.
64 * - diffie_hellman_create()
68 struct diffie_hellman_t
{
71 * @brief Returns the shared secret of this diffie hellman exchange.
73 * @warning Space for returned secret is allocated and must be
74 * freed by the caller.
76 * @param this calling diffie_hellman_t object
77 * @param[out] secret shared secret will be written into this chunk
80 * - FAILED if not both DH values are set
82 status_t (*get_shared_secret
) (diffie_hellman_t
*this, chunk_t
*secret
);
85 * @brief Sets the public value of partner.
87 * chunk gets cloned and can be destroyed afterwards.
89 * @param this calling diffie_hellman_t object
90 * @param public_value public value of partner
92 void (*set_other_public_value
) (diffie_hellman_t
*this, chunk_t public_value
);
95 * @brief Gets the public value of partner.
97 * @warning Space for returned chunk is allocated and must be
98 * freed by the caller.
100 * @param this calling diffie_hellman_t object
101 * @param[out] public_value public value of partner is stored at this location
104 * - FAILED if other public value not set
106 status_t (*get_other_public_value
) (diffie_hellman_t
*this, chunk_t
*public_value
);
109 * @brief Gets the public value of caller
111 * @warning Space for returned chunk is allocated and must be
112 * freed by the caller.
114 * @param this calling diffie_hellman_t object
115 * @param[out] public_value public value of caller is stored at this location
117 void (*get_my_public_value
) (diffie_hellman_t
*this, chunk_t
*public_value
);
120 * @brief Get the DH group used.
122 * @param this calling diffie_hellman_t object
123 * @return DH group set in construction
125 diffie_hellman_group_t (*get_dh_group
) (diffie_hellman_t
*this);
128 * @brief Destroys an diffie_hellman_t object.
130 * @param this diffie_hellman_t object to destroy
132 void (*destroy
) (diffie_hellman_t
*this);
136 * @brief Creates a new diffie_hellman_t object.
138 * The first diffie hellman public value gets automatically created.
140 * @param dh_group_number Diffie Hellman group number to use
142 * - diffie_hellman_t object
143 * - NULL if dh group not supported
145 * @ingroup transforms
147 diffie_hellman_t
*diffie_hellman_create(diffie_hellman_group_t dh_group_number
);
149 #endif /*DIFFIE_HELLMAN_H_*/