tls13_sign_generate.c
Go to the documentation of this file.
1 /**
2  * @file tls13_sign_generate.c
3  * @brief RSA/DSA/ECDSA/SM2/EdDSA signature generation (TLS 1.3)
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 CycloneSSL 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 //Switch to the appropriate trace level
32 #define TRACE_LEVEL TLS_TRACE_LEVEL
33 
34 //Dependencies
35 #include "tls/tls.h"
36 #include "tls/tls_sign_generate.h"
38 #include "tls/tls_misc.h"
40 #include "pkix/pem_key_import.h"
41 #include "debug.h"
42 
43 //Check TLS library configuration
44 #if (TLS_SUPPORT == ENABLED && TLS_MAX_VERSION >= TLS_VERSION_1_3)
45 
46 
47 /**
48  * @brief Digital signature generation (TLS 1.3)
49  * @param[in] context Pointer to the TLS context
50  * @param[out] p Buffer where to store the digitally-signed element
51  * @param[out] length Length of the digitally-signed element
52  * @return Error code
53  **/
54 
56  size_t *length)
57 {
58  error_t error;
59  size_t n;
60  uint8_t *buffer;
61  Tls13DigitalSignature *signature;
62  const HashAlgo *hashAlgo;
63 
64  //Point to the digitally-signed element
65  signature = (Tls13DigitalSignature *) p;
66  //The algorithm field specifies the signature scheme
67  signature->algorithm = htons(context->signScheme);
68 
69  //The hash function used by HKDF is the cipher suite hash algorithm
70  hashAlgo = context->cipherSuite.prfHashAlgo;
71  //Make sure the hash algorithm is valid
72  if(hashAlgo == NULL)
73  return ERROR_FAILURE;
74 
75  //Calculate the length of the content covered by the digital signature
76  n = hashAlgo->digestSize + 98;
77 
78  //Allocate a memory buffer
79  buffer = tlsAllocMem(n);
80 
81  //Successful memory allocation?
82  if(buffer != NULL)
83  {
84  //Form a string that consists of octet 32 (0x20) repeated 64 times
85  osMemset(buffer, ' ', 64);
86 
87  //Append the context string. It is used to provide separation between
88  //signatures made in different contexts, helping against potential
89  //cross-protocol attacks
90  if(context->entity == TLS_CONNECTION_END_CLIENT)
91  {
92  osMemcpy(buffer + 64, "TLS 1.3, client CertificateVerify", 33);
93  }
94  else
95  {
96  osMemcpy(buffer + 64, "TLS 1.3, server CertificateVerify", 33);
97  }
98 
99  //Append a single 0 byte which serves as the separator
100  buffer[97] = 0x00;
101 
102  //Compute the transcript hash
103  error = tlsFinalizeTranscriptHash(context, hashAlgo,
104  context->transcriptHashContext, buffer + 98);
105 
106  //Check status code
107  if(!error)
108  {
109 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
110  //RSA-PSS signature scheme?
111  if(context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
112  context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
113  context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512 ||
114  context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256 ||
115  context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384 ||
116  context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512)
117  {
118  //Generate an RSA-PSS signature
119  error = tls13GenerateRsaPssSignature(context, buffer, n, signature);
120  }
121  else
122 #endif
123 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
124  //ECDSA signature scheme?
125  if(context->signScheme == TLS_SIGN_SCHEME_ECDSA_SECP256R1_SHA256 ||
126  context->signScheme == TLS_SIGN_SCHEME_ECDSA_SECP384R1_SHA384 ||
127  context->signScheme == TLS_SIGN_SCHEME_ECDSA_SECP521R1_SHA512 ||
128  context->signScheme == TLS_SIGN_SCHEME_ECDSA_BP256R1_TLS13_SHA256 ||
129  context->signScheme == TLS_SIGN_SCHEME_ECDSA_BP384R1_TLS13_SHA384 ||
130  context->signScheme == TLS_SIGN_SCHEME_ECDSA_BP512R1_TLS13_SHA512)
131  {
132  //Generate an ECDSA signature
133  error = tls13GenerateEcdsaSignature(context, buffer, n, signature);
134  }
135  else
136 #endif
137 #if (TLS_SM2_SIGN_SUPPORT == ENABLED)
138  //SM2 signature scheme?
139  if(context->signScheme == TLS_SIGN_SCHEME_SM2SIG_SM3)
140  {
141  //Generate an SM2 signature
142  error = tls13GenerateSm2Signature(context, buffer, n, signature);
143  }
144  else
145 #endif
146 #if (TLS_ED25519_SIGN_SUPPORT == ENABLED)
147  //Ed25519 signature scheme?
148  if(context->signScheme == TLS_SIGN_SCHEME_ED25519)
149  {
150  //Generate an Ed25519 signature
151  error = tls13GenerateEd25519Signature(context, buffer, n, signature);
152  }
153  else
154 #endif
155 #if (TLS_ED448_SIGN_SUPPORT == ENABLED)
156  //Ed448 signature scheme?
157  if(context->signScheme == TLS_SIGN_SCHEME_ED448)
158  {
159  //Generate an Ed448 signature
160  error = tls13GenerateEd448Signature(context, buffer, n, signature);
161  }
162  else
163 #endif
164 #if (TLS_MLDSA44_SIGN_SUPPORT == ENABLED)
165  //ML-DSA-44 signature scheme?
166  if(context->signScheme == TLS_SIGN_SCHEME_MLDSA44)
167  {
168  //Generate an ML-DSA-44 signature
169  error = tls13GenerateMldsa44Signature(context, buffer, n, signature);
170  }
171  else
172 #endif
173 #if (TLS_MLDSA65_SIGN_SUPPORT == ENABLED)
174  //ML-DSA-65 signature scheme?
175  if(context->signScheme == TLS_SIGN_SCHEME_MLDSA65)
176  {
177  //Generate an ML-DSA-65 signature
178  error = tls13GenerateMldsa65Signature(context, buffer, n, signature);
179  }
180  else
181 #endif
182 #if (TLS_MLDSA87_SIGN_SUPPORT == ENABLED)
183  //ML-DSA-87 signature scheme?
184  if(context->signScheme == TLS_SIGN_SCHEME_MLDSA87)
185  {
186  //Generate an ML-DSA-87 signature
187  error = tls13GenerateMldsa87Signature(context, buffer, n, signature);
188  }
189  else
190 #endif
191  //Invalid signature scheme?
192  {
193  //Report an error
195  }
196  }
197 
198  //Release memory buffer
199  tlsFreeMem(buffer);
200  }
201  else
202  {
203  //Failed to allocate memory
204  error = ERROR_OUT_OF_MEMORY;
205  }
206 
207  //Check status code
208  if(!error)
209  {
210  //Total length of the digitally-signed element
211  *length = sizeof(Tls13DigitalSignature) + ntohs(signature->length);
212  }
213 
214  //Return status code
215  return error;
216 }
217 
218 
219 /**
220  * @brief RSA-PSS signature generation (TLS 1.3)
221  * @param[in] context Pointer to the TLS context
222  * @param[in] message Pointer to the message to be signed
223  * @param[in] length Length of the message, in bytes
224  * @param[out] signature Buffer where to store the digital signature
225  * @return Error code
226  **/
227 
229  size_t length, Tls13DigitalSignature *signature)
230 {
231 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
232  error_t error;
233  size_t n;
234  const HashAlgo *hashAlgo;
235 
236  //Retrieve the hash algorithm used for signing
237  if(context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
238  context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256)
239  {
240  //Select SHA-256 hash algorithm
242  }
243  else if(context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
244  context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384)
245  {
246  //Select SHA-384 hash algorithm
248  }
249  else if(context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512 ||
250  context->signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512)
251  {
252  //Select SHA-512 hash algorithm
254  }
255  else
256  {
257  //Invalid signature scheme
258  hashAlgo = NULL;
259  }
260 
261  //Pre-hash the content covered by the digital signature
262  if(hashAlgo != NULL)
263  {
264  error = hashAlgo->compute(message, length, context->clientVerifyData);
265  }
266  else
267  {
269  }
270 
271  //Check status code
272  if(!error)
273  {
274  //RSA signatures must use an RSASSA-PSS algorithm, regardless of whether
275  //RSASSA-PKCS1-v1_5 algorithms appear in SignatureAlgorithms
276  error = tlsGenerateRsaPssSignature(context, hashAlgo,
277  context->clientVerifyData, signature->value, &n);
278  }
279 
280  //Check status code
281  if(!error)
282  {
283  //The signature is preceded by a 2-byte length field
284  signature->length = htons(n);
285  }
286 
287  //Return status code
288  return error;
289 #else
290  //RSA-PSS signature algorithm not implemented
291  return ERROR_NOT_IMPLEMENTED;
292 #endif
293 }
294 
295 
296 /**
297  * @brief ECDSA signature generation (TLS 1.3)
298  * @param[in] context Pointer to the TLS context
299  * @param[in] message Pointer to the message to be signed
300  * @param[in] length Length of the message, in bytes
301  * @param[out] signature Buffer where to store the digital signature
302  * @return Error code
303  **/
304 
306  size_t length, Tls13DigitalSignature *signature)
307 {
308 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
309  error_t error;
310  size_t n;
311  const HashAlgo *hashAlgo;
312 
313  //Retrieve the hash algorithm used for signing
314  if(context->signScheme == TLS_SIGN_SCHEME_ECDSA_SECP256R1_SHA256 ||
315  context->signScheme == TLS_SIGN_SCHEME_ECDSA_BP256R1_TLS13_SHA256)
316  {
317  //Select SHA-256 hash algorithm
319  }
320  else if(context->signScheme == TLS_SIGN_SCHEME_ECDSA_SECP384R1_SHA384 ||
321  context->signScheme == TLS_SIGN_SCHEME_ECDSA_BP384R1_TLS13_SHA384)
322  {
323  //Select SHA-384 hash algorithm
325  }
326  else if(context->signScheme == TLS_SIGN_SCHEME_ECDSA_SECP521R1_SHA512 ||
327  context->signScheme == TLS_SIGN_SCHEME_ECDSA_BP512R1_TLS13_SHA512)
328  {
329  //Select SHA-512 hash algorithm
331  }
332  else
333  {
334  //Invalid signature scheme
335  hashAlgo = NULL;
336  }
337 
338  //Pre-hash the content covered by the digital signature
339  if(hashAlgo != NULL)
340  {
341  error = hashAlgo->compute(message, length, context->clientVerifyData);
342  }
343  else
344  {
346  }
347 
348  //Check status code
349  if(!error)
350  {
351  //Generate an ECDSA signature
352  error = tlsGenerateEcdsaSignature(context, context->clientVerifyData,
353  hashAlgo->digestSize, signature->value, &n);
354  }
355 
356  //Check status code
357  if(!error)
358  {
359  //The signature is preceded by a 2-byte length field
360  signature->length = htons(n);
361  }
362 
363  //Return status code
364  return error;
365 #else
366  //ECDSA signature algorithm not implemented
367  return ERROR_NOT_IMPLEMENTED;
368 #endif
369 }
370 
371 
372 /**
373  * @brief SM2 signature generation (TLS 1.3)
374  * @param[in] context Pointer to the TLS context
375  * @param[in] message Pointer to the message to be signed
376  * @param[in] length Length of the message, in bytes
377  * @param[out] signature Buffer where to store the digital signature
378  * @return Error code
379  **/
380 
382  size_t length, Tls13DigitalSignature *signature)
383 {
384 #if (TLS_SM2_SIGN_SUPPORT == ENABLED)
385  error_t error;
386  size_t n;
387  EcPrivateKey privateKey;
388  EcdsaSignature sm2Signature;
389 
390  //Initialize EC private key
391  ecInitPrivateKey(&privateKey);
392  //Initialize SM2 signature
393  ecdsaInitSignature(&sm2Signature);
394 
395  //Decode the PEM structure that holds the EC private key
396  error = pemImportEcPrivateKey(&privateKey, context->cert->privateKey,
397  context->cert->privateKeyLen, context->cert->password);
398 
399  //Check status code
400  if(!error)
401  {
402  //Generate SM2 signature
403  error = sm2GenerateSignature(context->prngAlgo, context->prngContext,
405  message, length, &sm2Signature);
406  }
407 
408  //Check status code
409  if(!error)
410  {
411  //Encode the resulting (R, S) integer pair using ASN.1
412  error = ecdsaExportSignature(&sm2Signature, signature->value, &n,
414  }
415 
416  //Check status code
417  if(!error)
418  {
419  //The signature is preceded by a 2-byte length field
420  signature->length = htons(n);
421  }
422 
423  //Release previously allocated resources
424  ecFreePrivateKey(&privateKey);
425  ecdsaFreeSignature(&sm2Signature);
426 
427  //Return status code
428  return error;
429 #else
430  //SM2 signature algorithm not implemented
431  return ERROR_NOT_IMPLEMENTED;
432 #endif
433 }
434 
435 
436 /**
437  * @brief Ed25519 signature generation (TLS 1.3)
438  * @param[in] context Pointer to the TLS context
439  * @param[in] message Pointer to the message to be signed
440  * @param[in] length Length of the message, in bytes
441  * @param[out] signature Buffer where to store the digital signature
442  * @return Error code
443  **/
444 
446  size_t length, Tls13DigitalSignature *signature)
447 {
448 #if (TLS_ED25519_SIGN_SUPPORT == ENABLED)
449  error_t error;
450  size_t n;
451  DataChunk messageChunks[1];
452 
453  //Data to be signed is run through the EdDSA algorithm without pre-hashing
454  messageChunks[0].buffer = message;
455  messageChunks[0].length = length;
456 
457  //Generate Ed25519 signature in PureEdDSA mode
458  error = tlsGenerateEd25519Signature(context, messageChunks,
459  arraysize(messageChunks), signature->value, &n);
460 
461  //Check status code
462  if(!error)
463  {
464  //The signature is preceded by a 2-byte length field
465  signature->length = htons(n);
466  }
467 
468  //Return status code
469  return error;
470 #else
471  //Ed25519 signature algorithm not implemented
472  return ERROR_NOT_IMPLEMENTED;
473 #endif
474 }
475 
476 
477 /**
478  * @brief Ed448 signature generation (TLS 1.3)
479  * @param[in] context Pointer to the TLS context
480  * @param[in] message Pointer to the message to be signed
481  * @param[in] length Length of the message, in bytes
482  * @param[out] signature Buffer where to store the digital signature
483  * @return Error code
484  **/
485 
487  size_t length, Tls13DigitalSignature *signature)
488 {
489 #if (TLS_ED448_SIGN_SUPPORT == ENABLED)
490  error_t error;
491  size_t n;
492  DataChunk messageChunks[1];
493 
494  //Data to be signed is run through the EdDSA algorithm without pre-hashing
495  messageChunks[0].buffer = message;
496  messageChunks[0].length = length;
497 
498  //Generate Ed448 signature in PureEdDSA mode
499  error = tlsGenerateEd448Signature(context, messageChunks,
500  arraysize(messageChunks), signature->value, &n);
501 
502  //Check status code
503  if(!error)
504  {
505  //The signature is preceded by a 2-byte length field
506  signature->length = htons(n);
507  }
508 
509  //Return status code
510  return error;
511 #else
512  //Ed448 signature algorithm not implemented
513  return ERROR_NOT_IMPLEMENTED;
514 #endif
515 }
516 
517 
518 /**
519  * @brief ML-DSA-44 signature generation (TLS 1.3)
520  * @param[in] context Pointer to the TLS context
521  * @param[in] message Pointer to the message to be signed
522  * @param[in] length Length of the message, in bytes
523  * @param[out] signature Buffer where to store the digital signature
524  * @return Error code
525  **/
526 
528  size_t length, Tls13DigitalSignature *signature)
529 {
530 #if (TLS_MLDSA44_SIGN_SUPPORT == ENABLED)
531  error_t error;
532  MldsaPrivateKey privateKey;
533 
534  //Initialize ML-DSA private key
535  mldsaInitPrivateKey(&privateKey);
536 
537  //Decode the PEM structure that holds the ML-DSA private key
538  error = pemImportMldsaPrivateKey(&privateKey, context->cert->privateKey,
539  context->cert->privateKeyLen, context->cert->password);
540 
541  //Check security level
542  if(privateKey.level == MLDSA44_SECURITY_LEVEL &&
543  privateKey.skLen == MLDSA44_PRIVATE_KEY_LEN)
544  {
545  //Generate ML-DSA-44 signature
546  error = mldsa44GenerateSignature(privateKey.sk, message, length,
547  NULL, 0, signature->value);
548 
549  //Check status code
550  if(!error)
551  {
552  //Length of the resulting ML-DSA signature
553  signature->length = HTONS(MLDSA44_SIGNATURE_LEN);
554  }
555  }
556  else
557  {
558  //The ML-DSA private key is not valid
559  error = ERROR_INVALID_KEY;
560  }
561 
562  //Free previously allocated resources
563  mldsaFreePrivateKey(&privateKey);
564 
565  //Return status code
566  return error;
567 #else
568  //ML-DSA-44 signature algorithm not implemented
569  return ERROR_NOT_IMPLEMENTED;
570 #endif
571 }
572 
573 
574 /**
575  * @brief ML-DSA-65 signature generation (TLS 1.3)
576  * @param[in] context Pointer to the TLS context
577  * @param[in] message Pointer to the message to be signed
578  * @param[in] length Length of the message, in bytes
579  * @param[out] signature Buffer where to store the digital signature
580  * @return Error code
581  **/
582 
584  size_t length, Tls13DigitalSignature *signature)
585 {
586 #if (TLS_MLDSA65_SIGN_SUPPORT == ENABLED)
587  error_t error;
588  MldsaPrivateKey privateKey;
589 
590  //Initialize ML-DSA private key
591  mldsaInitPrivateKey(&privateKey);
592 
593  //Decode the PEM structure that holds the ML-DSA private key
594  error = pemImportMldsaPrivateKey(&privateKey, context->cert->privateKey,
595  context->cert->privateKeyLen, context->cert->password);
596 
597  //Check security level
598  if(privateKey.level == MLDSA65_SECURITY_LEVEL &&
599  privateKey.skLen == MLDSA65_PRIVATE_KEY_LEN)
600  {
601  //Generate ML-DSA-65 signature
602  error = mldsa65GenerateSignature(privateKey.sk, message, length,
603  NULL, 0, signature->value);
604 
605  //Check status code
606  if(!error)
607  {
608  //Length of the resulting ML-DSA signature
609  signature->length = HTONS(MLDSA65_SIGNATURE_LEN);
610  }
611  }
612  else
613  {
614  //The ML-DSA private key is not valid
615  error = ERROR_INVALID_KEY;
616  }
617 
618  //Free previously allocated resources
619  mldsaFreePrivateKey(&privateKey);
620 
621  //Return status code
622  return error;
623 #else
624  //ML-DSA-65 signature algorithm not implemented
625  return ERROR_NOT_IMPLEMENTED;
626 #endif
627 }
628 
629 
630 /**
631  * @brief ML-DSA-87 signature generation (TLS 1.3)
632  * @param[in] context Pointer to the TLS context
633  * @param[in] message Pointer to the message to be signed
634  * @param[in] length Length of the message, in bytes
635  * @param[out] signature Buffer where to store the digital signature
636  * @return Error code
637  **/
638 
640  size_t length, Tls13DigitalSignature *signature)
641 {
642 #if (TLS_MLDSA87_SIGN_SUPPORT == ENABLED)
643  error_t error;
644  MldsaPrivateKey privateKey;
645 
646  //Initialize ML-DSA private key
647  mldsaInitPrivateKey(&privateKey);
648 
649  //Decode the PEM structure that holds the ML-DSA private key
650  error = pemImportMldsaPrivateKey(&privateKey, context->cert->privateKey,
651  context->cert->privateKeyLen, context->cert->password);
652 
653  //Check security level
654  if(privateKey.level == MLDSA87_SECURITY_LEVEL &&
655  privateKey.skLen == MLDSA87_PRIVATE_KEY_LEN)
656  {
657  //Generate ML-DSA-87 signature
658  error = mldsa87GenerateSignature(privateKey.sk, message, length,
659  NULL, 0, signature->value);
660 
661  //Check status code
662  if(!error)
663  {
664  //Length of the resulting ML-DSA signature
665  signature->length = HTONS(MLDSA87_SIGNATURE_LEN);
666  }
667  }
668  else
669  {
670  //The ML-DSA private key is not valid
671  error = ERROR_INVALID_KEY;
672  }
673 
674  //Free previously allocated resources
675  mldsaFreePrivateKey(&privateKey);
676 
677  //Return status code
678  return error;
679 #else
680  //ML-DSA-87 signature algorithm not implemented
681  return ERROR_NOT_IMPLEMENTED;
682 #endif
683 }
684 
685 #endif
#define tlsAllocMem(size)
Definition: tls.h:910
#define htons(value)
Definition: cpu_endian.h:413
ECDSA signature.
Definition: ecdsa.h:63
TLS helper functions.
@ TLS_SIGN_SCHEME_ECDSA_BP256R1_TLS13_SHA256
Definition: tls.h:1355
#define MLDSA65_SIGNATURE_LEN
Definition: mldsa.h:58
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1431
error_t tls13GenerateEd448Signature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
Ed448 signature generation (TLS 1.3)
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256
Definition: tls.h:1345
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
void mldsaFreePrivateKey(MldsaPrivateKey *key)
Release an ML-DSA private key.
Definition: mldsa.c:114
uint8_t p
Definition: ndp.h:300
@ TLS_SIGN_SCHEME_MLDSA44
Definition: tls.h:1368
uint8_t message[]
Definition: chap.h:154
error_t pemImportEcPrivateKey(EcPrivateKey *privateKey, const char_t *input, size_t length, const char_t *password)
Decode a PEM file containing an EC private key.
size_t digestSize
Definition: crypto.h:1171
const void * buffer
Definition: crypto.h:1094
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
error_t sm2GenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const EcPrivateKey *privateKey, const HashAlgo *hashAlgo, const char_t *id, size_t idLen, const void *message, size_t messageLen, EcdsaSignature *signature)
SM2 signature generation.
Definition: sm2.c:62
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512
Definition: tls.h:1350
error_t tls13GenerateMldsa87Signature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
ML-DSA-87 signature generation (TLS 1.3)
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
#define SM3_HASH_ALGO
Definition: sm3.h:49
uint_t level
Security level.
Definition: mldsa.h:95
PEM key file import functions.
#define MLDSA87_SECURITY_LEVEL
Definition: mldsa.h:61
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512
Definition: tls.h:1347
@ TLS_SIGN_SCHEME_ED25519
Definition: tls.h:1359
#define osStrlen(s)
Definition: os_port.h:171
error_t tlsFinalizeTranscriptHash(TlsContext *context, const HashAlgo *hash, const void *hashContext, uint8_t *output)
Finalize hash calculation from previous handshake messages.
#define MLDSA65_SECURITY_LEVEL
Definition: mldsa.h:50
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384
Definition: tls.h:1349
@ TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384
Definition: tls.h:1346
#define MLDSA65_PRIVATE_KEY_LEN
Definition: mldsa.h:54
error_t tls13GenerateMldsa44Signature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
ML-DSA-44 signature generation (TLS 1.3)
@ TLS_SIGN_SCHEME_MLDSA65
Definition: tls.h:1369
error_t tlsGenerateEcdsaSignature(TlsContext *context, const uint8_t *digest, size_t digestLen, uint8_t *signature, size_t *signatureLen)
Generate ECDSA signature.
error_t ecdsaExportSignature(const EcdsaSignature *signature, uint8_t *output, size_t *written, EcdsaSignatureFormat format)
Export an ECDSA signature.
Definition: ecdsa.c:275
@ TLS_SIGN_SCHEME_MLDSA87
Definition: tls.h:1370
void ecdsaFreeSignature(EcdsaSignature *signature)
Release an ECDSA signature.
Definition: ecdsa.c:90
@ TLS_HASH_ALGO_SHA512
Definition: tls.h:1308
#define MLDSA44_SECURITY_LEVEL
Definition: mldsa.h:39
#define osMemcpy(dest, src, length)
Definition: os_port.h:147
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256
Definition: tls.h:1348
@ TLS_SIGN_SCHEME_ECDSA_SECP521R1_SHA512
Definition: tls.h:1354
HashAlgoCompute compute
Definition: crypto.h:1174
error_t pemImportMldsaPrivateKey(MldsaPrivateKey *privateKey, const char_t *input, size_t length, const char_t *password)
Decode a PEM file containing a ML-DSA private key.
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
uint8_t * sk
Secret key.
Definition: mldsa.h:98
void ecdsaInitSignature(EcdsaSignature *signature)
Initialize an ECDSA signature.
Definition: ecdsa.c:74
#define MLDSA44_SIGNATURE_LEN
Definition: mldsa.h:47
@ TLS_HASH_ALGO_SHA384
Definition: tls.h:1307
error_t tls13GenerateEcdsaSignature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
ECDSA signature generation (TLS 1.3)
@ TLS_SIGN_SCHEME_ECDSA_BP512R1_TLS13_SHA512
Definition: tls.h:1357
EC private key.
Definition: ec.h:432
@ TLS_HASH_ALGO_SHA256
Definition: tls.h:1306
error_t tls13GenerateSignature(TlsContext *context, uint8_t *p, size_t *length)
Digital signature generation (TLS 1.3)
void mldsaInitPrivateKey(MldsaPrivateKey *key)
Initialize an ML-DSA private key.
Definition: mldsa.c:94
void ecFreePrivateKey(EcPrivateKey *key)
Release an EC private key.
Definition: ec.c:100
uint8_t length
Definition: tcp.h:375
#define MLDSA44_PRIVATE_KEY_LEN
Definition: mldsa.h:43
Transcript hash calculation.
RSA/DSA/ECDSA/SM2/EdDSA signature generation (TLS 1.3)
Data chunk descriptor.
Definition: crypto.h:1093
#define ntohs(value)
Definition: cpu_endian.h:421
#define SM2_TLS13_ID
Definition: sm2.h:41
@ ECDSA_SIGNATURE_FORMAT_ASN1
Definition: ecdsa.h:51
#define HTONS(value)
Definition: cpu_endian.h:410
uint8_t n
@ TLS_SIGN_SCHEME_SM2SIG_SM3
Definition: tls.h:1358
@ TLS_SIGN_SCHEME_ECDSA_BP384R1_TLS13_SHA384
Definition: tls.h:1356
@ TLS_SIGN_SCHEME_ED448
Definition: tls.h:1360
@ TLS_SIGN_SCHEME_ECDSA_SECP384R1_SHA384
Definition: tls.h:1353
Tls13DigitalSignature
Definition: tls13_misc.h:298
void ecInitPrivateKey(EcPrivateKey *key)
Initialize an EC private key.
Definition: ec.c:80
@ TLS_CONNECTION_END_CLIENT
Definition: tls.h:1050
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
TLS (Transport Layer Security)
ML-DSA private key.
Definition: mldsa.h:94
error_t tls13GenerateEd25519Signature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
Ed25519 signature generation (TLS 1.3)
error_t tlsGenerateEd25519Signature(TlsContext *context, const DataChunk *message, uint_t messageLen, uint8_t *signature, size_t *signatureLen)
Generate Ed25519 signature.
size_t length
Definition: crypto.h:1095
Common interface for hash algorithms.
Definition: crypto.h:1165
size_t skLen
Length of the secret key, in bytes.
Definition: mldsa.h:99
error_t tls13GenerateSm2Signature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
SM2 signature generation (TLS 1.3)
@ TLS_SIGN_SCHEME_ECDSA_SECP256R1_SHA256
Definition: tls.h:1352
@ ERROR_UNSUPPORTED_SIGNATURE_ALGO
Definition: error.h:132
#define osMemset(p, value, length)
Definition: os_port.h:141
#define tlsFreeMem(p)
Definition: tls.h:915
error_t tls13GenerateRsaPssSignature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
RSA-PSS signature generation (TLS 1.3)
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
error_t tls13GenerateMldsa65Signature(TlsContext *context, const uint8_t *message, size_t length, Tls13DigitalSignature *signature)
ML-DSA-65 signature generation (TLS 1.3)
error_t tlsGenerateEd448Signature(TlsContext *context, const DataChunk *message, uint_t messageLen, uint8_t *signature, size_t *signatureLen)
Generate Ed448 signature.
error_t tlsGenerateRsaPssSignature(TlsContext *context, const HashAlgo *hashAlgo, const uint8_t *digest, uint8_t *signature, size_t *signatureLen)
Generate RSA-PSS signature.
RSA/DSA/ECDSA/EdDSA signature generation.
@ ERROR_INVALID_KEY
Definition: error.h:106
Debugging facilities.
#define MLDSA87_SIGNATURE_LEN
Definition: mldsa.h:69
#define arraysize(a)
Definition: os_port.h:71
#define MLDSA87_PRIVATE_KEY_LEN
Definition: mldsa.h:65