32
32
33
33
#if WPC_MSG_PR_EN
34
34
35
- #define CA2_TRANSPORT_KEY 0x8000
35
+ #define CA2_TRANSPORT_KEY 0x8000
36
36
37
37
/** \brief WPC API - Builds the CHALLENGE message
38
38
*
@@ -46,7 +46,7 @@ ATCA_STATUS wpc_msg_challenge(
46
46
)
47
47
{
48
48
ATCA_STATUS status = ATCA_BAD_PARAM ;
49
- uint8_t nonce [32 ] = {0U };
49
+ uint8_t nonce [32 ] = { 0U };
50
50
51
51
ATCA_CHECK_INVALID_MSG ((!message || !msg_len ), ATCA_BAD_PARAM , "NULL pointer received" );
52
52
@@ -61,16 +61,16 @@ ATCA_STATUS wpc_msg_challenge(
61
61
else
62
62
#endif
63
63
{
64
- if (true == atcab_is_ca2_device (atcab_get_device_type_ext (device )))
64
+ if (true == atcab_is_ca2_device (atcab_get_device_type_ext (device )))
65
65
{
66
66
#if ATCA_CA2_SUPPORT
67
- uint8_t num_in [20 ] = {0u };
68
- status = ATCA_TRACE (calib_nonce_gen_session_key (device , CA2_TRANSPORT_KEY , num_in , nonce ), "atcab_nonce_rand failed" );
67
+ uint8_t num_in [20 ] = { 0u };
68
+ status = ATCA_TRACE (calib_nonce_gen_session_key (device , CA2_TRANSPORT_KEY , num_in , nonce ), "atcab_nonce_rand failed" );
69
69
#endif
70
70
}
71
71
else
72
72
{
73
- #if ATCA_ECC_SUPPORT
73
+ #if ( ATCA_ECC_SUPPORT || ATCA_TA_SUPPORT )
74
74
status = ATCA_TRACE (atcab_random_ext (device , nonce ), "atcab_random failed" );
75
75
#endif
76
76
}
@@ -181,12 +181,12 @@ ATCA_STATUS wpc_msg_challenge_auth(
181
181
response [0 ] = WPC_CHALLENGE_AUTH_HEADER ;
182
182
response [1 ] = (WPC_PROTOCOL_MAX_VERSION << 4 ) | wpccert_get_slots_populated ();
183
183
184
- if (ATCA_SUCCESS != (status = wpccert_get_slot_info (& handle , & cert_def , NULL , NULL , slot )))
184
+ if (ATCA_SUCCESS != (status = wpccert_get_slot_info (& handle , & cert_def , NULL , NULL , NULL , slot )))
185
185
{
186
186
return wpc_msg_error (response , resp_len , WPC_ERROR_INVALID_REQUEST , 0 );
187
187
}
188
188
189
- if (NULL == cert_def )
189
+ if (NULL == cert_def )
190
190
{
191
191
status = ATCA_TRACE (ATCA_BAD_PARAM , "NULL pointer received for cert def" );
192
192
return status ;
@@ -238,7 +238,7 @@ ATCA_STATUS wpc_msg_digests(
238
238
uint8_t slot_mask = (1 << slot );
239
239
if (request [1 ] & slot_mask )
240
240
{
241
- if (ATCA_SUCCESS == wpccert_get_slot_info (& handle , NULL , NULL , NULL , slot ))
241
+ if (ATCA_SUCCESS == wpccert_get_slot_info (& handle , NULL , NULL , NULL , NULL , slot ))
242
242
{
243
243
if (ATCA_SUCCESS != (status = atcab_read_bytes_zone_ext (device , ATCA_ZONE_DATA , handle , 0 ,
244
244
digest , ATCA_SHA256_DIGEST_SIZE )))
@@ -288,18 +288,32 @@ ATCA_STATUS wpc_msg_certificate(
288
288
uint16_t length ;
289
289
uint8_t * data ;
290
290
const atcacert_def_t * cert_def ;
291
- uint8_t * mfg_cert ;
292
- uint8_t root_digest [32 ] = {0 };
291
+ uint8_t * mfg_cert = NULL ;
292
+ uint8_t root_digest [32 ] = { 0 };
293
+ uint16_t root_digest_handle = 0 ;
293
294
294
295
ATCA_CHECK_INVALID_MSG ((!buffer || !request || !response || !resp_len ),
295
296
ATCA_BAD_PARAM , "NULL pointer received" );
296
297
297
- if (ATCA_SUCCESS != (status = wpccert_get_slot_info (NULL , & cert_def , & mfg_cert , root_digest , request [1 ] & 0x03 )))
298
+ #if (ATCA_TA_SUPPORT )
299
+ if (ATCA_SUCCESS != (status = wpccert_get_slot_info (NULL , & cert_def , NULL , NULL , & root_digest_handle , request [1 ] & 0x03 )))
300
+ #else
301
+ if (ATCA_SUCCESS != (status = wpccert_get_slot_info (NULL , & cert_def , & mfg_cert , root_digest , NULL , request [1 ] & 0x03 )))
302
+ #endif
298
303
{
299
304
return wpc_msg_error (response , resp_len , WPC_ERROR_INVALID_REQUEST , 0 );
300
305
}
301
306
302
- if (NULL == cert_def )
307
+ #if ATCA_TA_SUPPORT
308
+ if (ATCA_SUCCESS != (status = atcab_read_bytes_zone_ext (device , ATCA_ZONE_DATA , root_digest_handle , 0 ,
309
+ root_digest , ATCA_SHA256_DIGEST_SIZE )))
310
+ {
311
+ ATCA_TRACE (status , "atcab_read_bytes_zone execution failed" );
312
+ return wpc_msg_error (response , resp_len , WPC_ERROR_UNSPECIFIED , 0 );
313
+ }
314
+ #endif
315
+
316
+ if (NULL == cert_def )
303
317
{
304
318
status = ATCA_TRACE (ATCA_BAD_PARAM , "NULL pointer received for Product cert def" );
305
319
return status ;
@@ -331,10 +345,10 @@ ATCA_STATUS wpc_msg_certificate(
331
345
/* Get the product certificate length if the read will include it or the total chain length */
332
346
if ((length == 0 ) || (offset < 2 ) || ((WPC_CONST_OS_MC < offset ) && ((0x600 <= offset ) || (n_mc < offset + length ))))
333
347
{
334
- if (ATCA_SUCCESS != wpccert_read_cert_size (device , cert_def , & n_puc ))
348
+ if (ATCA_SUCCESS != wpccert_read_cert_size (device , cert_def , & n_puc ))
335
349
{
336
- status = ATCA_TRACE (status , "wpccert_read_cert_size execution is failed for pdu cert" );
337
- return status ;
350
+ status = ATCA_TRACE (status , "wpccert_read_cert_size execution is failed for pdu cert" );
351
+ return status ;
338
352
}
339
353
}
340
354
ATCA_CHECK_INVALID_MSG ((n_puc > buflen || n_mc > buflen ), ATCA_SMALL_BUFFER , "temporary buffer is too small for certificates" );
@@ -394,7 +408,7 @@ ATCA_STATUS wpc_msg_certificate(
394
408
{
395
409
uint16_t mc_length = length < n_mc ? length : n_mc ;
396
410
397
- if ((NULL != mfg_cert ) && (NULL == cert_def -> ca_cert_def ))
411
+ if ((NULL != mfg_cert ) && (NULL == cert_def -> ca_cert_def ))
398
412
{
399
413
memcpy (buffer , mfg_cert , mc_length );
400
414
}
@@ -459,12 +473,12 @@ ATCA_STATUS wpc_msg_certificate(
459
473
* \return ATCA_SUCCESS on success, otherwise an error code.
460
474
*/
461
475
ATCA_STATUS wpc_auth_signature (
462
- ATCADevice device , /**< [in] Device Context */
463
- const uint8_t * chain_digest , /**< [in] WPC Authentication Cert Chain digest*/
464
- const uint16_t private_key_slot , /**< [in] WPC Authentication private key slot*/
465
- const uint8_t * request , /**< [in] WPC authentication challenge request from host */
466
- const uint8_t * other_data , /**< [in] Challegen response b0, b1 and Digest LSB*/
467
- uint8_t * const signature /**< [out] Signature for WPC authentication TBS */
476
+ ATCADevice device , /**< [in] Device Context */
477
+ const uint8_t * chain_digest , /**< [in] WPC Authentication Cert Chain digest*/
478
+ const uint16_t private_key_slot , /**< [in] WPC Authentication private key slot*/
479
+ const uint8_t * request , /**< [in] WPC authentication challenge request from host */
480
+ const uint8_t * other_data , /**< [in] Challegen response b0, b1 and Digest LSB*/
481
+ uint8_t * const signature /**< [out] Signature for WPC authentication TBS */
468
482
)
469
483
{
470
484
ATCA_STATUS status ;
0 commit comments