ecdh.h
Go to the documentation of this file.
1 /**
2  * @file ecdh.h
3  * @brief ECDH (Elliptic Curve Diffie-Hellman) key exchange
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 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 2.4.4
29  **/
30 
31 #ifndef _ECDH_H
32 #define _ECDH_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "ecc/ec.h"
37 
38 //X25519 supported?
39 #if (X25519_SUPPORT == ENABLED)
40  #include "ecc/x25519.h"
41 #endif
42 
43 //X448 supported?
44 #if (X448_SUPPORT == ENABLED)
45  #include "ecc/x448.h"
46 #endif
47 
48 //C++ guard
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 
54 /**
55  * @brief ECDH context
56  **/
57 
58 typedef struct
59 {
60  EcDomainParameters params; ///<EC domain parameters
61  EcPrivateKey da; ///<One's own EC private key
62  EcPublicKey qa; ///<One's own EC public key
63  EcPublicKey qb; ///<Peer's EC public key
64 } EcdhContext;
65 
66 
67 //ECDH related functions
68 void ecdhInit(EcdhContext *context);
69 void ecdhFree(EcdhContext *context);
70 
71 error_t ecdhGenerateKeyPair(EcdhContext *context, const PrngAlgo *prngAlgo,
72  void *prngContext);
73 
74 error_t ecdhCheckPublicKey(const EcDomainParameters *params, EcPoint *publicKey);
75 
77  uint8_t *output, size_t outputSize, size_t *outputLen);
78 
79 //C++ guard
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
EcPublicKey qa
One's own EC public key.
Definition: ecdh.h:62
void ecdhInit(EcdhContext *context)
Initialize ECDH context.
Definition: ecdh.c:48
#define PrngAlgo
Definition: crypto.h:938
EcPublicKey qb
Peer's EC public key.
Definition: ecdh.h:63
error_t ecdhComputeSharedSecret(EcdhContext *context, uint8_t *output, size_t outputSize, size_t *outputLen)
Compute ECDH shared secret.
Definition: ecdh.c:340
EC domain parameters.
Definition: ec.h:76
X448 function implementation.
error_t ecdhCheckPublicKey(const EcDomainParameters *params, EcPoint *publicKey)
Check ECDH public key.
Definition: ecdh.c:227
error_t
Error codes.
Definition: error.h:43
void ecdhFree(EcdhContext *context)
Release ECDH context.
Definition: ecdh.c:65
General definitions for cryptographic algorithms.
EC private key.
Definition: ec.h:104
EC point.
Definition: ec.h:64
X25519 function implementation.
EC public key.
Definition: ec.h:94
EcPrivateKey da
One's own EC private key.
Definition: ecdh.h:61
error_t ecdhGenerateKeyPair(EcdhContext *context, const PrngAlgo *prngAlgo, void *prngContext)
ECDH key pair generation.
Definition: ecdh.c:85
ECC (Elliptic Curve Cryptography)
EcDomainParameters params
EC domain parameters.
Definition: ecdh.h:60
ECDH context.
Definition: ecdh.h:59