Skip to content

Commit 0c6ca7b

Browse files
authored
Merge branch 'main' into HSM_debug
2 parents 649d17e + 18f270b commit 0c6ca7b

44 files changed

Lines changed: 3190 additions & 368 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/clang-format-check.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
else
4444
status=$?
4545
fi
46+
4647
if [ "$status" -eq 0 ]; then
4748
echo "✅ Code is properly formatted!"
4849
exit 0
@@ -56,10 +57,14 @@ jobs:
5657
echo ""
5758
echo "Please run the following command locally on your feature branch and commit the changes:"
5859
echo " git-clang-format-15 $BASE_REF"
59-
exit 1
60+
exit 0
61+
# TEMPORARY DISABLE DUE TO BUGS
62+
#exit 1
6063
else
6164
echo "❌ git-clang-format-15 failed with exit code $status"
6265
echo "Output (if any):"
6366
cat "$DIFF_FILE"
64-
exit 1
67+
exit 0
68+
# TEMPORARY DISABLE DUE TO BUGS
69+
#exit 1
6570
fi
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Code Coverage
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'main', 'release/**' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
jobs:
10+
coverage:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
# List compiler version
17+
- name: List compiler and gcov version
18+
run: |
19+
gcc --version
20+
gcov --version
21+
22+
# Install gcovr for coverage report generation
23+
- name: Install gcovr
24+
run: |
25+
sudo apt-get update
26+
sudo apt-get install -y gcovr
27+
28+
# Checkout wolfssl
29+
- name: Checkout wolfssl
30+
uses: actions/checkout@v4
31+
with:
32+
repository: wolfssl/wolfssl
33+
path: wolfssl
34+
35+
# Run coverage
36+
- name: Build and run tests with coverage
37+
run: cd test && make coverage WOLFSSL_DIR=../wolfssl
38+
39+
# Display coverage summary in the action log
40+
- name: Display coverage summary
41+
run: |
42+
echo "=== Coverage Summary ==="
43+
cd test
44+
gcovr Build --root .. --filter '\.\./src/.*' --filter '\.\./wolfhsm/.*' --print-summary
45+
46+
# Upload coverage report as artifact
47+
- name: Upload coverage report
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: coverage-report
51+
path: coverage/
52+
retention-days: 30
53+

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ compile_commands.json
1414
tools/static-analysis/reports/
1515
*.xml
1616
*.html
17+
18+
# Code coverage
19+
*.gcda
20+
*.gcno
21+
coverage/

benchmark/bench_modules/wh_bench_mod_aes.c

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#if defined(WOLFHSM_CFG_BENCH_ENABLE)
2727

28+
#if defined(WOLFHSM_CFG_DMA) && defined(WOLFHSM_CFG_TEST_POSIX)
29+
#include "port/posix/posix_transport_shm.h"
30+
#endif /* WOLFHSM_CFG_DMA && WOLFHSM_CFG_TEST_POSIX */
31+
2832
#if !defined(NO_AES)
2933

3034
/* 128-bit key */
@@ -440,6 +444,164 @@ int wh_Bench_Mod_Aes256CBCDecrypt(whClientContext* client,
440444
#endif /* HAVE_AES_CBC */
441445

442446
#if defined(HAVE_AESGCM)
447+
#ifdef WOLFHSM_CFG_DMA
448+
static int _benchAesGcmDma(whClientContext* client, whBenchOpContext* ctx,
449+
int id, const uint8_t* key, size_t keyLen,
450+
int encrypt)
451+
{
452+
int ret = 0;
453+
int needEvict = 0;
454+
whKeyId keyId = WH_KEYID_ERASED;
455+
Aes aes[1];
456+
char keyLabel[] = "key label";
457+
byte iv[WC_AES_BLOCK_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7,
458+
8, 9, 10, 11, 12, 13, 14, 15};
459+
byte authData[WC_AES_BLOCK_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7,
460+
8, 9, 10, 11, 12, 13, 14, 15};
461+
byte authTag[WC_AES_BLOCK_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7,
462+
8, 9, 10, 11, 12, 13, 14, 15};
463+
const size_t inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE / 2;
464+
int i;
465+
const uint8_t* in = NULL;
466+
uint8_t* out = NULL;
467+
468+
#if defined(WOLFHSM_CFG_TEST_POSIX)
469+
/* Allocate buffers using XMALLOC with heap hints for DMA */
470+
if (ctx->transportType == WH_BENCH_TRANSPORT_POSIX_DMA) {
471+
void* heap =
472+
posixTransportShm_GetDmaHeap(client->comm->transport_context);
473+
in = XMALLOC(inLen, heap, DYNAMIC_TYPE_TMP_BUFFER);
474+
if (in == NULL) {
475+
WH_BENCH_PRINTF("Failed to allocate memory for DMA input\n");
476+
return WH_ERROR_NOSPACE;
477+
}
478+
479+
out = XMALLOC(inLen, heap, DYNAMIC_TYPE_TMP_BUFFER);
480+
if (out == NULL) {
481+
WH_BENCH_PRINTF("Failed to allocate memory for DMA output\n");
482+
XFREE((uint8_t*)in, heap, DYNAMIC_TYPE_TMP_BUFFER);
483+
return WH_ERROR_NOSPACE;
484+
}
485+
}
486+
else
487+
#endif /* WOLFHSM_CFG_TEST_POSIX */
488+
{
489+
in = WH_BENCH_DMA_BUFFER;
490+
out = (uint8_t*)in + inLen;
491+
}
492+
493+
#if defined(WOLFHSM_CFG_BENCH_INIT_DATA_BUFFERS)
494+
/* Initialize the buffers with something non-zero */
495+
memset((uint8_t*)in, 0xAA, inLen);
496+
memset(out, 0xAA, inLen);
497+
#endif
498+
499+
/* initialize the aes struct */
500+
ret = wc_AesInit(aes, NULL, WH_DEV_ID_DMA);
501+
if (ret != 0) {
502+
WH_BENCH_PRINTF("Failed to wc_AesInit %d\n", ret);
503+
return ret;
504+
}
505+
506+
/* cache the key on the HSM */
507+
ret = wh_Client_KeyCache(client, 0, (uint8_t*)keyLabel, sizeof(keyLabel),
508+
(uint8_t*)key, keyLen, &keyId);
509+
if (ret != 0) {
510+
WH_BENCH_PRINTF("Failed to wh_Client_KeyCache %d\n", ret);
511+
goto exit;
512+
}
513+
514+
needEvict = 1;
515+
516+
/* set the keyId on the struct */
517+
ret = wh_Client_AesSetKeyId(aes, keyId);
518+
if (ret != 0) {
519+
WH_BENCH_PRINTF("Failed to wh_Client_SetKeyIdAes %d\n", ret);
520+
goto exit;
521+
}
522+
523+
/* set the iv */
524+
ret = wc_AesSetIV(aes, iv);
525+
if (ret != 0) {
526+
WH_BENCH_PRINTF("Failed to wc_AesSetIV %d\n", ret);
527+
goto exit;
528+
}
529+
530+
ret = wh_Bench_SetDataSize(ctx, id, inLen);
531+
if (ret != 0) {
532+
WH_BENCH_PRINTF("Failed to wh_Bench_SetDataSize %d\n", ret);
533+
goto exit;
534+
}
535+
536+
for (i = 0; i < WOLFHSM_CFG_BENCH_CRYPT_ITERS; i++) {
537+
int benchStartRet;
538+
int benchStopRet;
539+
540+
if (encrypt == ENCRYPT) {
541+
benchStartRet = wh_Bench_StartOp(ctx, id);
542+
543+
ret = wh_Client_AesGcmDma(client, aes, ENCRYPT, in, inLen, iv,
544+
sizeof(iv), authData, sizeof(authData),
545+
NULL, authTag, sizeof(authTag), out);
546+
547+
benchStopRet = wh_Bench_StopOp(ctx, id);
548+
}
549+
else {
550+
benchStartRet = wh_Bench_StartOp(ctx, id);
551+
552+
ret = wh_Client_AesGcmDma(client, aes, DECRYPT, in, inLen, iv,
553+
sizeof(iv), authData, sizeof(authData),
554+
authTag, NULL, sizeof(authTag), out);
555+
556+
benchStopRet = wh_Bench_StopOp(ctx, id);
557+
558+
/* Squash auth error since we are using dummy data */
559+
if (ret == AES_GCM_AUTH_E) {
560+
ret = 0;
561+
}
562+
}
563+
564+
if (benchStartRet != 0) {
565+
WH_BENCH_PRINTF("Failed to wh_Bench_StartOp %d\n", benchStartRet);
566+
ret = benchStartRet;
567+
goto exit;
568+
}
569+
if (ret != 0) {
570+
WH_BENCH_PRINTF("Failed to wh_Client_AesGcmDma %d\n", ret);
571+
goto exit;
572+
}
573+
if (benchStopRet != 0) {
574+
WH_BENCH_PRINTF("Failed to wh_Bench_StopOp %d\n", benchStopRet);
575+
ret = benchStopRet;
576+
goto exit;
577+
}
578+
}
579+
580+
exit:
581+
wc_AesFree(aes);
582+
583+
if (needEvict) {
584+
int evictRet = wh_Client_KeyEvict(client, keyId);
585+
if (evictRet != 0) {
586+
WH_BENCH_PRINTF("Failed to evict key from cache: %d\n", evictRet);
587+
ret = evictRet;
588+
}
589+
}
590+
591+
#if defined(WOLFHSM_CFG_TEST_POSIX)
592+
if (ctx->transportType == WH_BENCH_TRANSPORT_POSIX_DMA) {
593+
/* if static memory was used with DMA then use XFREE */
594+
void* heap =
595+
posixTransportShm_GetDmaHeap(client->comm->transport_context);
596+
XFREE((uint8_t*)in, heap, DYNAMIC_TYPE_TMP_BUFFER);
597+
XFREE(out, heap, DYNAMIC_TYPE_TMP_BUFFER);
598+
}
599+
#endif /* WOLFHSM_CFG_TEST_POSIX */
600+
601+
return ret;
602+
}
603+
#endif /* WOLFHSM_CFG_DMA */
604+
443605
static int _benchAesGcm(whClientContext* client, whBenchOpContext* ctx, int id,
444606
const uint8_t* key, size_t keyLen, int encrypt)
445607
{
@@ -598,6 +760,74 @@ int wh_Bench_Mod_Aes256GCMDecrypt(whClientContext* client,
598760
return _benchAesGcm(client, ctx, id, (uint8_t*)key256, sizeof(key256),
599761
DECRYPT);
600762
}
763+
764+
int wh_Bench_Mod_Aes128GCMEncryptDma(whClientContext* client,
765+
whBenchOpContext* ctx, int id,
766+
void* params)
767+
{
768+
#if defined(WOLFHSM_CFG_DMA)
769+
(void)params;
770+
return _benchAesGcmDma(client, ctx, id, (uint8_t*)key128, sizeof(key128),
771+
ENCRYPT);
772+
#else
773+
(void)client;
774+
(void)ctx;
775+
(void)id;
776+
(void)params;
777+
return WH_ERROR_NOTIMPL;
778+
#endif
779+
}
780+
781+
int wh_Bench_Mod_Aes128GCMDecryptDma(whClientContext* client,
782+
whBenchOpContext* ctx, int id,
783+
void* params)
784+
{
785+
#if defined(WOLFHSM_CFG_DMA)
786+
(void)params;
787+
return _benchAesGcmDma(client, ctx, id, (uint8_t*)key128, sizeof(key128),
788+
DECRYPT);
789+
#else
790+
(void)client;
791+
(void)ctx;
792+
(void)id;
793+
(void)params;
794+
return WH_ERROR_NOTIMPL;
795+
#endif
796+
}
797+
798+
int wh_Bench_Mod_Aes256GCMEncryptDma(whClientContext* client,
799+
whBenchOpContext* ctx, int id,
800+
void* params)
801+
{
802+
#if defined(WOLFHSM_CFG_DMA)
803+
(void)params;
804+
return _benchAesGcmDma(client, ctx, id, (uint8_t*)key256, sizeof(key256),
805+
ENCRYPT);
806+
#else
807+
(void)client;
808+
(void)ctx;
809+
(void)id;
810+
(void)params;
811+
return WH_ERROR_NOTIMPL;
812+
#endif
813+
}
814+
815+
int wh_Bench_Mod_Aes256GCMDecryptDma(whClientContext* client,
816+
whBenchOpContext* ctx, int id,
817+
void* params)
818+
{
819+
#if defined(WOLFHSM_CFG_DMA)
820+
(void)params;
821+
return _benchAesGcmDma(client, ctx, id, (uint8_t*)key256, sizeof(key256),
822+
DECRYPT);
823+
#else
824+
(void)client;
825+
(void)ctx;
826+
(void)id;
827+
(void)params;
828+
return WH_ERROR_NOTIMPL;
829+
#endif
830+
}
601831
#endif /* HAVE_AESGCM */
602832

603833
#endif /* !defined(NO_AES) */

benchmark/bench_modules/wh_bench_mod_all.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ int wh_Bench_Mod_Aes128GCMEncrypt(whClientContext* client,
5151
int wh_Bench_Mod_Aes128GCMDecrypt(whClientContext* client,
5252
whBenchOpContext* ctx, int id, void* params);
5353

54+
int wh_Bench_Mod_Aes128GCMEncryptDma(whClientContext* client,
55+
whBenchOpContext* ctx, int id,
56+
void* params);
57+
58+
int wh_Bench_Mod_Aes128GCMDecryptDma(whClientContext* client,
59+
whBenchOpContext* ctx, int id,
60+
void* params);
61+
5462
int wh_Bench_Mod_Aes256CTREncrypt(whClientContext* client,
5563
whBenchOpContext* ctx, int id, void* params);
5664

@@ -75,6 +83,14 @@ int wh_Bench_Mod_Aes256GCMEncrypt(whClientContext* client,
7583
int wh_Bench_Mod_Aes256GCMDecrypt(whClientContext* client,
7684
whBenchOpContext* ctx, int id, void* params);
7785

86+
int wh_Bench_Mod_Aes256GCMEncryptDma(whClientContext* client,
87+
whBenchOpContext* ctx, int id,
88+
void* params);
89+
90+
int wh_Bench_Mod_Aes256GCMDecryptDma(whClientContext* client,
91+
whBenchOpContext* ctx, int id,
92+
void* params);
93+
7894
/*
7995
* CMAC benchmark module prototypes (wh_bench_mod_cmac.c)
8096
*/
@@ -143,6 +159,12 @@ int wh_Bench_Mod_HmacSha3256(whClientContext* client, whBenchOpContext* ctx,
143159
int wh_Bench_Mod_HmacSha3256Dma(whClientContext* client, whBenchOpContext* ctx,
144160
int id, void* params);
145161

162+
/*
163+
* HKDF benchmark module prototypes (wh_bench_mod_hkdf.c)
164+
*/
165+
int wh_Bench_Mod_HkdfSha256(whClientContext* client, whBenchOpContext* ctx,
166+
int id, void* params);
167+
146168
/*
147169
* ECC benchmark module prototypes (wh_bench_mod_ecc.c)
148170
*/

0 commit comments

Comments
 (0)