mldsa.h
Go to the documentation of this file.
1 /**
2  * @file mldsa.h
3  * @brief ML-DSA (Edwards-Curve Digital Signature Algorithm)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 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.6.4
29  **/
30 
31 #ifndef _MLDSA_H
32 #define _MLDSA_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "ecc/ec.h"
37 
38 //ML-DSA-44 security level
39 #define MLDSA44_SECURITY_LEVEL 2
40 //ML-DSA-44 seed size
41 #define MLDSA44_SEED_LEN 32
42 //ML-DSA-44 private key size
43 #define MLDSA44_PRIVATE_KEY_LEN 2560
44 //ML-DSA-44 public key size
45 #define MLDSA44_PUBLIC_KEY_LEN 1312
46 //ML-DSA-44 signature size
47 #define MLDSA44_SIGNATURE_LEN 2420
48 
49 //ML-DSA-65 security level
50 #define MLDSA65_SECURITY_LEVEL 3
51 //ML-DSA-65 seed size
52 #define MLDSA65_SEED_LEN 32
53 //ML-DSA-65 private key size
54 #define MLDSA65_PRIVATE_KEY_LEN 4032
55 //ML-DSA-65 public key size
56 #define MLDSA65_PUBLIC_KEY_LEN 1952
57 //ML-DSA-65 signature size
58 #define MLDSA65_SIGNATURE_LEN 3309
59 
60 //ML-DSA-87 security level
61 #define MLDSA87_SECURITY_LEVEL 5
62 //ML-DSA-87 seed size
63 #define MLDSA87_SEED_LEN 32
64 //ML-DSA-87 private key size
65 #define MLDSA87_PRIVATE_KEY_LEN 4896
66 //ML-DSA-87 public key size
67 #define MLDSA87_PUBLIC_KEY_LEN 2592
68 //ML-DSA-87 signature size
69 #define MLDSA87_SIGNATURE_LEN 4627
70 
71 //C++ guard
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 
76 
77 /**
78  * @brief ML-DSA public key
79  **/
80 
81 typedef struct
82 {
83  uint_t level; ///<Security level
84  uint8_t *pk; ///<Public key
85  size_t pkLen; ///<Length of the public key, in bytes
87 
88 
89 /**
90  * @brief ML-DSA private key
91  **/
92 
93 typedef struct
94 {
95  uint_t level; ///<Security level
96  uint8_t *seed; ///<Seed
97  size_t seedLen; ///<Length of the seed, in bytes
98  uint8_t *sk; ///<Secret key
99  size_t skLen; ///<Length of the secret key, in bytes
101 
102 //ML-DSA related constants
103 extern const uint8_t MLDSA44_OID[9];
104 extern const uint8_t MLDSA65_OID[9];
105 extern const uint8_t MLDSA87_OID[9];
106 
107 //ML-DSA related functions
110 
113 
115  const uint8_t *input, size_t length);
116 
117 error_t mldsaExportPublicKey(const MldsaPublicKey *key, uint8_t *output,
118  size_t *written);
119 
121  const uint8_t *input, size_t length);
122 
123 error_t mldsaExportPrivateKey(const MldsaPrivateKey *key, uint8_t *output,
124  size_t *written);
125 
127  const uint8_t *input, size_t length);
128 
129 error_t mldsaExportSeed(const MldsaPrivateKey *key, uint8_t *output,
130  size_t *written);
131 
132 error_t mldsa44GenerateSignature(const uint8_t *secretKey, const void *message,
133  size_t messageLen, const void *context, uint8_t contextLen,
134  uint8_t *signature);
135 
136 error_t mldsa65GenerateSignature(const uint8_t *secretKey, const void *message,
137  size_t messageLen, const void *context, uint8_t contextLen,
138  uint8_t *signature);
139 
140 error_t mldsa87GenerateSignature(const uint8_t *secretKey, const void *message,
141  size_t messageLen, const void *context, uint8_t contextLen,
142  uint8_t *signature);
143 
144 error_t mldsa44VerifySignature(const uint8_t *publicKey, const void *message,
145  size_t messageLen, const void *context, uint8_t contextLen,
146  const uint8_t *signature);
147 
148 error_t mldsa65VerifySignature(const uint8_t *publicKey, const void *message,
149  size_t messageLen, const void *context, uint8_t contextLen,
150  const uint8_t *signature);
151 
152 error_t mldsa87VerifySignature(const uint8_t *publicKey, const void *message,
153  size_t messageLen, const void *context, uint8_t contextLen,
154  const uint8_t *signature);
155 
156 //C++ guard
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif
uint8_t * seed
Seed.
Definition: mldsa.h:96
uint8_t message[]
Definition: chap.h:154
error_t mldsa44GenerateSignature(const uint8_t *secretKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t *signature)
ML-DSA-44 signature generation.
Definition: mldsa.c:542
uint_t level
Security level.
Definition: mldsa.h:95
error_t mldsa87GenerateSignature(const uint8_t *secretKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t *signature)
ML-DSA-87 signature generation.
Definition: mldsa.c:604
const uint8_t MLDSA44_OID[9]
Definition: mldsa.c:47
error_t mldsaExportSeed(const MldsaPrivateKey *key, uint8_t *output, size_t *written)
Export an ML-DSA seed.
Definition: mldsa.c:489
error_t mldsa65GenerateSignature(const uint8_t *secretKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t *signature)
ML-DSA-65 signature generation.
Definition: mldsa.c:574
size_t seedLen
Length of the seed, in bytes.
Definition: mldsa.h:97
ML-DSA public key.
Definition: mldsa.h:82
error_t
Error codes.
Definition: error.h:43
error_t mldsa65VerifySignature(const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, const uint8_t *signature)
ML-DSA-65 signature verification.
Definition: mldsa.c:667
error_t mldsaImportPublicKey(MldsaPublicKey *key, uint_t level, const uint8_t *input, size_t length)
Import an ML-DSA public key.
Definition: mldsa.c:144
error_t mldsaExportPrivateKey(const MldsaPrivateKey *key, uint8_t *output, size_t *written)
Export an ML-DSA private key.
Definition: mldsa.c:357
uint8_t * sk
Secret key.
Definition: mldsa.h:98
General definitions for cryptographic algorithms.
uint8_t length
Definition: tcp.h:375
error_t mldsaExportPublicKey(const MldsaPublicKey *key, uint8_t *output, size_t *written)
Export an ML-DSA public key.
Definition: mldsa.c:225
error_t mldsa44VerifySignature(const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, const uint8_t *signature)
ML-DSA-44 signature verification.
Definition: mldsa.c:636
void mldsaFreePrivateKey(MldsaPrivateKey *key)
Release an ML-DSA private key.
Definition: mldsa.c:114
void mldsaInitPublicKey(MldsaPublicKey *key)
Initialize an ML-DSA public key.
Definition: mldsa.c:59
void mldsaFreePublicKey(MldsaPublicKey *key)
Release an ML-DSA public key.
Definition: mldsa.c:75
error_t mldsa87VerifySignature(const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, const uint8_t *signature)
ML-DSA-87 signature verification.
Definition: mldsa.c:698
size_t pkLen
Length of the public key, in bytes.
Definition: mldsa.h:85
ML-DSA private key.
Definition: mldsa.h:94
uint8_t * pk
Public key.
Definition: mldsa.h:84
error_t mldsaImportPrivateKey(MldsaPrivateKey *key, uint_t level, const uint8_t *input, size_t length)
Import an ML-DSA private key.
Definition: mldsa.c:276
size_t skLen
Length of the secret key, in bytes.
Definition: mldsa.h:99
error_t mldsaImportSeed(MldsaPrivateKey *key, uint_t level, const uint8_t *input, size_t length)
Import an ML-DSA seed.
Definition: mldsa.c:408
unsigned int uint_t
Definition: compiler_port.h:57
uint_t level
Security level.
Definition: mldsa.h:83
const uint8_t MLDSA87_OID[9]
Definition: mldsa.c:51
ECC (Elliptic Curve Cryptography)
void mldsaInitPrivateKey(MldsaPrivateKey *key)
Initialize an ML-DSA private key.
Definition: mldsa.c:94
const uint8_t MLDSA65_OID[9]
Definition: mldsa.c:49