@@ -380,6 +380,138 @@ 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 wc_AesEcb%s %d\n" ,
482+ encrypt ? "Encrypt" : "Decrypt" , ret );
483+ goto exit ;
484+ }
485+ if (benchStopRet != 0 ) {
486+ WH_BENCH_PRINTF ("Failed to wh_Bench_StopOp %d\n" , benchStopRet );
487+ ret = benchStopRet ;
488+ goto exit ;
489+ }
490+ }
491+
492+ exit :
493+ if (needEvict ) {
494+ (void )wh_Client_KeyEvict (client , keyId );
495+ }
496+ wc_AesFree (aes );
497+
498+ #if defined(WOLFHSM_CFG_TEST_POSIX )
499+ if (ctx -> transportType == WH_BENCH_TRANSPORT_POSIX_DMA ) {
500+ void * heap =
501+ posixTransportShm_GetDmaHeap (client -> comm -> transport_context );
502+ if (in != NULL ) {
503+ XFREE ((uint8_t * )in , heap , DYNAMIC_TYPE_TMP_BUFFER );
504+ }
505+ if (out != NULL ) {
506+ XFREE (out , heap , DYNAMIC_TYPE_TMP_BUFFER );
507+ }
508+ }
509+ #endif /* WOLFHSM_CFG_TEST_POSIX */
510+
511+ return ret ;
512+ }
513+ #endif /* WOLFHSM_CFG_DMA */
514+
383515static int _benchAesEcb (whClientContext * client , whBenchOpContext * ctx , int id ,
384516 const uint8_t * key , size_t keyLen , int encrypt )
385517{
@@ -510,6 +642,74 @@ int wh_Bench_Mod_Aes256ECBDecrypt(whClientContext* client,
510642 return _benchAesEcb (client , ctx , id , (uint8_t * )key256 , sizeof (key256 ),
511643 DECRYPT );
512644}
645+
646+ int wh_Bench_Mod_Aes128ECBEncryptDma (whClientContext * client ,
647+ whBenchOpContext * ctx , int id ,
648+ void * params )
649+ {
650+ #if defined(WOLFHSM_CFG_DMA )
651+ (void )params ;
652+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key128 , sizeof (key128 ),
653+ ENCRYPT );
654+ #else
655+ (void )client ;
656+ (void )ctx ;
657+ (void )id ;
658+ (void )params ;
659+ return WH_ERROR_NOTIMPL ;
660+ #endif
661+ }
662+
663+ int wh_Bench_Mod_Aes128ECBDecryptDma (whClientContext * client ,
664+ whBenchOpContext * ctx , int id ,
665+ void * params )
666+ {
667+ #if defined(WOLFHSM_CFG_DMA )
668+ (void )params ;
669+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key128 , sizeof (key128 ),
670+ DECRYPT );
671+ #else
672+ (void )client ;
673+ (void )ctx ;
674+ (void )id ;
675+ (void )params ;
676+ return WH_ERROR_NOTIMPL ;
677+ #endif
678+ }
679+
680+ int wh_Bench_Mod_Aes256ECBEncryptDma (whClientContext * client ,
681+ whBenchOpContext * ctx , int id ,
682+ void * params )
683+ {
684+ #if defined(WOLFHSM_CFG_DMA )
685+ (void )params ;
686+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key256 , sizeof (key256 ),
687+ ENCRYPT );
688+ #else
689+ (void )client ;
690+ (void )ctx ;
691+ (void )id ;
692+ (void )params ;
693+ return WH_ERROR_NOTIMPL ;
694+ #endif
695+ }
696+
697+ int wh_Bench_Mod_Aes256ECBDecryptDma (whClientContext * client ,
698+ whBenchOpContext * ctx , int id ,
699+ void * params )
700+ {
701+ #if defined(WOLFHSM_CFG_DMA )
702+ (void )params ;
703+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key256 , sizeof (key256 ),
704+ DECRYPT );
705+ #else
706+ (void )client ;
707+ (void )ctx ;
708+ (void )id ;
709+ (void )params ;
710+ return WH_ERROR_NOTIMPL ;
711+ #endif
712+ }
513713#endif /* HAVE_AES_ECB */
514714
515715#if defined(HAVE_AES_CBC )
0 commit comments