@@ -290,7 +290,9 @@ int wh_Client_RngGenerateDma(whClientContext* ctx, uint8_t* out, uint32_t size)
290290 ret = wh_Client_DmaProcessClientAddress (
291291 ctx , (uintptr_t )out , (void * * )& outAddr , req -> output .sz ,
292292 WH_DMA_OPER_CLIENT_WRITE_PRE , (whDmaFlags ){0 });
293- req -> output .addr = outAddr ;
293+ if (ret == WH_ERROR_OK ) {
294+ req -> output .addr = outAddr ;
295+ }
294296
295297 if (ret == WH_ERROR_OK ) {
296298 /* Send the request to the server */
@@ -912,39 +914,49 @@ int wh_Client_AesGcmDma(whClientContext* ctx, Aes* aes, int enc,
912914 ret = wh_Client_DmaProcessClientAddress (
913915 ctx , (uintptr_t )key , (void * * )& keyAddr , req -> key .sz ,
914916 WH_DMA_OPER_CLIENT_READ_PRE , (whDmaFlags ){0 });
915- req -> key .addr = keyAddr ;
917+ if (ret == WH_ERROR_OK ) {
918+ req -> key .addr = keyAddr ;
919+ }
916920 }
917921
918922 if (ret == WH_ERROR_OK && in != NULL ) {
919923 req -> input .sz = len ;
920924 ret = wh_Client_DmaProcessClientAddress (
921925 ctx , (uintptr_t )in , (void * * )& inAddr , req -> input .sz ,
922926 WH_DMA_OPER_CLIENT_READ_PRE , (whDmaFlags ){0 });
923- req -> input .addr = inAddr ;
927+ if (ret == WH_ERROR_OK ) {
928+ req -> input .addr = inAddr ;
929+ }
924930 }
925931
926932 if (ret == WH_ERROR_OK && out != NULL ) {
927933 req -> output .sz = len ;
928934 ret = wh_Client_DmaProcessClientAddress (
929935 ctx , (uintptr_t )out , (void * * )& outAddr , req -> output .sz ,
930936 WH_DMA_OPER_CLIENT_WRITE_PRE , (whDmaFlags ){0 });
931- req -> output .addr = outAddr ;
937+ if (ret == WH_ERROR_OK ) {
938+ req -> output .addr = outAddr ;
939+ }
932940 }
933941
934942 if (ret == WH_ERROR_OK && iv != NULL ) {
935943 req -> iv .sz = iv_len ;
936944 ret = wh_Client_DmaProcessClientAddress (
937945 ctx , (uintptr_t )iv , (void * * )& ivAddr , req -> iv .sz ,
938946 WH_DMA_OPER_CLIENT_READ_PRE , (whDmaFlags ){0 });
939- req -> iv .addr = ivAddr ;
947+ if (ret == WH_ERROR_OK ) {
948+ req -> iv .addr = ivAddr ;
949+ }
940950 }
941951
942952 if (ret == WH_ERROR_OK && authin != NULL ) {
943953 req -> aad .sz = authin_len ;
944954 ret = wh_Client_DmaProcessClientAddress (
945955 ctx , (uintptr_t )authin , (void * * )& aadAddr , req -> aad .sz ,
946956 WH_DMA_OPER_CLIENT_READ_PRE , (whDmaFlags ){0 });
947- req -> aad .addr = aadAddr ;
957+ if (ret == WH_ERROR_OK ) {
958+ req -> aad .addr = aadAddr ;
959+ }
948960 }
949961
950962 /* set auth tag by direction */
@@ -954,7 +966,9 @@ int wh_Client_AesGcmDma(whClientContext* ctx, Aes* aes, int enc,
954966 ret = wh_Client_DmaProcessClientAddress (
955967 ctx , (uintptr_t )dec_tag , (void * * )& authTagAddr , req -> authTag .sz ,
956968 WH_DMA_OPER_CLIENT_READ_PRE , (whDmaFlags ){0 });
957- req -> authTag .addr = authTagAddr ;
969+ if (ret == WH_ERROR_OK ) {
970+ req -> authTag .addr = authTagAddr ;
971+ }
958972#ifdef DEBUG_CRYPTOCB_VERBOSE
959973 wh_Utils_Hexdump ("[client] dec tag: \n" , dec_tag , tag_len );
960974#endif
@@ -965,7 +979,9 @@ int wh_Client_AesGcmDma(whClientContext* ctx, Aes* aes, int enc,
965979 ret = wh_Client_DmaProcessClientAddress (
966980 ctx , (uintptr_t )enc_tag , (void * * )& authTagAddr , req -> authTag .sz ,
967981 WH_DMA_OPER_CLIENT_WRITE_PRE , (whDmaFlags ){0 });
968- req -> authTag .addr = authTagAddr ;
982+ if (ret == WH_ERROR_OK ) {
983+ req -> authTag .addr = authTagAddr ;
984+ }
969985#ifdef DEBUG_CRYPTOCB_VERBOSE
970986 wh_Utils_Hexdump ("[client] enc tag buffer: \n" , enc_tag , tag_len );
971987#endif
@@ -976,7 +992,9 @@ int wh_Client_AesGcmDma(whClientContext* ctx, Aes* aes, int enc,
976992#ifdef DEBUG_CRYPTOCB_VERBOSE
977993 wh_Utils_Hexdump ("[client] AESGCM DMA req packet: \n" , dataPtr , reqLen );
978994#endif
979- ret = wh_Client_SendRequest (ctx , group , action , reqLen , dataPtr );
995+ if (ret == WH_ERROR_OK ) {
996+ ret = wh_Client_SendRequest (ctx , group , action , reqLen , dataPtr );
997+ }
980998 if (ret == 0 ) {
981999 uint16_t resLen = 0 ;
9821000 do {
@@ -3014,7 +3032,9 @@ int wh_Client_CmacDma(whClientContext* ctx, Cmac* cmac, CmacType type,
30143032 ret = wh_Client_DmaProcessClientAddress (
30153033 ctx , (uintptr_t )in , (void * * )& inAddr , req -> input .sz ,
30163034 WH_DMA_OPER_CLIENT_READ_PRE , (whDmaFlags ){0 });
3017- req -> input .addr = inAddr ;
3035+ if (ret == WH_ERROR_OK ) {
3036+ req -> input .addr = inAddr ;
3037+ }
30183038 }
30193039
30203040 if (ret == WH_ERROR_OK && outMac != NULL ) {
@@ -3023,11 +3043,13 @@ int wh_Client_CmacDma(whClientContext* ctx, Cmac* cmac, CmacType type,
30233043 ret = wh_Client_DmaProcessClientAddress (
30243044 ctx , (uintptr_t )outMac , (void * * )& outAddr , req -> output .sz ,
30253045 WH_DMA_OPER_CLIENT_WRITE_PRE , (whDmaFlags ){0 });
3026- req -> output .addr = outAddr ;
3027- req -> finalize = 1 ;
3028- /* Also set local flag, as request will be trashed after a response
3029- * is received */
3030- finalize = 1 ;
3046+ if (ret == WH_ERROR_OK ) {
3047+ req -> output .addr = outAddr ;
3048+ req -> finalize = 1 ;
3049+ /* Also set local flag, as request will be trashed after a response
3050+ * is received */
3051+ finalize = 1 ;
3052+ }
30313053 }
30323054
30333055 /* If this is just a deferred initialization (NULL key, but keyId set),
@@ -3037,11 +3059,13 @@ int wh_Client_CmacDma(whClientContext* ctx, Cmac* cmac, CmacType type,
30373059 return 0 ;
30383060 }
30393061
3040- /* Send the request */
3041- ret = wh_Client_SendRequest (
3042- ctx , WH_MESSAGE_GROUP_CRYPTO_DMA , WC_ALGO_TYPE_CMAC ,
3043- sizeof (whMessageCrypto_GenericRequestHeader ) + sizeof (* req ),
3044- (uint8_t * )dataPtr );
3062+ if (ret == WH_ERROR_OK ) {
3063+ /* Send the request */
3064+ ret = wh_Client_SendRequest (
3065+ ctx , WH_MESSAGE_GROUP_CRYPTO_DMA , WC_ALGO_TYPE_CMAC ,
3066+ sizeof (whMessageCrypto_GenericRequestHeader ) + sizeof (* req ),
3067+ (uint8_t * )dataPtr );
3068+ }
30453069
30463070 if (ret == WH_ERROR_OK ) {
30473071 uint16_t respSz = 0 ;
@@ -4887,7 +4911,9 @@ static int _MlDsaMakeKeyDma(whClientContext* ctx, int level,
48874911 ret = wh_Client_DmaProcessClientAddress (
48884912 ctx , (uintptr_t )buffer , (void * * )& keyAddr , keyAddrSz ,
48894913 WH_DMA_OPER_CLIENT_WRITE_PRE , (whDmaFlags ){0 });
4890- req -> key .addr = (uint64_t )(uintptr_t )keyAddr ;
4914+ if (ret == WH_ERROR_OK ) {
4915+ req -> key .addr = (uint64_t )(uintptr_t )keyAddr ;
4916+ }
48914917
48924918 if ((label != NULL ) && (label_len > 0 )) {
48934919 if (label_len > WH_NVM_LABEL_LEN ) {
@@ -4897,8 +4923,10 @@ static int _MlDsaMakeKeyDma(whClientContext* ctx, int level,
48974923 req -> labelSize = label_len ;
48984924 }
48994925
4900- ret = wh_Client_SendRequest (ctx , group , action , req_len ,
4901- (uint8_t * )dataPtr );
4926+ if (ret == WH_ERROR_OK ) {
4927+ ret = wh_Client_SendRequest (ctx , group , action , req_len ,
4928+ (uint8_t * )dataPtr );
4929+ }
49024930 if (ret == WH_ERROR_OK ) {
49034931 uint16_t res_len ;
49044932 do {
@@ -5035,17 +5063,25 @@ int wh_Client_MlDsaSignDma(whClientContext* ctx, const byte* in, word32 in_len,
50355063 ret = wh_Client_DmaProcessClientAddress (
50365064 ctx , (uintptr_t )in , (void * * )& inAddr , req -> msg .sz ,
50375065 WH_DMA_OPER_CLIENT_READ_PRE , (whDmaFlags ){0 });
5038- req -> msg .addr = inAddr ;
5066+ if (ret == WH_ERROR_OK ) {
5067+ req -> msg .addr = inAddr ;
5068+ }
50395069
5040- req -> sig .sz = * out_len ;
5041- ret = wh_Client_DmaProcessClientAddress (
5042- ctx , (uintptr_t )out , (void * * )& outAddr , req -> sig .sz ,
5043- WH_DMA_OPER_CLIENT_WRITE_PRE , (whDmaFlags ){0 });
5044- req -> sig .addr = outAddr ;
5070+ if (ret == WH_ERROR_OK ) {
5071+ req -> sig .sz = * out_len ;
5072+ ret = wh_Client_DmaProcessClientAddress (
5073+ ctx , (uintptr_t )out , (void * * )& outAddr , req -> sig .sz ,
5074+ WH_DMA_OPER_CLIENT_WRITE_PRE , (whDmaFlags ){0 });
5075+ if (ret == WH_ERROR_OK ) {
5076+ req -> sig .addr = outAddr ;
5077+ }
5078+ }
50455079
50465080 /* Send Request */
5047- ret = wh_Client_SendRequest (ctx , group , action , req_len ,
5048- (uint8_t * )dataPtr );
5081+ if (ret == WH_ERROR_OK ) {
5082+ ret = wh_Client_SendRequest (ctx , group , action , req_len ,
5083+ (uint8_t * )dataPtr );
5084+ }
50495085 if (ret == WH_ERROR_OK ) {
50505086 /* Server will evict at this point if requested */
50515087 evict = 0 ;
@@ -5163,16 +5199,24 @@ int wh_Client_MlDsaVerifyDma(whClientContext* ctx, const byte* sig,
51635199 ret = wh_Client_DmaProcessClientAddress (
51645200 ctx , (uintptr_t )sig , (void * * )& sigAddr , sig_len ,
51655201 WH_DMA_OPER_CLIENT_READ_PRE , (whDmaFlags ){0 });
5166- req -> sig .addr = sigAddr ;
5167- req -> msg .sz = msg_len ;
5168- ret = wh_Client_DmaProcessClientAddress (
5169- ctx , (uintptr_t )msg , (void * * )& msgAddr , msg_len ,
5170- WH_DMA_OPER_CLIENT_WRITE_PRE , (whDmaFlags ){0 });
5171- req -> msg .addr = msgAddr ;
5202+ if (ret == WH_ERROR_OK ) {
5203+ req -> sig .addr = sigAddr ;
5204+ }
5205+ if (ret == WH_ERROR_OK ) {
5206+ req -> msg .sz = msg_len ;
5207+ ret = wh_Client_DmaProcessClientAddress (
5208+ ctx , (uintptr_t )msg , (void * * )& msgAddr , msg_len ,
5209+ WH_DMA_OPER_CLIENT_WRITE_PRE , (whDmaFlags ){0 });
5210+ if (ret == WH_ERROR_OK ) {
5211+ req -> msg .addr = msgAddr ;
5212+ }
5213+ }
51725214
51735215 /* Send Request */
5174- ret = wh_Client_SendRequest (ctx , group , action , req_len ,
5175- (uint8_t * )dataPtr );
5216+ if (ret == WH_ERROR_OK ) {
5217+ ret = wh_Client_SendRequest (ctx , group , action , req_len ,
5218+ (uint8_t * )dataPtr );
5219+ }
51765220 if (ret == WH_ERROR_OK ) {
51775221 /* Server will evict at this point if requested */
51785222 evict = 0 ;
0 commit comments