@@ -52,11 +52,10 @@ static int _showNvm(whClientContext* clientContext);
5252
5353static int _provisionMakeCommitKey (whClientContext * clientContext );
5454static int _sha256File (const char * file_to_measure , uint8_t * hash );
55- static int _signHash ( const uint8_t * hash , size_t hash_len ,
56- uint8_t * sig , uint16_t * sig_len );
57- static int _verifyHash ( const uint8_t * hash , size_t hash_len ,
58- const uint8_t * sig , uint16_t sig_len ,
59- int32_t * rc );
55+ static int _signHash (const uint8_t * hash , size_t hash_len , uint8_t * sig ,
56+ uint16_t * sig_len );
57+ static int _verifyHash (const uint8_t * hash , size_t hash_len , const uint8_t * sig ,
58+ uint16_t sig_len , int32_t * rc );
6059
6160static int _showNvm (whClientContext * clientContext )
6261{
@@ -68,34 +67,29 @@ static int _showNvm(whClientContext* clientContext)
6867
6968 printf ("NVM Contents:\n" );
7069 do {
71- ret = wh_Client_NvmList ( clientContext ,
72- access , flags ,
73- id , NULL ,
74- & count , & id );
70+ ret = wh_Client_NvmList (clientContext , access , flags , id , NULL , & count ,
71+ & id );
7572 if (ret != WH_ERROR_OK ) {
7673 printf ("wh_Client_NvmList failed with ret:%d\n" , ret );
7774 break ;
7875 }
79- printf ( "NVM List: count=%u, id=%u\n" ,
80- ( unsigned int ) count , (unsigned int )id );
76+ printf ("NVM List: count=%u, id=%u\n" , ( unsigned int ) count ,
77+ (unsigned int )id );
8178
8279 if (count > 0 ) {
8380 whNvmSize data_len = 0 ;
8481 uint8_t label [WH_NVM_LABEL_LEN ] = {0 };
85- ret = wh_Client_NvmGetMetadata ( clientContext , id ,
86- NULL , NULL ,
87- NULL , NULL ,
88- & data_len ,
89- sizeof (label ), label );
82+ ret =
83+ wh_Client_NvmGetMetadata (clientContext , id , NULL , NULL , NULL ,
84+ NULL , & data_len , sizeof (label ), label );
9085 if (ret != WH_ERROR_OK ) {
9186 printf ("wh_Client_NvmGetMetadata failed with ret:%d\n" , ret );
9287 break ;
9388 }
9489
95- printf ( "NVM Object ID %u has label '%-*s' and size:%u\n" ,
96- (unsigned int )id ,
97- (int )sizeof (label ), label ,
98- (unsigned int )data_len );
90+ printf ("NVM Object ID %u has label '%-*s' and size:%u\n" ,
91+ (unsigned int )id , (int )sizeof (label ), label ,
92+ (unsigned int )data_len );
9993 }
10094 } while (count > 0 );
10195 printf ("End of NVM Contents\n" );
@@ -112,9 +106,9 @@ static int _provisionMakeCommitKey(whClientContext* clientContext)
112106 uint8_t keyLabel [WH_NVM_LABEL_LEN ] = {0 };
113107 memcpy (keyLabel , prov_keyLabel , sizeof (prov_keyLabel ));
114108
115- ret = wh_Client_EccMakeCacheKey (clientContext , 32 , ECC_CURVE_DEF ,
116- & keyId , WH_NVM_FLAGS_NONE ,
117- sizeof ( prov_keyLabel ), keyLabel );
109+ ret = wh_Client_EccMakeCacheKey (clientContext , 32 , ECC_CURVE_DEF , & keyId ,
110+ WH_NVM_FLAGS_NONE , sizeof ( prov_keyLabel ) ,
111+ keyLabel );
118112 if (ret == WH_ERROR_OK ) {
119113 ret = wh_Client_KeyCommit (clientContext , prov_keyId );
120114 }
@@ -139,7 +133,7 @@ static int _sha256File(const char* file_to_measure, uint8_t* hash)
139133
140134 if (ptr != (void * )-1 ) {
141135 printf ("Generating SHA256 of %s over %u bytes at %p\n" ,
142- file_to_measure , (unsigned int )size , ptr );
136+ file_to_measure , (unsigned int )size , ptr );
143137 wc_Sha256 sha256 [1 ];
144138 ret = wc_InitSha256_ex (sha256 , NULL , WH_DEV_ID );
145139 if (ret == 0 ) {
@@ -168,8 +162,8 @@ static int _sha256File(const char* file_to_measure, uint8_t* hash)
168162#endif
169163}
170164
171- static int _signHash ( const uint8_t * hash , size_t hash_len ,
172- uint8_t * sig , uint16_t * sig_len )
165+ static int _signHash (const uint8_t * hash , size_t hash_len , uint8_t * sig ,
166+ uint16_t * sig_len )
173167{
174168#ifndef WOLFHSM_CFG_NO_CRYPTO
175169 ecc_key key [1 ];
@@ -196,9 +190,8 @@ static int _signHash( const uint8_t* hash, size_t hash_len,
196190#endif
197191}
198192
199- static int _verifyHash ( const uint8_t * hash , size_t hash_len ,
200- const uint8_t * sig , uint16_t sig_len ,
201- int32_t * rc )
193+ static int _verifyHash (const uint8_t * hash , size_t hash_len , const uint8_t * sig ,
194+ uint16_t sig_len , int32_t * rc )
202195{
203196#ifndef WOLFHSM_CFG_NO_CRYPTO
204197 ecc_key key [1 ];
@@ -207,9 +200,8 @@ static int _verifyHash( const uint8_t* hash, size_t hash_len,
207200 ret = wh_Client_EccSetKeyId (key , prov_keyId );
208201 if (ret == 0 ) {
209202 int res = 0 ;
210- ret = wc_ecc_verify_hash ( sig , (word32 )sig_len ,
211- hash , (word32 )hash_len ,
212- & res , key );
203+ ret = wc_ecc_verify_hash (sig , (word32 )sig_len , hash ,
204+ (word32 )hash_len , & res , key );
213205 if (ret == 0 ) {
214206 * rc = res ;
215207 }
@@ -255,8 +247,7 @@ int wh_DemoClient_SecBoot_Provision(whClientContext* clientContext)
255247 uint16_t siglen = sizeof (sig );
256248
257249 printf ("Signing hash...\n" );
258- ret = _signHash ( hash , sizeof (hash ),
259- sig , & siglen );
250+ ret = _signHash (hash , sizeof (hash ), sig , & siglen );
260251 if (ret == WH_ERROR_OK ) {
261252 int32_t rc = 0 ;
262253 uint8_t sigLabel [WH_NVM_LABEL_LEN ] = {0 };
@@ -265,11 +256,10 @@ int wh_DemoClient_SecBoot_Provision(whClientContext* clientContext)
265256 wh_Utils_Hexdump ("Signature:\n" , sig , siglen );
266257 printf ("Storing the signature in NVM as nvmId %u\n" ,
267258 sig_nvmId );
268- ret = wh_Client_NvmAddObject (clientContext , sig_nvmId ,
269- WH_NVM_ACCESS_NONE , WH_NVM_FLAGS_NONE ,
270- sizeof (sig_nvmLabel ), sigLabel ,
271- siglen , sig ,
272- & rc );
259+ ret = wh_Client_NvmAddObject (
260+ clientContext , sig_nvmId , WH_NVM_ACCESS_NONE ,
261+ WH_NVM_FLAGS_NONE , sizeof (sig_nvmLabel ), sigLabel ,
262+ siglen , sig , & rc );
273263 printf ("Stored signature with ret:%d and rc:%d\n" , ret , rc );
274264 }
275265 }
@@ -305,9 +295,8 @@ int wh_DemoClient_SecBoot_Boot(whClientContext* clientContext)
305295 ret = wh_Client_NvmGetMetadata (clientContext ,
306296 sig_nvmId , & rc , NULL , NULL , NULL , & siglen , 0 , NULL );
307297 printf ("SecBoot got siglen %d with ret:%d rc:%d\n" , siglen , ret , rc );
308- ret = wh_Client_NvmRead (clientContext , sig_nvmId ,
309- 0 , siglen , & rc ,
310- NULL , sig );
298+ ret = wh_Client_NvmRead (clientContext , sig_nvmId , 0 , siglen , & rc , NULL ,
299+ sig );
311300 wh_Utils_Hexdump ("Signature:\n" , sig , siglen );
312301
313302
@@ -317,9 +306,7 @@ int wh_DemoClient_SecBoot_Boot(whClientContext* clientContext)
317306 if (ret == WH_ERROR_OK ) {
318307
319308 printf ("SecBoot Client Verifying signature using keyId %u\n" , prov_keyId );
320- ret = _verifyHash ( hash , sizeof (hash ),
321- sig , siglen ,
322- & rc );
309+ ret = _verifyHash (hash , sizeof (hash ), sig , siglen , & rc );
323310 printf ("ecc_verify:%d rc:%d\n" , ret , rc );
324311
325312 if ((ret == 0 ) && (rc == 1 )) {
@@ -355,7 +342,7 @@ int wh_DemoClient_SecBoot_Zeroize(whClientContext* clientContext)
355342
356343 ret = wh_Client_NvmDestroyObjects (clientContext , 1 , & sig_nvmId , & rc );
357344 printf ("Zeroize Client destroyed NVM object:%u ret:%d with rc:%d\n" ,
358- sig_nvmId , ret , rc );
345+ sig_nvmId , ret , rc );
359346
360347 _showNvm (clientContext );
361348 }
0 commit comments