x509_sign_verify.c
Go to the documentation of this file.
1 /**
2  * @file x509_sign_verify.c
3  * @brief RSA/DSA/ECDSA/EdDSA signature verification
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 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.4.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "pkix/x509_key_parse.h"
37 #include "pkix/x509_sign_verify.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 X509SignVerifyCallback x509SignVerifyCallback = NULL;
46 #endif
47 
48 
49 /**
50  * @brief Register signature verification callback function
51  * @param[in] callback Signature verification callback function
52  * @return Error code
53  **/
54 
56 {
57 #if (X509_SIGN_CALLBACK_SUPPORT == ENABLED)
58  //Save callback function
59  x509SignVerifyCallback = 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 Certificate signature verification
71  * @param[in] tbsData Data whose signature is to be verified
72  * @param[in] signAlgoId Signature algorithm identifier
73  * @param[in] publicKeyInfo Issuer's public key
74  * @param[in] signature Signature to be verified
75  * @return Error code
76  **/
77 
79  const X509SignAlgoId *signAlgoId,
80  const X509SubjectPublicKeyInfo *publicKeyInfo,
81  const X509OctetString *signature)
82 {
83  error_t error;
84  X509SignatureAlgo signAlgo;
85  const HashAlgo *hashAlgo;
86 
87 #if (X509_SIGN_CALLBACK_SUPPORT == ENABLED)
88  //Valid signature verification callback function?
89  if(x509SignVerifyCallback != NULL)
90  {
91  //Invoke user-defined callback
92  error = x509SignVerifyCallback(tbsData, signAlgoId, publicKeyInfo,
93  signature);
94  }
95  else
96 #endif
97  {
98  //No callback function registered
100  }
101 
102  //Check status code
104  {
105  //Retrieve the signature algorithm that was used to sign the certificate
106  error = x509GetSignHashAlgo(signAlgoId, &signAlgo, &hashAlgo);
107 
108  //Check status code
109  if(!error)
110  {
111 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
112  //RSA signature algorithm?
113  if(signAlgo == X509_SIGN_ALGO_RSA)
114  {
115  //Verify RSA signature (RSASSA-PKCS1-v1_5 signature scheme)
116  error = x509VerifyRsaSignature(tbsData, hashAlgo, publicKeyInfo,
117  signature);
118  }
119  else
120 #endif
121 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
122  //RSA-PSS signature algorithm?
123  if(signAlgo == X509_SIGN_ALGO_RSA_PSS)
124  {
125  //Verify RSA signature (RSASSA-PSS signature scheme)
126  error = x509VerifyRsaPssSignature(tbsData, hashAlgo,
127  signAlgoId->rsaPssParams.saltLen, publicKeyInfo, signature);
128  }
129  else
130 #endif
131 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
132  //DSA signature algorithm?
133  if(signAlgo == X509_SIGN_ALGO_DSA)
134  {
135  //Verify DSA signature
136  error = x509VerifyDsaSignature(tbsData, hashAlgo, publicKeyInfo,
137  signature);
138  }
139  else
140 #endif
141 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
142  //ECDSA signature algorithm?
143  if(signAlgo == X509_SIGN_ALGO_ECDSA)
144  {
145  //Verify ECDSA signature
146  error = x509VerifyEcdsaSignature(tbsData, hashAlgo, publicKeyInfo,
147  signature);
148  }
149  else
150 #endif
151 #if (X509_SM2_SUPPORT == ENABLED && SM2_SUPPORT == ENABLED)
152  //SM2 signature algorithm?
153  if(signAlgo == X509_SIGN_ALGO_SM2)
154  {
155  //Verify SM2 signature
156  error = x509VerifySm2Signature(tbsData, hashAlgo, publicKeyInfo,
157  signature);
158  }
159  else
160 #endif
161 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
162  //Ed25519 signature algorithm?
163  if(signAlgo == X509_SIGN_ALGO_ED25519)
164  {
165  //Verify Ed25519 signature (PureEdDSA mode)
166  error = x509VerifyEd25519Signature(tbsData, publicKeyInfo,
167  signature);
168  }
169  else
170 #endif
171 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
172  //Ed448 signature algorithm?
173  if(signAlgo == X509_SIGN_ALGO_ED448)
174  {
175  //Verify Ed448 signature (PureEdDSA mode)
176  error = x509VerifyEd448Signature(tbsData, publicKeyInfo,
177  signature);
178  }
179  else
180 #endif
181  //Invalid signature algorithm?
182  {
183  //Report an error
185  }
186  }
187  }
188 
189  //Return status code
190  return error;
191 }
192 
193 
194 /**
195  * @brief RSA signature verification
196  * @param[in] tbsData Data whose signature is to be verified
197  * @param[in] hashAlgo Underlying hash function
198  * @param[in] publicKeyInfo Issuer's public key
199  * @param[in] signature Signature to be verified
200  * @return Error code
201  **/
202 
204  const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo,
205  const X509OctetString *signature)
206 {
207 #if (X509_RSA_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
208  error_t error;
209  uint_t k;
210  RsaPublicKey rsaPublicKey;
211  uint8_t digest[MAX_HASH_DIGEST_SIZE];
212 
213  //Initialize RSA public key
214  rsaInitPublicKey(&rsaPublicKey);
215 
216  //Digest the TBSCertificate structure using the specified hash algorithm
217  error = hashAlgo->compute(tbsData->value, tbsData->length, digest);
218 
219  //Check status code
220  if(!error)
221  {
222  //Import the RSA public key
223  error = x509ImportRsaPublicKey(publicKeyInfo, &rsaPublicKey);
224  }
225 
226  //Check status code
227  if(!error)
228  {
229  //Get the length of the modulus, in bits
230  k = mpiGetBitLength(&rsaPublicKey.n);
231 
232  //Make sure the modulus is acceptable
233  if(k < X509_MIN_RSA_MODULUS_SIZE || k > X509_MAX_RSA_MODULUS_SIZE)
234  {
235  //Report an error
236  error = ERROR_INVALID_KEY;
237  }
238  }
239 
240  //Check status code
241  if(!error)
242  {
243  //Verify RSA signature (RSASSA-PKCS1-v1_5 signature scheme)
244  error = rsassaPkcs1v15Verify(&rsaPublicKey, hashAlgo, digest,
245  signature->value, signature->length);
246  }
247 
248  //Release previously allocated resources
249  rsaFreePublicKey(&rsaPublicKey);
250 
251  //Return status code
252  return error;
253 #else
254  //Not implemented
255  return ERROR_NOT_IMPLEMENTED;
256 #endif
257 }
258 
259 
260 /**
261  * @brief RSA-PSS signature verification
262  * @param[in] tbsData Data whose signature is to be verified
263  * @param[in] hashAlgo Underlying hash function
264  * @param[in] saltLen Length of the salt, in bytes
265  * @param[in] publicKeyInfo Issuer's public key
266  * @param[in] signature Signature to be verified
267  * @return Error code
268  **/
269 
271  const HashAlgo *hashAlgo, size_t saltLen,
272  const X509SubjectPublicKeyInfo *publicKeyInfo,
273  const X509OctetString *signature)
274 {
275 #if (X509_RSA_PSS_SUPPORT == ENABLED && RSA_SUPPORT == ENABLED)
276  error_t error;
277  uint_t k;
278  RsaPublicKey rsaPublicKey;
279  uint8_t digest[MAX_HASH_DIGEST_SIZE];
280 
281  //Initialize RSA public key
282  rsaInitPublicKey(&rsaPublicKey);
283 
284  //Digest the TBSCertificate structure using the specified hash algorithm
285  error = hashAlgo->compute(tbsData->value, tbsData->length, digest);
286 
287  //Check status code
288  if(!error)
289  {
290  //Import the RSA public key
291  error = x509ImportRsaPublicKey(publicKeyInfo, &rsaPublicKey);
292  }
293 
294  //Check status code
295  if(!error)
296  {
297  //Get the length of the modulus, in bits
298  k = mpiGetBitLength(&rsaPublicKey.n);
299 
300  //Make sure the modulus is acceptable
301  if(k < X509_MIN_RSA_MODULUS_SIZE || k > X509_MAX_RSA_MODULUS_SIZE)
302  {
303  //Report an error
304  error = ERROR_INVALID_KEY;
305  }
306  }
307 
308  //Check status code
309  if(!error)
310  {
311  //Verify RSA signature (RSASSA-PSS signature scheme)
312  error = rsassaPssVerify(&rsaPublicKey, hashAlgo, saltLen, digest,
313  signature->value, signature->length);
314  }
315 
316  //Release previously allocated resources
317  rsaFreePublicKey(&rsaPublicKey);
318 
319  //Return status code
320  return error;
321 #else
322  //Not implemented
323  return ERROR_NOT_IMPLEMENTED;
324 #endif
325 }
326 
327 
328 /**
329  * @brief DSA signature verification
330  * @param[in] tbsData Data whose signature is to be verified
331  * @param[in] hashAlgo Underlying hash function
332  * @param[in] publicKeyInfo Issuer's public key
333  * @param[in] signature Signature to be verified
334  * @return Error code
335  **/
336 
338  const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo,
339  const X509OctetString *signature)
340 {
341 #if (X509_DSA_SUPPORT == ENABLED && DSA_SUPPORT == ENABLED)
342  error_t error;
343  uint_t k;
344  DsaPublicKey dsaPublicKey;
345  DsaSignature dsaSignature;
346  uint8_t digest[MAX_HASH_DIGEST_SIZE];
347 
348  //Initialize DSA public key
349  dsaInitPublicKey(&dsaPublicKey);
350  //Initialize DSA signature
351  dsaInitSignature(&dsaSignature);
352 
353  //Digest the TBSCertificate structure using the specified hash algorithm
354  error = hashAlgo->compute(tbsData->value, tbsData->length, digest);
355 
356  //Check status code
357  if(!error)
358  {
359  //Import the DSA public key
360  error = x509ImportDsaPublicKey(publicKeyInfo, &dsaPublicKey);
361  }
362 
363  //Check status code
364  if(!error)
365  {
366  //Get the length of the prime modulus, in bits
367  k = mpiGetBitLength(&dsaPublicKey.params.p);
368 
369  //Make sure the prime modulus is acceptable
370  if(k < X509_MIN_DSA_MODULUS_SIZE || k > X509_MAX_DSA_MODULUS_SIZE)
371  {
372  //Report an error
373  error = ERROR_INVALID_KEY;
374  }
375  }
376 
377  //Check status code
378  if(!error)
379  {
380  //Read the ASN.1 encoded signature
381  error = dsaReadSignature(signature->value, signature->length,
382  &dsaSignature);
383  }
384 
385  //Check status code
386  if(!error)
387  {
388  //Verify DSA signature
389  error = dsaVerifySignature(&dsaPublicKey, digest, hashAlgo->digestSize,
390  &dsaSignature);
391  }
392 
393  //Release previously allocated resources
394  dsaFreePublicKey(&dsaPublicKey);
395  dsaFreeSignature(&dsaSignature);
396 
397  //Return status code
398  return error;
399 #else
400  //Not implemented
401  return ERROR_NOT_IMPLEMENTED;
402 #endif
403 }
404 
405 
406 /**
407  * @brief ECDSA signature verification
408  * @param[in] tbsData Data whose signature is to be verified
409  * @param[in] hashAlgo Underlying hash function
410  * @param[in] publicKeyInfo Issuer's public key
411  * @param[in] signature Signature to be verified
412  * @return Error code
413  **/
414 
416  const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo,
417  const X509OctetString *signature)
418 {
419 #if (X509_ECDSA_SUPPORT == ENABLED && ECDSA_SUPPORT == ENABLED)
420  error_t error;
421  const EcCurveInfo *curveInfo;
422  EcDomainParameters ecParams;
423  EcPublicKey ecPublicKey;
424  EcdsaSignature ecdsaSignature;
425  uint8_t digest[MAX_HASH_DIGEST_SIZE];
426 
427  //Initialize EC domain parameters
428  ecInitDomainParameters(&ecParams);
429  //Initialize EC public key
430  ecInitPublicKey(&ecPublicKey);
431  //Initialize ECDSA signature
432  ecdsaInitSignature(&ecdsaSignature);
433 
434  //Retrieve EC domain parameters
435  curveInfo = x509GetCurveInfo(publicKeyInfo->ecParams.namedCurve.value,
436  publicKeyInfo->ecParams.namedCurve.length);
437 
438  //Make sure the specified elliptic curve is supported
439  if(curveInfo != NULL)
440  {
441  //Load EC domain parameters
442  error = ecLoadDomainParameters(&ecParams, curveInfo);
443  }
444  else
445  {
446  //Invalid EC domain parameters
447  error = ERROR_BAD_CERTIFICATE;
448  }
449 
450  //Check status code
451  if(!error)
452  {
453  //Digest the TBSCertificate structure using the specified hash algorithm
454  error = hashAlgo->compute(tbsData->value, tbsData->length, digest);
455  }
456 
457  //Check status code
458  if(!error)
459  {
460  //Retrieve the EC public key
461  error = ecImport(&ecParams, &ecPublicKey.q,
462  publicKeyInfo->ecPublicKey.q.value,
463  publicKeyInfo->ecPublicKey.q.length);
464  }
465 
466  //Check status code
467  if(!error)
468  {
469  //Read the ASN.1 encoded signature
470  error = ecdsaReadSignature(signature->value, signature->length,
471  &ecdsaSignature);
472  }
473 
474  //Check status code
475  if(!error)
476  {
477  //Verify ECDSA signature
478  error = ecdsaVerifySignature(&ecParams, &ecPublicKey, digest,
479  hashAlgo->digestSize, &ecdsaSignature);
480  }
481 
482  //Release previously allocated resources
483  ecFreeDomainParameters(&ecParams);
484  ecFreePublicKey(&ecPublicKey);
485  ecdsaFreeSignature(&ecdsaSignature);
486 
487  //Return status code
488  return error;
489 #else
490  //Not implemented
491  return ERROR_NOT_IMPLEMENTED;
492 #endif
493 }
494 
495 
496 /**
497  * @brief SM2 signature verification
498  * @param[in] tbsData Data whose signature is to be verified
499  * @param[in] hashAlgo Underlying hash function
500  * @param[in] publicKeyInfo Issuer's public key
501  * @param[in] signature Signature to be verified
502  * @return Error code
503  **/
504 
506  const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo,
507  const X509OctetString *signature)
508 {
509 #if (X509_SM2_SUPPORT == ENABLED && SM2_SUPPORT == ENABLED)
510  error_t error;
511  EcDomainParameters ecParams;
512  EcPublicKey ecPublicKey;
513  EcdsaSignature sm2Signature;
514 
515  //Initialize EC domain parameters
516  ecInitDomainParameters(&ecParams);
517  //Initialize EC public key
518  ecInitPublicKey(&ecPublicKey);
519  //Initialize SM2 signature
520  ecdsaInitSignature(&sm2Signature);
521 
522  //Load EC domain parameters
523  error = ecLoadDomainParameters(&ecParams, SM2_CURVE);
524 
525  //Check status code
526  if(!error)
527  {
528  //Retrieve the EC public key
529  error = ecImport(&ecParams, &ecPublicKey.q,
530  publicKeyInfo->ecPublicKey.q.value,
531  publicKeyInfo->ecPublicKey.q.length);
532  }
533 
534  //Check status code
535  if(!error)
536  {
537  //Read the ASN.1 encoded signature
538  error = ecdsaReadSignature(signature->value, signature->length,
539  &sm2Signature);
540  }
541 
542  //Check status code
543  if(!error)
544  {
545  //Verify SM2 signature
546  error = sm2VerifySignature(&ecParams, &ecPublicKey, hashAlgo,
548  tbsData->length, &sm2Signature);
549  }
550 
551  //Release previously allocated resources
552  ecFreeDomainParameters(&ecParams);
553  ecFreePublicKey(&ecPublicKey);
554  ecdsaFreeSignature(&sm2Signature);
555 
556  //Return status code
557  return error;
558 #else
559  //Not implemented
560  return ERROR_NOT_IMPLEMENTED;
561 #endif
562 }
563 
564 
565 /**
566  * @brief Ed25519 signature verification
567  * @param[in] tbsData Data whose signature is to be verified
568  * @param[in] publicKeyInfo Issuer's public key
569  * @param[in] signature Signature to be verified
570  * @return Error code
571  **/
572 
574  const X509SubjectPublicKeyInfo *publicKeyInfo,
575  const X509OctetString *signature)
576 {
577 #if (X509_ED25519_SUPPORT == ENABLED && ED25519_SUPPORT == ENABLED)
578  error_t error;
579 
580  //Check the length of the public key
581  if(publicKeyInfo->ecPublicKey.q.length == ED25519_PUBLIC_KEY_LEN)
582  {
583  //Check the length of the EdDSA signature
584  if(signature->length == ED25519_SIGNATURE_LEN)
585  {
586  //Verify signature (PureEdDSA mode)
587  error = ed25519VerifySignature(publicKeyInfo->ecPublicKey.q.value,
588  tbsData->value, tbsData->length, NULL, 0, 0, signature->value);
589  }
590  else
591  {
592  //The length of the EdDSA signature is not valid
593  error = ERROR_INVALID_SIGNATURE;
594  }
595  }
596  else
597  {
598  //The length of the Ed25519 public key is not valid
599  error = ERROR_ILLEGAL_PARAMETER;
600  }
601 
602  //Return status code
603  return error;
604 #else
605  //Not implemented
606  return ERROR_NOT_IMPLEMENTED;
607 #endif
608 }
609 
610 
611 /**
612  * @brief Ed448 signature verification
613  * @param[in] tbsData Data whose signature is to be verified
614  * @param[in] publicKeyInfo Issuer's public key
615  * @param[in] signature Signature to be verified
616  * @return Error code
617  **/
618 
620  const X509SubjectPublicKeyInfo *publicKeyInfo,
621  const X509OctetString *signature)
622 {
623 #if (X509_ED448_SUPPORT == ENABLED && ED448_SUPPORT == ENABLED)
624  error_t error;
625 
626  //Check the length of the public key
627  if(publicKeyInfo->ecPublicKey.q.length == ED448_PUBLIC_KEY_LEN)
628  {
629  //Check the length of the EdDSA signature
630  if(signature->length == ED448_SIGNATURE_LEN)
631  {
632  //Verify signature (PureEdDSA mode)
633  error = ed448VerifySignature(publicKeyInfo->ecPublicKey.q.value,
634  tbsData->value, tbsData->length, NULL, 0, 0, signature->value);
635  }
636  else
637  {
638  //The length of the EdDSA signature is not valid
639  error = ERROR_INVALID_SIGNATURE;
640  }
641  }
642  else
643  {
644  //The length of the Ed448 public key is not valid
645  error = ERROR_ILLEGAL_PARAMETER;
646  }
647 
648  //Return status code
649  return error;
650 #else
651  //Not implemented
652  return ERROR_NOT_IMPLEMENTED;
653 #endif
654 }
655 
656 #endif
unsigned int uint_t
Definition: compiler_port.h:50
General definitions for cryptographic algorithms.
Debugging facilities.
error_t dsaReadSignature(const uint8_t *data, size_t length, DsaSignature *signature)
Read an ASN.1 encoded DSA signature.
Definition: dsa.c:349
error_t dsaVerifySignature(const DsaPublicKey *key, const uint8_t *digest, size_t digestLen, const DsaSignature *signature)
DSA signature verification.
Definition: dsa.c:585
void dsaInitSignature(DsaSignature *signature)
Initialize a DSA signature.
Definition: dsa.c:164
void dsaFreeSignature(DsaSignature *signature)
Release a DSA signature.
Definition: dsa.c:177
void dsaInitPublicKey(DsaPublicKey *key)
Initialize a DSA public key.
Definition: dsa.c:105
void dsaFreePublicKey(DsaPublicKey *key)
Release a DSA public key.
Definition: dsa.c:119
void ecFreeDomainParameters(EcDomainParameters *params)
Release EC domain parameters.
Definition: ec.c:72
void ecInitDomainParameters(EcDomainParameters *params)
Initialize EC domain parameters.
Definition: ec.c:51
void ecInitPublicKey(EcPublicKey *key)
Initialize an EC public key.
Definition: ec.c:153
error_t ecLoadDomainParameters(EcDomainParameters *params, const EcCurveInfo *curveInfo)
Load EC domain parameters.
Definition: ec.c:90
void ecFreePublicKey(EcPublicKey *key)
Release an EC public key.
Definition: ec.c:165
error_t ecImport(const EcDomainParameters *params, EcPoint *r, const uint8_t *data, size_t length)
Convert an octet string to an EC point.
Definition: ec.c:365
#define SM2_CURVE
Definition: ec_curves.h:250
error_t ecdsaReadSignature(const uint8_t *data, size_t length, EcdsaSignature *signature)
Read an ASN.1 encoded ECDSA signature.
Definition: ecdsa.c:260
__weak_func error_t ecdsaVerifySignature(const EcDomainParameters *params, const EcPublicKey *publicKey, const uint8_t *digest, size_t digestLen, const EcdsaSignature *signature)
ECDSA signature verification.
Definition: ecdsa.c:507
void ecdsaFreeSignature(EcdsaSignature *signature)
Release an ECDSA signature.
Definition: ecdsa.c:82
void ecdsaInitSignature(EcdsaSignature *signature)
Initialize an ECDSA signature.
Definition: ecdsa.c:69
error_t ed25519VerifySignature(const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, const uint8_t *signature)
EdDSA signature verification.
Definition: ed25519.c:429
#define ED25519_PUBLIC_KEY_LEN
Definition: ed25519.h:42
#define ED25519_SIGNATURE_LEN
Definition: ed25519.h:44
error_t ed448VerifySignature(const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, const uint8_t *signature)
EdDSA signature verification.
Definition: ed448.c:404
#define ED448_PUBLIC_KEY_LEN
Definition: ed448.h:42
#define ED448_SIGNATURE_LEN
Definition: ed448.h:44
error_t
Error codes.
Definition: error.h:43
@ ERROR_ILLEGAL_PARAMETER
Definition: error.h:242
@ ERROR_INVALID_KEY
Definition: error.h:106
@ ERROR_UNSUPPORTED_SIGNATURE_ALGO
Definition: error.h:132
@ ERROR_INVALID_SIGNATURE
Definition: error.h:226
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_BAD_CERTIFICATE
Definition: error.h:234
#define MAX_HASH_DIGEST_SIZE
uint_t mpiGetBitLength(const Mpi *a)
Get the actual length in bits.
Definition: mpi.c:234
#define osStrlen(s)
Definition: os_port.h:165
error_t rsassaPssVerify(const RsaPublicKey *key, const HashAlgo *hash, size_t saltLen, const uint8_t *digest, const uint8_t *signature, size_t signatureLen)
RSASSA-PSS signature verification operation.
Definition: rsa.c:1079
void rsaFreePublicKey(RsaPublicKey *key)
Release an RSA public key.
Definition: rsa.c:118
error_t rsassaPkcs1v15Verify(const RsaPublicKey *key, const HashAlgo *hash, const uint8_t *digest, const uint8_t *signature, size_t signatureLen)
RSASSA-PKCS1-v1_5 signature verification operation.
Definition: rsa.c:838
void rsaInitPublicKey(RsaPublicKey *key)
Initialize an RSA public key.
Definition: rsa.c:105
error_t sm2VerifySignature(const EcDomainParameters *params, const EcPublicKey *publicKey, const HashAlgo *hashAlgo, const char_t *id, size_t idLen, const void *message, size_t messageLen, const EcdsaSignature *signature)
SM2 signature verification.
Definition: sm2.c:216
#define SM2_DEFAULT_ID
Definition: sm2.h:39
Mpi p
Prime modulus.
Definition: dsa.h:50
DSA public key.
Definition: dsa.h:61
DsaDomainParameters params
DSA domain parameters.
Definition: dsa.h:62
DSA signature.
Definition: dsa.h:84
Elliptic curve parameters.
Definition: ec_curves.h:295
EC domain parameters.
Definition: ec.h:76
EC public key.
Definition: ec.h:94
EcPoint q
Public key.
Definition: ec.h:95
ECDSA signature.
Definition: ecdsa.h:49
Common interface for hash algorithms.
Definition: crypto.h:1014
HashAlgoCompute compute
Definition: crypto.h:1023
size_t digestSize
Definition: crypto.h:1020
RSA public key.
Definition: rsa.h:57
Mpi n
Modulus.
Definition: rsa.h:58
X509OctetString namedCurve
Definition: x509_common.h:764
X509OctetString q
Definition: x509_common.h:774
Octet string.
Definition: x509_common.h:646
const uint8_t * value
Definition: x509_common.h:647
Signature algorithm identifier.
Definition: x509_common.h:1033
X509RsaPssParameters rsaPssParams
Definition: x509_common.h:1036
Subject Public Key Information extension.
Definition: x509_common.h:783
X509EcPublicKey ecPublicKey
Definition: x509_common.h:796
X509EcParameters ecParams
Definition: x509_common.h:795
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:377
const EcCurveInfo * x509GetCurveInfo(const uint8_t *oid, size_t length)
Get the elliptic curve that matches the specified OID.
Definition: x509_common.c:910
#define X509_MAX_DSA_MODULUS_SIZE
Definition: x509_common.h:353
#define X509_MAX_RSA_MODULUS_SIZE
Definition: x509_common.h:339
X509SignatureAlgo
Signature algorithms.
Definition: x509_common.h:597
@ X509_SIGN_ALGO_ED448
Definition: x509_common.h:605
@ X509_SIGN_ALGO_ED25519
Definition: x509_common.h:604
@ X509_SIGN_ALGO_SM2
Definition: x509_common.h:603
@ X509_SIGN_ALGO_RSA
Definition: x509_common.h:599
@ X509_SIGN_ALGO_DSA
Definition: x509_common.h:601
@ X509_SIGN_ALGO_ECDSA
Definition: x509_common.h:602
@ X509_SIGN_ALGO_RSA_PSS
Definition: x509_common.h:600
error_t x509ImportRsaPublicKey(const X509SubjectPublicKeyInfo *publicKeyInfo, RsaPublicKey *publicKey)
Import an RSA public key.
error_t x509ImportDsaPublicKey(const X509SubjectPublicKeyInfo *publicKeyInfo, DsaPublicKey *publicKey)
Import a DSA public key.
Parsing of ASN.1 encoded keys.
error_t x509VerifyDsaSignature(const X509OctetString *tbsData, const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509OctetString *signature)
DSA signature verification.
error_t x509VerifyRsaPssSignature(const X509OctetString *tbsData, const HashAlgo *hashAlgo, size_t saltLen, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509OctetString *signature)
RSA-PSS signature verification.
error_t x509VerifySm2Signature(const X509OctetString *tbsData, const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509OctetString *signature)
SM2 signature verification.
error_t x509VerifyRsaSignature(const X509OctetString *tbsData, const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509OctetString *signature)
RSA signature verification.
error_t x509VerifyEd448Signature(const X509OctetString *tbsData, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509OctetString *signature)
Ed448 signature verification.
error_t x509VerifySignature(const X509OctetString *tbsData, const X509SignAlgoId *signAlgoId, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509OctetString *signature)
Certificate signature verification.
error_t x509RegisterSignVerifyCallback(X509SignVerifyCallback callback)
Register signature verification callback function.
error_t x509VerifyEcdsaSignature(const X509OctetString *tbsData, const HashAlgo *hashAlgo, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509OctetString *signature)
ECDSA signature verification.
error_t x509VerifyEd25519Signature(const X509OctetString *tbsData, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509OctetString *signature)
Ed25519 signature verification.
RSA/DSA/ECDSA/EdDSA signature verification.
error_t(* X509SignVerifyCallback)(const X509OctetString *tbsData, const X509SignAlgoId *signAlgoId, const X509SubjectPublicKeyInfo *publicKeyInfo, const X509OctetString *signature)
Signature verification callback function.