From: lizhi lizhi206@huawei.com
1. Wformat, solve format dismatch 2. Wdiffarded qualifiers, const pointer lost const qualifier 3. Wmissing prototypes, use static to limit scope of internal function 4. Wunused, unused functions and variables 5. Wswitch, add default branch and break to switch 6. Redundant decls, duplicate declarations in macro definitions
Signed-off-by: lizhi lizhi206@huawei.com --- src/Makefile.am | 16 ++++++++++++++++ src/uadk_aead.c | 2 +- src/uadk_prov_bio.c | 2 ++ src/uadk_prov_cipher.c | 6 +++--- src/uadk_prov_der_writer.c | 2 +- src/uadk_prov_dh.c | 9 +++++---- src/uadk_prov_digest.c | 18 +++++++++--------- src/uadk_prov_ecx.c | 34 +++------------------------------- src/uadk_prov_ffc.c | 24 ++++++++++++------------ src/uadk_prov_ffc.h | 1 - src/uadk_prov_pkey.c | 8 ++++---- src/uadk_prov_pkey.h | 2 +- 12 files changed, 57 insertions(+), 67 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am index a165d3a..20f20c5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,14 @@ uadk_engine_la_CFLAGS=$(WD_CFLAGS) $(libcrypto_CFLAGS) uadk_engine_la_CFLAGS+=-DCRYPTO uadk_engine_la_CFLAGS+=-fPIC -fPIE -pie -fstack-protector-strong -D_FORTIFY_SOURCE=2 \ -O2 -ftrapv -Wl,-z,relro,-z,now -Wl,-s +uadk_engine_la_CFLAGS += -Wall -Wuninitialized -Wno-error -Wno-error=format -Wundef \ +-Wunused -Wdate-time -Wfloat-equal -Wshadow -Wvla -Wdisabled-optimization \ +-Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wtype-limits \ +-Wshift-negative-value -Wswitch-default -Wframe-larger-than=8192 -Wshift-overflow=2 \ +-Wwrite-strings -Wmissing-format-attribute -Wformat-nonliteral -Wduplicated-cond \ +-Wtrampolines -Wlogical-op -Wsuggest-attribute=format -Wduplicated-branches \ +-Wmissing-include-dirs -Wformat-signedness -Wmissing-declarations -Wreturn-local-addr \ +-Wredundant-decls -Wfloat-conversion -Wmissing-prototypes -Wstrict-prototypes if WD_ENGINE uadk_engine_la_CFLAGS+=-DOPENSSL_SUPPRESS_DEPRECATED endif #WD_ENGINE @@ -73,3 +81,11 @@ uadk_provider_la_LDFLAGS=-module -version-number $(VERSION) uadk_provider_la_LIBADD=$(WD_LIBS) -lpthread uadk_provider_la_CFLAGS=$(WD_CFLAGS) $(libcrypto_CFLAGS) uadk_provider_la_CFLAGS+=-DOPENSSL_SUPPRESS_DEPRECATED +uadk_provider_la_CFLAGS+=-Wall -Wuninitialized -Wno-error -Wno-error=format -Wundef \ +-Wunused -Wdate-time -Wfloat-equal -Wshadow -Wvla -Wdisabled-optimization \ +-Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wtype-limits \ +-Wshift-negative-value -Wswitch-default -Wframe-larger-than=8192 -Wshift-overflow=2 \ +-Wwrite-strings -Wmissing-format-attribute -Wformat-nonliteral -Wduplicated-cond \ +-Wtrampolines -Wlogical-op -Wsuggest-attribute=format -Wduplicated-branches \ +-Wmissing-include-dirs -Wformat-signedness -Wmissing-declarations -Wreturn-local-addr \ +-Wredundant-decls -Wfloat-conversion -Wmissing-prototypes -Wstrict-prototypes \ No newline at end of file diff --git a/src/uadk_aead.c b/src/uadk_aead.c index 1da7753..23f4329 100644 --- a/src/uadk_aead.c +++ b/src/uadk_aead.c @@ -469,7 +469,7 @@ static int do_aead_sync_inner(struct aead_priv_ctx *priv, unsigned char *out, priv->req.state = 0; ret = wd_do_aead_sync(priv->sess, &priv->req); if (unlikely(ret < 0 || priv->req.state)) { - fprintf(stderr, "do aead task failed, msg state: %d, ret: %d, state: %u!\n", + fprintf(stderr, "do aead task failed, msg state: %u, ret: %d, state: %u!\n", state, ret, priv->req.state); return RET_FAIL; } diff --git a/src/uadk_prov_bio.c b/src/uadk_prov_bio.c index 5be3e8a..d419a6a 100644 --- a/src/uadk_prov_bio.c +++ b/src/uadk_prov_bio.c @@ -71,6 +71,8 @@ void ossl_prov_bio_from_dispatch(const OSSL_DISPATCH *fns) if (c_bio_vprintf == NULL) c_bio_vprintf = OSSL_FUNC_BIO_vprintf(fns); break; + default: + break; } fns++; } diff --git a/src/uadk_prov_cipher.c b/src/uadk_prov_cipher.c index e511b71..c098115 100644 --- a/src/uadk_prov_cipher.c +++ b/src/uadk_prov_cipher.c @@ -124,7 +124,7 @@ struct cipher_priv_ctx { unsigned int pad : 1; /* Whether padding should be used or not */ unsigned int cts_mode; /* Use to set the type for CTS modes */ unsigned int key_set : 1; /* Whether key is copied to priv key buffers */ - unsigned int iv_set : 1; /* Whether key is copied to priv iv buffers */ + unsigned int iv_set : 1; /* Whether iv is copied to priv iv buffers */ size_t blksize; size_t keylen; size_t ivlen; @@ -180,7 +180,7 @@ static struct cts_mode_name2id_st cts_modes[] = { { WD_CIPHER_CBC_CS3, OSSL_CIPHER_CTS_MODE_CS3, UADK_CIPHER_CTS_CS3_NAME }, };
-const char *ossl_cipher_cbc_cts_mode_id2name(unsigned int id) +static const char *ossl_cipher_cbc_cts_mode_id2name(unsigned int id) { size_t i;
@@ -191,7 +191,7 @@ const char *ossl_cipher_cbc_cts_mode_id2name(unsigned int id) return NULL; }
-int ossl_cipher_cbc_cts_mode_name2id(const char *name) +static int ossl_cipher_cbc_cts_mode_name2id(const char *name) { size_t i;
diff --git a/src/uadk_prov_der_writer.c b/src/uadk_prov_der_writer.c index 3876d49..e7e7e49 100644 --- a/src/uadk_prov_der_writer.c +++ b/src/uadk_prov_der_writer.c @@ -139,7 +139,7 @@ int ossl_DER_w_uint32(WPACKET *pkt, int tag, uint32_t v) return int_der_w_integer(pkt, tag, int_put_bytes_uint32, &v); }
-BN_ULONG *bn_get_words(const BIGNUM *a) +static BN_ULONG *bn_get_words(const BIGNUM *a) { return a->d; } diff --git a/src/uadk_prov_dh.c b/src/uadk_prov_dh.c index 8d2c6f6..f3724ac 100644 --- a/src/uadk_prov_dh.c +++ b/src/uadk_prov_dh.c @@ -1629,7 +1629,7 @@ static int uadk_prov_dh_plain_derive(PROV_DH_KEYEXCH_CTX *pdhctx, unsigned char else ret = uadk_dh_compute_key(secret, pubkey, pdhctx->dh); if (ret <= 0) { - fprintf(stderr, "failed to do dh compute, pad(%d)\n", pad); + fprintf(stderr, "failed to do dh compute, pad(%u)\n", pad); return ret; }
@@ -1639,9 +1639,9 @@ static int uadk_prov_dh_plain_derive(PROV_DH_KEYEXCH_CTX *pdhctx, unsigned char }
/* Key derivation function from X9.63/SECG */ -int ossl_dh_kdf_X9_42_asn1(unsigned char *out, PROV_DH_KEYEXCH_CTX *pdhctx, - const unsigned char *z, size_t z_len, - const char *propq) +static int ossl_dh_kdf_X9_42_asn1(unsigned char *out, PROV_DH_KEYEXCH_CTX *pdhctx, + const unsigned char *z, size_t z_len, + const char *propq) { OSSL_LIB_CTX *libctx = pdhctx->libctx; const char *cek_alg = pdhctx->kdf_cekalg; @@ -1749,6 +1749,7 @@ static int uadk_keyexch_dh_derive(void *dhctx, unsigned char *secret, break; case PROV_DH_KDF_X9_42_ASN1: ret = uadk_prov_dh_X9_42_kdf_derive(pdhctx, secret, psecretlen, outlen); + break; default: fprintf(stderr, "invalid: unsupport kdf type\n"); break; diff --git a/src/uadk_prov_digest.c b/src/uadk_prov_digest.c index 0fe31d2..8c539ed 100644 --- a/src/uadk_prov_digest.c +++ b/src/uadk_prov_digest.c @@ -629,6 +629,15 @@ static void uadk_digest_cleanup(struct digest_priv_ctx *priv) OPENSSL_free(priv->soft_ctx); }
+static OSSL_FUNC_digest_freectx_fn uadk_prov_freectx; +static OSSL_FUNC_digest_dupctx_fn uadk_prov_dupctx; +static OSSL_FUNC_digest_init_fn uadk_prov_init; +static OSSL_FUNC_digest_update_fn uadk_prov_update; +static OSSL_FUNC_digest_final_fn uadk_prov_final; +static OSSL_FUNC_digest_digest_fn uadk_prov_digest; +static OSSL_FUNC_digest_gettable_params_fn + uadk_prov_gettable_params; + /* some params related code is copied from OpenSSL v3.0 prov/digestcommon.h */ static const OSSL_PARAM uadk_digest_default_known_gettable_params[] = { OSSL_PARAM_size_t(OSSL_DIGEST_PARAM_BLOCK_SIZE, NULL), @@ -791,15 +800,6 @@ void uadk_prov_destroy_digest(void) pthread_mutex_unlock(&digest_mutex); }
-static OSSL_FUNC_digest_freectx_fn uadk_prov_freectx; -static OSSL_FUNC_digest_dupctx_fn uadk_prov_dupctx; -static OSSL_FUNC_digest_init_fn uadk_prov_init; -static OSSL_FUNC_digest_update_fn uadk_prov_update; -static OSSL_FUNC_digest_final_fn uadk_prov_final; -static OSSL_FUNC_digest_digest_fn uadk_prov_digest; -static OSSL_FUNC_digest_gettable_params_fn - uadk_prov_gettable_params; - #define UADK_PROVIDER_IMPLEMENTATION(name, nid, mdsize, blksize) \ static OSSL_FUNC_digest_newctx_fn uadk_##name##_newctx; \ static void *uadk_##name##_newctx(void *provctx) \ diff --git a/src/uadk_prov_ecx.c b/src/uadk_prov_ecx.c index 302dc48..d7954b7 100644 --- a/src/uadk_prov_ecx.c +++ b/src/uadk_prov_ecx.c @@ -88,12 +88,6 @@ typedef struct { handle_t sess; } PROV_ECX_KEYEXCH_CTX;
-static const OSSL_PARAM ecx_key_types[] = { - OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PUB_KEY, NULL, 0), - OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0), - OSSL_PARAM_END -}; - struct x448_res { int pid; } g_x448_prov; @@ -258,23 +252,6 @@ static int ossl_param_build_set_octet_string(OSSL_PARAM_BLD *bld, OSSL_PARAM *p, return UADK_P_SUCCESS; }
-static int ossl_param_build_set_bn_pad(OSSL_PARAM_BLD *bld, OSSL_PARAM *p, - const char *key, const BIGNUM *bn, size_t sz) -{ - if (bld != NULL) - return OSSL_PARAM_BLD_push_BN_pad(bld, key, bn, sz); - - p = OSSL_PARAM_locate(p, key); - if (p != NULL) { - if (sz > p->data_size) - return UADK_P_FAIL; - p->data_size = sz; - return OSSL_PARAM_set_BN(p, bn); - } - - return UADK_P_SUCCESS; -} - static int uadk_prov_key_to_params(ECX_KEY *key, OSSL_PARAM_BLD *tmpl, OSSL_PARAM params[], int include_private) { @@ -430,9 +407,6 @@ static void uadk_keymgmt_x448_gen_cleanup(void *genctx) static void *uadk_keymgmt_x448_gen_init(void *provctx, int selection, const OSSL_PARAM params[]) { - PROV_ECX_KEYMGMT_CTX *gctx = NULL; - int ret; - if (provctx == NULL) { fprintf(stderr, "invalid: provctx is NULL\n"); return NULL; @@ -441,8 +415,8 @@ static void *uadk_keymgmt_x448_gen_init(void *provctx, int selection, return ossl_ecx_gen_init(provctx, selection, params, ECX_KEY_TYPE_X448); }
-ECX_KEY *uadk_prov_ecx_key_new(OSSL_LIB_CTX *libctx, ECX_KEY_TYPE type, int haspubkey, - const char *propq) +static ECX_KEY *uadk_prov_ecx_key_new(OSSL_LIB_CTX *libctx, ECX_KEY_TYPE type, int haspubkey, + const char *propq) { ECX_KEY *ecx_key = OPENSSL_zalloc(sizeof(ECX_KEY));
@@ -807,7 +781,6 @@ static UADK_PKEY_KEYEXCH get_default_x448_keyexch(void) static void *uadk_keyexch_x448_newctx(void *provctx) { PROV_ECX_KEYEXCH_CTX *ecxctx = NULL; - int ret;
ecxctx = OPENSSL_zalloc(sizeof(PROV_ECX_KEYEXCH_CTX)); if (ecxctx == NULL) { @@ -870,7 +843,6 @@ static int uadk_keyexch_x448_init(void *vecxctx, void *vkey, { PROV_ECX_KEYEXCH_CTX *ecxctx = (PROV_ECX_KEYEXCH_CTX *)vecxctx; ECX_KEY *key = vkey; - int ret;
if (ecxctx == NULL) { fprintf(stderr, "invalid: ecxctx is NULL\n"); @@ -894,7 +866,7 @@ static int uadk_keyexch_x448_init(void *vecxctx, void *vkey, return UADK_P_SUCCESS; }
-int ossl_ecx_key_up_ref(ECX_KEY *key) +static int ossl_ecx_key_up_ref(ECX_KEY *key) { int i = 0;
diff --git a/src/uadk_prov_ffc.c b/src/uadk_prov_ffc.c index ed5e037..015c1b9 100644 --- a/src/uadk_prov_ffc.c +++ b/src/uadk_prov_ffc.c @@ -937,7 +937,7 @@ err: return ret; }
-OSSL_LIB_CTX *ossl_bn_get_libctx(BN_CTX *ctx) +static OSSL_LIB_CTX *ossl_bn_get_libctx(BN_CTX *ctx) { if (ctx == NULL) return NULL; @@ -1064,9 +1064,9 @@ static int ffc_validate_LN(size_t L, size_t N, int type, int verify) } #endif /* FIPS_MODULE */
-int ossl_ffc_params_set_validate_params(FFC_PARAMS *params, - const unsigned char *seed, - size_t seedlen, int counter) +static int ossl_ffc_params_set_validate_params(FFC_PARAMS *params, + const unsigned char *seed, + size_t seedlen, int counter) { if (!ossl_ffc_params_set_seed(params, seed, seedlen)) return 0; @@ -1086,10 +1086,10 @@ static const char *default_mdname(size_t N) }
/* FIPS186-4 A.2.2 Unverifiable partial validation of Generator g */ -int ossl_ffc_params_validate_unverifiable_g(BN_CTX *ctx, BN_MONT_CTX *mont, - const BIGNUM *p, const BIGNUM *q, - const BIGNUM *g, BIGNUM *tmp, - int *ret) +static int ossl_ffc_params_validate_unverifiable_g(BN_CTX *ctx, BN_MONT_CTX *mont, + const BIGNUM *p, const BIGNUM *q, + const BIGNUM *g, BIGNUM *tmp, + int *ret) { /* * A.2.2 Step (1) AND @@ -1574,10 +1574,10 @@ static int generate_canonical_g(BN_CTX *ctx, BN_MONT_CTX *mont, * - FFC_PARAM_RET_STATUS_UNVERIFIABLE_G if the validation of G succeeded, * but G is unverifiable. */ -int ossl_ffc_params_FIPS186_4_gen_verify(OSSL_LIB_CTX *libctx, - FFC_PARAMS *params, int mode, int type, - size_t L, size_t N, int *res, - BN_GENCB *cb) +static int ossl_ffc_params_FIPS186_4_gen_verify(OSSL_LIB_CTX *libctx, + FFC_PARAMS *params, int mode, + int type, size_t L, size_t N, + int *res, BN_GENCB *cb) { int ok = FFC_PARAM_RET_STATUS_FAILED; unsigned char *seed = NULL, *seed_tmp = NULL; diff --git a/src/uadk_prov_ffc.h b/src/uadk_prov_ffc.h index 92102d3..d63a5ce 100644 --- a/src/uadk_prov_ffc.h +++ b/src/uadk_prov_ffc.h @@ -99,7 +99,6 @@ #define OSSL_NELEM(x) (sizeof(x)/sizeof((x)[0])) /* Macro to make a BIGNUM from static data */ #define make_dh_bn(x) \ - extern const BIGNUM ossl_bignum_##x; \ const BIGNUM ossl_bignum_##x = { \ (BN_ULONG *) x, \ OSSL_NELEM(x), \ diff --git a/src/uadk_prov_pkey.c b/src/uadk_prov_pkey.c index 0615b61..244cdb4 100644 --- a/src/uadk_prov_pkey.c +++ b/src/uadk_prov_pkey.c @@ -178,7 +178,7 @@ static void uadk_prov_init_dtb_param(void *dtb, char *start, }
int uadk_prov_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, - BIGNUM *x, BIGNUM *y, BN_CTX *ctx) + BIGNUM *x, BIGNUM *y, BN_CTX *ctx) { # if OPENSSL_VERSION_NUMBER > 0x10101000L if (!EC_POINT_get_affine_coordinates(group, p, x, y, ctx)) @@ -190,8 +190,8 @@ int uadk_prov_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, return UADK_P_SUCCESS; }
-int uadk_prov_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, - BIGNUM *b, BN_CTX *ctx) +static int uadk_prov_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, + BIGNUM *b, BN_CTX *ctx) { # if OPENSSL_VERSION_NUMBER > 0x10101000L if (!EC_GROUP_get_curve(group, p, a, b, ctx)) @@ -293,7 +293,7 @@ free_ctx: return ret; }
-handle_t uadk_prov_ecc_alloc_sess(const EC_KEY *eckey, char *alg) +handle_t uadk_prov_ecc_alloc_sess(const EC_KEY *eckey, const char *alg) { char buff[UADK_ECC_MAX_KEY_BYTES * UADK_ECC_CV_PARAM_NUM]; struct sched_params sch_p = {0}; diff --git a/src/uadk_prov_pkey.h b/src/uadk_prov_pkey.h index e79fc52..f40313d 100644 --- a/src/uadk_prov_pkey.h +++ b/src/uadk_prov_pkey.h @@ -439,7 +439,7 @@ const OSSL_DISPATCH uadk_##nm##_keyexch_functions[] = { \ { 0, NULL } \ } \
-handle_t uadk_prov_ecc_alloc_sess(const EC_KEY *eckey, char *alg); +handle_t uadk_prov_ecc_alloc_sess(const EC_KEY *eckey, const char *alg); int uadk_prov_ecc_crypto(handle_t sess, struct wd_ecc_req *req, void *usr); int uadk_prov_keymgmt_get_support_state(int alg_tag); int uadk_prov_ecc_get_numa_id(void);