@@ -180,6 +180,27 @@ static int _getCryptoResponse(uint8_t* respBuf, uint16_t type,
180180
181181 return header -> rc ;
182182}
183+ static int _wait_response_with_crypttimeout (whClientContext * ctx ,
184+ uint16_t * out_group , uint16_t * out_action ,
185+ uint16_t * out_size , void * data )
186+ {
187+ int ret = WH_ERROR_OK ;
188+ do {
189+ ret = wh_Client_RecvResponse (ctx , out_group , out_action , out_size , data );
190+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
191+ if (ret == WH_ERROR_NOTREADY ) {
192+ /* Check for crypto timeout */
193+ int chk = wh_CommClient_CheckTimeout (ctx -> comm );
194+ if (chk == WH_ERROR_CRYPTIMEOUT ) {
195+ return WH_ERROR_CRYPTIMEOUT ;
196+ } else if (chk < 0 && chk != WH_ERROR_OK ) {
197+ return chk ;
198+ }
199+ }
200+ #endif
201+ } while (ret == WH_ERROR_NOTREADY );
202+ return ret ;
203+ }
183204
184205/** Implementations */
185206int wh_Client_RngGenerate (whClientContext * ctx , uint8_t * out , uint32_t size )
@@ -233,9 +254,14 @@ int wh_Client_RngGenerate(whClientContext* ctx, uint8_t* out, uint32_t size)
233254
234255 /* Send request and get response */
235256 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
257+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
258+ if (ret == WH_ERROR_OK ) {
259+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
260+ }
261+ #endif
236262 if (ret == 0 ) {
237263 do {
238- ret = wh_Client_RecvResponse (ctx , & group , & action , & res_len ,
264+ ret = _wait_response_with_crypttimeout (ctx , & group , & action , & res_len ,
239265 dataPtr );
240266 } while (ret == WH_ERROR_NOTREADY );
241267 }
@@ -418,14 +444,21 @@ int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
418444 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
419445#endif
420446 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
447+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
448+ if (ret == WH_ERROR_OK ) {
449+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
450+ }
451+ #endif
421452 /* read response */
422453 if (ret == WH_ERROR_OK ) {
423454 /* Response packet */
424455 uint16_t res_len = 0 ;
425456 do {
426457 ret =
427- wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
458+ _wait_response_with_crypttimeout (ctx , & group , & action ,
459+ & res_len , dataPtr );
428460 } while (ret == WH_ERROR_NOTREADY );
461+
429462 if (ret == WH_ERROR_OK ) {
430463 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
431464 if (ret == WH_ERROR_OK ) {
@@ -540,14 +573,21 @@ int wh_Client_AesEcb(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
540573 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
541574#endif
542575 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
576+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
577+ if (ret == WH_ERROR_OK ) {
578+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
579+ }
580+ #endif
543581 /* read response */
544582 if (ret == WH_ERROR_OK ) {
545583 /* Response packet */
546584 uint16_t res_len = 0 ;
547585 do {
548586 ret =
549- wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
587+ _wait_response_with_crypttimeout (ctx , & group , & action ,
588+ & res_len , dataPtr );
550589 } while (ret == WH_ERROR_NOTREADY );
590+
551591 if (ret == WH_ERROR_OK ) {
552592 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
553593 if (ret == WH_ERROR_OK ) {
@@ -659,14 +699,21 @@ int wh_Client_AesCbc(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
659699 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
660700#endif
661701 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
702+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
703+ if (ret == WH_ERROR_OK ) {
704+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
705+ }
706+ #endif
662707 /* read response */
663708 if (ret == WH_ERROR_OK ) {
664709 /* Response packet */
665710 uint16_t res_len = 0 ;
666711 do {
667712 ret =
668- wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
713+ _wait_response_with_crypttimeout (ctx , & group , & action ,
714+ & res_len , dataPtr );
669715 } while (ret == WH_ERROR_NOTREADY );
716+
670717 if (ret == WH_ERROR_OK ) {
671718 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
672719 if (ret == WH_ERROR_OK ) {
@@ -793,11 +840,17 @@ int wh_Client_AesGcm(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
793840
794841 /* Send request and receive response */
795842 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
843+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
844+ if (ret == WH_ERROR_OK ) {
845+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
846+ }
847+ #endif
796848 if (ret == 0 ) {
797849 uint16_t res_len = 0 ;
798850 do {
799851 ret =
800- wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
852+ _wait_response_with_crypttimeout (ctx , & group , & action ,
853+ & res_len , dataPtr );
801854 } while (ret == WH_ERROR_NOTREADY );
802855
803856 if (ret == WH_ERROR_OK ) {
@@ -987,11 +1040,17 @@ int wh_Client_AesGcmDma(whClientContext* ctx, Aes* aes, int enc,
9871040 wh_Utils_Hexdump ("[client] AESGCM DMA req packet: \n" , dataPtr , reqLen );
9881041#endif
9891042 ret = wh_Client_SendRequest (ctx , group , action , reqLen , dataPtr );
1043+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
1044+ if (ret == WH_ERROR_OK ) {
1045+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
1046+ }
1047+ #endif
9901048 if (ret == 0 ) {
9911049 uint16_t resLen = 0 ;
9921050 do {
9931051 ret =
994- wh_Client_RecvResponse (ctx , & group , & action , & resLen , dataPtr );
1052+ _wait_response_with_crypttimeout (ctx , & group , & action ,
1053+ & resLen , dataPtr );
9951054 } while (ret == WH_ERROR_NOTREADY );
9961055
9971056 if (ret == WH_ERROR_OK ) {
0 commit comments