Skip to content

Commit 732e964

Browse files
authored
Add scan build github action (#195)
add scan build github action and necessary code fixes
1 parent 8ac56d7 commit 732e964

38 files changed

+270
-56
lines changed

.github/workflows/static-analysis.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,37 @@ jobs:
6363
echo "❌ Static analysis failed - errors or warnings were found"
6464
exit 1
6565
66+
scan-build:
67+
runs-on: ubuntu-latest
68+
69+
steps:
70+
- name: Checkout wolfHSM
71+
uses: actions/checkout@v4
72+
with:
73+
path: wolfHSM
74+
75+
- name: Checkout wolfssl
76+
uses: actions/checkout@v4
77+
with:
78+
repository: wolfssl/wolfssl
79+
path: wolfssl
80+
81+
- name: Install dependencies
82+
run: |
83+
sudo apt-get update
84+
sudo apt-get install -y clang build-essential clang-tools
85+
86+
- name: Run scan-build
87+
id: scan-build
88+
run:
89+
cd wolfHSM && make scan
90+
91+
- name: Fail if scan-build issues found
92+
if: steps.scan-build.outcome == 'failure'
93+
run: |
94+
echo "❌ scan-build analysis failed - errors or warnings were found"
95+
exit 1
96+
6697
clang-tidy:
6798
runs-on: ubuntu-latest
6899

@@ -106,7 +137,6 @@ jobs:
106137
echo ""
107138
# Show first 50 issues to avoid overwhelming output
108139
head -50 tools/static-analysis/reports/clang_tidy_summary.txt
109-
110140
TOTAL_ISSUES=$((ERROR_COUNT + WARNING_COUNT))
111141
if [ "$TOTAL_ISSUES" -gt 50 ]; then
112142
echo ""

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,41 @@ tools:
1515
examples:
1616
make -C examples
1717

18+
SCAN_DIR = ./scan_out
19+
20+
scan_result_check:
21+
@err=$$(grep -h -o 'error: .*' ./$(SCAN_DIR)/*.log | wc -l); \
22+
if [ -z "$$err" ]; then \
23+
err=0; \
24+
fi; \
25+
wrn=$$(grep -h -o '^[0-9]\+ warnings\? generated' ./$(SCAN_DIR)/*.log | grep -o '^[0-9]\+' | awk '{s+=$$1} END {print s}');\
26+
if [ -z "$$wrn" ]; then \
27+
wrn=0; \
28+
fi; \
29+
if [ $$err -eq 0 -a $$wrn -eq 0 ]; then \
30+
echo "no errors or warnings found";\
31+
exit 0; \
32+
else\
33+
echo "scan-build detected $$err errors and $$wrn warnings";\
34+
for f in $(SCAN_DIR)/*.log; do \
35+
echo "---- $$f ----"; \
36+
cat $$f; \
37+
echo ""; \
38+
done; \
39+
exit 1; \
40+
fi;
41+
42+
scan:
43+
@echo "Running scan-build static analysis"
44+
@rm -rf $(SCAN_DIR)
45+
@mkdir -p $(SCAN_DIR)
46+
@make clean
47+
-@make SCAN=1 -C test scan
48+
-@make SCAN=1 -C benchmark scan
49+
-@make NOCRYPTO=1 SCAN=1 -C tools/whnvmtool scan
50+
-@make NOCRYPTO=1 SCAN=1 -C examples
51+
@$(MAKE) scan_result_check
52+
1853
clean:
1954
make -C test clean
2055
make -C benchmark clean

benchmark/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ ifeq ($(NOCRYPTO),1)
103103
DEF += -DWOLFHSM_CFG_NO_CRYPTO
104104
endif
105105

106+
ifeq ($(SCAN),1)
107+
SCAN_LOG = scan_benchmark.log
108+
# Default target
109+
.DEFAULT_GOAL := scan
110+
endif
111+
106112
# Support a DMA-capable build
107113
ifeq ($(DMA),1)
108114
DEF += -DWOLFHSM_CFG_DMA
@@ -161,6 +167,13 @@ build_static: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).a
161167
@echo ""
162168
$(CMD_ECHO) $(SIZE) $(BUILD_DIR)/$(BIN).a
163169

170+
analyze: $(OBJS_ASM) $(OBJS_C)
171+
172+
scan:$(BUILD_DIR)
173+
@echo "Running scan-build static analysis"
174+
@mkdir -p $(WOLFHSM_DIR)/scan_out/
175+
@scan-build --status-bugs $(MAKE) analyze 2> $(WOLFHSM_DIR)/scan_out/$(SCAN_LOG)
176+
164177
$(BUILD_DIR):
165178
$(CMD_ECHO) mkdir -p $(BUILD_DIR)
166179

benchmark/bench_modules/wh_bench_mod_aes.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
#include "wolfhsm/wh_client.h"
2222
#include "wolfhsm/wh_client_crypto.h"
2323

24+
#if !defined(WOLFHSM_CFG_NO_CRYPTO) && defined(WOLFHSM_CFG_BENCH_ENABLE)
2425
#include "wolfssl/wolfcrypt/aes.h"
2526

26-
#if defined(WOLFHSM_CFG_BENCH_ENABLE)
27-
2827
#if defined(WOLFHSM_CFG_DMA) && defined(WOLFHSM_CFG_TEST_POSIX)
2928
#include "port/posix/posix_transport_shm.h"
3029
#endif /* WOLFHSM_CFG_DMA && WOLFHSM_CFG_TEST_POSIX */
@@ -832,4 +831,4 @@ int wh_Bench_Mod_Aes256GCMDecryptDma(whClientContext* client,
832831

833832
#endif /* !defined(NO_AES) */
834833

835-
#endif /* WOLFHSM_CFG_BENCH_ENABLE */
834+
#endif /* !WOLFHSM_CFG_NO_CRYPTO && WOLFHSM_CFG_BENCH_ENABLE */

benchmark/bench_modules/wh_bench_mod_cmac.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
#include "wolfhsm/wh_error.h"
2222
#include "wolfhsm/wh_client_crypto.h"
2323

24+
#if !defined(WOLFHSM_CFG_NO_CRYPTO) && defined(WOLFHSM_CFG_BENCH_ENABLE)
2425
#include "wolfssl/wolfcrypt/cmac.h"
2526

26-
#if defined(WOLFHSM_CFG_BENCH_ENABLE)
27-
2827
#if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT)
2928

3029
static const uint8_t key128[] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae,
@@ -184,4 +183,4 @@ int wh_Bench_Mod_CmacAes256Dma(whClientContext* client, whBenchOpContext* ctx,
184183

185184
#endif /* WOLFSSL_CMAC && !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT) */
186185

187-
#endif /* WOLFHSM_CFG_BENCH_ENABLE */
186+
#endif /* !WOLFHSM_CFG_NO_CRYPTO && WOLFHSM_CFG_BENCH_ENABLE */

benchmark/bench_modules/wh_bench_mod_curve25519.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
#include "wolfhsm/wh_client.h"
2222
#include "wolfhsm/wh_client_crypto.h"
2323

24+
25+
#if !defined(WOLFHSM_CFG_NO_CRYPTO) && defined(WOLFHSM_CFG_BENCH_ENABLE)
2426
#include "wolfssl/wolfcrypt/settings.h"
2527
#include "wolfssl/wolfcrypt/random.h"
2628
#include "wolfssl/wolfcrypt/curve25519.h"
2729

28-
#if defined(WOLFHSM_CFG_BENCH_ENABLE)
29-
3030
#if defined(HAVE_CURVE25519)
3131

3232
uint8_t key1_der[] = {
@@ -252,4 +252,4 @@ int wh_Bench_Mod_Curve25519SharedSecret(whClientContext* client,
252252

253253
#endif /* HAVE_CURVE25519 */
254254

255-
#endif /* WOLFHSM_CFG_BENCH_ENABLE */
255+
#endif /* !WOLFHSM_CFG_NO_CRYPTO && WOLFHSM_CFG_BENCH_ENABLE */

benchmark/bench_modules/wh_bench_mod_ecc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#include "wolfhsm/wh_client.h"
2222
#include "wolfhsm/wh_client_crypto.h"
2323

24+
25+
#if !defined(WOLFHSM_CFG_NO_CRYPTO) && defined(WOLFHSM_CFG_BENCH_ENABLE)
26+
2427
#include "wolfssl/wolfcrypt/ecc.h"
2528
#include "wolfssl/wolfcrypt/random.h"
2629

27-
#if defined(WOLFHSM_CFG_BENCH_ENABLE)
28-
2930
#if defined(HAVE_ECC)
3031

3132
/* hardcoded DER-encoded ECC keys for benchmarking */
@@ -566,4 +567,4 @@ int wh_Bench_Mod_EccP256Ecdh(whClientContext* client, whBenchOpContext* ctx,
566567

567568
#endif /* HAVE_ECC */
568569

569-
#endif /* WOLFHSM_CFG_BENCH_ENABLE */
570+
#endif /* !WOLFHSM_CFG_NO_CRYPTO && WOLFHSM_CFG_BENCH_ENABLE */

benchmark/bench_modules/wh_bench_mod_hkdf.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
#include "wh_bench_mod.h"
2121
#include "wolfhsm/wh_error.h"
2222

23+
#if !defined(WOLFHSM_CFG_NO_CRYPTO) && defined(WOLFHSM_CFG_BENCH_ENABLE)
2324
#include "wolfssl/wolfcrypt/hmac.h"
2425
#include "wolfssl/wolfcrypt/kdf.h"
2526
#include "wolfssl/wolfcrypt/sha256.h"
2627

27-
#if defined(WOLFHSM_CFG_BENCH_ENABLE)
28-
2928
#if defined(HAVE_HKDF)
3029

3130

@@ -93,4 +92,4 @@ int wh_Bench_Mod_HkdfSha256(whClientContext* client, whBenchOpContext* ctx,
9392

9493
#endif /* defined(HAVE_HKDF) */
9594

96-
#endif /* WOLFHSM_CFG_BENCH_ENABLE */
95+
#endif /* !WOLFHSM_CFG_NO_CRYPTO && WOLFHSM_CFG_BENCH_ENABLE */

benchmark/bench_modules/wh_bench_mod_hmac.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
#include "wh_bench_mod.h"
2020
#include "wolfhsm/wh_error.h"
2121

22+
#if !defined(WOLFHSM_CFG_NO_CRYPTO) && defined(WOLFHSM_CFG_BENCH_ENABLE)
2223
#include "wolfssl/wolfcrypt/hmac.h"
2324
#include "wolfssl/wolfcrypt/sha256.h"
2425

25-
#if defined(WOLFHSM_CFG_BENCH_ENABLE)
26-
2726
#if !defined(NO_HMAC)
2827

2928
#if !defined(NO_SHA256)
@@ -176,4 +175,4 @@ int wh_Bench_Mod_HmacSha3256Dma(whClientContext* client, whBenchOpContext* ctx,
176175

177176
#endif /* !defined(NO_HMAC) */
178177

179-
#endif /* WOLFHSM_CFG_BENCH_ENABLE */
178+
#endif /* !WOLFHSM_CFG_NO_CRYPTO && WOLFHSM_CFG_BENCH_ENABLE */

benchmark/bench_modules/wh_bench_mod_mldsa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#include "wolfhsm/wh_client.h"
2222
#include "wolfhsm/wh_client_crypto.h"
2323

24+
25+
#if !defined(WOLFHSM_CFG_NO_CRYPTO) && defined(WOLFHSM_CFG_BENCH_ENABLE)
2426
#include "wolfssl/wolfcrypt/dilithium.h"
2527
#include "wolfssl/wolfcrypt/random.h"
2628

27-
#if defined(WOLFHSM_CFG_BENCH_ENABLE)
28-
2929
#if defined(HAVE_DILITHIUM)
3030

3131
#if !defined(WOLFSSL_DILITHIUM_NO_SIGN)
@@ -1193,4 +1193,4 @@ int wh_Bench_Mod_MlDsa87KeyGenDma(whClientContext* client,
11931193

11941194
#endif /* HAVE_DILITHIUM */
11951195

1196-
#endif /* WOLFHSM_CFG_BENCH_ENABLE */
1196+
#endif /* !WOLFHSM_CFG_NO_CRYPTO && WOLFHSM_CFG_BENCH_ENABLE */

0 commit comments

Comments
 (0)