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