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