Skip to content

Commit b8392ef

Browse files
authored
Merge pull request #7092 from douzzer/20231224-clang-unreachable-code-aggressive
20231224-clang-unreachable-code-aggressive
2 parents daf1d17 + e68facd commit b8392ef

6 files changed

Lines changed: 46 additions & 29 deletions

File tree

src/ssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30338,9 +30338,9 @@ int wolfSSL_curve_is_disabled(const WOLFSSL* ssl, word16 curve_id)
3033830338
}
3033930339
if (curve_id >= 32) {
3034030340
/* 0 is for invalid and 1-14 aren't used otherwise. */
30341-
return (ssl->disabledCurves & (1 << (curve_id - 32))) != 0;
30341+
return (ssl->disabledCurves & (1U << (curve_id - 32))) != 0;
3034230342
}
30343-
return (ssl->disabledCurves & (1 << curve_id)) != 0;
30343+
return (ssl->disabledCurves & (1U << curve_id)) != 0;
3034430344
}
3034530345

3034630346
#if (defined(HAVE_ECC) || \

tests/suites.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,8 @@ int SuiteTest(int argc, char** argv)
14551455

14561456
return args.return_code;
14571457
#else
1458-
return NOT_COMPILED_IN;
14591458
(void)argc;
14601459
(void)argv;
1460+
return NOT_COMPILED_IN;
14611461
#endif /* !NO_WOLFSSL_SERVER && !NO_WOLFSSL_CLIENT */
14621462
}

wolfcrypt/src/chacha.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz)
200200
return 0;
201201
}
202202

203+
#ifndef USE_INTEL_CHACHA_SPEEDUP
203204
/**
204205
* Converts word into bytes with rotations having been done.
205206
*/
@@ -228,6 +229,7 @@ static WC_INLINE void wc_Chacha_wordtobyte(word32 x[CHACHA_CHUNK_WORDS],
228229
#endif
229230
}
230231
}
232+
#endif /* !USE_INTEL_CHACHA_SPEEDUP */
231233

232234

233235
#ifdef HAVE_XCHACHA
@@ -325,6 +327,7 @@ extern void chacha_encrypt_avx2(ChaCha* ctx, const byte* m, byte* c,
325327
#endif
326328

327329

330+
#ifndef USE_INTEL_CHACHA_SPEEDUP
328331
/**
329332
* Encrypt a stream of bytes
330333
*/
@@ -372,6 +375,8 @@ static void wc_Chacha_encrypt_bytes(ChaCha* ctx, const byte* m, byte* c,
372375
ctx->left = CHACHA_CHUNK_BYTES - bytes;
373376
}
374377
}
378+
#endif /* !USE_INTEL_CHACHA_SPEEDUP */
379+
375380

376381
/**
377382
* API to encrypt/decrypt a message of any size.
@@ -423,10 +428,10 @@ int wc_Chacha_Process(ChaCha* ctx, byte* output, const byte* input,
423428
chacha_encrypt_x64(ctx, input, output, msglen);
424429
return 0;
425430
}
426-
#endif
431+
#else
427432
wc_Chacha_encrypt_bytes(ctx, input, output, msglen);
428-
429433
return 0;
434+
#endif
430435
}
431436

432437
void wc_Chacha_purge_current_block(ChaCha* ctx) {

wolfcrypt/src/sha256.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static int InitSha256(wc_Sha256* sha256)
356356
intel_flags = cpuid_get_flags();
357357

358358
#ifdef HAVE_INTEL_AVX2
359-
if (1 && IS_INTEL_AVX2(intel_flags)) {
359+
if (IS_INTEL_AVX2(intel_flags)) {
360360
#ifdef HAVE_INTEL_RORX
361361
if (IS_INTEL_BMI2(intel_flags)) {
362362
Transform_Sha256_p = Transform_Sha256_AVX2_RORX;
@@ -365,27 +365,29 @@ static int InitSha256(wc_Sha256* sha256)
365365
}
366366
else
367367
#endif
368-
if (1)
369368
{
370369
Transform_Sha256_p = Transform_Sha256_AVX2;
371370
Transform_Sha256_Len_p = Transform_Sha256_AVX2_Len;
372371
Transform_Sha256_is_vectorized = 1;
373372
}
373+
}
374+
else
375+
#endif
376+
#ifdef HAVE_INTEL_AVX1
377+
if (IS_INTEL_AVX1(intel_flags)) {
374378
#ifdef HAVE_INTEL_RORX
375-
else {
379+
if (IS_INTEL_BMI2(intel_flags)) {
376380
Transform_Sha256_p = Transform_Sha256_AVX1_RORX;
377381
Transform_Sha256_Len_p = Transform_Sha256_AVX1_RORX_Len;
378382
Transform_Sha256_is_vectorized = 1;
379383
}
384+
else
380385
#endif
381-
}
382-
else
383-
#endif
384-
#ifdef HAVE_INTEL_AVX1
385-
if (IS_INTEL_AVX1(intel_flags)) {
386-
Transform_Sha256_p = Transform_Sha256_AVX1;
387-
Transform_Sha256_Len_p = Transform_Sha256_AVX1_Len;
388-
Transform_Sha256_is_vectorized = 1;
386+
{
387+
Transform_Sha256_p = Transform_Sha256_AVX1;
388+
Transform_Sha256_Len_p = Transform_Sha256_AVX1_Len;
389+
Transform_Sha256_is_vectorized = 1;
390+
}
389391
}
390392
else
391393
#endif

wolfcrypt/src/sha512.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,32 +452,36 @@ static int InitSha512_256(wc_Sha512* sha512)
452452
}
453453
else
454454
#endif
455-
if (1) {
455+
{
456456
Transform_Sha512_p = Transform_Sha512_AVX2;
457457
Transform_Sha512_Len_p = Transform_Sha512_AVX2_Len;
458458
Transform_Sha512_is_vectorized = 1;
459459
}
460+
}
461+
else
462+
#endif
463+
#if defined(HAVE_INTEL_AVX1)
464+
if (IS_INTEL_AVX1(intel_flags)) {
460465
#ifdef HAVE_INTEL_RORX
461-
else {
466+
if (IS_INTEL_BMI2(intel_flags)) {
462467
Transform_Sha512_p = Transform_Sha512_AVX1_RORX;
463468
Transform_Sha512_Len_p = Transform_Sha512_AVX1_RORX_Len;
464469
Transform_Sha512_is_vectorized = 1;
465470
}
471+
else
466472
#endif
467-
}
468-
else
469-
#endif
470-
#if defined(HAVE_INTEL_AVX1)
471-
if (IS_INTEL_AVX1(intel_flags)) {
472-
Transform_Sha512_p = Transform_Sha512_AVX1;
473-
Transform_Sha512_Len_p = Transform_Sha512_AVX1_Len;
474-
Transform_Sha512_is_vectorized = 1;
473+
{
474+
Transform_Sha512_p = Transform_Sha512_AVX1;
475+
Transform_Sha512_Len_p = Transform_Sha512_AVX1_Len;
476+
Transform_Sha512_is_vectorized = 1;
477+
}
475478
}
476479
else
477480
#endif
478481
{
479482
Transform_Sha512_p = _Transform_Sha512;
480-
Transform_Sha512_is_vectorized = 1;
483+
Transform_Sha512_Len_p = NULL;
484+
Transform_Sha512_is_vectorized = 0;
481485
}
482486

483487
transform_check = 1;

wolfssl/internal.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6139,9 +6139,15 @@ WOLFSSL_LOCAL int SetECKeyExternal(WOLFSSL_EC_KEY* eckey);
61396139

61406140
#if defined(OPENSSL_EXTRA) || defined(HAVE_CURL)
61416141
WOLFSSL_LOCAL int wolfSSL_curve_is_disabled(const WOLFSSL* ssl,
6142-
word16 named_curve);
6142+
word16 curve_id);
61436143
#else
6144-
#define wolfSSL_curve_is_disabled(ssl, c) ((void)(ssl), (void)(c), 0)
6144+
static WC_INLINE int wolfSSL_curve_is_disabled(const WOLFSSL* ssl,
6145+
word16 curve_id)
6146+
{
6147+
(void)ssl;
6148+
(void)curve_id;
6149+
return 0;
6150+
}
61456151
#endif
61466152

61476153
WOLFSSL_LOCAL WC_RNG* WOLFSSL_RSA_GetRNG(WOLFSSL_RSA *rsa, WC_RNG **tmpRNG,

0 commit comments

Comments
 (0)