x509_sign_generate.c
Go to the documentation of this file.
1 /**
2  * @file x509_sign_generate.c
3  * @brief RSA/DSA/ECDSA/EdDSA signature generation
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.2
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/crypto.h"
37 #include "ecc/ec_misc.h"
38 #include "debug.h"
39 
40 //Check crypto library configuration
41 #if (X509_SUPPORT == ENABLED)
42 
43 //Signature generation/verification callback functions
44 #if (X509_SIGN_CALLBACK_SUPPORT == ENABLED)
45  static X509SignGenCallback x509SignGenCallback = NULL;
46 #endif
47 
48 
49 /**
50  * @brief Register signature generation callback function
51  * @param[in] callback Signature generation callback function
52  * @return Error code
53  **/
54 
56 {
57 #if (X509_SIGN_CALLBACK_SUPPORT == ENABLED)
58  //Save callback function
59  x509SignGenCallback = callback;
60  //Successful processing
61  return NO_ERROR;
62 #else
63  //Not implemented
64  return ERROR_NOT_IMPLEMENTED;
65 #endif
66 }
67 
68 
69 /**
70  * @brief Signature generation
71  * @param[in] prngAlgo PRNG algorithm
72  * @param[in] prngContext Pointer to the PRNG context
73  * @param[in] tbsData Pointer to the data to be signed
74  * @param[in] signAlgoId Signature algorithm identifier
75  * @param[in] privateKey Signer's private key
76  * @param[out] output Resulting signature
77  * @param[out] written Length of the resulting signature
78  * @return Error code
79  **/
80 
81 error_t x509GenerateSignature(const PrngAlgo *prngAlgo, void *prngContext,
82  const X509OctetString *tbsData, const X509SignAlgoId *signAlgoId,
83  const void *privateKey, uint8_t *output, size_t *written)
84 {
85  error_t error;
86  X509SignatureAlgo signAlgo;
87  const HashAlgo *hashAlgo;
88 
89 #if (X509_SIGN_CALLBACK_SUPPORT == ENABLED)
90  //Valid signature generation callback function?
91  if(x509SignGenCallback != NULL)
92  {
93  //Invoke user-defined callback
94  error = x509SignGenCallback(prngAlgo, prngContext, tbsData,
95  signAlgoId, privateKey, output, written);
96  }
97  else
98 #endif
99  {
100  //No callback function registered
102  }
103 
104  //Check status code
105  if(error == ERROR_UNSUPPORTED_SIGNATURE_ALGO ||
106  error == ERROR_UNKOWN_KEY)
107  {
108  //Retrieve the signature algorithm that will be used to sign the
109  //certificate
110  error = x509GetSignHashAlgo(signAlgoId, &signAlgo, &hashAlgo);
111 
112  //Check status code
113  if(!error)
114  {
115 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
116  //RSA signature algorithm?
117  if(signAlgo == X509_SIGN_ALGO_RSA)
118  {
119  //Generate RSA signature (RSASSA-PKCS1-v1_5 signature scheme)
120  error = x509GenerateRsaSignature(tbsData, hashAlgo, privateKey,
121  output, written);
122  }
123  else
124 #endif
125 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
126  //RSA-PSS signature algorithm?
127  if(signAlgo == X509_SIGN_ALGO_RSA_PSS)
128  {
129  //Generate RSA signature (RSASSA-PSS signature scheme)
130  error = x509GenerateRsaPssSignature(prngAlgo, prngContext, tbsData,
131  hashAlgo, signAlgoId->rsaPssParams.saltLen, privateKey, output,
132  written);
133  }
134  else
135 #endif
136 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
137  //DSA signature algorithm?
138  if(signAlgo == X509_SIGN_ALGO_DSA)
139  {
140  //Generate DSA signature
141  error = x509GenerateDsaSignature(prngAlgo, prngContext, tbsData,
142  hashAlgo, privateKey, output, written);
143  }
144  else
145 #endif
146 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
147  //ECDSA signature algorithm?
148  if(signAlgo == X509_SIGN_ALGO_ECDSA)
149  {
150  //Generate ECDSA signature
151  error = x509GenerateEcdsaSignature(prngAlgo, prngContext, tbsData,
152  hashAlgo, privateKey, output, written);
153  }
154  else
155 #endif
156 #if (X509_SM2_SUPPORT == ENABLED && SM2_SUPPORT == ENABLED)
157  //SM2 signature algorithm?
158  if(signAlgo == X509_SIGN_ALGO_SM2)
159  {
160  //Generate SM2 signature
161  error = x509GenerateSm2Signature(prngAlgo, prngContext, tbsData,
162  hashAlgo, privateKey, output, written);
163  }
164  else
165 #endif
166 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
167  //Ed25519 signature algorithm?
168  if(signAlgo == X509_SIGN_ALGO_ED25519)
169  {
170  //Generate Ed25519 signature (PureEdDSA mode)
171  error = x509GenerateEd25519Signature(tbsData, privateKey, output,
172  written);
173  }
174  else
175 #endif
176 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
177  //Ed448 signature algorithm?
178  if(signAlgo == X509_SIGN_ALGO_ED448)
179  {
180  //Generate Ed448 signature (PureEdDSA mode)
181  error = x509GenerateEd448Signature(tbsData, privateKey, output,
182  written);
183  }
184  else
185 #endif
186  //Invalid signature algorithm?
187  {
188  //Report an error
190  }
191  }
192  }
193 
194  //Return status code
195  return error;
196 }
197 
198 
199 /**
200  * @brief RSA signature generation
201  * @param[in] tbsData Pointer to the data to be signed
202  * @param[in] hashAlgo Underlying hash function
203  * @param[in] privateKey Signer's private key
204  * @param[out] output Resulting signature
205  * @param[out] written Length of the resulting signature
206  * @return Error code
207  **/
208 
210  const HashAlgo *hashAlgo, const RsaPrivateKey *privateKey, uint8_t *output,
211  size_t *written)
212 {
213 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
214  error_t error;
215  uint8_t digest[MAX_HASH_DIGEST_SIZE];
216 
217  //Initialize status code
218  error = NO_ERROR;
219 
220  //If the output parameter is NULL, then the function calculates the length
221  //of the resulting signature but will not generate a signature
222  if(output != NULL)
223  {
224  //Digest the TBSCertificate structure using the specified hash algorithm
225  error = hashAlgo->compute(tbsData->value, tbsData->length, digest);
226 
227  //Check status code
228  if(!error)
229  {
230  //Generate RSA signature
231  error = rsassaPkcs1v15Sign(privateKey, hashAlgo, digest, output,
232  written);
233  }
234  }
235  else
236  {
237  //Length of the resulting RSA signature
238  *written = mpiGetByteLength(&privateKey->n);
239  }
240 
241  //Return status code
242  return error;
243 #else
244  //Not implemented
245  return ERROR_NOT_IMPLEMENTED;
246 #endif
247 }
248 
249 
250 /**
251  * @brief RSA-PSS signature generation
252  * @param[in] prngAlgo PRNG algorithm
253  * @param[in] prngContext Pointer to the PRNG context
254  * @param[in] tbsData Pointer to the data to be signed
255  * @param[in] hashAlgo Underlying hash function
256  * @param[in] saltLen Length of the salt, in bytes
257  * @param[in] privateKey Signer's private key
258  * @param[out] output Resulting signature
259  * @param[out] written Length of the resulting signature
260  * @return Error code
261  **/
262 
263 error_t x509GenerateRsaPssSignature(const PrngAlgo *prngAlgo, void *prngContext,
264  const X509OctetString *tbsData, const HashAlgo *hashAlgo, size_t saltLen,
265  const RsaPrivateKey *privateKey, uint8_t *output, size_t *written)
266 {
267 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
268  error_t error;
269  uint8_t digest[MAX_HASH_DIGEST_SIZE];
270 
271  //Initialize status code
272  error = NO_ERROR;
273 
274  //If the output parameter is NULL, then the function calculates the length
275  //of the resulting signature but will not generate a signature
276  if(output != NULL)
277  {
278  //Digest the TBSCertificate structure using the specified hash algorithm
279  error = hashAlgo->compute(tbsData->value, tbsData->length, digest);
280 
281  //Check status code
282  if(!error)
283  {
284  //Generate RSA-PSS signature
285  error = rsassaPssSign(prngAlgo, prngContext, privateKey, hashAlgo,
286  saltLen, digest, output, written);
287  }
288  }
289  else
290  {
291  //Length of the resulting RSA-PSS signature
292  *written = mpiGetByteLength(&privateKey->n);
293  }
294 
295  //Return status code
296  return error;
297 #else
298  //Not implemented
299  return ERROR_NOT_IMPLEMENTED;
300 #endif
301 }
302 
303 
304 /**
305  * @brief DSA signature generation
306  * @param[in] prngAlgo PRNG algorithm
307  * @param[in] prngContext Pointer to the PRNG context
308  * @param[in] tbsData Pointer to the data to be signed
309  * @param[in] hashAlgo Underlying hash function
310  * @param[in] privateKey Signer's private key
311  * @param[out] output Resulting signature
312  * @param[out] written Length of the resulting signature
313  * @return Error code
314  **/
315 
316 error_t x509GenerateDsaSignature(const PrngAlgo *prngAlgo, void *prngContext,
317  const X509OctetString *tbsData, const HashAlgo *hashAlgo,
318  const DsaPrivateKey *privateKey, uint8_t *output, size_t *written)
319 {
320 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
321  error_t error;
322  DsaSignature dsaSignature;
323  uint8_t digest[MAX_HASH_DIGEST_SIZE];
324 
325  //Initialize DSA signature
326  dsaInitSignature(&dsaSignature);
327 
328  //If the output parameter is NULL, then the function calculates the length
329  //of the resulting signature but will not generate a signature
330  if(output != NULL)
331  {
332  //Digest the TBSCertificate structure using the specified hash algorithm
333  error = hashAlgo->compute(tbsData->value, tbsData->length, digest);
334 
335  //Check status code
336  if(!error)
337  {
338  //Generate DSA signature
339  error = dsaGenerateSignature(prngAlgo, prngContext, privateKey, digest,
340  hashAlgo->digestSize, &dsaSignature);
341  }
342  }
343  else
344  {
345  //Generate a dummy (R, S) integer pair
346  error = mpiSubInt(&dsaSignature.r, &privateKey->params.q, 1);
347 
348  //Check status code
349  if(!error)
350  {
351  error = mpiSubInt(&dsaSignature.s, &privateKey->params.q, 1);
352  }
353  }
354 
355  //Check status code
356  if(!error)
357  {
358  //Encode DSA signature using ASN.1
359  error = dsaExportSignature(&dsaSignature, output, written);
360  }
361 
362  //Release previously allocated resources
363  dsaFreeSignature(&dsaSignature);
364 
365  //Return status code
366  return error;
367 #else
368  //Not implemented
369  return ERROR_NOT_IMPLEMENTED;
370 #endif
371 }
372 
373 
374 /**
375  * @brief ECDSA signature generation
376  * @param[in] prngAlgo PRNG algorithm
377  * @param[in] prngContext Pointer to the PRNG context
378  * @param[in] tbsData Pointer to the data to be signed
379  * @param[in] hashAlgo Underlying hash function
380  * @param[in] privateKey Signer's private key
381  * @param[out] output Resulting signature
382  * @param[out] written Length of the resulting signature
383  * @return Error code
384  **/
385 
386 error_t x509GenerateEcdsaSignature(const PrngAlgo *prngAlgo, void *prngContext,
387  const X509OctetString *tbsData, const HashAlgo *hashAlgo,
388  const EcPrivateKey *privateKey, uint8_t *output, size_t *written)
389 {
390 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
391  error_t error;
392  EcdsaSignature ecdsaSignature;
393  uint8_t digest[MAX_HASH_DIGEST_SIZE];
394 
395  //Initialize status code
396  error = NO_ERROR;
397 
398  //Initialize ECDSA signature
399  ecdsaInitSignature(&ecdsaSignature);
400 
401  //Valid elliptic curve?
402  if(privateKey->curve != NULL)
403  {
404  //If the output parameter is NULL, then the function calculates the
405  //length of the resulting signature but will not generate a signature
406  if(output != NULL)
407  {
408  //Digest the TBSCertificate structure using the specified hash
409  //algorithm
410  error = hashAlgo->compute(tbsData->value, tbsData->length, digest);
411 
412  //Check status code
413  if(!error)
414  {
415  //Generate ECDSA signature
416  error = ecdsaGenerateSignature(prngAlgo, prngContext, privateKey,
417  digest, hashAlgo->digestSize, &ecdsaSignature);
418  }
419  }
420  else
421  {
422  //Save elliptic curve parameters
423  ecdsaSignature.curve = privateKey->curve;
424 
425  //Generate a dummy (R, S) integer pair
426  ecScalarSubInt(ecdsaSignature.r, privateKey->curve->q, 1,
428 
429  ecScalarSubInt(ecdsaSignature.s, privateKey->curve->q, 1,
431  }
432 
433  //Check status code
434  if(!error)
435  {
436  //Encode ECDSA signature using ASN.1
437  error = ecdsaExportSignature(&ecdsaSignature, output, written,
439  }
440  }
441  else
442  {
443  //Invalid elliptic curve
445  }
446 
447  //Release previously allocated resources
448  ecdsaFreeSignature(&ecdsaSignature);
449 
450  //Return status code
451  return error;
452 #else
453  //Not implemented
454  return ERROR_NOT_IMPLEMENTED;
455 #endif
456 }
457 
458 
459 /**
460  * @brief SM2 signature generation
461  * @param[in] prngAlgo PRNG algorithm
462  * @param[in] prngContext Pointer to the PRNG context
463  * @param[in] tbsData Pointer to the data to be signed
464  * @param[in] hashAlgo Underlying hash function
465  * @param[in] privateKey Signer's private key
466  * @param[out] output Resulting signature
467  * @param[out] written Length of the resulting signature
468  * @return Error code
469  **/
470 
471 error_t x509GenerateSm2Signature(const PrngAlgo *prngAlgo, void *prngContext,
472  const X509OctetString *tbsData, const HashAlgo *hashAlgo,
473  const EcPrivateKey *privateKey, uint8_t *output, size_t *written)
474 {
475 #if (X509_SM2_SUPPORT == ENABLED && SM2_SUPPORT == ENABLED)
476  error_t error;
477  EcdsaSignature sm2Signature;
478 
479  //Initialize status code
480  error = NO_ERROR;
481 
482  //Initialize SM2 signature
483  ecdsaInitSignature(&sm2Signature);
484 
485  //If the output parameter is NULL, then the function calculates the length
486  //of the resulting signature but will not generate a signature
487  if(output != NULL)
488  {
489  //Generate SM2 signature
490  error = sm2GenerateSignature(prngAlgo, prngContext, privateKey, hashAlgo,
492  tbsData->length, &sm2Signature);
493  }
494  else
495  {
496  //Generate a dummy (R, S) integer pair
497  sm2Signature.curve = SM2_CURVE;
498  ecScalarSubInt(sm2Signature.r, sm2Curve.q, 1, EC_MAX_ORDER_SIZE);
499  ecScalarSubInt(sm2Signature.s, sm2Curve.q, 1, EC_MAX_ORDER_SIZE);
500  }
501 
502  //Check status code
503  if(!error)
504  {
505  //Encode SM2 signature using ASN.1
506  error = ecdsaExportSignature(&sm2Signature, output, written,
508  }
509 
510  //Release previously allocated resources
511  ecdsaFreeSignature(&sm2Signature);
512 
513  //Return status code
514  return error;
515 #else
516  //Not implemented
517  return ERROR_NOT_IMPLEMENTED;
518 #endif
519 }
520 
521 
522 /**
523  * @brief Ed25519 signature generation
524  * @param[in] tbsData Pointer to the data to be signed
525  * @param[in] privateKey Signer's private key
526  * @param[out] output Resulting signature
527  * @param[out] written Length of the resulting signature
528  * @return Error code
529  **/
530 
532  const EddsaPrivateKey *privateKey, uint8_t *output, size_t *written)
533 {
534 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
535  error_t error;
536  const uint8_t *q;
537 
538  //Initialize status code
539  error = NO_ERROR;
540 
541  //Check elliptic curve parameters
542  if(privateKey->curve == ED25519_CURVE)
543  {
544  //If the output parameter is NULL, then the function calculates the
545  //length of the resulting signature but will not generate a signature
546  if(output != NULL)
547  {
548  //The public key is optional
549  q = (privateKey->q.curve != NULL) ? privateKey->q.q : NULL;
550 
551  //Generate Ed25519 signature (PureEdDSA mode)
552  error = ed25519GenerateSignature(privateKey->d, q, tbsData->value,
553  tbsData->length, NULL, 0, 0, output);
554  }
555 
556  //Check status code
557  if(!error)
558  {
559  //Length of the resulting EdDSA signature
560  *written = ED25519_SIGNATURE_LEN;
561  }
562  }
563  else
564  {
565  //The private key is not valid
566  error = ERROR_INVALID_KEY;
567  }
568 
569  //Return status code
570  return error;
571 #else
572  //Not implemented
573  return ERROR_NOT_IMPLEMENTED;
574 #endif
575 }
576 
577 
578 /**
579  * @brief Ed448 signature generation
580  * @param[in] tbsData Pointer to the data to be signed
581  * @param[in] privateKey Signer's private key
582  * @param[out] output Resulting signature
583  * @param[out] written Length of the resulting signature
584  * @return Error code
585  **/
586 
588  const EddsaPrivateKey *privateKey, uint8_t *output, size_t *written)
589 {
590 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
591  error_t error;
592  const uint8_t *q;
593 
594  //Initialize status code
595  error = NO_ERROR;
596 
597  //Check elliptic curve parameters
598  if(privateKey->curve == ED448_CURVE)
599  {
600  //If the output parameter is NULL, then the function calculates the
601  //length of the resulting signature but will not generate a signature
602  if(output != NULL)
603  {
604  //The public key is optional
605  q = (privateKey->q.curve != NULL) ? privateKey->q.q : NULL;
606 
607  //Generate Ed448 signature (PureEdDSA mode)
608  error = ed448GenerateSignature(privateKey->d, q, tbsData->value,
609  tbsData->length, NULL, 0, 0, output);
610  }
611 
612  //Check status code
613  if(!error)
614  {
615  //Length of the resulting EdDSA signature
616  *written = ED448_SIGNATURE_LEN;
617  }
618  }
619  else
620  {
621  //The private key is not valid
622  error = ERROR_INVALID_KEY;
623  }
624 
625  //Return status code
626  return error;
627 #else
628  //Not implemented
629  return ERROR_NOT_IMPLEMENTED;
630 #endif
631 }
632 
633 #endif
__weak_func error_t ecdsaGenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const EcPrivateKey *privateKey, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
ECDSA signature generation.
Definition: ecdsa.c:492
Mpi s
Definition: dsa.h:87
ECDSA signature.
Definition: ecdsa.h:63
uint8_t d[EDDSA_MAX_PRIVATE_KEY_LEN]
Private key.
Definition: eddsa.h:77
#define PrngAlgo
Definition: crypto.h:980
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
const EcCurve * curve
Elliptic curve parameters.
Definition: eddsa.h:76
error_t x509RegisterSignGenCallback(X509SignGenCallback callback)
Register signature generation callback function.
const EcCurve * curve
Elliptic curve parameters.
Definition: ecdsa.h:64
const EcCurve * curve
Elliptic curve parameters.
Definition: ec.h:433
Mpi q
Group order.
Definition: dsa.h:51
size_t digestSize
Definition: crypto.h:1095
#define EC_MAX_ORDER_SIZE
Definition: ec.h:315
Mpi n
Modulus.
Definition: rsa.h:69
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
#define ED25519_CURVE
Definition: ec_curves.h:72
#define ED448_SIGNATURE_LEN
Definition: ed448.h:44
Mpi r
Definition: dsa.h:86
#define ED448_CURVE
Definition: ec_curves.h:73
#define ED25519_SIGNATURE_LEN
Definition: ed25519.h:44
#define osStrlen(s)
Definition: os_port.h:168
error_t x509GenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const X509OctetString *tbsData, const X509SignAlgoId *signAlgoId, const void *privateKey, uint8_t *output, size_t *written)
Signature generation.
error_t mpiSubInt(Mpi *r, const Mpi *a, mpi_sword_t b)
Subtract an integer from a multiple precision integer.
Definition: mpi.c:1018
error_t ecdsaExportSignature(const EcdsaSignature *signature, uint8_t *output, size_t *written, EcdsaSignatureFormat format)
Export an ECDSA signature.
Definition: ecdsa.c:272
error_t x509GenerateEcdsaSignature(const PrngAlgo *prngAlgo, void *prngContext, const X509OctetString *tbsData, const HashAlgo *hashAlgo, const EcPrivateKey *privateKey, uint8_t *output, size_t *written)
ECDSA signature generation.
@ ERROR_INVALID_ELLIPTIC_CURVE
Definition: error.h:134
void ecdsaFreeSignature(EcdsaSignature *signature)
Release an ECDSA signature.
Definition: ecdsa.c:86
#define MAX_HASH_DIGEST_SIZE
X509SignatureAlgo
Signature algorithms.
Definition: x509_common.h:652
error_t ed25519GenerateSignature(const uint8_t *privateKey, const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, uint8_t *signature)
EdDSA signature generation.
Definition: ed25519.c:234
error_t x509GenerateRsaPssSignature(const PrngAlgo *prngAlgo, void *prngContext, const X509OctetString *tbsData, const HashAlgo *hashAlgo, size_t saltLen, const RsaPrivateKey *privateKey, uint8_t *output, size_t *written)
RSA-PSS signature generation.
uint8_t q[EDDSA_MAX_PUBLIC_KEY_LEN]
Public key.
Definition: eddsa.h:66
const EcCurve * curve
Elliptic curve parameters.
Definition: eddsa.h:65
error_t
Error codes.
Definition: error.h:43
void dsaInitSignature(DsaSignature *signature)
Initialize a DSA signature.
Definition: dsa.c:168
HashAlgoCompute compute
Definition: crypto.h:1098
@ X509_SIGN_ALGO_ECDSA
Definition: x509_common.h:657
error_t rsassaPssSign(const PrngAlgo *prngAlgo, void *prngContext, const RsaPrivateKey *key, const HashAlgo *hash, size_t saltLen, const uint8_t *digest, uint8_t *signature, size_t *signatureLen)
RSASSA-PSS signature generation operation.
Definition: rsa.c:1189
Helper routines for ECC.
void ecdsaInitSignature(EcdsaSignature *signature)
Initialize an ECDSA signature.
Definition: ecdsa.c:73
error_t dsaGenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const DsaPrivateKey *key, const uint8_t *digest, size_t digestLen, DsaSignature *signature)
DSA signature generation.
Definition: dsa.c:457
uint32_t ecScalarSubInt(uint32_t *r, const uint32_t *a, uint32_t b, uint_t n)
Subtraction of two integers.
Definition: ec_misc.c:736
uint32_t r[EC_MAX_ORDER_SIZE]
Integer R.
Definition: ecdsa.h:65
General definitions for cryptographic algorithms.
error_t x509GetSignHashAlgo(const X509SignAlgoId *signAlgoId, X509SignatureAlgo *signAlgo, const HashAlgo **hashAlgo)
Get the signature and hash algorithms that match the specified identifier.
Definition: x509_common.c:408
EC private key.
Definition: ec.h:432
DSA private key.
Definition: dsa.h:72
#define SM2_CURVE
Definition: ec_curves.h:69
error_t x509GenerateSm2Signature(const PrngAlgo *prngAlgo, void *prngContext, const X509OctetString *tbsData, const HashAlgo *hashAlgo, const EcPrivateKey *privateKey, uint8_t *output, size_t *written)
SM2 signature generation.
@ X509_SIGN_ALGO_RSA
Definition: x509_common.h:654
error_t x509GenerateRsaSignature(const X509OctetString *tbsData, const HashAlgo *hashAlgo, const RsaPrivateKey *privateKey, uint8_t *output, size_t *written)
RSA signature generation.
EdDSA private key.
Definition: eddsa.h:75
error_t dsaExportSignature(const DsaSignature *signature, uint8_t *output, size_t *written)
Export a DSA signature to ASN.1 format.
Definition: dsa.c:334
@ ECDSA_SIGNATURE_FORMAT_ASN1
Definition: ecdsa.h:51
RSA/DSA/ECDSA/EdDSA signature generation.
@ X509_SIGN_ALGO_RSA_PSS
Definition: x509_common.h:655
error_t x509GenerateEd25519Signature(const X509OctetString *tbsData, const EddsaPrivateKey *privateKey, uint8_t *output, size_t *written)
Ed25519 signature generation.
RSA private key.
Definition: rsa.h:68
@ ERROR_UNKOWN_KEY
Definition: error.h:295
const EcCurve sm2Curve
SM2 elliptic curve.
Definition: ec_curves.c:1794
void dsaFreeSignature(DsaSignature *signature)
Release a DSA signature.
Definition: dsa.c:181
uint32_t s[EC_MAX_ORDER_SIZE]
Integer S.
Definition: ecdsa.h:66
error_t(* X509SignGenCallback)(const PrngAlgo *prngAlgo, void *prngContext, const X509OctetString *tbsData, const X509SignAlgoId *signAlgoId, const void *privateKey, uint8_t *output, size_t *written)
Signature generation callback function.
error_t x509GenerateDsaSignature(const PrngAlgo *prngAlgo, void *prngContext, const X509OctetString *tbsData, const HashAlgo *hashAlgo, const DsaPrivateKey *privateKey, uint8_t *output, size_t *written)
DSA signature generation.
EddsaPublicKey q
Public key.
Definition: eddsa.h:79
DsaDomainParameters params
DSA domain parameters.
Definition: dsa.h:73
error_t x509GenerateEd448Signature(const X509OctetString *tbsData, const EddsaPrivateKey *privateKey, uint8_t *output, size_t *written)
Ed448 signature generation.
const uint8_t * value
Definition: x509_common.h:702
Common interface for hash algorithms.
Definition: crypto.h:1089
error_t rsassaPkcs1v15Sign(const RsaPrivateKey *key, const HashAlgo *hash, const uint8_t *digest, uint8_t *signature, size_t *signatureLen)
RSASSA-PKCS1-v1_5 signature generation operation.
Definition: rsa.c:935
DSA signature.
Definition: dsa.h:85
@ ERROR_UNSUPPORTED_SIGNATURE_ALGO
Definition: error.h:132
@ X509_SIGN_ALGO_SM2
Definition: x509_common.h:658
Octet string.
Definition: x509_common.h:701
#define SM2_DEFAULT_ID
Definition: sm2.h:40
@ X509_SIGN_ALGO_ED25519
Definition: x509_common.h:659
X509RsaPssParameters rsaPssParams
Definition: x509_common.h:1091
error_t ed448GenerateSignature(const uint8_t *privateKey, const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, uint8_t *signature)
EdDSA signature generation.
Definition: ed448.c:223
Signature algorithm identifier.
Definition: x509_common.h:1088
@ ERROR_INVALID_KEY
Definition: error.h:106
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
@ X509_SIGN_ALGO_DSA
Definition: x509_common.h:656
@ X509_SIGN_ALGO_ED448
Definition: x509_common.h:660
uint_t mpiGetByteLength(const Mpi *a)
Get the actual length in bytes.
Definition: mpi.c:215