3232#include "suit/handlers.h"
3333#include "suit.h"
3434
35+ bool suit_get_public_key (uint8_t idx , cose_key_t * pkey )
36+ {
37+ if (idx >= ARRAY_SIZE (public_key )) {
38+ return false;
39+ }
40+
41+ /* Initialize key from hardcoded public key */
42+ cose_key_init (pkey );
43+ cose_key_set_keys (pkey , COSE_EC_CURVE_ED25519 , COSE_ALGO_EDDSA ,
44+ (void * )public_key [idx ], NULL , NULL );
45+ return true;
46+ }
47+
3548static int _verify_with_key (suit_manifest_t * manifest , const nanocbor_value_t * it ,
36- const void * key )
49+ cose_key_t * pkey )
3750{
3851 cose_sign_dec_t verify ;
3952 const uint8_t * cose_buf ;
@@ -48,12 +61,6 @@ static int _verify_with_key(suit_manifest_t *manifest, const nanocbor_value_t *i
4861 return SUIT_ERR_INVALID_MANIFEST ;
4962 }
5063
51- /* Initialize key from hardcoded public key */
52- cose_key_t pkey ;
53- cose_key_init (& pkey );
54- cose_key_set_keys (& pkey , COSE_EC_CURVE_ED25519 , COSE_ALGO_EDDSA ,
55- (void * )key , NULL , NULL );
56-
5764 nanocbor_value_t _cont , arr ;
5865 nanocbor_decoder_init (& _cont , auth_container , auth_container_len );
5966
@@ -87,7 +94,7 @@ static int _verify_with_key(suit_manifest_t *manifest, const nanocbor_value_t *i
8794 }
8895 LOG_INFO ("suit: verifying manifest signature\n" );
8996 int verification = cose_sign_verify (& verify , & signature ,
90- & pkey , manifest -> validation_buf ,
97+ pkey , manifest -> validation_buf ,
9198 SUIT_COSE_BUF_SIZE );
9299 if (verification == 0 ) {
93100 manifest -> state |= SUIT_STATE_COSE_AUTHENTICATED ;
@@ -111,9 +118,11 @@ static int _auth_handler(suit_manifest_t *manifest, int key,
111118 (void )key ;
112119
113120 int res = 0 ;
121+ unsigned idx = 0 ;
122+ cose_key_t pkey ;
114123
115- for ( unsigned i = 0 ; i < ARRAY_SIZE ( public_key ); ++ i ) {
116- res = _verify_with_key (manifest , it , public_key [ i ] );
124+ while ( suit_get_public_key ( idx ++ , & pkey ) ) {
125+ res = _verify_with_key (manifest , it , & pkey );
117126 if (res != SUIT_ERR_SIGNATURE ) {
118127 break ;
119128 }
0 commit comments