@@ -380,6 +380,137 @@ int wh_Bench_Mod_Aes256CTRDecryptDma(whClientContext* client,
380380
381381#endif /* WOLFSSL_AES_COUNTER */
382382#if defined(HAVE_AES_ECB )
383+ #if defined(WOLFHSM_CFG_DMA )
384+ static int _benchAesEcbDma (whClientContext * client , whBenchOpContext * ctx ,
385+ int id , const uint8_t * key , size_t keyLen ,
386+ int encrypt )
387+ {
388+ int ret = 0 ;
389+ int needEvict = 0 ;
390+ whKeyId keyId = WH_KEYID_ERASED ;
391+ Aes aes [1 ];
392+ char keyLabel [] = "key label" ;
393+ const size_t inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE / 2 ;
394+ int i ;
395+ const uint8_t * in = NULL ;
396+ uint8_t * out = NULL ;
397+
398+ #if defined(WOLFHSM_CFG_TEST_POSIX )
399+ /* Allocate buffers using XMALLOC with heap hints for DMA */
400+ if (ctx -> transportType == WH_BENCH_TRANSPORT_POSIX_DMA ) {
401+ void * heap =
402+ posixTransportShm_GetDmaHeap (client -> comm -> transport_context );
403+ in = XMALLOC (inLen , heap , DYNAMIC_TYPE_TMP_BUFFER );
404+ if (in == NULL ) {
405+ WH_BENCH_PRINTF ("Failed to allocate memory for DMA input\n" );
406+ return WH_ERROR_NOSPACE ;
407+ }
408+
409+ out = XMALLOC (inLen , heap , DYNAMIC_TYPE_TMP_BUFFER );
410+ if (out == NULL ) {
411+ WH_BENCH_PRINTF ("Failed to allocate memory for DMA output\n" );
412+ XFREE ((uint8_t * )in , heap , DYNAMIC_TYPE_TMP_BUFFER );
413+ return WH_ERROR_NOSPACE ;
414+ }
415+ }
416+ else
417+ #endif /* WOLFHSM_CFG_TEST_POSIX */
418+ {
419+ in = WH_BENCH_DMA_BUFFER ;
420+ out = (uint8_t * )in + inLen ;
421+ }
422+
423+ #if defined(WOLFHSM_CFG_BENCH_INIT_DATA_BUFFERS )
424+ /* Initialize the input buffer with something non-zero */
425+ memset ((uint8_t * )in , 0xAA , inLen );
426+ memset (out , 0xAA , inLen );
427+ #endif
428+
429+ /* Initialize the aes struct */
430+ ret = wc_AesInit (aes , NULL , WH_DEV_ID_DMA );
431+ if (ret != 0 ) {
432+ WH_BENCH_PRINTF ("Failed to wc_AesInit %d\n" , ret );
433+ goto exit ;
434+ }
435+
436+ /* cache the key on the HSM */
437+ ret = wh_Client_KeyCache (client , 0 , (uint8_t * )keyLabel , sizeof (keyLabel ),
438+ (uint8_t * )key , keyLen , & keyId );
439+ if (ret != 0 ) {
440+ WH_BENCH_PRINTF ("Failed to wh_Client_KeyCache %d\n" , ret );
441+ goto exit ;
442+ }
443+
444+ needEvict = 1 ;
445+
446+ /* set the keyId on the struct */
447+ ret = wh_Client_AesSetKeyId (aes , keyId );
448+ if (ret != 0 ) {
449+ WH_BENCH_PRINTF ("Failed to wh_Client_SetKeyIdAes %d\n" , ret );
450+ goto exit ;
451+ }
452+
453+ ret = wh_Bench_SetDataSize (ctx , id , inLen );
454+ if (ret != 0 ) {
455+ WH_BENCH_PRINTF ("Failed to wh_Bench_SetDataSize %d\n" , ret );
456+ goto exit ;
457+ }
458+
459+ /* Perform the benchmark */
460+ for (i = 0 ; i < WOLFHSM_CFG_BENCH_CRYPT_ITERS ; i ++ ) {
461+ int benchStartRet ;
462+ int benchStopRet ;
463+
464+ if (encrypt ) {
465+ benchStartRet = wh_Bench_StartOp (ctx , id );
466+ ret = wc_AesEcbEncrypt (aes , out , in , inLen );
467+ benchStopRet = wh_Bench_StopOp (ctx , id );
468+ }
469+ else {
470+ benchStartRet = wh_Bench_StartOp (ctx , id );
471+ ret = wc_AesEcbDecrypt (aes , out , in , inLen );
472+ benchStopRet = wh_Bench_StopOp (ctx , id );
473+ }
474+
475+ if (benchStartRet != 0 ) {
476+ WH_BENCH_PRINTF ("Failed to wh_Bench_StartOp %d\n" , benchStartRet );
477+ ret = benchStartRet ;
478+ goto exit ;
479+ }
480+ if (ret != 0 ) {
481+ WH_BENCH_PRINTF ("Failed to wh_Client_AesCbcDma %d\n" , ret );
482+ goto exit ;
483+ }
484+ if (benchStopRet != 0 ) {
485+ WH_BENCH_PRINTF ("Failed to wh_Bench_StopOp %d\n" , benchStopRet );
486+ ret = benchStopRet ;
487+ goto exit ;
488+ }
489+ }
490+
491+ exit :
492+ if (needEvict ) {
493+ (void )wh_Client_KeyEvict (client , keyId );
494+ }
495+ wc_AesFree (aes );
496+
497+ #if defined(WOLFHSM_CFG_TEST_POSIX )
498+ if (ctx -> transportType == WH_BENCH_TRANSPORT_POSIX_DMA ) {
499+ void * heap =
500+ posixTransportShm_GetDmaHeap (client -> comm -> transport_context );
501+ if (in != NULL ) {
502+ XFREE ((uint8_t * )in , heap , DYNAMIC_TYPE_TMP_BUFFER );
503+ }
504+ if (out != NULL ) {
505+ XFREE (out , heap , DYNAMIC_TYPE_TMP_BUFFER );
506+ }
507+ }
508+ #endif /* WOLFHSM_CFG_TEST_POSIX */
509+
510+ return ret ;
511+ }
512+ #endif /* WOLFHSM_CFG_DMA */
513+
383514static int _benchAesEcb (whClientContext * client , whBenchOpContext * ctx , int id ,
384515 const uint8_t * key , size_t keyLen , int encrypt )
385516{
@@ -510,6 +641,74 @@ int wh_Bench_Mod_Aes256ECBDecrypt(whClientContext* client,
510641 return _benchAesEcb (client , ctx , id , (uint8_t * )key256 , sizeof (key256 ),
511642 DECRYPT );
512643}
644+
645+ int wh_Bench_Mod_Aes128ECBEncryptDma (whClientContext * client ,
646+ whBenchOpContext * ctx , int id ,
647+ void * params )
648+ {
649+ #if defined(WOLFHSM_CFG_DMA )
650+ (void )params ;
651+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key128 , sizeof (key128 ),
652+ ENCRYPT );
653+ #else
654+ (void )client ;
655+ (void )ctx ;
656+ (void )id ;
657+ (void )params ;
658+ return WH_ERROR_NOTIMPL ;
659+ #endif
660+ }
661+
662+ int wh_Bench_Mod_Aes128ECBDecryptDma (whClientContext * client ,
663+ whBenchOpContext * ctx , int id ,
664+ void * params )
665+ {
666+ #if defined(WOLFHSM_CFG_DMA )
667+ (void )params ;
668+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key128 , sizeof (key128 ),
669+ DECRYPT );
670+ #else
671+ (void )client ;
672+ (void )ctx ;
673+ (void )id ;
674+ (void )params ;
675+ return WH_ERROR_NOTIMPL ;
676+ #endif
677+ }
678+
679+ int wh_Bench_Mod_Aes256ECBEncryptDma (whClientContext * client ,
680+ whBenchOpContext * ctx , int id ,
681+ void * params )
682+ {
683+ #if defined(WOLFHSM_CFG_DMA )
684+ (void )params ;
685+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key256 , sizeof (key256 ),
686+ ENCRYPT );
687+ #else
688+ (void )client ;
689+ (void )ctx ;
690+ (void )id ;
691+ (void )params ;
692+ return WH_ERROR_NOTIMPL ;
693+ #endif
694+ }
695+
696+ int wh_Bench_Mod_Aes256ECBDecryptDma (whClientContext * client ,
697+ whBenchOpContext * ctx , int id ,
698+ void * params )
699+ {
700+ #if defined(WOLFHSM_CFG_DMA )
701+ (void )params ;
702+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key256 , sizeof (key256 ),
703+ DECRYPT );
704+ #else
705+ (void )client ;
706+ (void )ctx ;
707+ (void )id ;
708+ (void )params ;
709+ return WH_ERROR_NOTIMPL ;
710+ #endif
711+ }
513712#endif /* HAVE_AES_ECB */
514713
515714#if defined(HAVE_AES_CBC )
0 commit comments