@@ -367,6 +367,138 @@ int wh_Bench_Mod_Aes256CTRDecryptDma(whClientContext* client,
367367
368368#endif /* WOLFSSL_AES_COUNTER */
369369#if defined(HAVE_AES_ECB )
370+ #if defined(WOLFHSM_CFG_DMA )
371+ static int _benchAesEcbDma (whClientContext * client , whBenchOpContext * ctx ,
372+ int id , const uint8_t * key , size_t keyLen ,
373+ int encrypt )
374+ {
375+ int ret = 0 ;
376+ int needEvict = 0 ;
377+ whKeyId keyId = WH_KEYID_ERASED ;
378+ Aes aes [1 ];
379+ char keyLabel [] = "key label" ;
380+ const size_t inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE / 2 ;
381+ int i ;
382+ const uint8_t * in = NULL ;
383+ uint8_t * out = NULL ;
384+
385+ #if defined(WOLFHSM_CFG_TEST_POSIX )
386+ /* Allocate buffers using XMALLOC with heap hints for DMA */
387+ if (ctx -> transportType == WH_BENCH_TRANSPORT_POSIX_DMA ) {
388+ void * heap =
389+ posixTransportShm_GetDmaHeap (client -> comm -> transport_context );
390+ in = XMALLOC (inLen , heap , DYNAMIC_TYPE_TMP_BUFFER );
391+ if (in == NULL ) {
392+ WH_BENCH_PRINTF ("Failed to allocate memory for DMA input\n" );
393+ return WH_ERROR_NOSPACE ;
394+ }
395+
396+ out = XMALLOC (inLen , heap , DYNAMIC_TYPE_TMP_BUFFER );
397+ if (out == NULL ) {
398+ WH_BENCH_PRINTF ("Failed to allocate memory for DMA output\n" );
399+ XFREE ((uint8_t * )in , heap , DYNAMIC_TYPE_TMP_BUFFER );
400+ return WH_ERROR_NOSPACE ;
401+ }
402+ }
403+ else
404+ #endif /* WOLFHSM_CFG_TEST_POSIX */
405+ {
406+ in = WH_BENCH_DMA_BUFFER ;
407+ out = (uint8_t * )in + inLen ;
408+ }
409+
410+ #if defined(WOLFHSM_CFG_BENCH_INIT_DATA_BUFFERS )
411+ /* Initialize the input buffer with something non-zero */
412+ memset ((uint8_t * )in , 0xAA , inLen );
413+ memset (out , 0xAA , inLen );
414+ #endif
415+
416+ /* Initialize the aes struct */
417+ ret = wc_AesInit (aes , NULL , WH_DEV_ID_DMA );
418+ if (ret != 0 ) {
419+ WH_BENCH_PRINTF ("Failed to wc_AesInit %d\n" , ret );
420+ goto exit ;
421+ }
422+
423+ /* cache the key on the HSM */
424+ ret = wh_Client_KeyCache (client , WH_NVM_FLAGS_USAGE_ANY , (uint8_t * )keyLabel ,
425+ sizeof (keyLabel ), (uint8_t * )key , keyLen , & keyId );
426+ if (ret != 0 ) {
427+ WH_BENCH_PRINTF ("Failed to wh_Client_KeyCache %d\n" , ret );
428+ goto exit ;
429+ }
430+
431+ needEvict = 1 ;
432+
433+ /* set the keyId on the struct */
434+ ret = wh_Client_AesSetKeyId (aes , keyId );
435+ if (ret != 0 ) {
436+ WH_BENCH_PRINTF ("Failed to wh_Client_SetKeyIdAes %d\n" , ret );
437+ goto exit ;
438+ }
439+
440+ ret = wh_Bench_SetDataSize (ctx , id , inLen );
441+ if (ret != 0 ) {
442+ WH_BENCH_PRINTF ("Failed to wh_Bench_SetDataSize %d\n" , ret );
443+ goto exit ;
444+ }
445+
446+ /* Perform the benchmark */
447+ for (i = 0 ; i < WOLFHSM_CFG_BENCH_CRYPT_ITERS ; i ++ ) {
448+ int benchStartRet ;
449+ int benchStopRet ;
450+
451+ if (encrypt ) {
452+ benchStartRet = wh_Bench_StartOp (ctx , id );
453+ ret = wc_AesEcbEncrypt (aes , out , in , inLen );
454+ benchStopRet = wh_Bench_StopOp (ctx , id );
455+ }
456+ else {
457+ benchStartRet = wh_Bench_StartOp (ctx , id );
458+ ret = wc_AesEcbDecrypt (aes , out , in , inLen );
459+ benchStopRet = wh_Bench_StopOp (ctx , id );
460+ }
461+
462+ if (benchStartRet != 0 ) {
463+ WH_BENCH_PRINTF ("Failed to wh_Bench_StartOp %d\n" , benchStartRet );
464+ ret = benchStartRet ;
465+ goto exit ;
466+ }
467+ if (ret != 0 ) {
468+ WH_BENCH_PRINTF ("Failed to wc_AesEcb%s %d\n" ,
469+ encrypt ? "Encrypt" : "Decrypt" , ret );
470+ goto exit ;
471+ }
472+ if (benchStopRet != 0 ) {
473+ WH_BENCH_PRINTF ("Failed to wh_Bench_StopOp %d\n" , benchStopRet );
474+ ret = benchStopRet ;
475+ goto exit ;
476+ }
477+ }
478+
479+ exit :
480+ if (needEvict ) {
481+ (void )wh_Client_KeyEvict (client , keyId );
482+ }
483+ wc_AesFree (aes );
484+
485+ #if defined(WOLFHSM_CFG_TEST_POSIX )
486+ if (ctx -> transportType == WH_BENCH_TRANSPORT_POSIX_DMA ) {
487+ void * heap =
488+ posixTransportShm_GetDmaHeap (client -> comm -> transport_context );
489+ if (in != NULL ) {
490+ XFREE ((uint8_t * )in , heap , DYNAMIC_TYPE_TMP_BUFFER );
491+ }
492+ if (out != NULL ) {
493+ XFREE (out , heap , DYNAMIC_TYPE_TMP_BUFFER );
494+ }
495+ }
496+ #endif /* WOLFHSM_CFG_TEST_POSIX */
497+
498+ return ret ;
499+ }
500+ #endif /* WOLFHSM_CFG_DMA */
501+
370502static int _benchAesEcb (whClientContext * client , whBenchOpContext * ctx , int id ,
371503 const uint8_t * key , size_t keyLen , int encrypt )
372504{
@@ -391,7 +523,7 @@ static int _benchAesEcb(whClientContext* client, whBenchOpContext* ctx, int id,
391523 ret = wc_AesInit (aes , NULL , WH_DEV_ID );
392524 if (ret != 0 ) {
393525 WH_BENCH_PRINTF ("Failed to wc_AesInit %d\n" , ret );
394- return ret ;
526+ goto exit ;
395527 }
396528
397529 /* cache the key on the HSM */
@@ -497,6 +629,74 @@ int wh_Bench_Mod_Aes256ECBDecrypt(whClientContext* client,
497629 return _benchAesEcb (client , ctx , id , (uint8_t * )key256 , sizeof (key256 ),
498630 DECRYPT );
499631}
632+
633+ int wh_Bench_Mod_Aes128ECBEncryptDma (whClientContext * client ,
634+ whBenchOpContext * ctx , int id ,
635+ void * params )
636+ {
637+ #if defined(WOLFHSM_CFG_DMA )
638+ (void )params ;
639+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key128 , sizeof (key128 ),
640+ ENCRYPT );
641+ #else
642+ (void )client ;
643+ (void )ctx ;
644+ (void )id ;
645+ (void )params ;
646+ return WH_ERROR_NOTIMPL ;
647+ #endif
648+ }
649+
650+ int wh_Bench_Mod_Aes128ECBDecryptDma (whClientContext * client ,
651+ whBenchOpContext * ctx , int id ,
652+ void * params )
653+ {
654+ #if defined(WOLFHSM_CFG_DMA )
655+ (void )params ;
656+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key128 , sizeof (key128 ),
657+ DECRYPT );
658+ #else
659+ (void )client ;
660+ (void )ctx ;
661+ (void )id ;
662+ (void )params ;
663+ return WH_ERROR_NOTIMPL ;
664+ #endif
665+ }
666+
667+ int wh_Bench_Mod_Aes256ECBEncryptDma (whClientContext * client ,
668+ whBenchOpContext * ctx , int id ,
669+ void * params )
670+ {
671+ #if defined(WOLFHSM_CFG_DMA )
672+ (void )params ;
673+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key256 , sizeof (key256 ),
674+ ENCRYPT );
675+ #else
676+ (void )client ;
677+ (void )ctx ;
678+ (void )id ;
679+ (void )params ;
680+ return WH_ERROR_NOTIMPL ;
681+ #endif
682+ }
683+
684+ int wh_Bench_Mod_Aes256ECBDecryptDma (whClientContext * client ,
685+ whBenchOpContext * ctx , int id ,
686+ void * params )
687+ {
688+ #if defined(WOLFHSM_CFG_DMA )
689+ (void )params ;
690+ return _benchAesEcbDma (client , ctx , id , (uint8_t * )key256 , sizeof (key256 ),
691+ DECRYPT );
692+ #else
693+ (void )client ;
694+ (void )ctx ;
695+ (void )id ;
696+ (void )params ;
697+ return WH_ERROR_NOTIMPL ;
698+ #endif
699+ }
500700#endif /* HAVE_AES_ECB */
501701
502702#if defined(HAVE_AES_CBC )
0 commit comments