dh.h
Go to the documentation of this file.
1 /**
2  * @file dh.h
3  * @brief Diffie-Hellman key exchange
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneCrypto Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _DH_H
30 #define _DH_H
31 
32 //Dependencies
33 #include "core/crypto.h"
34 #include "mpi/mpi.h"
35 
36 //C++ guard
37 #ifdef __cplusplus
38  extern "C" {
39 #endif
40 
41 
42 /**
43  * @brief Diffie-Hellman parameters
44  **/
45 
46 typedef struct
47 {
48  Mpi p; ///<Prime modulus
49  Mpi g; ///<Generator
50 } DhParameters;
51 
52 
53 /**
54  * @brief Diffie-Hellman context
55  **/
56 
57 typedef struct
58 {
59  DhParameters params; //Diffie-Hellman parameters
60  Mpi xa; ///<One's own private value
61  Mpi ya; ///<One's own public value
62  Mpi yb; ///<Peer's public value
63 } DhContext;
64 
65 
66 //Diffie-Hellman related functions
67 void dhInit(DhContext *context);
68 void dhFree(DhContext *context);
69 
71  const PrngAlgo *prngAlgo, void *prngContext);
72 
73 error_t dhCheckPublicKey(DhParameters *params, const Mpi *publicKey);
74 
76  uint8_t *output, size_t outputSize, size_t *outputLen);
77 
78 //C++ guard
79 #ifdef __cplusplus
80  }
81 #endif
82 
83 #endif
Mpi xa
One&#39;s own private value.
Definition: dh.h:60
Arbitrary precision integer.
Definition: mpi.h:67
General definitions for cryptographic algorithms.
error_t dhGenerateKeyPair(DhContext *context, const PrngAlgo *prngAlgo, void *prngContext)
Diffie-Hellman key pair generation.
Definition: dh.c:89
Diffie-Hellman context.
Definition: dh.h:57
Mpi g
Generator.
Definition: dh.h:49
void dhInit(DhContext *context)
Initialize Diffie-Hellman context.
Definition: dh.c:52
DhParameters params
Definition: dh.h:59
error_t dhCheckPublicKey(DhParameters *params, const Mpi *publicKey)
Check Diffie-Hellman public value.
Definition: dh.c:152
Mpi ya
One&#39;s own public value.
Definition: dh.h:61
error_t
Error codes.
Definition: error.h:40
MPI (Multiple Precision Integer Arithmetic)
error_t dhComputeSharedSecret(DhContext *context, uint8_t *output, size_t outputSize, size_t *outputLen)
Compute Diffie-Hellman shared secret.
Definition: dh.c:188
Common interface for pseudo-random number generators.
Definition: crypto.h:1091
Mpi yb
Peer&#39;s public value.
Definition: dh.h:62
void dhFree(DhContext *context)
Release Diffie-Hellman context.
Definition: dh.c:69
Diffie-Hellman parameters.
Definition: dh.h:46
Mpi p
Prime modulus.
Definition: dh.h:48