Skip to content

Commit 5b1d2d7

Browse files
authored
Merge pull request #10086 from douzzer/20260326-various-fixes
20260326-various-fixes
2 parents 7efc962 + 53f3ce6 commit 5b1d2d7

14 files changed

Lines changed: 99 additions & 69 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[];

tests/api/test_aes.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
#include <tests/api/api.h>
3535
#include <tests/api/test_aes.h>
3636

37-
#define WC_ALLOC_DO_ON_FAILURE() WC_DO_NOTHING
38-
3937
/*******************************************************************************
4038
* AES
4139
******************************************************************************/

tests/api/test_rsa.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
#include <tests/api/api.h>
3434
#include <tests/api/test_rsa.h>
3535

36-
#define WC_ALLOC_DO_ON_FAILURE() WC_DO_NOTHING
37-
3836
/*
3937
* Testing wc_Init RsaKey()
4038
*/

wolfcrypt/benchmark/benchmark.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
/* Macro to disable benchmark */
7070
#ifndef NO_CRYPT_BENCHMARK
7171

72+
#undef WC_ALLOC_DO_ON_FAILURE
7273
#define WC_ALLOC_DO_ON_FAILURE() do { printf("out of memory at benchmark.c L %d\n", __LINE__); ret = MEMORY_E; goto exit; } while (0)
7374

7475
#include <wolfssl/wolfcrypt/types.h>

wolfcrypt/src/asn.c

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11461,14 +11461,15 @@ int wc_DsaPublicKeyDecode(const byte* input, word32* inOutIdx, DsaKey* key,
1146111461

1146211462
/* Validated parameters. */
1146311463
if ((input == NULL) || (inOutIdx == NULL) || (key == NULL)) {
11464-
ret = BAD_FUNC_ARG;
11464+
return BAD_FUNC_ARG;
1146511465
}
1146611466

11467-
if (ret == 0) {
11468-
ALLOC_ASNGETDATA(dataASN, dsaPubKeyASN_Length, ret, key->heap);
11469-
}
11467+
ALLOC_ASNGETDATA(dataASN, dsaPubKeyASN_Length, ret, key->heap);
1147011468

11471-
if (ret == 0) {
11469+
if (ret != 0)
11470+
return ret;
11471+
11472+
{
1147211473
int i;
1147311474

1147411475
/* Clear dynamic data items. */
@@ -30137,44 +30138,42 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
3013730138
int pubIdx = ECCPUBLICKEYASN_IDX_PUBKEY;
3013830139

3013930140
if ((input == NULL) || (inOutIdx == NULL) || (key == NULL) || (inSz == 0)) {
30140-
ret = BAD_FUNC_ARG;
30141+
return BAD_FUNC_ARG;
3014130142
}
3014230143

30143-
if (ret == 0) {
30144-
ALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap);
30145-
}
30144+
ALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap);
30145+
if (ret != 0)
30146+
return ret;
3014630147

30147-
if (ret == 0) {
30148-
/* Clear dynamic data for ECC public key. */
30149-
XMEMSET(dataASN, 0, sizeof(*dataASN) * eccPublicKeyASN_Length);
30148+
/* Clear dynamic data for ECC public key. */
30149+
XMEMSET(dataASN, 0, sizeof(*dataASN) * eccPublicKeyASN_Length);
3015030150
#if !defined(WOLFSSL_SM2) || !defined(WOLFSSL_SM3)
30151-
/* Set required ECDSA OID and ignore the curve OID type. */
30152-
GetASN_ExpBuffer(&dataASN[ECCPUBLICKEYASN_IDX_ALGOID_OID], keyEcdsaOid,
30153-
sizeof(keyEcdsaOid));
30151+
/* Set required ECDSA OID and ignore the curve OID type. */
30152+
GetASN_ExpBuffer(&dataASN[ECCPUBLICKEYASN_IDX_ALGOID_OID], keyEcdsaOid,
30153+
sizeof(keyEcdsaOid));
3015430154
#else
30155-
GetASN_OID(&dataASN[ECCPUBLICKEYASN_IDX_ALGOID_OID], oidKeyType);
30155+
GetASN_OID(&dataASN[ECCPUBLICKEYASN_IDX_ALGOID_OID], oidKeyType);
3015630156
#endif
30157+
GetASN_OID(&dataASN[oidIdx], oidCurveType);
30158+
/* Decode the public ECC key. */
30159+
ret = GetASN_Items(eccPublicKeyASN, dataASN, eccPublicKeyASN_Length, 1,
30160+
input, inOutIdx, inSz);
30161+
if (ret != 0) {
30162+
oidIdx = ECCKEYASN_IDX_CURVEID;
30163+
#ifdef WOLFSSL_CUSTOM_CURVES
30164+
specIdx = ECCKEYASN_IDX_CURVEPARAMS;
30165+
#endif
30166+
pubIdx = ECCKEYASN_IDX_PUBKEY_VAL;
30167+
30168+
/* Clear dynamic data for ECC private key. */
30169+
XMEMSET(dataASN, 0, sizeof(*dataASN) * eccKeyASN_Length);
30170+
/* Check named curve OID type. */
3015730171
GetASN_OID(&dataASN[oidIdx], oidCurveType);
30158-
/* Decode the public ECC key. */
30159-
ret = GetASN_Items(eccPublicKeyASN, dataASN, eccPublicKeyASN_Length, 1,
30160-
input, inOutIdx, inSz);
30172+
/* Try private key format .*/
30173+
ret = GetASN_Items(eccKeyASN, dataASN, eccKeyASN_Length, 1, input,
30174+
inOutIdx, inSz);
3016130175
if (ret != 0) {
30162-
oidIdx = ECCKEYASN_IDX_CURVEID;
30163-
#ifdef WOLFSSL_CUSTOM_CURVES
30164-
specIdx = ECCKEYASN_IDX_CURVEPARAMS;
30165-
#endif
30166-
pubIdx = ECCKEYASN_IDX_PUBKEY_VAL;
30167-
30168-
/* Clear dynamic data for ECC private key. */
30169-
XMEMSET(dataASN, 0, sizeof(*dataASN) * eccKeyASN_Length);
30170-
/* Check named curve OID type. */
30171-
GetASN_OID(&dataASN[oidIdx], oidCurveType);
30172-
/* Try private key format .*/
30173-
ret = GetASN_Items(eccKeyASN, dataASN, eccKeyASN_Length, 1, input,
30174-
inOutIdx, inSz);
30175-
if (ret != 0) {
30176-
ret = ASN_PARSE_E;
30177-
}
30176+
ret = ASN_PARSE_E;
3017830177
}
3017930178
}
3018030179

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

0 commit comments

Comments
 (0)