3939/* Helper function to send a certificate verification request */
4040static int _certVerifyRequest (whClientContext * c , const uint8_t * cert ,
4141 uint32_t cert_len , whNvmId trustedRootNvmId ,
42- uint16_t flags , whKeyId keyId );
42+ uint16_t verifyFlags , whNvmFlags cachedKeyFlags ,
43+ whKeyId keyId );
4344
4445/* Helper function to receive a verify response */
4546static int _certVerifyResponse (whClientContext * c , whKeyId * out_keyId ,
@@ -48,7 +49,8 @@ static int _certVerifyResponse(whClientContext* c, whKeyId* out_keyId,
4849/* Helper function to perform certificate verification */
4950static int _certVerify (whClientContext * c , const uint8_t * cert ,
5051 uint32_t cert_len , whNvmId trustedRootNvmId ,
51- uint16_t flags , whKeyId * inout_keyId , int32_t * out_rc );
52+ uint16_t flags , whNvmFlags cachedKeyFlags ,
53+ whKeyId * inout_keyId , int32_t * out_rc );
5254
5355
5456/* Initialize the certificate manager */
@@ -362,7 +364,8 @@ int wh_Client_CertReadTrusted(whClientContext* c, whNvmId id, uint8_t* cert,
362364/* Helper function to send a verify request */
363365static int _certVerifyRequest (whClientContext * c , const uint8_t * cert ,
364366 uint32_t cert_len , whNvmId trustedRootNvmId ,
365- uint16_t flags , whKeyId keyId )
367+ uint16_t verifyFlags , whNvmFlags cachedKeyFlags ,
368+ whKeyId keyId )
366369{
367370 whMessageCert_VerifyRequest req = {0 };
368371 uint8_t buffer [WOLFHSM_CFG_COMM_DATA_LEN ] = {0 };
@@ -377,7 +380,8 @@ static int _certVerifyRequest(whClientContext* c, const uint8_t* cert,
377380 /* Prepare request */
378381 req .cert_len = cert_len ;
379382 req .trustedRootNvmId = trustedRootNvmId ;
380- req .flags = flags ;
383+ req .flags = verifyFlags ;
384+ req .cachedKeyFlags = cachedKeyFlags ;
381385 req .keyId = keyId ;
382386
383387 /* Copy request struct and certificate data */
@@ -427,7 +431,8 @@ static int _certVerifyResponse(whClientContext* c, whKeyId* out_keyId,
427431
428432static int _certVerify (whClientContext * c , const uint8_t * cert ,
429433 uint32_t cert_len , whNvmId trustedRootNvmId ,
430- uint16_t flags , whKeyId * inout_keyId , int32_t * out_rc )
434+ uint16_t flags , whNvmFlags cachedKeyFlags ,
435+ whKeyId * inout_keyId , int32_t * out_rc )
431436{
432437 int rc = 0 ;
433438 whKeyId keyId = WH_KEYID_ERASED ;
@@ -442,7 +447,7 @@ static int _certVerify(whClientContext* c, const uint8_t* cert,
442447
443448 do {
444449 rc = _certVerifyRequest (c , cert , cert_len , trustedRootNvmId , flags ,
445- keyId );
450+ cachedKeyFlags , keyId );
446451 } while (rc == WH_ERROR_NOTREADY );
447452
448453 if (rc == 0 ) {
@@ -458,7 +463,8 @@ int wh_Client_CertVerifyRequest(whClientContext* c, const uint8_t* cert,
458463 uint32_t cert_len , whNvmId trustedRootNvmId )
459464{
460465 return _certVerifyRequest (c , cert , cert_len , trustedRootNvmId ,
461- WH_CERT_FLAGS_NONE , WH_KEYID_ERASED );
466+ WH_CERT_FLAGS_NONE , WH_NVM_FLAGS_USAGE_ANY ,
467+ WH_KEYID_ERASED );
462468}
463469
464470int wh_Client_CertVerifyResponse (whClientContext * c , int32_t * out_rc )
@@ -471,17 +477,16 @@ int wh_Client_CertVerify(whClientContext* c, const uint8_t* cert,
471477 int32_t * out_rc )
472478{
473479 return _certVerify (c , cert , cert_len , trustedRootNvmId , WH_CERT_FLAGS_NONE ,
474- NULL , out_rc );
480+ WH_NVM_FLAGS_USAGE_ANY , NULL , out_rc );
475481}
476482
477- int wh_Client_CertVerifyAndCacheLeafPubKeyRequest (whClientContext * c ,
478- const uint8_t * cert ,
479- uint32_t cert_len ,
480- whNvmId trustedRootNvmId ,
481- whKeyId keyId )
483+ int wh_Client_CertVerifyAndCacheLeafPubKeyRequest (
484+ whClientContext * c , const uint8_t * cert , uint32_t cert_len ,
485+ whNvmId trustedRootNvmId , whNvmFlags cachedKeyFlags , whKeyId keyId )
482486{
483487 return _certVerifyRequest (c , cert , cert_len , trustedRootNvmId ,
484- WH_CERT_FLAGS_CACHE_LEAF_PUBKEY , keyId );
488+ WH_CERT_FLAGS_CACHE_LEAF_PUBKEY , cachedKeyFlags ,
489+ keyId );
485490}
486491
487492int wh_Client_CertVerifyAndCacheLeafPubKeyResponse (whClientContext * c ,
@@ -494,10 +499,12 @@ int wh_Client_CertVerifyAndCacheLeafPubKeyResponse(whClientContext* c,
494499
495500int wh_Client_CertVerifyAndCacheLeafPubKey (
496501 whClientContext * c , const uint8_t * cert , uint32_t cert_len ,
497- whNvmId trustedRootNvmId , whKeyId * inout_keyId , int32_t * out_rc )
502+ whNvmId trustedRootNvmId , whNvmFlags cachedKeyFlags , whKeyId * inout_keyId ,
503+ int32_t * out_rc )
498504{
499505 return _certVerify (c , cert , cert_len , trustedRootNvmId ,
500- WH_CERT_FLAGS_CACHE_LEAF_PUBKEY , inout_keyId , out_rc );
506+ WH_CERT_FLAGS_CACHE_LEAF_PUBKEY , cachedKeyFlags ,
507+ inout_keyId , out_rc );
501508}
502509
503510#ifdef WOLFHSM_CFG_DMA
@@ -658,7 +665,8 @@ int wh_Client_CertReadTrustedDma(whClientContext* c, whNvmId id, void* cert,
658665
659666static int _certVerifyDmaRequest (whClientContext * c , const void * cert ,
660667 uint32_t cert_len , whNvmId trustedRootNvmId ,
661- uint16_t flags , whKeyId keyId )
668+ uint16_t flags , whNvmFlags cachedKeyFlags ,
669+ whKeyId keyId )
662670{
663671 whMessageCert_VerifyDmaRequest req = {0 };
664672
@@ -671,6 +679,7 @@ static int _certVerifyDmaRequest(whClientContext* c, const void* cert,
671679 req .cert_len = cert_len ;
672680 req .trustedRootNvmId = trustedRootNvmId ;
673681 req .flags = flags ;
682+ req .cachedKeyFlags = cachedKeyFlags ;
674683 req .keyId = keyId ;
675684 return wh_Client_SendRequest (c , WH_MESSAGE_GROUP_CERT ,
676685 WH_MESSAGE_CERT_ACTION_VERIFY_DMA , sizeof (req ),
@@ -713,7 +722,8 @@ static int _certVerifyDmaResponse(whClientContext* c, whKeyId* out_keyId,
713722
714723static int _certVerifyDma (whClientContext * c , const void * cert ,
715724 uint32_t cert_len , whNvmId trustedRootNvmId ,
716- uint16_t flags , whKeyId * inout_keyId , int32_t * out_rc )
725+ uint16_t flags , whNvmFlags cachedKeyFlags ,
726+ whKeyId * inout_keyId , int32_t * out_rc )
717727{
718728 int rc = 0 ;
719729 whKeyId keyId = WH_KEYID_ERASED ;
@@ -731,7 +741,7 @@ static int _certVerifyDma(whClientContext* c, const void* cert,
731741
732742 do {
733743 rc = _certVerifyDmaRequest (c , cert , cert_len , trustedRootNvmId , flags ,
734- keyId );
744+ cachedKeyFlags , keyId );
735745 } while (rc == WH_ERROR_NOTREADY );
736746
737747 if (rc == 0 ) {
@@ -747,7 +757,8 @@ int wh_Client_CertVerifyDmaRequest(whClientContext* c, const void* cert,
747757 uint32_t cert_len , whNvmId trustedRootNvmId )
748758{
749759 return _certVerifyDmaRequest (c , cert , cert_len , trustedRootNvmId ,
750- WH_CERT_FLAGS_NONE , WH_KEYID_ERASED );
760+ WH_CERT_FLAGS_NONE , WH_NVM_FLAGS_USAGE_ANY ,
761+ WH_KEYID_ERASED );
751762}
752763
753764int wh_Client_CertVerifyDmaResponse (whClientContext * c , int32_t * out_rc )
@@ -760,17 +771,17 @@ int wh_Client_CertVerifyDma(whClientContext* c, const void* cert,
760771 int32_t * out_rc )
761772{
762773 return _certVerifyDma (c , cert , cert_len , trustedRootNvmId ,
763- WH_CERT_FLAGS_NONE , NULL , out_rc );
774+ WH_CERT_FLAGS_NONE , WH_NVM_FLAGS_USAGE_ANY , NULL ,
775+ out_rc );
764776}
765777
766- int wh_Client_CertVerifyDmaAndCacheLeafPubKeyRequest (whClientContext * c ,
767- const void * cert ,
768- uint32_t cert_len ,
769- whNvmId trustedRootNvmId ,
770- whKeyId keyId )
778+ int wh_Client_CertVerifyDmaAndCacheLeafPubKeyRequest (
779+ whClientContext * c , const void * cert , uint32_t cert_len ,
780+ whNvmId trustedRootNvmId , whNvmFlags cachedKeyFlags , whKeyId keyId )
771781{
772782 return _certVerifyDmaRequest (c , cert , cert_len , trustedRootNvmId ,
773- WH_CERT_FLAGS_CACHE_LEAF_PUBKEY , keyId );
783+ WH_CERT_FLAGS_CACHE_LEAF_PUBKEY ,
784+ cachedKeyFlags , keyId );
774785}
775786
776787int wh_Client_CertVerifyDmaAndCacheLeafPubKeyResponse (whClientContext * c ,
@@ -782,10 +793,12 @@ int wh_Client_CertVerifyDmaAndCacheLeafPubKeyResponse(whClientContext* c,
782793
783794int wh_Client_CertVerifyDmaAndCacheLeafPubKey (
784795 whClientContext * c , const void * cert , uint32_t cert_len ,
785- whNvmId trustedRootNvmId , whKeyId * inout_keyId , int32_t * out_rc )
796+ whNvmId trustedRootNvmId , whNvmFlags cachedKeyFlags , whKeyId * inout_keyId ,
797+ int32_t * out_rc )
786798{
787799 return _certVerifyDma (c , cert , cert_len , trustedRootNvmId ,
788- WH_CERT_FLAGS_CACHE_LEAF_PUBKEY , inout_keyId , out_rc );
800+ WH_CERT_FLAGS_CACHE_LEAF_PUBKEY , cachedKeyFlags ,
801+ inout_keyId , out_rc );
789802}
790803
791804#endif /* WOLFHSM_CFG_DMA */
0 commit comments