@@ -4536,7 +4536,66 @@ static int _HandleCmacDma(whServerContext* ctx, uint16_t magic, uint16_t seq,
45364536 /* return value populates rc in response message */
45374537 return ret ;
45384538}
4539- #endif /* WOLFHSM_CFG_DMA */
4539+ #endif /* WOLFSSL_CMAC */
4540+
4541+ #ifndef WC_NO_RNG
4542+ static int _HandleRngDma (whServerContext * ctx , uint16_t magic , uint16_t seq ,
4543+ const void * cryptoDataIn , uint16_t inSize ,
4544+ void * cryptoDataOut , uint16_t * outSize )
4545+ {
4546+ (void )seq ;
4547+ (void )inSize ;
4548+
4549+ int ret = 0 ;
4550+ whMessageCrypto_RngDmaRequest req ;
4551+ whMessageCrypto_RngDmaResponse res ;
4552+ void * outAddr = NULL ;
4553+
4554+ /* Translate the request */
4555+ ret = wh_MessageCrypto_TranslateRngDmaRequest (
4556+ magic , (whMessageCrypto_RngDmaRequest * )cryptoDataIn , & req );
4557+ if (ret != WH_ERROR_OK ) {
4558+ return ret ;
4559+ }
4560+
4561+ /* Process the output address (PRE operation) */
4562+ if (ret == WH_ERROR_OK ) {
4563+ ret = wh_Server_DmaProcessClientAddress (
4564+ ctx , req .output .addr , & outAddr , req .output .sz ,
4565+ WH_DMA_OPER_CLIENT_WRITE_PRE , (whServerDmaFlags ){0 });
4566+ if (ret == WH_ERROR_ACCESS ) {
4567+ res .dmaAddrStatus .badAddr = req .output ;
4568+ }
4569+ }
4570+
4571+ /* Generate random bytes directly into client memory */
4572+ if (ret == WH_ERROR_OK ) {
4573+ #ifdef DEBUG_CRYPTOCB_VERBOSE
4574+ printf ("[server] RNG DMA: generating %llu bytes to addr=%p\n" ,
4575+ (long long unsigned int )req .output .sz , outAddr );
4576+ #endif
4577+ ret = wc_RNG_GenerateBlock (ctx -> crypto -> rng , outAddr , req .output .sz );
4578+ }
4579+
4580+ /* Process the output address (POST operation) */
4581+ if (ret == WH_ERROR_OK ) {
4582+ ret = wh_Server_DmaProcessClientAddress (
4583+ ctx , req .output .addr , & outAddr , req .output .sz ,
4584+ WH_DMA_OPER_CLIENT_WRITE_POST , (whServerDmaFlags ){0 });
4585+ if (ret == WH_ERROR_ACCESS ) {
4586+ res .dmaAddrStatus .badAddr = req .output ;
4587+ }
4588+ }
4589+
4590+ /* Translate the response */
4591+ (void )wh_MessageCrypto_TranslateRngDmaResponse (
4592+ magic , & res , (whMessageCrypto_RngDmaResponse * )cryptoDataOut );
4593+ * outSize = sizeof (res );
4594+
4595+ /* return value populates rc in response message */
4596+ return ret ;
4597+ }
4598+ #endif /* !WC_NO_RNG */
45404599
45414600int wh_Server_HandleCryptoDmaRequest (whServerContext * ctx , uint16_t magic ,
45424601 uint16_t action , uint16_t seq ,
@@ -4657,6 +4716,13 @@ int wh_Server_HandleCryptoDmaRequest(whServerContext* ctx, uint16_t magic,
46574716 break ;
46584717#endif /* WOLFSSL_CMAC */
46594718
4719+ #ifndef WC_NO_RNG
4720+ case WC_ALGO_TYPE_RNG :
4721+ ret = _HandleRngDma (ctx , magic , seq , cryptoDataIn , cryptoInSize ,
4722+ cryptoDataOut , & cryptoOutSize );
4723+ break ;
4724+ #endif /* !WC_NO_RNG */
4725+
46604726 case WC_ALGO_TYPE_NONE :
46614727 default :
46624728 ret = NOT_COMPILED_IN ;
0 commit comments