@@ -4517,7 +4517,66 @@ static int _HandleCmacDma(whServerContext* ctx, uint16_t magic, uint16_t seq,
45174517 /* return value populates rc in response message */
45184518 return ret ;
45194519}
4520- #endif /* WOLFHSM_CFG_DMA */
4520+ #endif /* WOLFSSL_CMAC */
4521+
4522+ #ifndef WC_NO_RNG
4523+ static int _HandleRngDma (whServerContext * ctx , uint16_t magic , uint16_t seq ,
4524+ const void * cryptoDataIn , uint16_t inSize ,
4525+ void * cryptoDataOut , uint16_t * outSize )
4526+ {
4527+ (void )seq ;
4528+ (void )inSize ;
4529+
4530+ int ret = 0 ;
4531+ whMessageCrypto_RngDmaRequest req ;
4532+ whMessageCrypto_RngDmaResponse res ;
4533+ void * outAddr = NULL ;
4534+
4535+ /* Translate the request */
4536+ ret = wh_MessageCrypto_TranslateRngDmaRequest (
4537+ magic , (whMessageCrypto_RngDmaRequest * )cryptoDataIn , & req );
4538+ if (ret != WH_ERROR_OK ) {
4539+ return ret ;
4540+ }
4541+
4542+ /* Process the output address (PRE operation) */
4543+ if (ret == WH_ERROR_OK ) {
4544+ ret = wh_Server_DmaProcessClientAddress (
4545+ ctx , req .output .addr , & outAddr , req .output .sz ,
4546+ WH_DMA_OPER_CLIENT_WRITE_PRE , (whServerDmaFlags ){0 });
4547+ if (ret == WH_ERROR_ACCESS ) {
4548+ res .dmaAddrStatus .badAddr = req .output ;
4549+ }
4550+ }
4551+
4552+ /* Generate random bytes directly into client memory */
4553+ if (ret == WH_ERROR_OK ) {
4554+ #ifdef DEBUG_CRYPTOCB_VERBOSE
4555+ printf ("[server] RNG DMA: generating %llu bytes to addr=%p\n" ,
4556+ (long long unsigned int )req .output .sz , outAddr );
4557+ #endif
4558+ ret = wc_RNG_GenerateBlock (ctx -> crypto -> rng , outAddr , req .output .sz );
4559+ }
4560+
4561+ /* Process the output address (POST 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_POST , (whServerDmaFlags ){0 });
4566+ if (ret == WH_ERROR_ACCESS ) {
4567+ res .dmaAddrStatus .badAddr = req .output ;
4568+ }
4569+ }
4570+
4571+ /* Translate the response */
4572+ (void )wh_MessageCrypto_TranslateRngDmaResponse (
4573+ magic , & res , (whMessageCrypto_RngDmaResponse * )cryptoDataOut );
4574+ * outSize = sizeof (res );
4575+
4576+ /* return value populates rc in response message */
4577+ return ret ;
4578+ }
4579+ #endif /* !WC_NO_RNG */
45214580
45224581int wh_Server_HandleCryptoDmaRequest (whServerContext * ctx , uint16_t magic ,
45234582 uint16_t action , uint16_t seq ,
@@ -4638,6 +4697,13 @@ int wh_Server_HandleCryptoDmaRequest(whServerContext* ctx, uint16_t magic,
46384697 break ;
46394698#endif /* WOLFSSL_CMAC */
46404699
4700+ #ifndef WC_NO_RNG
4701+ case WC_ALGO_TYPE_RNG :
4702+ ret = _HandleRngDma (ctx , magic , seq , cryptoDataIn , cryptoInSize ,
4703+ cryptoDataOut , & cryptoOutSize );
4704+ break ;
4705+ #endif /* !WC_NO_RNG */
4706+
46414707 case WC_ALGO_TYPE_NONE :
46424708 default :
46434709 ret = NOT_COMPILED_IN ;
0 commit comments