Skip to content

Commit 63e5225

Browse files
committed
add sha2-224, 384 and 512
1 parent 848af18 commit 63e5225

File tree

16 files changed

+2417
-5
lines changed

16 files changed

+2417
-5
lines changed

benchmark/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ SRC_C += \
104104
$(WOLFSSL_DIR)/wolfcrypt/src/hash.c \
105105
$(WOLFSSL_DIR)/wolfcrypt/src/hmac.c \
106106
$(WOLFSSL_DIR)/wolfcrypt/src/sha256.c \
107+
$(WOLFSSL_DIR)/wolfCrypt/src/sha512.c \
107108
$(WOLFSSL_DIR)/wolfcrypt/src/aes.c \
108109
$(WOLFSSL_DIR)/wolfcrypt/src/ecc.c \
109110
$(WOLFSSL_DIR)/wolfcrypt/src/cmac.c \

benchmark/bench_modules/wh_bench_mod_all.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,21 @@ int wh_Bench_Mod_Sha256(whClientContext* client, whBenchOpContext* ctx, int id,
9393

9494
int wh_Bench_Mod_Sha256Dma(whClientContext* client, whBenchOpContext* ctx,
9595
int id, void* params);
96+
int wh_Bench_Mod_Sha224(whClientContext* client, whBenchOpContext* ctx, int id,
97+
void* params);
98+
99+
int wh_Bench_Mod_Sha224Dma(whClientContext* client, whBenchOpContext* ctx,
100+
int id, void* params);
101+
int wh_Bench_Mod_Sha384(whClientContext* client, whBenchOpContext* ctx, int id,
102+
void* params);
96103

104+
int wh_Bench_Mod_Sha384Dma(whClientContext* client, whBenchOpContext* ctx,
105+
int id, void* params);
106+
int wh_Bench_Mod_Sha512(whClientContext* client, whBenchOpContext* ctx, int id,
107+
void* params);
108+
109+
int wh_Bench_Mod_Sha512Dma(whClientContext* client, whBenchOpContext* ctx,
110+
int id, void* params);
97111
/*
98112
* SHA3 benchmark module prototypes (wh_bench_mod_sha3.c)
99113
*/

benchmark/bench_modules/wh_bench_mod_sha2.c

Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,331 @@ int wh_Bench_Mod_Sha256Dma(whClientContext* client, whBenchOpContext* ctx,
146146

147147
#endif /* !defined(NO_SHA256) */
148148

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

benchmark/config/user_settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ extern "C" {
127127
/** SHA Options */
128128
#define NO_SHA
129129
/* #define NO_SHA256 */
130+
/* #define WOLFSSL_SHA224 */
130131
/* #define WOLFSSL_SHA384 */
131132
/* #define WOLFSSL_SHA512 */
132133

0 commit comments

Comments
 (0)