eddsa.h
Go to the documentation of this file.
1 /**
2  * @file eddsa.h
3  * @brief EdDSA (Edwards-Curve Digital Signature Algorithm)
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 _EDDSA_H
32 #define _EDDSA_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "ecc/ec.h"
37 #include "ecc/ec_curves.h"
38 
39 //Maximum size of EdDSA public keys
40 #if (ED448_SUPPORT == ENABLED)
41  #define EDDSA_MAX_PUBLIC_KEY_LEN 57
42 #else
43  #define EDDSA_MAX_PUBLIC_KEY_LEN 32
44 #endif
45 
46 //Maximum size of EdDSA private keys
47 #if (ED448_SUPPORT == ENABLED)
48  #define EDDSA_MAX_PRIVATE_KEY_LEN 57
49 #else
50  #define EDDSA_MAX_PRIVATE_KEY_LEN 32
51 #endif
52 
53 //C++ guard
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 
59 /**
60  * @brief EdDSA public key
61  **/
62 
63 typedef struct
64 {
65  const EcCurve *curve; ///<Elliptic curve parameters
66  uint8_t q[EDDSA_MAX_PUBLIC_KEY_LEN]; ///<Public key
68 
69 
70 /**
71  * @brief EdDSA private key
72  **/
73 
74 typedef struct
75 {
76  const EcCurve *curve; ///<Elliptic curve parameters
77  uint8_t d[EDDSA_MAX_PRIVATE_KEY_LEN]; ///<Private key
78  int_t slot; ///<Private key slot
79  EddsaPublicKey q; ///<Public key
81 
82 
83 //EdDSA related functions
86 
89 
90 error_t eddsaGenerateKeyPair(const PrngAlgo *prngAlgo, void *prngContext,
91  const EcCurve *curve, EddsaPrivateKey *privateKey,
92  EddsaPublicKey *publicKey);
93 
94 error_t eddsaGeneratePrivateKey(const PrngAlgo *prngAlgo, void *prngContext,
95  const EcCurve *curve, EddsaPrivateKey *privateKey);
96 
98  EddsaPublicKey *publicKey);
99 
101  const uint8_t *data, size_t length);
102 
103 error_t eddsaExportPublicKey(const EddsaPublicKey *key, uint8_t *data,
104  size_t *length);
105 
107  const uint8_t *data, size_t length);
108 
110  size_t *length);
111 
112 //C++ guard
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 //Ed25519 supported?
118 #if (ED25519_SUPPORT == ENABLED)
119  #include "ecc/ed25519.h"
120 #endif
121 
122 //Ed448 supported?
123 #if (ED448_SUPPORT == ENABLED)
124  #include "ecc/ed448.h"
125 #endif
126 
127 #endif
Ed25519 elliptic curve (constant-time implementation)
#define EDDSA_MAX_PRIVATE_KEY_LEN
Definition: eddsa.h:48
#define EDDSA_MAX_PUBLIC_KEY_LEN
Definition: eddsa.h:41
signed int int_t
Definition: compiler_port.h:56
#define PrngAlgo
Definition: crypto.h:973
const EcCurve * curve
Elliptic curve parameters.
Definition: eddsa.h:76
error_t eddsaImportPublicKey(EddsaPublicKey *key, const EcCurve *curve, const uint8_t *data, size_t length)
Import an EdDSA public key.
Definition: eddsa.c:274
uint8_t data[]
Definition: ethernet.h:222
error_t eddsaGenerateKeyPair(const PrngAlgo *prngAlgo, void *prngContext, const EcCurve *curve, EddsaPrivateKey *privateKey, EddsaPublicKey *publicKey)
EdDSA key pair generation.
Definition: eddsa.c:112
error_t eddsaExportPrivateKey(const EddsaPrivateKey *key, uint8_t *data, size_t *length)
Export an EdDSA private key.
Definition: eddsa.c:424
void eddsaFreePublicKey(EddsaPublicKey *key)
Release an EdDSA public key.
Definition: eddsa.c:63
const EcCurve * curve
Elliptic curve parameters.
Definition: eddsa.h:65
error_t
Error codes.
Definition: error.h:43
EdDSA public key.
Definition: eddsa.h:64
void eddsaInitPublicKey(EddsaPublicKey *key)
Initialize an EdDSA public key.
Definition: eddsa.c:48
int_t slot
Private key slot.
Definition: eddsa.h:78
General definitions for cryptographic algorithms.
error_t eddsaImportPrivateKey(EddsaPrivateKey *key, const EcCurve *curve, const uint8_t *data, size_t length)
Import an EdDSA private key.
Definition: eddsa.c:371
uint8_t length
Definition: tcp.h:375
error_t eddsaGeneratePrivateKey(const PrngAlgo *prngAlgo, void *prngContext, const EcCurve *curve, EddsaPrivateKey *privateKey)
EdDSA private key generation.
Definition: eddsa.c:154
EdDSA private key.
Definition: eddsa.h:75
error_t eddsaExportPublicKey(const EddsaPublicKey *key, uint8_t *data, size_t *length)
Export an EdDSA public key.
Definition: eddsa.c:327
void eddsaFreePrivateKey(EddsaPrivateKey *key)
Release an EdDSA private key.
Definition: eddsa.c:95
void eddsaInitPrivateKey(EddsaPrivateKey *key)
Initialize an EdDSA private key.
Definition: eddsa.c:75
EddsaPublicKey q
Public key.
Definition: eddsa.h:79
error_t eddsaGeneratePublicKey(const EddsaPrivateKey *privateKey, EddsaPublicKey *publicKey)
Derive the public key from an EdDSA private key.
Definition: eddsa.c:217
#define EcCurve
Definition: ec.h:346
Elliptic curves.
ECC (Elliptic Curve Cryptography)
Ed448 elliptic curve (constant-time implementation)