@@ -4563,7 +4563,66 @@ static int _HandleCmacDma(whServerContext* ctx, uint16_t magic, uint16_t seq,
45634563 /* return value populates rc in response message */
45644564 return ret ;
45654565}
4566- #endif /* WOLFHSM_CFG_DMA */
4566+ #endif /* WOLFSSL_CMAC */
4567+
4568+ #ifndef WC_NO_RNG
4569+ static int _HandleRngDma (whServerContext * ctx , uint16_t magic , uint16_t seq ,
4570+ const void * cryptoDataIn , uint16_t inSize ,
4571+ void * cryptoDataOut , uint16_t * outSize )
4572+ {
4573+ (void )seq ;
4574+ (void )inSize ;
4575+
4576+ int ret = 0 ;
4577+ whMessageCrypto_RngDmaRequest req ;
4578+ whMessageCrypto_RngDmaResponse res ;
4579+ void * outAddr = NULL ;
4580+
4581+ /* Translate the request */
4582+ ret = wh_MessageCrypto_TranslateRngDmaRequest (
4583+ magic , (whMessageCrypto_RngDmaRequest * )cryptoDataIn , & req );
4584+ if (ret != WH_ERROR_OK ) {
4585+ return ret ;
4586+ }
4587+
4588+ /* Process the output address (PRE operation) */
4589+ if (ret == WH_ERROR_OK ) {
4590+ ret = wh_Server_DmaProcessClientAddress (
4591+ ctx , req .output .addr , & outAddr , req .output .sz ,
4592+ WH_DMA_OPER_CLIENT_WRITE_PRE , (whServerDmaFlags ){0 });
4593+ if (ret == WH_ERROR_ACCESS ) {
4594+ res .dmaAddrStatus .badAddr = req .output ;
4595+ }
4596+ }
4597+
4598+ /* Generate random bytes directly into client memory */
4599+ if (ret == WH_ERROR_OK ) {
4600+ #ifdef DEBUG_CRYPTOCB_VERBOSE
4601+ printf ("[server] RNG DMA: generating %llu bytes to addr=%p\n" ,
4602+ (long long unsigned int )req .output .sz , outAddr );
4603+ #endif
4604+ ret = wc_RNG_GenerateBlock (ctx -> crypto -> rng , outAddr , req .output .sz );
4605+ }
4606+
4607+ /* Process the output address (POST operation) */
4608+ if (ret == WH_ERROR_OK ) {
4609+ ret = wh_Server_DmaProcessClientAddress (
4610+ ctx , req .output .addr , & outAddr , req .output .sz ,
4611+ WH_DMA_OPER_CLIENT_WRITE_POST , (whServerDmaFlags ){0 });
4612+ if (ret == WH_ERROR_ACCESS ) {
4613+ res .dmaAddrStatus .badAddr = req .output ;
4614+ }
4615+ }
4616+
4617+ /* Translate the response */
4618+ (void )wh_MessageCrypto_TranslateRngDmaResponse (
4619+ magic , & res , (whMessageCrypto_RngDmaResponse * )cryptoDataOut );
4620+ * outSize = sizeof (res );
4621+
4622+ /* return value populates rc in response message */
4623+ return ret ;
4624+ }
4625+ #endif /* !WC_NO_RNG */
45674626
45684627int wh_Server_HandleCryptoDmaRequest (whServerContext * ctx , uint16_t magic ,
45694628 uint16_t action , uint16_t seq ,
@@ -4684,6 +4743,13 @@ int wh_Server_HandleCryptoDmaRequest(whServerContext* ctx, uint16_t magic,
46844743 break ;
46854744#endif /* WOLFSSL_CMAC */
46864745
4746+ #ifndef WC_NO_RNG
4747+ case WC_ALGO_TYPE_RNG :
4748+ ret = _HandleRngDma (ctx , magic , seq , cryptoDataIn , cryptoInSize ,
4749+ cryptoDataOut , & cryptoOutSize );
4750+ break ;
4751+ #endif /* !WC_NO_RNG */
4752+
46874753 case WC_ALGO_TYPE_NONE :
46884754 default :
46894755 ret = NOT_COMPILED_IN ;
0 commit comments