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-2025 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.5.0
29  **/
30 
31 #ifndef _ECDH_H
32 #define _ECDH_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "ecc/ec.h"
37 #include "ecc/ec_curves.h"
38 
39 //X25519 supported?
40 #if (X25519_SUPPORT == ENABLED)
41  #include "ecc/x25519.h"
42 #endif
43 
44 //X448 supported?
45 #if (X448_SUPPORT == ENABLED)
46  #include "ecc/x448.h"
47 #endif
48 
49 //C++ guard
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 
55 /**
56  * @brief ECDH context
57  **/
58 
59 typedef struct
60 {
61  const EcCurve *curve; ///<Elliptic curve parameters
62  EcPrivateKey da; ///<One's own EC key pair
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(EcdhContext *context, const EcPublicKey *publicKey);
75 
76 error_t ecdhComputeSharedSecret(EcdhContext *context, uint8_t *output,
77  size_t outputSize, size_t *outputLen);
78 
79 //C++ guard
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
void ecdhInit(EcdhContext *context)
Initialize ECDH context.
Definition: ecdh.c:49
#define PrngAlgo
Definition: crypto.h:973
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:338
const EcCurve * curve
Elliptic curve parameters.
Definition: ecdh.h:61
X448 function implementation.
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:432
X25519 function implementation.
EC public key.
Definition: ec.h:421
EcPrivateKey da
One's own EC key pair.
Definition: ecdh.h:62
error_t ecdhGenerateKeyPair(EcdhContext *context, const PrngAlgo *prngAlgo, void *prngContext)
ECDH key pair generation.
Definition: ecdh.c:84
error_t ecdhCheckPublicKey(EcdhContext *context, const EcPublicKey *publicKey)
Check ECDH public key.
Definition: ecdh.c:224
#define EcCurve
Definition: ec.h:346
Elliptic curves.
ECC (Elliptic Curve Cryptography)
ECDH context.
Definition: ecdh.h:60