@@ -233,10 +233,25 @@ int wh_Client_RngGenerate(whClientContext* ctx, uint8_t* out, uint32_t size)
233233
234234 /* Send request and get response */
235235 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
236+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
237+ if (ret == WH_ERROR_OK ) {
238+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
239+ }
240+ #endif
236241 if (ret == 0 ) {
237242 do {
238243 ret = wh_Client_RecvResponse (ctx , & group , & action , & res_len ,
239244 dataPtr );
245+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
246+ if (ret == WH_ERROR_NOTREADY ) {
247+ /* Check for crypto timeout */
248+ if (wh_CommClient_CheckTimeout (ctx -> comm )
249+ == WH_ERROR_CRYPTIMEOUT ) {
250+ ret = WH_ERROR_CRYPTIMEOUT ;
251+ break ;
252+ }
253+ }
254+ #endif
240255 } while (ret == WH_ERROR_NOTREADY );
241256 }
242257 if (ret == WH_ERROR_OK ) {
@@ -418,14 +433,30 @@ int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
418433 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
419434#endif
420435 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
436+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
437+ if (ret == WH_ERROR_OK ) {
438+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
439+ }
440+ #endif
421441 /* read response */
422442 if (ret == WH_ERROR_OK ) {
423443 /* Response packet */
424444 uint16_t res_len = 0 ;
425445 do {
426446 ret =
427447 wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
448+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
449+ if (ret == WH_ERROR_NOTREADY ) {
450+ /* Check for crypto timeout */
451+ if (wh_CommClient_CheckTimeout (ctx -> comm )
452+ == WH_ERROR_CRYPTIMEOUT ) {
453+ ret = WH_ERROR_CRYPTIMEOUT ;
454+ break ;
455+ }
456+ }
457+ #endif
428458 } while (ret == WH_ERROR_NOTREADY );
459+
429460 if (ret == WH_ERROR_OK ) {
430461 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
431462 if (ret == WH_ERROR_OK ) {
@@ -540,14 +571,30 @@ int wh_Client_AesEcb(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
540571 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
541572#endif
542573 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
574+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
575+ if (ret == WH_ERROR_OK ) {
576+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
577+ }
578+ #endif
543579 /* read response */
544580 if (ret == WH_ERROR_OK ) {
545581 /* Response packet */
546582 uint16_t res_len = 0 ;
547583 do {
548584 ret =
549585 wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
586+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
587+ if (ret == WH_ERROR_NOTREADY ) {
588+ /* Check for crypto timeout */
589+ if (wh_CommClient_CheckTimeout (ctx -> comm )
590+ == WH_ERROR_CRYPTIMEOUT ) {
591+ ret = WH_ERROR_CRYPTIMEOUT ;
592+ break ;
593+ }
594+ }
595+ #endif
550596 } while (ret == WH_ERROR_NOTREADY );
597+
551598 if (ret == WH_ERROR_OK ) {
552599 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
553600 if (ret == WH_ERROR_OK ) {
@@ -659,14 +706,30 @@ int wh_Client_AesCbc(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
659706 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
660707#endif
661708 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
709+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
710+ if (ret == WH_ERROR_OK ) {
711+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
712+ }
713+ #endif
662714 /* read response */
663715 if (ret == WH_ERROR_OK ) {
664716 /* Response packet */
665717 uint16_t res_len = 0 ;
666718 do {
667719 ret =
668720 wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
721+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
722+ if (ret == WH_ERROR_NOTREADY ) {
723+ /* Check for crypto timeout */
724+ if (wh_CommClient_CheckTimeout (ctx -> comm )
725+ == WH_ERROR_CRYPTIMEOUT ) {
726+ ret = WH_ERROR_CRYPTIMEOUT ;
727+ break ;
728+ }
729+ }
730+ #endif
669731 } while (ret == WH_ERROR_NOTREADY );
732+
670733 if (ret == WH_ERROR_OK ) {
671734 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
672735 if (ret == WH_ERROR_OK ) {
@@ -793,11 +856,26 @@ int wh_Client_AesGcm(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
793856
794857 /* Send request and receive response */
795858 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
859+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
860+ if (ret == WH_ERROR_OK ) {
861+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
862+ }
863+ #endif
796864 if (ret == 0 ) {
797865 uint16_t res_len = 0 ;
798866 do {
799867 ret =
800868 wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
869+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
870+ if (ret == WH_ERROR_NOTREADY ) {
871+ /* Check for crypto timeout */
872+ if (wh_CommClient_CheckTimeout (ctx -> comm )
873+ == WH_ERROR_CRYPTIMEOUT ) {
874+ ret = WH_ERROR_CRYPTIMEOUT ;
875+ break ;
876+ }
877+ }
878+ #endif
801879 } while (ret == WH_ERROR_NOTREADY );
802880
803881 if (ret == WH_ERROR_OK ) {
@@ -987,11 +1065,26 @@ int wh_Client_AesGcmDma(whClientContext* ctx, Aes* aes, int enc,
9871065 wh_Utils_Hexdump ("[client] AESGCM DMA req packet: \n" , dataPtr , reqLen );
9881066#endif
9891067 ret = wh_Client_SendRequest (ctx , group , action , reqLen , dataPtr );
1068+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
1069+ if (ret == WH_ERROR_OK ) {
1070+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
1071+ }
1072+ #endif
9901073 if (ret == 0 ) {
9911074 uint16_t resLen = 0 ;
9921075 do {
9931076 ret =
9941077 wh_Client_RecvResponse (ctx , & group , & action , & resLen , dataPtr );
1078+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
1079+ if (ret == WH_ERROR_NOTREADY ) {
1080+ /* Check for crypto timeout */
1081+ if (wh_CommClient_CheckTimeout (ctx -> comm )
1082+ == WH_ERROR_CRYPTIMEOUT ) {
1083+ ret = WH_ERROR_CRYPTIMEOUT ;
1084+ break ;
1085+ }
1086+ }
1087+ #endif
9951088 } while (ret == WH_ERROR_NOTREADY );
9961089
9971090 if (ret == WH_ERROR_OK ) {
0 commit comments