-
Notifications
You must be signed in to change notification settings - Fork 16
/
tls_sign_verify.c
702 lines (620 loc) · 20.7 KB
/
tls_sign_verify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
/**
* @file tls_sign_verify.c
* @brief RSA/DSA/ECDSA/EdDSA signature verification
*
* @section License
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
*
* This file is part of CycloneSSL Open.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @author Oryx Embedded SARL (www.oryx-embedded.com)
* @version 2.4.4
**/
//Switch to the appropriate trace level
#define TRACE_LEVEL TLS_TRACE_LEVEL
//Dependencies
#include "tls.h"
#include "tls_sign_verify.h"
#include "tls_sign_misc.h"
#include "tls_transcript_hash.h"
#include "tls_misc.h"
#include "pkc/rsa.h"
#include "pkc/dsa.h"
#include "ecc/ecdsa.h"
#include "ecc/eddsa.h"
#include "debug.h"
//Check TLS library configuration
#if (TLS_SUPPORT == ENABLED)
/**
* @brief Digital signature verification (TLS 1.0 and TLS 1.1)
* @param[in] context Pointer to the TLS context
* @param[in] p Pointer to the digitally-signed element to be verified
* @param[in] length Length of the digitally-signed element
* @return Error code
**/
error_t tlsVerifySignature(TlsContext *context, const uint8_t *p,
size_t length)
{
#if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1)
error_t error;
const TlsDigitalSignature *signature;
//The digitally-signed element does not convey the signature algorithm
//to use, and hence implementations need to inspect the certificate to
//find out the signature algorithm to use
signature = (TlsDigitalSignature *) p;
//Check the length of the digitally-signed element
if(length < sizeof(TlsDigitalSignature))
return ERROR_DECODING_FAILED;
if(length != (sizeof(TlsDigitalSignature) + ntohs(signature->length)))
return ERROR_DECODING_FAILED;
#if (TLS_RSA_SIGN_SUPPORT == ENABLED)
//RSA certificate?
if(context->peerCertType == TLS_CERT_RSA_SIGN)
{
//Digest all the handshake messages starting at ClientHello using MD5
error = tlsFinalizeTranscriptHash(context, MD5_HASH_ALGO,
context->transcriptMd5Context, "", context->clientVerifyData);
//Check status code
if(!error)
{
//Digest all the handshake messages starting at ClientHello using SHA-1
error = tlsFinalizeTranscriptHash(context, SHA1_HASH_ALGO,
context->transcriptSha1Context, "",
context->clientVerifyData + MD5_DIGEST_SIZE);
}
//Check status code
if(!error)
{
//Verify RSA signature using client's public key
error = tlsVerifyRsaSignature(&context->peerRsaPublicKey,
context->clientVerifyData, signature->value,
ntohs(signature->length));
}
}
else
#endif
#if (TLS_DSA_SIGN_SUPPORT == ENABLED)
//DSA certificate?
if(context->peerCertType == TLS_CERT_DSS_SIGN)
{
//Digest all the handshake messages starting at ClientHello
error = tlsFinalizeTranscriptHash(context, SHA1_HASH_ALGO,
context->transcriptSha1Context, "", context->clientVerifyData);
//Check status code
if(!error)
{
//Verify DSA signature using client's public key
error = tlsVerifyDsaSignature(context, context->clientVerifyData,
SHA1_DIGEST_SIZE, signature->value, ntohs(signature->length));
}
}
else
#endif
#if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
//ECDSA certificate?
if(context->peerCertType == TLS_CERT_ECDSA_SIGN)
{
//Digest all the handshake messages starting at ClientHello
error = tlsFinalizeTranscriptHash(context, SHA1_HASH_ALGO,
context->transcriptSha1Context, "", context->clientVerifyData);
//Check status code
if(!error)
{
//Verify ECDSA signature using client's public key
error = tlsVerifyEcdsaSignature(context, context->clientVerifyData,
SHA1_DIGEST_SIZE, signature->value, ntohs(signature->length));
}
}
else
#endif
//Invalid signature algorithm?
{
//Report an error
error = ERROR_INVALID_SIGNATURE;
}
//Return status code
return error;
#else
//Not implemented
return ERROR_NOT_IMPLEMENTED;
#endif
}
/**
* @brief Digital signature verification (TLS 1.2)
* @param[in] context Pointer to the TLS context
* @param[in] p Pointer to the digitally-signed element to be verified
* @param[in] length Length of the digitally-signed element
* @return Error code
**/
error_t tls12VerifySignature(TlsContext *context, const uint8_t *p,
size_t length)
{
#if (TLS_MAX_VERSION >= TLS_VERSION_1_2 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
error_t error;
TlsSignatureScheme signScheme;
const Tls12DigitalSignature *signature;
const HashAlgo *hashAlgo;
//Point to the digitally-signed element
signature = (Tls12DigitalSignature *) p;
//Check the length of the digitally-signed element
if(length < sizeof(Tls12DigitalSignature))
return ERROR_DECODING_FAILED;
if(length != (sizeof(Tls12DigitalSignature) + ntohs(signature->length)))
return ERROR_DECODING_FAILED;
//The algorithm field specifies the signature scheme
signScheme = (TlsSignatureScheme) ntohs(signature->algorithm);
//The certificates must be signed using an acceptable hash/signature
//algorithm pair (refer to RFC 5246, section 7.4.6)
if(!tlsIsSignAlgoSupported(context, signScheme))
return ERROR_ILLEGAL_PARAMETER;
//Check signature scheme
if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA ||
TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA ||
TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA)
{
//Retrieve the hash algorithm used for signing
hashAlgo = tlsGetHashAlgo(TLS_HASH_ALGO(signScheme));
}
else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256)
{
//The hashing is intrinsic to the signature algorithm
hashAlgo = tlsGetHashAlgo(TLS_HASH_ALGO_SHA256);
}
else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384)
{
//The hashing is intrinsic to the signature algorithm
hashAlgo = tlsGetHashAlgo(TLS_HASH_ALGO_SHA384);
}
else if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512 ||
signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512)
{
//The hashing is intrinsic to the signature algorithm
hashAlgo = tlsGetHashAlgo(TLS_HASH_ALGO_SHA512);
}
else
{
//Unknown signature scheme
hashAlgo = NULL;
}
//Digest all the handshake messages starting at ClientHello
if(hashAlgo == SHA1_HASH_ALGO)
{
//Use SHA-1 hash algorithm
error = tlsFinalizeTranscriptHash(context, SHA1_HASH_ALGO,
context->transcriptSha1Context, "", context->clientVerifyData);
}
else if(hashAlgo == context->cipherSuite.prfHashAlgo)
{
//Use PRF hash algorithm (SHA-256 or SHA-384)
error = tlsFinalizeTranscriptHash(context, hashAlgo,
context->transcriptHashContext, "", context->clientVerifyData);
}
else
{
//The specified hash algorithm is not supported
error = ERROR_INVALID_SIGNATURE;
}
//Check status code
if(!error)
{
#if (TLS_RSA_SIGN_SUPPORT == ENABLED)
//RSASSA-PKCS1-v1_5 signature scheme?
if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_RSA &&
context->peerCertType == TLS_CERT_RSA_SIGN)
{
//Verify RSA signature (RSASSA-PKCS1-v1_5 signature scheme)
error = rsassaPkcs1v15Verify(&context->peerRsaPublicKey,
hashAlgo, context->clientVerifyData, signature->value,
ntohs(signature->length));
}
else
#endif
#if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
//RSASSA-PSS signature scheme (with public key OID rsaEncryption)?
if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA256 ||
signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA384 ||
signScheme == TLS_SIGN_SCHEME_RSA_PSS_RSAE_SHA512)
{
//The signature algorithm must be compatible with the key in the
//server's end-entity certificate (refer to RFC 5246, section 7.4.3)
if(context->peerCertType == TLS_CERT_RSA_SIGN)
{
//Verify RSA signature (RSASSA-PSS signature scheme)
error = rsassaPssVerify(&context->peerRsaPublicKey, hashAlgo,
hashAlgo->digestSize, context->clientVerifyData,
signature->value, ntohs(signature->length));
}
else
{
//Invalid certificate
error = ERROR_INVALID_SIGNATURE;
}
}
else
#endif
#if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
//RSASSA-PSS signature scheme (with public key OID RSASSA-PSS)?
if(signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256 ||
signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384 ||
signScheme == TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512)
{
//The signature algorithm must be compatible with the key in the
//server's end-entity certificate (refer to RFC 5246, section 7.4.3)
if(context->peerCertType == TLS_CERT_RSA_PSS_SIGN)
{
//Verify RSA signature (RSASSA-PSS signature scheme)
error = rsassaPssVerify(&context->peerRsaPublicKey, hashAlgo,
hashAlgo->digestSize, context->clientVerifyData,
signature->value, ntohs(signature->length));
}
else
{
//Invalid certificate
error = ERROR_INVALID_SIGNATURE;
}
}
else
#endif
#if (TLS_DSA_SIGN_SUPPORT == ENABLED)
//DSA signature scheme?
if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_DSA &&
context->peerCertType == TLS_CERT_DSS_SIGN)
{
//Verify DSA signature using client's public key
error = tlsVerifyDsaSignature(context, context->clientVerifyData,
hashAlgo->digestSize, signature->value, ntohs(signature->length));
}
else
#endif
#if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
//ECDSA signature scheme?
if(TLS_SIGN_ALGO(signScheme) == TLS_SIGN_ALGO_ECDSA &&
context->peerCertType == TLS_CERT_ECDSA_SIGN)
{
//Verify ECDSA signature using client's public key
error = tlsVerifyEcdsaSignature(context, context->clientVerifyData,
hashAlgo->digestSize, signature->value, ntohs(signature->length));
}
else
#endif
//Invalid signature scheme?
{
//Report an error
error = ERROR_INVALID_SIGNATURE;
}
}
//Return status code
return error;
#else
//Not implemented
return ERROR_NOT_IMPLEMENTED;
#endif
}
/**
* @brief Verify RSA signature (TLS 1.0 and TLS 1.1)
* @param[in] key Signer's RSA public key
* @param[in] digest Digest of the message whose signature is to be verified
* @param[in] signature Signature to be verified
* @param[in] signatureLen Length of the signature to be verified
* @return Error code
**/
error_t tlsVerifyRsaSignature(const RsaPublicKey *key,
const uint8_t *digest, const uint8_t *signature, size_t signatureLen)
{
#if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1 && \
TLS_RSA_SIGN_SUPPORT == ENABLED)
error_t error;
uint_t k;
uint8_t *em;
Mpi s;
Mpi m;
//Debug message
TRACE_DEBUG("RSA signature verification...\r\n");
TRACE_DEBUG(" Modulus:\r\n");
TRACE_DEBUG_MPI(" ", &key->n);
TRACE_DEBUG(" Public exponent:\r\n");
TRACE_DEBUG_MPI(" ", &key->e);
TRACE_DEBUG(" Message digest:\r\n");
TRACE_DEBUG_ARRAY(" ", digest, MD5_DIGEST_SIZE + SHA1_DIGEST_SIZE);
TRACE_DEBUG(" Signature:\r\n");
TRACE_DEBUG_ARRAY(" ", signature, signatureLen);
//Get the length in octets of the modulus n
k = mpiGetByteLength(&key->n);
//Check the length of the signature
if(signatureLen != k)
return ERROR_INVALID_SIGNATURE;
//Initialize multiple-precision integers
mpiInit(&s);
mpiInit(&m);
//Allocate a memory buffer to hold the encoded message
em = tlsAllocMem(k);
//Failed to allocate memory?
if(em == NULL)
return ERROR_OUT_OF_MEMORY;
//Start of exception handling block
do
{
//Convert the signature to an integer signature representative s
error = mpiImport(&s, signature, signatureLen, MPI_FORMAT_BIG_ENDIAN);
//Conversion failed?
if(error)
break;
//Apply the RSAVP1 verification primitive
error = rsavp1(key, &s, &m);
//Any error to report?
if(error)
break;
//Convert the message representative m to an encoded message EM of
//length k octets
error = mpiExport(&m, em, k, MPI_FORMAT_BIG_ENDIAN);
//Conversion failed?
if(error)
break;
//Debug message
TRACE_DEBUG(" Encoded message\r\n");
TRACE_DEBUG_ARRAY(" ", em, k);
//Verify the encoded message EM
error = tlsVerifyRsaEm(digest, em, k);
//End of exception handling block
} while(0);
//Release multiple precision integers
mpiFree(&s);
mpiFree(&m);
//Release previously allocated memory
tlsFreeMem(em);
//Return status code
return error;
#else
//RSA signature algorithm is not supported
return ERROR_NOT_IMPLEMENTED;
#endif
}
/**
* @brief Verify RSA encoded message
* @param[in] digest Digest value
* @param[in] em Encoded message
* @param[in] emLen Length of the encoded message
* @return Error code
**/
error_t tlsVerifyRsaEm(const uint8_t *digest, const uint8_t *em, size_t emLen)
{
#if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1 && \
TLS_RSA_SIGN_SUPPORT == ENABLED)
size_t i;
size_t j;
size_t n;
uint8_t bad;
//Check the length of the encoded message
if(emLen < (MD5_DIGEST_SIZE + SHA1_DIGEST_SIZE + 11))
return ERROR_INVALID_LENGTH;
//Point to the first byte of the encoded message
i = 0;
//The first octet of EM must have hexadecimal value 0x00
bad = em[i++];
//The second octet of EM must have hexadecimal value 0x01
bad |= em[i++] ^ 0x01;
//Determine the length of the padding string PS
n = emLen - MD5_DIGEST_SIZE - SHA1_DIGEST_SIZE - 3;
//Each byte of PS must be set to 0xFF when the block type is 0x01
for(j = 0; j < n; j++)
{
bad |= em[i++] ^ 0xFF;
}
//The padding string must be followed by a 0x00 octet
bad |= em[i++];
//Recover the underlying hash value, and then compare it to the newly
//computed hash value
for(j = 0; j < (MD5_DIGEST_SIZE + SHA1_DIGEST_SIZE); j++)
{
bad |= em[i++] ^ digest[j];
}
//Verification result
return (bad != 0) ? ERROR_INVALID_SIGNATURE : NO_ERROR;
#else
//RSA signature algorithm is not supported
return ERROR_NOT_IMPLEMENTED;
#endif
}
/**
* @brief Verify DSA signature
* @param[in] context Pointer to the TLS context
* @param[in] digest Digest of the message whose signature is to be verified
* @param[in] digestLen Length in octets of the digest
* @param[in] signature Signature to be verified
* @param[in] signatureLen Length of the signature to be verified
* @return Error code
**/
error_t tlsVerifyDsaSignature(TlsContext *context, const uint8_t *digest,
size_t digestLen, const uint8_t *signature, size_t signatureLen)
{
#if (TLS_DSA_SIGN_SUPPORT == ENABLED)
error_t error;
DsaSignature dsaSignature;
//Initialize DSA signature
dsaInitSignature(&dsaSignature);
//Read the ASN.1 encoded DSA signature
error = dsaReadSignature(signature, signatureLen, &dsaSignature);
//Check status code
if(!error)
{
//DSA signature verification
error = dsaVerifySignature(&context->peerDsaPublicKey,
digest, digestLen, &dsaSignature);
}
else
{
//Malformed DSA signature
error = ERROR_INVALID_SIGNATURE;
}
//Free previously allocated resources
dsaFreeSignature(&dsaSignature);
//Return status code
return error;
#else
//DSA signature algorithm is not supported
return ERROR_NOT_IMPLEMENTED;
#endif
}
/**
* @brief Verify ECDSA signature
* @param[in] context Pointer to the TLS context
* @param[in] digest Digest of the message whose signature is to be verified
* @param[in] digestLen Length in octets of the digest
* @param[in] signature Signature to be verified
* @param[in] signatureLen Length of the signature to be verified
* @return Error code
**/
error_t tlsVerifyEcdsaSignature(TlsContext *context, const uint8_t *digest,
size_t digestLen, const uint8_t *signature, size_t signatureLen)
{
#if (TLS_ECDSA_SIGN_SUPPORT == ENABLED)
error_t error;
EcdsaSignature ecdsaSignature;
//Initialize ECDSA signature
ecdsaInitSignature(&ecdsaSignature);
//Read the ASN.1 encoded ECDSA signature
error = ecdsaReadSignature(signature, signatureLen, &ecdsaSignature);
//Check status code
if(!error)
{
#if (TLS_ECC_CALLBACK_SUPPORT == ENABLED)
//Any registered callback?
if(context->ecdsaVerifyCallback != NULL)
{
//Invoke user callback function
error = context->ecdsaVerifyCallback(context, digest, digestLen,
&ecdsaSignature);
}
else
#endif
{
//No callback function defined
error = ERROR_UNSUPPORTED_ELLIPTIC_CURVE;
}
//Check status code
if(error == ERROR_UNSUPPORTED_ELLIPTIC_CURVE ||
error == ERROR_UNSUPPORTED_HASH_ALGO)
{
//ECDSA signature verification
error = ecdsaVerifySignature(&context->peerEcParams,
&context->peerEcPublicKey, digest, digestLen, &ecdsaSignature);
}
}
else
{
//Malformed ECDSA signature
error = ERROR_INVALID_SIGNATURE;
}
//Free previously allocated resources
ecdsaFreeSignature(&ecdsaSignature);
//Return status code
return error;
#else
//ECDSA signature algorithm is not supported
return ERROR_NOT_IMPLEMENTED;
#endif
}
/**
* @brief Verify Ed25519 signature
* @param[in] context Pointer to the TLS context
* @param[in] messageChunks Array of data chunks representing the message
* whose signature is to be verified
* @param[in] signature Signature to be verified
* @param[in] signatureLen Length of the signature to be verified
* @return Error code
**/
error_t tlsVerifyEd25519Signature(TlsContext *context,
const DataChunk *messageChunks, const uint8_t *signature,
size_t signatureLen)
{
#if (TLS_ED25519_SIGN_SUPPORT == ENABLED)
error_t error;
uint8_t publicKey[ED25519_PUBLIC_KEY_LEN];
//Check the length of the EdDSA signature
if(signatureLen == ED25519_SIGNATURE_LEN)
{
//Get peer's public key
error = mpiExport(&context->peerEcPublicKey.q.x, publicKey,
ED25519_PUBLIC_KEY_LEN, MPI_FORMAT_LITTLE_ENDIAN);
//Check status code
if(!error)
{
//Verify Ed25519 signature (PureEdDSA mode)
error = ed25519VerifySignatureEx(publicKey, messageChunks, NULL, 0, 0,
signature);
}
}
else
{
//The length of the EdDSA signature is not valid
error = ERROR_INVALID_SIGNATURE;
}
//Return status code
return error;
#else
//Ed25519 signature algorithm is not supported
return ERROR_NOT_IMPLEMENTED;
#endif
}
/**
* @brief Verify Ed448 signature
* @param[in] context Pointer to the TLS context
* @param[in] messageChunks Array of data chunks representing the message
* whose signature is to be verified
* @param[in] signature Signature to be verified
* @param[in] signatureLen Length of the signature to be verified
* @return Error code
**/
error_t tlsVerifyEd448Signature(TlsContext *context,
const DataChunk *messageChunks, const uint8_t *signature,
size_t signatureLen)
{
#if (TLS_ED448_SIGN_SUPPORT == ENABLED)
error_t error;
uint8_t publicKey[ED448_PUBLIC_KEY_LEN];
//Check the length of the EdDSA signature
if(signatureLen == ED448_SIGNATURE_LEN)
{
//Get peer's public key
error = mpiExport(&context->peerEcPublicKey.q.x, publicKey,
ED448_PUBLIC_KEY_LEN, MPI_FORMAT_LITTLE_ENDIAN);
//Check status code
if(!error)
{
//Verify Ed448 signature (PureEdDSA mode)
error = ed448VerifySignatureEx(publicKey, messageChunks, NULL, 0, 0,
signature);
}
}
else
{
//The length of the EdDSA signature is not valid
error = ERROR_INVALID_SIGNATURE;
}
//Return status code
return error;
#else
//Ed448 signature algorithm is not supported
return ERROR_NOT_IMPLEMENTED;
#endif
}
#endif