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/uadk_prov_bio.c | 2 ++ src/uadk_prov_cipher.c | 2 +- src/uadk_prov_der_writer.c | 2 +- src/uadk_prov_dh.c | 9 +++++---- 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 +- 9 files changed, 29 insertions(+), 55 deletions(-)
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 45f5d6e..0d01a6a 100644 --- a/src/uadk_prov_cipher.c +++ b/src/uadk_prov_cipher.c @@ -125,7 +125,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; 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 391d9ff..4328937 100644 --- a/src/uadk_prov_dh.c +++ b/src/uadk_prov_dh.c @@ -1628,7 +1628,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; }
@@ -1638,9 +1638,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; @@ -1748,6 +1748,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_ecx.c b/src/uadk_prov_ecx.c index 46d439a..759bdb8 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));
@@ -788,7 +762,6 @@ static void *uadk_keymgmt_x448_gen(void *genctx, OSSL_CALLBACK *cb, void *cb_par 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) { @@ -851,7 +824,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"); @@ -875,7 +847,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 1618db9..c1e12c0 100644 --- a/src/uadk_prov_pkey.c +++ b/src/uadk_prov_pkey.c @@ -176,7 +176,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)) @@ -188,8 +188,8 @@ int uadk_prov_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, return 0; }
-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)) @@ -291,7 +291,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 e37c6a5..2d4c3e0 100644 --- a/src/uadk_prov_pkey.h +++ b/src/uadk_prov_pkey.h @@ -496,7 +496,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);