Skip to content

Commit

Permalink
replace fallthrough statements
Browse files Browse the repository at this point in the history
  • Loading branch information
TJ-91 authored and falko-strenzke committed Sep 11, 2023
1 parent e42827a commit 89e91a3
Show file tree
Hide file tree
Showing 22 changed files with 342 additions and 354 deletions.
7 changes: 7 additions & 0 deletions src/lib/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,10 @@
((defined(__clang__) && (__clang_major__ >= 4)) )
#define RNP_USE_STD_REGEX 1
#endif

/* do not use the statement for old MSVC versions */
#if (!defined(_MSVC_LANG) || _MSVC_LANG >= 201703L)
# define FALLTHROUGH_STATEMENT [[fallthrough]];
#else
# define FALLTHROUGH_STATEMENT
#endif
70 changes: 34 additions & 36 deletions src/lib/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ pgp_generate_seckey(const rnp_keygen_crypto_params_t &crypto,
seckey.material.ec.curve = crypto.ecc.curve;
break;
}
#if (!defined(_MSVC_LANG) || _MSVC_LANG >= 201703L)
[[fallthrough]];
#endif
FALLTHROUGH_STATEMENT;
case PGP_PKA_ECDSA:
case PGP_PKA_SM2:
if (!curve_supported(crypto.ecc.curve)) {
Expand Down Expand Up @@ -175,14 +173,14 @@ pgp_generate_seckey(const rnp_keygen_crypto_params_t &crypto,
#endif
#if defined(ENABLE_PQC)
case PGP_PKA_KYBER768_X25519:
[[fallthrough]];
// TODO add case PGP_PKA_KYBER1024_X448: [[fallthrough]];
FALLTHROUGH_STATEMENT;
// TODO add case PGP_PKA_KYBER1024_X448: FALLTHROUGH_STATEMENT;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
case PGP_PKA_KYBER768_P256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER1024_P384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER768_BP256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER1024_BP384:
if (pgp_kyber_ecdh_composite_key_t::gen_keypair(
&crypto.ctx->rng, &seckey.material.kyber_ecdh, seckey.alg)) {
Expand All @@ -191,14 +189,14 @@ pgp_generate_seckey(const rnp_keygen_crypto_params_t &crypto,
}
break;
case PGP_PKA_DILITHIUM3_ED25519:
[[fallthrough]];
// TODO: add case PGP_PKA_DILITHIUM5_ED448: [[fallthrough]];
FALLTHROUGH_STATEMENT;
// TODO: add case PGP_PKA_DILITHIUM5_ED448: FALLTHROUGH_STATEMENT;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
case PGP_PKA_DILITHIUM3_P256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_P384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM3_BP256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_BP384:
if (pgp_dilithium_exdsa_composite_key_t::gen_keypair(
&crypto.ctx->rng, &seckey.material.dilithium_exdsa, seckey.alg)) {
Expand All @@ -208,7 +206,7 @@ pgp_generate_seckey(const rnp_keygen_crypto_params_t &crypto,
}
break;
case PGP_PKA_SPHINCSPLUS_SHA2:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_SPHINCSPLUS_SHAKE:
if (pgp_sphincsplus_generate(&crypto.ctx->rng,
&seckey.material.sphincsplus,
Expand Down Expand Up @@ -267,29 +265,29 @@ key_material_equal(const pgp_key_material_t *key1, const pgp_key_material_t *key
#endif
#if defined(ENABLE_PQC)
case PGP_PKA_KYBER768_X25519:
[[fallthrough]];
// TODO add case PGP_PKA_KYBER1024_X448: [[fallthrough]];
FALLTHROUGH_STATEMENT;
// TODO add case PGP_PKA_KYBER1024_X448: FALLTHROUGH_STATEMENT;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
case PGP_PKA_KYBER768_P256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER1024_P384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER768_BP256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER1024_BP384:
return (key1->kyber_ecdh.pub == key2->kyber_ecdh.pub);
case PGP_PKA_DILITHIUM3_ED25519:
[[fallthrough]];
// TODO: add case PGP_PKA_DILITHIUM5_ED448: [[fallthrough]];
FALLTHROUGH_STATEMENT;
// TODO: add case PGP_PKA_DILITHIUM5_ED448: FALLTHROUGH_STATEMENT;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
case PGP_PKA_DILITHIUM3_P256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_P384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM3_BP256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_BP384:
return (key1->dilithium_exdsa.pub == key2->dilithium_exdsa.pub);
case PGP_PKA_SPHINCSPLUS_SHA2:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_SPHINCSPLUS_SHAKE:
return (key1->sphincsplus.pub == key2->sphincsplus.pub);
#endif
Expand Down Expand Up @@ -348,29 +346,29 @@ validate_pgp_key_material(const pgp_key_material_t *material, rnp::RNG *rng)
#endif
#if defined(ENABLE_PQC)
case PGP_PKA_KYBER768_X25519:
[[fallthrough]];
// TODO add case PGP_PKA_KYBER1024_X448: [[fallthrough]];
FALLTHROUGH_STATEMENT;
// TODO add case PGP_PKA_KYBER1024_X448: FALLTHROUGH_STATEMENT;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
case PGP_PKA_KYBER768_P256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER1024_P384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER768_BP256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER1024_BP384:
return kyber_ecdh_validate_key(rng, &material->kyber_ecdh, material->secret);
case PGP_PKA_DILITHIUM3_ED25519:
[[fallthrough]];
// TODO: add case PGP_PKA_DILITHIUM5_ED448: [[fallthrough]];
FALLTHROUGH_STATEMENT;
// TODO: add case PGP_PKA_DILITHIUM5_ED448: FALLTHROUGH_STATEMENT;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
case PGP_PKA_DILITHIUM3_P256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_P384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM3_BP256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_BP384:
return dilithium_exdsa_validate_key(rng, &material->dilithium_exdsa, material->secret);
case PGP_PKA_SPHINCSPLUS_SHA2:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_SPHINCSPLUS_SHAKE:
return sphincsplus_validate_key(rng, &material->sphincsplus, material->secret);
#endif
Expand Down
8 changes: 3 additions & 5 deletions src/lib/crypto/dilithium_exdsa_composite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,14 @@ pgp_dilithium_exdsa_composite_key_t::pk_alg_to_dilithium_id(pgp_pubkey_alg_t pk_
{
switch (pk_alg) {
case PGP_PKA_DILITHIUM3_ED25519:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM3_P256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM3_BP256:
return dilithium_L3;
case PGP_PKA_DILITHIUM5_BP384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_P384:
//[[fallthrough]];
// case PGP_PKA_DILITHIUM5_ED448:
return dilithium_L5;
default:
RNP_LOG("invalid PK alg given");
Expand Down
12 changes: 6 additions & 6 deletions src/lib/crypto/ec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,17 @@ is_generic_prime_curve(pgp_curve_t curve)
{
switch (curve) {
case PGP_CURVE_NIST_P_256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_NIST_P_384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_NIST_P_521:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_BP256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_BP384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_BP512:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_P256K1:
return true;
default:
Expand Down
12 changes: 6 additions & 6 deletions src/lib/crypto/ecdh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,17 +412,17 @@ exdsa_gen_keypair_native(rnp::RNG * rng,
alg = PGP_PKA_EDDSA;
break;
case PGP_CURVE_NIST_P_256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_NIST_P_384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_NIST_P_521:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_BP256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_BP384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_BP512:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_CURVE_P256K1:
alg = PGP_PKA_ECDSA;
break;
Expand Down
8 changes: 3 additions & 5 deletions src/lib/crypto/kyber_ecdh_composite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,14 @@ pgp_kyber_ecdh_composite_key_t::pk_alg_to_kyber_id(pgp_pubkey_alg_t pk_alg)
{
switch (pk_alg) {
case PGP_PKA_KYBER768_X25519:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER768_P256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER768_BP256:
return kyber_768;
case PGP_PKA_KYBER1024_BP384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_KYBER1024_P384:
//[[fallthrough]];
// case PGP_PKA_KYBER1024_X448:
return kyber_1024;
default:
RNP_LOG("invalid PK alg given");
Expand Down
26 changes: 13 additions & 13 deletions src/lib/crypto/signatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,20 @@ signature_calculate(pgp_signature_t & sig,
}
#if defined(ENABLE_PQC)
case PGP_PKA_DILITHIUM3_ED25519:
[[fallthrough]];
// TODO: add case PGP_PKA_DILITHIUM5_ED448: [[fallthrough]];
FALLTHROUGH_STATEMENT;
// TODO: add case PGP_PKA_DILITHIUM5_ED448: FALLTHROUGH_STATEMENT;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
case PGP_PKA_DILITHIUM3_P256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_P384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM3_BP256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_BP384:
ret = seckey.dilithium_exdsa.priv.sign(
&ctx.rng, &material.dilithium_exdsa, hash_alg, hval, hlen);
break;
case PGP_PKA_SPHINCSPLUS_SHA2:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_SPHINCSPLUS_SHAKE:
ret = seckey.sphincsplus.priv.sign(&ctx.rng, &material.sphincsplus, hval, hlen);
break;
Expand Down Expand Up @@ -256,7 +256,7 @@ signature_validate(const pgp_signature_t & sig,
bool hash_alg_valid = false;
switch (key.alg) {
case PGP_PKA_SPHINCSPLUS_SHA2:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_SPHINCSPLUS_SHAKE:
hash_alg_valid = key.sphincsplus.pub.validate_signature_hash_requirements(hash.alg());
break;
Expand Down Expand Up @@ -339,20 +339,20 @@ signature_validate(const pgp_signature_t & sig,
break;
#if defined(ENABLE_PQC)
case PGP_PKA_DILITHIUM3_ED25519:
[[fallthrough]];
// TODO: add case PGP_PKA_DILITHIUM5_ED448: [[fallthrough]];
FALLTHROUGH_STATEMENT;
// TODO: add case PGP_PKA_DILITHIUM5_ED448: FALLTHROUGH_STATEMENT;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
case PGP_PKA_DILITHIUM3_P256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_P384:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM3_BP256:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_DILITHIUM5_BP384:
ret =
key.dilithium_exdsa.pub.verify(&material.dilithium_exdsa, hash.alg(), hval, hlen);
break;
case PGP_PKA_SPHINCSPLUS_SHA2:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case PGP_PKA_SPHINCSPLUS_SHAKE:
ret = key.sphincsplus.pub.verify(&material.sphincsplus, hval, hlen);
break;
Expand Down
16 changes: 8 additions & 8 deletions src/lib/crypto/sphincsplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,18 @@ sphincsplus_hash_allowed(pgp_pubkey_alg_t pk_alg,
case PGP_PKA_SPHINCSPLUS_SHA2:
switch (sphincsplus_param) {
case sphincsplus_simple_128s:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case sphincsplus_simple_128f:
if (hash_alg != PGP_HASH_SHA256) {
return false;
}
break;
case sphincsplus_simple_192s:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case sphincsplus_simple_192f:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case sphincsplus_simple_256s:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case sphincsplus_simple_256f:
if (hash_alg != PGP_HASH_SHA512) {
return false;
Expand All @@ -360,18 +360,18 @@ sphincsplus_hash_allowed(pgp_pubkey_alg_t pk_alg,
case PGP_PKA_SPHINCSPLUS_SHAKE:
switch (sphincsplus_param) {
case sphincsplus_simple_128s:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case sphincsplus_simple_128f:
if (hash_alg != PGP_HASH_SHA3_256) {
return false;
}
break;
case sphincsplus_simple_192s:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case sphincsplus_simple_192f:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case sphincsplus_simple_256s:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
case sphincsplus_simple_256f:
if (hash_alg != PGP_HASH_SHA3_512) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/fingerprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pgp_fingerprint(pgp_fingerprint_t &fp, const pgp_key_pkt_t &key)
switch (key.version) {
#if defined(ENABLE_CRYPTO_REFRESH)
case PGP_V6:
[[fallthrough]];
FALLTHROUGH_STATEMENT;
#endif
case PGP_V4:
break;
Expand Down
Loading

0 comments on commit 89e91a3

Please sign in to comment.