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.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 
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
General definitions for cryptographic algorithms.
#define PrngAlgo
Definition: crypto.h:917
ECC (Elliptic Curve Cryptography)
error_t ecdhComputeSharedSecret(EcdhContext *context, uint8_t *output, size_t outputSize, size_t *outputLen)
Compute ECDH shared secret.
Definition: ecdh.c:340
void ecdhFree(EcdhContext *context)
Release ECDH context.
Definition: ecdh.c:65
error_t ecdhGenerateKeyPair(EcdhContext *context, const PrngAlgo *prngAlgo, void *prngContext)
ECDH key pair generation.
Definition: ecdh.c:85
error_t ecdhCheckPublicKey(const EcDomainParameters *params, EcPoint *publicKey)
Check ECDH public key.
Definition: ecdh.c:227
void ecdhInit(EcdhContext *context)
Initialize ECDH context.
Definition: ecdh.c:48
error_t
Error codes.
Definition: error.h:43
EC domain parameters.
Definition: ec.h:76
EC point.
Definition: ec.h:64
EC private key.
Definition: ec.h:104
EC public key.
Definition: ec.h:94
ECDH context.
Definition: ecdh.h:59
EcDomainParameters params
EC domain parameters.
Definition: ecdh.h:60
EcPublicKey qa
One's own EC public key.
Definition: ecdh.h:62
EcPublicKey qb
Peer's EC public key.
Definition: ecdh.h:63
EcPrivateKey da
One's own EC private key.
Definition: ecdh.h:61
X25519 function implementation.
X448 function implementation.