Skip to content

Commit 52d5d0a

Browse files
committed
linuxkm/, wolfcrypt/src/dh.c, wolfcrypt/test/test.c, wolfcrypt/test/test.h, wolfssl/wolfcrypt/wc_port.h:
fixes and workarounds for clang-tidy complaints: * clang-diagnostic-unknown-warning-option * bugprone-sizeof-expression * clang-diagnostic-error "address argument to atomic operation must be a pointer to a trivially-copyable type" * bugprone-macro-parentheses * clang-diagnostic-unused-but-set-variable * readability-redundant-declaration
1 parent 7efc962 commit 52d5d0a

9 files changed

Lines changed: 61 additions & 28 deletions

File tree

linuxkm/linuxkm_wc_port.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@
276276
_Pragma("GCC diagnostic ignored \"-Wsign-compare\"");
277277
_Pragma("GCC diagnostic ignored \"-Wpointer-sign\"");
278278
_Pragma("GCC diagnostic ignored \"-Wbad-function-cast\"");
279+
#ifndef __clang__
279280
_Pragma("GCC diagnostic ignored \"-Wdiscarded-qualifiers\"");
281+
#endif
280282
_Pragma("GCC diagnostic ignored \"-Wtype-limits\"");
281283
_Pragma("GCC diagnostic ignored \"-Wswitch-enum\"");
282284
_Pragma("GCC diagnostic ignored \"-Wcast-function-type\""); /* needed for kernel 4.14.336 */
@@ -1870,8 +1872,10 @@
18701872
* them to be evaluable by the preprocessor, for use in sp_int.h.
18711873
*/
18721874
#if BITS_PER_LONG == 64
1875+
/* NOLINTBEGIN(bugprone-sizeof-expression) */
18731876
static_assert(sizeof(ULONG_MAX) == 8,
18741877
"BITS_PER_LONG is 64, but ULONG_MAX is not.");
1878+
/* NOLINTEND(bugprone-sizeof-expression) */
18751879

18761880
#undef UCHAR_MAX
18771881
#define UCHAR_MAX 255

linuxkm/lkcapi_glue.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static int linuxkm_lkcapi_register(void)
379379
"with return code %d.\n", \
380380
(alg).base.cra_driver_name, ret); \
381381
(crypto_unregister_ ## alg_class)(&(alg)); \
382-
if (! (alg.base.cra_flags & CRYPTO_ALG_DEAD)) { \
382+
if (! ((alg).base.cra_flags & CRYPTO_ALG_DEAD)) { \
383383
pr_err("ERROR: alg %s not _DEAD " \
384384
"after crypto_unregister_%s -- " \
385385
"marking as loaded despite test failure.", \
@@ -787,18 +787,18 @@ static int linuxkm_lkcapi_unregister(void)
787787
#define UNREGISTER_ALG(alg, alg_class) \
788788
do { \
789789
if (alg ## _loaded) { \
790-
if (alg.base.cra_flags & CRYPTO_ALG_DEAD) { \
790+
if ((alg).base.cra_flags & CRYPTO_ALG_DEAD) { \
791791
pr_err("alg %s already CRYPTO_ALG_DEAD.", \
792-
alg.base.cra_driver_name); \
792+
(alg).base.cra_driver_name); \
793793
alg ## _loaded = 0; \
794794
++n_deregistered; \
795795
} \
796796
else { \
797797
int cur_refcnt = \
798-
WC_LKM_REFCOUNT_TO_INT(alg.base.cra_refcnt); \
798+
WC_LKM_REFCOUNT_TO_INT((alg).base.cra_refcnt); \
799799
if (cur_refcnt == 1) { \
800800
(crypto_unregister_ ## alg_class)(&(alg)); \
801-
if (! (alg.base.cra_flags & CRYPTO_ALG_DEAD)) { \
801+
if (! ((alg).base.cra_flags & CRYPTO_ALG_DEAD)) { \
802802
pr_err("ERROR: alg %s not _DEAD after " \
803803
"crypto_unregister_%s -- " \
804804
"leaving marked as loaded.", \
@@ -812,7 +812,7 @@ static int linuxkm_lkcapi_unregister(void)
812812
} \
813813
else { \
814814
pr_err("alg %s cannot be uninstalled (refcnt = %d)", \
815-
alg.base.cra_driver_name, cur_refcnt); \
815+
(alg).base.cra_driver_name, cur_refcnt); \
816816
if (cur_refcnt > 0) { seen_err = -EBUSY; } \
817817
} \
818818
} \

linuxkm/lkcapi_rsa_glue.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,7 +2935,9 @@ static int linuxkm_test_pkcs1pad_driver(const char * driver, int nbits,
29352935
pr_info("info: %s, %d, %d: self test returned: %d\n", driver,
29362936
nbits, key_len, ret);
29372937
}
2938-
#endif /* WOLFKM_DEBUG_RSA */
2938+
#else /* !WOLFKM_DEBUG_RSA */
2939+
(void)skipped;
2940+
#endif /* !WOLFKM_DEBUG_RSA */
29392941

29402942
return test_rc;
29412943
}
@@ -3292,7 +3294,9 @@ static int linuxkm_test_pkcs1_driver(const char * driver, int nbits,
32923294
pr_info("info: %s, %d, %d: self test returned: %d\n", driver,
32933295
nbits, key_len, ret);
32943296
}
3295-
#endif /* WOLFKM_DEBUG_RSA */
3297+
#else /* !WOLFKM_DEBUG_RSA */
3298+
(void)skipped;
3299+
#endif /* !WOLFKM_DEBUG_RSA */
32963300

32973301
return test_rc;
32983302
}

linuxkm/lkcapi_sha_glue.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ static struct shash_alg name ## _alg = \
565565
.digest = km_ ## name ## _digest, \
566566
.descsize = sizeof(struct km_sha_state), \
567567
.base = { \
568-
.cra_name = this_cra_name, \
569-
.cra_driver_name = this_cra_driver_name, \
568+
.cra_name = (this_cra_name), \
569+
.cra_driver_name = (this_cra_driver_name), \
570570
.cra_priority = WOLFSSL_LINUXKM_LKCAPI_PRIORITY, \
571571
.cra_blocksize = (block_size), \
572572
.cra_module = THIS_MODULE \
@@ -671,8 +671,8 @@ static struct shash_alg name ## _alg = \
671671
.digest = km_ ## name ## _digest, \
672672
.descsize = sizeof(struct km_sha_state), \
673673
.base = { \
674-
.cra_name = this_cra_name, \
675-
.cra_driver_name = this_cra_driver_name, \
674+
.cra_name = (this_cra_name), \
675+
.cra_driver_name = (this_cra_driver_name), \
676676
.cra_priority = WOLFSSL_LINUXKM_LKCAPI_PRIORITY, \
677677
.cra_blocksize = (block_size), \
678678
.cra_module = THIS_MODULE \
@@ -909,8 +909,8 @@ static struct shash_alg name ## _alg = \
909909
.exit_tfm = km_hmac_exit_tfm, \
910910
.descsize = sizeof(struct km_sha_hmac_state), \
911911
.base = { \
912-
.cra_name = this_cra_name, \
913-
.cra_driver_name = this_cra_driver_name, \
912+
.cra_name = (this_cra_name), \
913+
.cra_driver_name = (this_cra_driver_name), \
914914
.cra_priority = WOLFSSL_LINUXKM_LKCAPI_PRIORITY, \
915915
.cra_blocksize = (block_size), \
916916
.cra_ctxsize = sizeof(struct km_sha_hmac_pstate), \

linuxkm/module_hooks.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,11 @@ static unsigned int hash_span(const u8 *start, const u8 *end, unsigned int sum)
136136
return sum;
137137
}
138138

139-
#ifdef WC_SYM_RELOC_TABLES
140139
struct wc_reloc_counts reloc_counts = {};
141-
#endif
142140

143141
#endif /* DEBUG_LINUXKM_PIE_SUPPORT */
144142

145-
#ifdef WC_SYM_RELOC_TABLES
146-
extern struct wolfssl_linuxkm_pie_redirect_table wolfssl_linuxkm_pie_redirect_table;
147143
static int set_up_wolfssl_linuxkm_pie_redirect_table(void);
148-
#endif /* WC_SYM_RELOC_TABLES */
149144

150145
#ifdef HAVE_FIPS
151146
extern const unsigned int wolfCrypt_FIPS_ro_start[];

wolfcrypt/src/dh.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,13 +1032,13 @@ static int _ffc_pairwise_consistency_test(DhKey* key,
10321032
#ifndef WOLFSSL_DH_CONST
10331033
#define WOLFSSL_DH_ROUND(x) WC_DO_NOTHING
10341034
#else
1035-
#define WOLFSSL_DH_ROUND(x) \
1036-
do { \
1037-
if (x % 128) { \
1038-
x &= 0xffffff80;\
1039-
x += 128; \
1040-
} \
1041-
} \
1035+
#define WOLFSSL_DH_ROUND(x) \
1036+
do { \
1037+
if ((x) % 128) { \
1038+
(x) &= 0xffffff80;\
1039+
(x) += 128; \
1040+
} \
1041+
} \
10421042
while (0)
10431043
#endif
10441044

wolfcrypt/test/test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ typedef struct testVector {
581581
#define WOLFSSL_TEST_SUBROUTINE
582582
#endif
583583

584+
#ifndef WC_TEST_EXPORT_SUBTESTS
585+
584586
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t macro_test(void);
585587
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void);
586588
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void);
@@ -900,6 +902,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void);
900902
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t drbg_continuous_main(void);
901903
#endif
902904

905+
#endif /* !WC_TEST_EXPORT_SUBTESTS */
906+
903907
/* General big buffer size for many tests. */
904908
#define FOURK_BUF 4096
905909

wolfcrypt/test/test.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ wc_static_assert(-(long)MIN_CODE_E < 0x7ffL);
104104

105105
#ifdef WC_TEST_EXPORT_SUBTESTS
106106

107+
#if defined(NO_FILESYSTEM) || defined(WC_NO_RNG)
108+
#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
109+
!defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
110+
#define USE_CERT_BUFFERS_2048
111+
#endif
112+
#if !defined(USE_CERT_BUFFERS_256)
113+
#define USE_CERT_BUFFERS_256
114+
#endif
115+
#endif
116+
117+
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t macro_test(void);
107118
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void);
108119
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void);
109120
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void);
@@ -172,6 +183,15 @@ extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void);
172183
#ifdef WC_SRTP_KDF
173184
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void);
174185
#endif
186+
187+
#if defined(WC_KDF_NIST_SP_800_56C) && \
188+
(!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
189+
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t nist_sp80056c_kdf_test(void);
190+
#endif
191+
#if defined(HAVE_CMAC_KDF) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
192+
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t nist_sp800108_cmac(void);
193+
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t nist_sp80056c_twostep_cmac(void);
194+
#endif
175195
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void);
176196
#ifdef WC_RC2
177197
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void);
@@ -221,12 +241,15 @@ extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void);
221241
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void);
222242
#ifndef WC_NO_RNG
223243
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void);
244+
#ifdef WC_RNG_BANK_SUPPORT
245+
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_bank_test(void);
246+
#endif
224247
#endif /* WC_NO_RNG */
225248
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void);
226249
#if defined(USE_CERT_BUFFERS_2048) && \
227250
defined(HAVE_PKCS12) && \
228251
!defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
229-
!defined(NO_CERTS) && !defined(NO_DES3)
252+
!defined(NO_CERTS) && !defined(NO_DES3) && !defined(NO_SHA)
230253
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void);
231254
#endif
232255
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ripemd_test(void);
@@ -307,9 +330,11 @@ extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void);
307330
#endif
308331
#ifdef HAVE_BLAKE2
309332
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_test(void);
333+
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_hmac_test(void);
310334
#endif
311335
#ifdef HAVE_BLAKE2S
312336
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_test(void);
337+
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_hmac_test(void);
313338
#endif
314339
#ifdef HAVE_LIBZ
315340
extern WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void);

wolfssl/wolfcrypt/wc_port.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@
539539
* should not be included. Use FreeBSD <machine/atomic.h> instead.
540540
* definitions are in bsdkm/bsdkm_wc_port.h */
541541
#elif defined(HAVE_C___ATOMIC) && defined(WOLFSSL_HAVE_ATOMIC_H) && \
542-
!defined(__cplusplus)
542+
!defined(__cplusplus) && \
543+
!(defined(__clang__) && defined(WOLFSSL_KERNEL_MODE))
543544
/* Default C Implementation */
544545
#include <stdatomic.h>
545546
typedef atomic_int wolfSSL_Atomic_Int;

0 commit comments

Comments
 (0)