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-2020 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.8
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 //C++ guard
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 
44 /**
45  * @brief ECDH context
46  **/
47 
48 typedef struct
49 {
50  EcDomainParameters params; //EC domain parameters
51  Mpi da; ///<One's own private key
52  EcPoint qa; ///<One's own public key
53  EcPoint qb; ///<Peer's public key
54 } EcdhContext;
55 
56 
57 //ECDH related functions
58 void ecdhInit(EcdhContext *context);
59 void ecdhFree(EcdhContext *context);
60 
62  const PrngAlgo *prngAlgo, void *prngContext);
63 
64 error_t ecdhCheckPublicKey(const EcDomainParameters *params, EcPoint *publicKey);
65 
67  uint8_t *output, size_t outputSize, size_t *outputLen);
68 
69 //C++ guard
70 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif
void ecdhInit(EcdhContext *context)
Initialize ECDH context.
Definition: ecdh.c:50
Arbitrary precision integer.
Definition: mpi.h:69
Common interface for pseudo-random number generators.
Definition: crypto.h:1102
EcPoint qa
One's own public key.
Definition: ecdh.h:52
EcPoint qb
Peer's public key.
Definition: ecdh.h:53
error_t ecdhComputeSharedSecret(EcdhContext *context, uint8_t *output, size_t outputSize, size_t *outputLen)
Compute ECDH shared secret.
Definition: ecdh.c:385
EC domain parameters.
Definition: ec.h:63
error_t ecdhCheckPublicKey(const EcDomainParameters *params, EcPoint *publicKey)
Check ECDH public key.
Definition: ecdh.c:272
error_t
Error codes.
Definition: error.h:42
void ecdhFree(EcdhContext *context)
Release ECDH context.
Definition: ecdh.c:67
Mpi da
One's own private key.
Definition: ecdh.h:51
General definitions for cryptographic algorithms.
Elliptic curve point.
Definition: ec.h:51
error_t ecdhGenerateKeyPair(EcdhContext *context, const PrngAlgo *prngAlgo, void *prngContext)
ECDH key pair generation.
Definition: ecdh.c:87
ECC (Elliptic Curve Cryptography)
EcDomainParameters params
Definition: ecdh.h:50
ECDH context.
Definition: ecdh.h:48