@@ -134,4 +134,331 @@ int wh_Bench_Mod_Sha256Dma(whClientContext* client, whBenchOpContext* ctx,
134134
135135#endif /* !defined(NO_SHA256) */
136136
137+
138+ #if defined(WOLFSSL_SHA224 )
139+
140+ int _benchSha224 (whClientContext * client , whBenchOpContext * ctx , int id ,
141+ int devId )
142+ {
143+ int ret = 0 ;
144+ wc_Sha224 sha224 [1 ];
145+ uint8_t out [WC_SHA224_DIGEST_SIZE ];
146+ int i = 0 ;
147+ int sha224Initialized = 0 ;
148+ const uint8_t * in ;
149+ size_t inLen ;
150+
151+ #if defined(WOLFHSM_CFG_DMA )
152+ if (devId == WH_DEV_ID_DMA ) {
153+ in = WH_BENCH_DMA_BUFFER ;
154+ inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE ;
155+ }
156+ else
157+ #endif
158+ {
159+ in = WH_BENCH_DATA_IN_BUFFER ;
160+ inLen = WOLFHSM_CFG_BENCH_DATA_BUFFER_SIZE ;
161+ #if defined(WOLFHSM_CFG_BENCH_INIT_DATA_BUFFERS )
162+ memset (WH_BENCH_DATA_IN_BUFFER , 0xAA , inLen );
163+ #endif
164+ }
165+
166+ ret = wh_Bench_SetDataSize (ctx , id , inLen );
167+ if (ret != 0 ) {
168+ WH_BENCH_PRINTF ("Failed to wh_Bench_SetDataSize %d\n" , ret );
169+ return ret ;
170+ }
171+
172+ for (i = 0 ; i < WOLFHSM_CFG_BENCH_CRYPT_ITERS ; i ++ ) {
173+ int benchStartRet ;
174+ int benchStopRet ;
175+ int initRet ;
176+ int updateRet ;
177+ int finalRet ;
178+
179+ /* Defer error checking until after all operations are complete */
180+ benchStartRet = wh_Bench_StartOp (ctx , id );
181+ initRet = wc_InitSha224_ex (sha224 , NULL , devId );
182+ updateRet = wc_Sha224Update (sha224 , in , inLen );
183+ finalRet = wc_Sha224Final (sha224 , out );
184+ benchStopRet = wh_Bench_StopOp (ctx , id );
185+
186+ /* Check for errors after all operations are complete */
187+ if (benchStartRet != 0 ) {
188+ WH_BENCH_PRINTF ("Failed to wh_Bench_StartOp: %d\n" , benchStartRet );
189+ ret = benchStartRet ;
190+ break ;
191+ }
192+ if (initRet != 0 ) {
193+ WH_BENCH_PRINTF ("Failed to wc_InitSha224_ex %d\n" , initRet );
194+ ret = initRet ;
195+ break ;
196+ }
197+
198+ sha224Initialized = 1 ;
199+
200+ if (updateRet != 0 ) {
201+ WH_BENCH_PRINTF ("Failed to wc_Sha224Update %d\n" , updateRet );
202+ ret = updateRet ;
203+ break ;
204+ }
205+ if (finalRet != 0 ) {
206+ WH_BENCH_PRINTF ("Failed to wc_Sha224Final %d\n" , finalRet );
207+ ret = finalRet ;
208+ break ;
209+ }
210+ if (benchStopRet != 0 ) {
211+ WH_BENCH_PRINTF ("Failed to wh_Bench_StopOp: %d\n" , benchStopRet );
212+ ret = benchStopRet ;
213+ break ;
214+ }
215+ }
216+
217+ /* Only free SHA224 if it was initialized */
218+ if (sha224Initialized ) {
219+ (void )wc_Sha224Free (sha224 );
220+ }
221+
222+ return ret ;
223+ }
224+
225+ int wh_Bench_Mod_Sha224 (whClientContext * client , whBenchOpContext * ctx , int id ,
226+ void * params )
227+ {
228+ #if defined(WOLFHSM_CFG_DMA )
229+ return _benchSha224 (client , ctx , id , WH_DEV_ID );
230+ #else
231+ return WH_ERROR_NOTIMPL ;
232+ #endif
233+ }
234+
235+ int wh_Bench_Mod_Sha224Dma (whClientContext * client , whBenchOpContext * ctx ,
236+ int id , void * params )
237+ {
238+ #if defined(WOLFHSM_CFG_DMA )
239+ return _benchSha224 (client , ctx , id , WH_DEV_ID_DMA );
240+ #else
241+ return WH_ERROR_NOTIMPL ;
242+ #endif
243+ }
244+
245+ #endif /* WOLFSSL_SHA224 */
246+
247+ #if defined(WOLFSSL_SHA384 )
248+
249+ int _benchSha384 (whClientContext * client , whBenchOpContext * ctx , int id ,
250+ int devId )
251+ {
252+ int ret = 0 ;
253+ wc_Sha384 sha384 [1 ];
254+ uint8_t out [WC_SHA384_DIGEST_SIZE ];
255+ int i = 0 ;
256+ int sha384Initialized = 0 ;
257+ const uint8_t * in ;
258+ size_t inLen ;
259+
260+ #if defined(WOLFHSM_CFG_DMA )
261+ if (devId == WH_DEV_ID_DMA ) {
262+ in = WH_BENCH_DMA_BUFFER ;
263+ inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE ;
264+ }
265+ else
266+ #endif
267+ {
268+ in = WH_BENCH_DATA_IN_BUFFER ;
269+ inLen = WOLFHSM_CFG_BENCH_DATA_BUFFER_SIZE ;
270+ #if defined(WOLFHSM_CFG_BENCH_INIT_DATA_BUFFERS )
271+ memset (WH_BENCH_DATA_IN_BUFFER , 0xAA , inLen );
272+ #endif
273+ }
274+
275+ ret = wh_Bench_SetDataSize (ctx , id , inLen );
276+ if (ret != 0 ) {
277+ WH_BENCH_PRINTF ("Failed to wh_Bench_SetDataSize %d\n" , ret );
278+ return ret ;
279+ }
280+
281+ for (i = 0 ; i < WOLFHSM_CFG_BENCH_CRYPT_ITERS ; i ++ ) {
282+ int benchStartRet ;
283+ int benchStopRet ;
284+ int initRet ;
285+ int updateRet ;
286+ int finalRet ;
287+
288+ /* Defer error checking until after all operations are complete */
289+ benchStartRet = wh_Bench_StartOp (ctx , id );
290+ initRet = wc_InitSha384_ex (sha384 , NULL , devId );
291+ updateRet = wc_Sha384Update (sha384 , in , inLen );
292+ finalRet = wc_Sha384Final (sha384 , out );
293+ benchStopRet = wh_Bench_StopOp (ctx , id );
294+
295+ /* Check for errors after all operations are complete */
296+ if (benchStartRet != 0 ) {
297+ WH_BENCH_PRINTF ("Failed to wh_Bench_StartOp: %d\n" , benchStartRet );
298+ ret = benchStartRet ;
299+ break ;
300+ }
301+ if (initRet != 0 ) {
302+ WH_BENCH_PRINTF ("Failed to wc_InitSha384_ex %d\n" , initRet );
303+ ret = initRet ;
304+ break ;
305+ }
306+
307+ sha384Initialized = 1 ;
308+
309+ if (updateRet != 0 ) {
310+ WH_BENCH_PRINTF ("Failed to wc_Sha384Update %d\n" , updateRet );
311+ ret = updateRet ;
312+ break ;
313+ }
314+ if (finalRet != 0 ) {
315+ WH_BENCH_PRINTF ("Failed to wc_Sha384Final %d\n" , finalRet );
316+ ret = finalRet ;
317+ break ;
318+ }
319+ if (benchStopRet != 0 ) {
320+ WH_BENCH_PRINTF ("Failed to wh_Bench_StopOp: %d\n" , benchStopRet );
321+ ret = benchStopRet ;
322+ break ;
323+ }
324+ }
325+
326+ /* Only free SHA384 if it was initialized */
327+ if (sha384Initialized ) {
328+ (void )wc_Sha384Free (sha384 );
329+ }
330+
331+ return ret ;
332+ }
333+
334+ int wh_Bench_Mod_Sha384 (whClientContext * client , whBenchOpContext * ctx , int id ,
335+ void * params )
336+ {
337+ #if defined(WOLFHSM_CFG_DMA )
338+ return _benchSha384 (client , ctx , id , WH_DEV_ID );
339+ #else
340+ return WH_ERROR_NOTIMPL ;
341+ #endif
342+ }
343+
344+ int wh_Bench_Mod_Sha384Dma (whClientContext * client , whBenchOpContext * ctx ,
345+ int id , void * params )
346+ {
347+ #if defined(WOLFHSM_CFG_DMA )
348+ return _benchSha384 (client , ctx , id , WH_DEV_ID_DMA );
349+ #else
350+ return WH_ERROR_NOTIMPL ;
351+ #endif
352+ }
353+
354+ #endif /* WOLFSSL_SHA384 */
355+ #if defined(WOLFSSL_SHA512 )
356+
357+ int _benchSha512 (whClientContext * client , whBenchOpContext * ctx , int id ,
358+ int devId )
359+ {
360+ int ret = 0 ;
361+ wc_Sha512 sha512 [1 ];
362+ uint8_t out [WC_SHA512_DIGEST_SIZE ];
363+ int i = 0 ;
364+ int sha512Initialized = 0 ;
365+ const uint8_t * in ;
366+ size_t inLen ;
367+
368+ #if defined(WOLFHSM_CFG_DMA )
369+ if (devId == WH_DEV_ID_DMA ) {
370+ in = WH_BENCH_DMA_BUFFER ;
371+ inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE ;
372+ }
373+ else
374+ #endif
375+ {
376+ in = WH_BENCH_DATA_IN_BUFFER ;
377+ inLen = WOLFHSM_CFG_BENCH_DATA_BUFFER_SIZE ;
378+ #if defined(WOLFHSM_CFG_BENCH_INIT_DATA_BUFFERS )
379+ memset (WH_BENCH_DATA_IN_BUFFER , 0xAA , inLen );
380+ #endif
381+ }
382+
383+ ret = wh_Bench_SetDataSize (ctx , id , inLen );
384+ if (ret != 0 ) {
385+ WH_BENCH_PRINTF ("Failed to wh_Bench_SetDataSize %d\n" , ret );
386+ return ret ;
387+ }
388+
389+ for (i = 0 ; i < WOLFHSM_CFG_BENCH_CRYPT_ITERS ; i ++ ) {
390+ int benchStartRet ;
391+ int benchStopRet ;
392+ int initRet ;
393+ int updateRet ;
394+ int finalRet ;
395+
396+ /* Defer error checking until after all operations are complete */
397+ benchStartRet = wh_Bench_StartOp (ctx , id );
398+ initRet = wc_InitSha512_ex (sha512 , NULL , devId );
399+ updateRet = wc_Sha512Update (sha512 , in , inLen );
400+ finalRet = wc_Sha512Final (sha512 , out );
401+ benchStopRet = wh_Bench_StopOp (ctx , id );
402+
403+ /* Check for errors after all operations are complete */
404+ if (benchStartRet != 0 ) {
405+ WH_BENCH_PRINTF ("Failed to wh_Bench_StartOp: %d\n" , benchStartRet );
406+ ret = benchStartRet ;
407+ break ;
408+ }
409+ if (initRet != 0 ) {
410+ WH_BENCH_PRINTF ("Failed to wc_InitSha512_ex %d\n" , initRet );
411+ ret = initRet ;
412+ break ;
413+ }
414+
415+ sha512Initialized = 1 ;
416+
417+ if (updateRet != 0 ) {
418+ WH_BENCH_PRINTF ("Failed to wc_Sha512Update %d\n" , updateRet );
419+ ret = updateRet ;
420+ break ;
421+ }
422+ if (finalRet != 0 ) {
423+ WH_BENCH_PRINTF ("Failed to wc_Sha512Final %d\n" , finalRet );
424+ ret = finalRet ;
425+ break ;
426+ }
427+ if (benchStopRet != 0 ) {
428+ WH_BENCH_PRINTF ("Failed to wh_Bench_StopOp: %d\n" , benchStopRet );
429+ ret = benchStopRet ;
430+ break ;
431+ }
432+ }
433+
434+ /* Only free SHA512 if it was initialized */
435+ if (sha512Initialized ) {
436+ (void )wc_Sha512Free (sha512 );
437+ }
438+
439+ return ret ;
440+ }
441+
442+ int wh_Bench_Mod_Sha512 (whClientContext * client , whBenchOpContext * ctx , int id ,
443+ void * params )
444+ {
445+ #if defined(WOLFHSM_CFG_DMA )
446+ return _benchSha512 (client , ctx , id , WH_DEV_ID );
447+ #else
448+ return WH_ERROR_NOTIMPL ;
449+ #endif
450+ }
451+
452+ int wh_Bench_Mod_Sha512Dma (whClientContext * client , whBenchOpContext * ctx ,
453+ int id , void * params )
454+ {
455+ #if defined(WOLFHSM_CFG_DMA )
456+ return _benchSha512 (client , ctx , id , WH_DEV_ID_DMA );
457+ #else
458+ return WH_ERROR_NOTIMPL ;
459+ #endif
460+ }
461+
462+ #endif /* WOLFSSL_SHA512 */
463+
137464#endif /* WOLFHSM_CFG_BENCH_ENABLE */
0 commit comments