Skip to content

Commit

Permalink
Remove cl building warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzhi committed May 13, 2024
1 parent 623fe13 commit e17df32
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int format_print(FILE *fp, int format, int indent, const char *str, ...)

int format_bytes(FILE *fp, int format, int indent, const char *str, const uint8_t *data, size_t datalen)
{
int i;
size_t i;

if (datalen > (1<<24)) {
error_print();
Expand Down
15 changes: 10 additions & 5 deletions src/sm2_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ int sm2_do_encrypt_ex(const SM2_KEY *key, const SM2_ENC_PRE_COMP *pre_comp,
uint8_t x2y2[64];
SM3_CTX sm3_ctx;

if (inlen < 1 || inlen > SM2_MAX_PLAINTEXT_SIZE) {
error_print();
return -1;
}

// output C1
out->point = pre_comp->C1;

Expand All @@ -159,7 +164,7 @@ int sm2_do_encrypt_ex(const SM2_KEY *key, const SM2_ENC_PRE_COMP *pre_comp,

// output C2 = M xor t
gmssl_memxor(out->ciphertext, out->ciphertext, in, inlen);
out->ciphertext_size = (uint32_t)inlen;
out->ciphertext_size = (uint8_t)inlen;

// output C3 = Hash(x2 || m || y2)
sm3_init(&sm3_ctx);
Expand All @@ -182,7 +187,7 @@ int sm2_do_encrypt(const SM2_KEY *key, const uint8_t *in, size_t inlen, SM2_CIPH
uint8_t x2y2[64];
SM3_CTX sm3_ctx;

if (!(SM2_MIN_PLAINTEXT_SIZE <= inlen && inlen <= SM2_MAX_PLAINTEXT_SIZE)) {
if (inlen < 1 || inlen > SM2_MAX_PLAINTEXT_SIZE) {
error_print();
return -1;
}
Expand Down Expand Up @@ -214,7 +219,7 @@ int sm2_do_encrypt(const SM2_KEY *key, const uint8_t *in, size_t inlen, SM2_CIPH

// output C2 = M xor t
gmssl_memxor(out->ciphertext, out->ciphertext, in, inlen);
out->ciphertext_size = (uint32_t)inlen;
out->ciphertext_size = (uint8_t)inlen;

// output C3 = Hash(x2 || m || y2)
sm3_init(&sm3_ctx);
Expand All @@ -238,7 +243,7 @@ int sm2_do_encrypt_fixlen(const SM2_KEY *key, const uint8_t *in, size_t inlen, i
uint8_t x2y2[64];
SM3_CTX sm3_ctx;

if (!(SM2_MIN_PLAINTEXT_SIZE <= inlen && inlen <= SM2_MAX_PLAINTEXT_SIZE)) {
if (inlen < 1 || inlen > SM2_MAX_PLAINTEXT_SIZE) {
error_print();
return -1;
}
Expand Down Expand Up @@ -295,7 +300,7 @@ int sm2_do_encrypt_fixlen(const SM2_KEY *key, const uint8_t *in, size_t inlen, i

// output C2 = M xor t
gmssl_memxor(out->ciphertext, out->ciphertext, in, inlen);
out->ciphertext_size = (uint32_t)inlen;
out->ciphertext_size = (uint8_t)inlen;

// output C3 = Hash(x2 || m || y2)
sm3_init(&sm3_ctx);
Expand Down
3 changes: 0 additions & 3 deletions src/sm2_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ int sm2_fast_sign_pre_compute(SM2_SIGN_PRE_COMP pre_comp[32])
int sm2_fast_sign(const sm2_z256_t fast_private, SM2_SIGN_PRE_COMP *pre_comp,
const uint8_t dgst[32], SM2_SIGNATURE *sig)
{
SM2_Z256_POINT R;
sm2_z256_t e;
sm2_z256_t r;
sm2_z256_t s;
Expand Down Expand Up @@ -504,8 +503,6 @@ int sm2_compute_z(uint8_t z[32], const SM2_Z256_POINT *pub, const char *id, size

int sm2_sign_init(SM2_SIGN_CTX *ctx, const SM2_KEY *key, const char *id, size_t idlen)
{
size_t i;

if (!ctx || !key) {
error_print();
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/sm4_ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int sm4_ccm_encrypt(const SM4_KEY *sm4_key, const uint8_t *iv, size_t ivlen,
}

inlen_size = 15 - ivlen;
if (inlen_size < 8 && inlen >= (1 << (inlen_size * 8))) {
if (inlen_size < 8 && inlen >= ((size_t)1 << (inlen_size * 8))) {
error_print();
return -1;
}
Expand Down
6 changes: 0 additions & 6 deletions src/sm4_xts.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ int sm4_xts_encrypt_update(SM4_XTS_CTX *ctx,
const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen)
{
size_t DATA_UNIT_SIZE = ctx->data_unit_size;

size_t left;
size_t nblocks;
size_t len;

if (ctx->block_nbytes >= DATA_UNIT_SIZE) {
error_print();
Expand Down Expand Up @@ -253,10 +250,7 @@ int sm4_xts_decrypt_update(SM4_XTS_CTX *ctx,
const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen)
{
size_t DATA_UNIT_SIZE = ctx->data_unit_size;

size_t left;
size_t nblocks;
size_t len;

if (ctx->block_nbytes >= DATA_UNIT_SIZE) {
error_print();
Expand Down
4 changes: 2 additions & 2 deletions src/x509_crl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static const size_t x509_crl_reason_names_count =

const char *x509_crl_reason_name(int reason)
{
if (reason < 0 || reason >= x509_crl_reason_names_count) {
if (reason < 0 || reason >= (int)x509_crl_reason_names_count) {
error_print();
return NULL;
}
Expand All @@ -51,7 +51,7 @@ const char *x509_crl_reason_name(int reason)

int x509_crl_reason_from_name(int *reason, const char *name)
{
int i;
size_t i;
for (i = 0; i < x509_crl_reason_names_count; i++) {
if (strcmp(name, x509_crl_reason_names[i]) == 0) {
*reason = i;
Expand Down
8 changes: 4 additions & 4 deletions src/x509_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ static size_t x509_key_usages_count =

const char *x509_key_usage_name(int flag)
{
int i;
size_t i;
for (i = 0; i < x509_key_usages_count; i++) {
if (flag & 1) {
if (flag >> 1) {
Expand All @@ -1233,7 +1233,7 @@ const char *x509_key_usage_name(int flag)

int x509_key_usage_from_name(int *flag, const char *name)
{
int i;
size_t i;
for (i = 0; i < x509_key_usages_count; i++) {
if (strcmp(name, x509_key_usages[i]) == 0) {
*flag = 1 << i;
Expand Down Expand Up @@ -2527,7 +2527,7 @@ static size_t x509_revoke_reason_flags_count =

const char *x509_revoke_reason_flag_name(int flag)
{
int i;
size_t i;
for (i = 0; i < x509_revoke_reason_flags_count; i++) {
if (flag & 1) {
if (flag >> 1) {
Expand All @@ -2543,7 +2543,7 @@ const char *x509_revoke_reason_flag_name(int flag)

int x509_revoke_reason_flag_from_name(int *flag, const char *name)
{
int i;
size_t i;
for (i = 0; i < x509_revoke_reason_flags_count; i++) {
if (strcmp(name, x509_revoke_reason_flags[i]) == 0) {
*flag = 1 << i;
Expand Down
3 changes: 1 addition & 2 deletions tests/sm2_enctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static int test_sm2_ciphertext(void)
}

sm2_z256_point_to_bytes(&sm2_key.public_key, (uint8_t *)&(C.point));
C.ciphertext_size = tests[i].ciphertext_size;
C.ciphertext_size = (uint8_t)tests[i].ciphertext_size;

if (sm2_ciphertext_to_der(&C, &p, &len) != 1) {
error_print();
Expand Down Expand Up @@ -176,7 +176,6 @@ static int test_sm2_encrypt_fixlen(void)
};

SM2_KEY sm2_key;
size_t point_size;
uint8_t plaintext[SM2_MAX_PLAINTEXT_SIZE];
uint8_t encrypted[SM2_MAX_CIPHERTEXT_SIZE];
uint8_t decrypted[SM2_MAX_PLAINTEXT_SIZE];
Expand Down
2 changes: 0 additions & 2 deletions tests/sm4_ccmtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ static int test_sm4_ccm_test_vectors(void)

SM4_KEY sm4_key;
uint8_t *encrypted;
size_t encrypted_len;
uint8_t *decrypted;
size_t decrypted_len;
uint8_t mac[16];
size_t i;

Expand Down
2 changes: 0 additions & 2 deletions tests/sm4_cfbtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ static int test_sm4_cfb_test_vectors(void)

SM4_KEY sm4_key;
uint8_t *encrypted;
size_t encrypted_len;
uint8_t *decrypted;
size_t decrypted_len;
size_t i;

for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
Expand Down
2 changes: 0 additions & 2 deletions tests/sm4_ofbtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ static int test_sm4_ofb_test_vectors(void)

SM4_KEY sm4_key;
uint8_t *encrypted;
size_t encrypted_len;
uint8_t *decrypted;
size_t decrypted_len;
size_t i;

for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
Expand Down
6 changes: 0 additions & 6 deletions tests/sm4_xtstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,13 @@ static int test_sm4_xts_test_vectors(void)
size_t key_len;
uint8_t iv[16];
size_t iv_len;
uint8_t *aad;
size_t aad_len;
uint8_t tag[16];
size_t tag_len;
uint8_t *plaintext;
size_t plaintext_len;
uint8_t *ciphertext;
size_t ciphertext_len;

uint8_t *encrypted;
size_t encrypted_len;
uint8_t *decrypted;
size_t decrypted_len;
size_t i;

for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
Expand Down
2 changes: 1 addition & 1 deletion tests/sm9test.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ int test_sm9_z256_exchange()
SM9_Z256_TWIST_POINT de;
SM9_Z256_POINT RA, RB;
sm9_z256_t rA;
int i, j = 1;
size_t i, j = 1;

uint8_t idA[5] = {0x41, 0x6C, 0x69, 0x63, 0x65};
uint8_t idB[3] = {0x42, 0x6F, 0x62};
Expand Down
3 changes: 0 additions & 3 deletions tools/sm4_ecb.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ int sm4_ecb_main(int argc, char **argv)
char *outfile = NULL;
uint8_t key[16];
size_t keylen;
uint8_t iv[16];
size_t ivlen;
FILE *infp = stdin;
FILE *outfp = stdout;
SM4_ECB_CTX ctx;
Expand Down Expand Up @@ -182,7 +180,6 @@ int sm4_ecb_main(int argc, char **argv)

end:
gmssl_secure_clear(key, sizeof(key));
gmssl_secure_clear(iv, sizeof(iv));
gmssl_secure_clear(&ctx, sizeof(ctx));
gmssl_secure_clear(buf, sizeof(buf));
if (infile && infp) fclose(infp);
Expand Down
1 change: 0 additions & 1 deletion tools/tls12_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ int tls12_server_main(int argc , char **argv)
tls_socket_t conn_sock;
struct sockaddr_in server_addr;
struct sockaddr_in client_addr;
tls_socklen_t client_addrlen;

argc--;
argv++;
Expand Down
1 change: 0 additions & 1 deletion tools/tls13_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ int tls13_server_main(int argc , char **argv)
tls_socket_t conn_sock;
struct sockaddr_in server_addr;
struct sockaddr_in client_addr;
tls_socklen_t client_addrlen;

argc--;
argv++;
Expand Down

0 comments on commit e17df32

Please sign in to comment.