@@ -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 }
@@ -420,14 +446,21 @@ int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
420446 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
421447#endif
422448 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
449+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
450+ if (ret == WH_ERROR_OK ) {
451+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
452+ }
453+ #endif
423454 /* read response */
424455 if (ret == WH_ERROR_OK ) {
425456 /* Response packet */
426457 uint16_t res_len = 0 ;
427458 do {
428459 ret =
429- wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
460+ _wait_response_with_crypttimeout (ctx , & group , & action ,
461+ & res_len , dataPtr );
430462 } while (ret == WH_ERROR_NOTREADY );
463+
431464 if (ret == WH_ERROR_OK ) {
432465 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
433466 if (ret == WH_ERROR_OK ) {
@@ -542,14 +575,21 @@ int wh_Client_AesEcb(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
542575 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
543576#endif
544577 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
578+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
579+ if (ret == WH_ERROR_OK ) {
580+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
581+ }
582+ #endif
545583 /* read response */
546584 if (ret == WH_ERROR_OK ) {
547585 /* Response packet */
548586 uint16_t res_len = 0 ;
549587 do {
550588 ret =
551- wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
589+ _wait_response_with_crypttimeout (ctx , & group , & action ,
590+ & res_len , dataPtr );
552591 } while (ret == WH_ERROR_NOTREADY );
592+
553593 if (ret == WH_ERROR_OK ) {
554594 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
555595 if (ret == WH_ERROR_OK ) {
@@ -661,14 +701,21 @@ int wh_Client_AesCbc(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
661701 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
662702#endif
663703 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
704+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
705+ if (ret == WH_ERROR_OK ) {
706+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
707+ }
708+ #endif
664709 /* read response */
665710 if (ret == WH_ERROR_OK ) {
666711 /* Response packet */
667712 uint16_t res_len = 0 ;
668713 do {
669714 ret =
670- wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
715+ _wait_response_with_crypttimeout (ctx , & group , & action ,
716+ & res_len , dataPtr );
671717 } while (ret == WH_ERROR_NOTREADY );
718+
672719 if (ret == WH_ERROR_OK ) {
673720 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
674721 if (ret == WH_ERROR_OK ) {
@@ -795,11 +842,17 @@ int wh_Client_AesGcm(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
795842
796843 /* Send request and receive response */
797844 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
845+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
846+ if (ret == WH_ERROR_OK ) {
847+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
848+ }
849+ #endif
798850 if (ret == 0 ) {
799851 uint16_t res_len = 0 ;
800852 do {
801853 ret =
802- wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
854+ _wait_response_with_crypttimeout (ctx , & group , & action ,
855+ & res_len , dataPtr );
803856 } while (ret == WH_ERROR_NOTREADY );
804857
805858 if (ret == WH_ERROR_OK ) {
@@ -1005,11 +1058,17 @@ int wh_Client_AesGcmDma(whClientContext* ctx, Aes* aes, int enc,
10051058 if (ret == WH_ERROR_OK ) {
10061059 ret = wh_Client_SendRequest (ctx , group , action , reqLen , dataPtr );
10071060 }
1061+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
1062+ if (ret == WH_ERROR_OK ) {
1063+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
1064+ }
1065+ #endif
10081066 if (ret == 0 ) {
10091067 uint16_t resLen = 0 ;
10101068 do {
10111069 ret =
1012- wh_Client_RecvResponse (ctx , & group , & action , & resLen , dataPtr );
1070+ _wait_response_with_crypttimeout (ctx , & group , & action ,
1071+ & resLen , dataPtr );
10131072 } while (ret == WH_ERROR_NOTREADY );
10141073
10151074 if (ret == WH_ERROR_OK ) {
0 commit comments