@@ -372,6 +372,80 @@ static void wolfBoot_verify_signature(uint8_t key_slot,
372
372
#endif /* WOLFBOOT_SIGN_RSA2048 || WOLFBOOT_SIGN_3072 || \
373
373
* WOLFBOOT_SIGN_RSA4096 */
374
374
375
+ #ifdef WOLFBOOT_SIGN_LMS
376
+ #include <wolfssl/wolfcrypt/lms.h>
377
+ #ifdef HAVE_LIBLMS
378
+ #include <wolfssl/wolfcrypt/ext_lms.h>
379
+ #endif
380
+
381
+ static void wolfBoot_verify_signature (uint8_t key_slot ,
382
+ struct wolfBoot_image * img , uint8_t * sig )
383
+ {
384
+ int ret = 0 ;
385
+ LmsKey lms ;
386
+ word32 pub_len = 0 ;
387
+ uint8_t * pubkey = NULL ;
388
+
389
+ wolfBoot_printf ("info: LMS wolfBoot_verify_signature\n" );
390
+
391
+ pubkey = keystore_get_buffer (key_slot );
392
+ if (pubkey == NULL ) {
393
+ wolfBoot_printf ("error: Lms pubkey not found\n" );
394
+ return ;
395
+ }
396
+
397
+ ret = wc_LmsKey_Init (& lms , NULL , INVALID_DEVID );
398
+ if (ret != 0 ) {
399
+ wolfBoot_printf ("error: wc_LmsKey_Init returned %d\n" , ret );
400
+ return ;
401
+ }
402
+
403
+ /* Set the LMS parameters. */
404
+ ret = wc_LmsKey_SetParameters (& lms , LMS_LEVELS , LMS_HEIGHT ,
405
+ LMS_WINTERNITZ );
406
+ if (ret != 0 ) {
407
+ /* Something is wrong with the pub key or LMS parameters. */
408
+ wolfBoot_printf ("error: wc_LmsKey_SetParameters(%d, %d, %d)" \
409
+ " returned %d\n" , LMS_LEVELS , LMS_HEIGHT ,
410
+ LMS_WINTERNITZ , ret );
411
+ return ;
412
+ }
413
+
414
+ wolfBoot_printf ("info: using LMS parameters: L%d-H%d-W%d\n" , LMS_LEVELS ,
415
+ LMS_HEIGHT , LMS_WINTERNITZ );
416
+
417
+ /* Set the public key. */
418
+ XMEMCPY (lms .pub , pubkey , KEYSTORE_PUBKEY_SIZE );
419
+
420
+ ret = wc_LmsKey_GetPubLen (& lms , & pub_len );
421
+
422
+ if (ret != 0 ) {
423
+ /* Something is wrong with the pub key or LMS parameters. */
424
+ wolfBoot_printf ("error: wc_LmsKey_GetPubLen %d\n" , ret );
425
+ return ;
426
+ }
427
+
428
+ if (pub_len != KEYSTORE_PUBKEY_SIZE ) {
429
+ /* Something is wrong with the pub key or LMS parameters. */
430
+ wolfBoot_printf ("error: wc_LmsKey_GetPubLen mismatch: " \
431
+ " got %d, expected %d\n" , pub_len ,
432
+ KEYSTORE_PUBKEY_SIZE );
433
+ return ;
434
+ }
435
+
436
+ ret = wc_LmsKey_Verify (& lms , sig , IMAGE_SIGNATURE_SIZE , img -> sha_hash ,
437
+ WOLFBOOT_SHA_DIGEST_SIZE );
438
+
439
+ if (ret == 0 ) {
440
+ wolfBoot_printf ("info: wc_LmsKey_Verify returned OK\n" );
441
+ wolfBoot_image_confirm_signature_ok (img );
442
+ }
443
+ else {
444
+ wolfBoot_printf ("error: wc_LmsKey_Verify returned %d\n" , ret );
445
+ }
446
+ }
447
+ #endif /* WOLFBOOT_SIGN_LMS */
448
+
375
449
376
450
static uint16_t get_header_ext (struct wolfBoot_image * img , uint16_t type ,
377
451
uint8_t * * ptr );
0 commit comments