@@ -221,11 +221,23 @@ int wh_Client_RngGenerate(whClientContext* ctx, uint8_t* out, uint32_t size)
221221
222222 /* Send request and get response */
223223 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
224+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
225+ if (ret == WH_ERROR_OK ) {
226+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
227+ }
228+ #endif
224229 if (ret == 0 ) {
225230 do {
226231 ret = wh_Client_RecvResponse (ctx , & group , & action , & res_len ,
227232 dataPtr );
228- } while (ret == WH_ERROR_NOTREADY );
233+ } while ((ret == WH_ERROR_NOTREADY )
234+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
235+ &&
236+ ((ret = wh_CommClient_CheckTimeout (ctx -> comm )) !=
237+ WH_ERROR_CRYPTIMEOUT ));
238+ #else
239+ );
240+ #endif
229241 }
230242 if (ret == WH_ERROR_OK ) {
231243 /* Get response */
@@ -339,14 +351,26 @@ int wh_Client_AesCtr(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
339351 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
340352#endif
341353 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
354+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
355+ if (ret == WH_ERROR_OK ) {
356+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
357+ }
358+ #endif
342359 /* read response */
343360 if (ret == WH_ERROR_OK ) {
344361 /* Response packet */
345362 uint16_t res_len = 0 ;
346363 do {
347364 ret =
348365 wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
349- } while (ret == WH_ERROR_NOTREADY );
366+ } while ((ret == WH_ERROR_NOTREADY )
367+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
368+ &&
369+ ((ret = wh_CommClient_CheckTimeout (ctx -> comm )) !=
370+ WH_ERROR_CRYPTIMEOUT ));
371+ #else
372+ );
373+ #endif
350374 if (ret == WH_ERROR_OK ) {
351375 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
352376 if (ret == WH_ERROR_OK ) {
@@ -460,14 +484,26 @@ int wh_Client_AesEcb(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
460484 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
461485#endif
462486 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
487+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
488+ if (ret == WH_ERROR_OK ) {
489+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
490+ }
491+ #endif
463492 /* read response */
464493 if (ret == WH_ERROR_OK ) {
465494 /* Response packet */
466495 uint16_t res_len = 0 ;
467496 do {
468497 ret =
469498 wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
470- } while (ret == WH_ERROR_NOTREADY );
499+ } while ((ret == WH_ERROR_NOTREADY )
500+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
501+ &&
502+ ((ret = wh_CommClient_CheckTimeout (ctx -> comm )) !=
503+ WH_ERROR_CRYPTIMEOUT ));
504+ #else
505+ );
506+ #endif
471507 if (ret == WH_ERROR_OK ) {
472508 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
473509 if (ret == WH_ERROR_OK ) {
@@ -576,14 +612,26 @@ int wh_Client_AesCbc(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
576612 wh_Utils_Hexdump ("[client] req packet: \n" , (uint8_t * )req , req_len );
577613#endif
578614 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
615+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
616+ if (ret == WH_ERROR_OK ) {
617+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
618+ }
619+ #endif
579620 /* read response */
580621 if (ret == WH_ERROR_OK ) {
581622 /* Response packet */
582623 uint16_t res_len = 0 ;
583624 do {
584625 ret =
585626 wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
586- } while (ret == WH_ERROR_NOTREADY );
627+ } while ((ret == WH_ERROR_NOTREADY )
628+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
629+ &&
630+ ((ret = wh_CommClient_CheckTimeout (ctx -> comm )) !=
631+ WH_ERROR_CRYPTIMEOUT ));
632+ #else
633+ );
634+ #endif
587635 if (ret == WH_ERROR_OK ) {
588636 ret = _getCryptoResponse (dataPtr , type , (uint8_t * * )& res );
589637 if (ret == WH_ERROR_OK ) {
@@ -708,12 +756,24 @@ int wh_Client_AesGcm(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
708756
709757 /* Send request and receive response */
710758 ret = wh_Client_SendRequest (ctx , group , action , req_len , dataPtr );
759+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
760+ if (ret == WH_ERROR_OK ) {
761+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
762+ }
763+ #endif
711764 if (ret == 0 ) {
712765 uint16_t res_len = 0 ;
713766 do {
714767 ret =
715768 wh_Client_RecvResponse (ctx , & group , & action , & res_len , dataPtr );
716- } while (ret == WH_ERROR_NOTREADY );
769+ } while ((ret == WH_ERROR_NOTREADY )
770+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
771+ &&
772+ ((ret = wh_CommClient_CheckTimeout (ctx -> comm )) !=
773+ WH_ERROR_CRYPTIMEOUT ));
774+ #else
775+ );
776+ #endif
717777
718778 if (ret == WH_ERROR_OK ) {
719779 /* Get response */
@@ -902,12 +962,24 @@ int wh_Client_AesGcmDma(whClientContext* ctx, Aes* aes, int enc,
902962 wh_Utils_Hexdump ("[client] AESGCM DMA req packet: \n" , dataPtr , reqLen );
903963#endif
904964 ret = wh_Client_SendRequest (ctx , group , action , reqLen , dataPtr );
965+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
966+ if (ret == WH_ERROR_OK ) {
967+ ret = wh_CommClient_InitCryptTimeout (ctx -> comm );
968+ }
969+ #endif
905970 if (ret == 0 ) {
906971 uint16_t resLen = 0 ;
907972 do {
908973 ret =
909974 wh_Client_RecvResponse (ctx , & group , & action , & resLen , dataPtr );
910- } while (ret == WH_ERROR_NOTREADY );
975+ } while ((ret == WH_ERROR_NOTREADY )
976+ #if defined(WOLFHSM_CFG_ENABLE_CLIENT_CRYPTIMEOUT )
977+ &&
978+ ((ret = wh_CommClient_CheckTimeout (ctx -> comm )) !=
979+ WH_ERROR_CRYPTIMEOUT ));
980+ #else
981+ );
982+ #endif
911983
912984 if (ret == WH_ERROR_OK ) {
913985 /* Get response */
0 commit comments