Skip to content

Commit

Permalink
Remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzhi committed May 23, 2024
1 parent 9d8da9c commit 4f21be0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
9 changes: 4 additions & 5 deletions src/sm3_xmss.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void adrs_set_tree_index(uint8_t adrs[32], uint32_t index) {
}

static void adrs_set_key_and_mask(uint8_t adrs[32], uint8_t key_and_mask) {
uint32_to_bytes(key_and_mask, adrs + 4*7);
uint32_to_bytes((uint32_t)key_and_mask, adrs + 4*7);
}

/*
Expand Down Expand Up @@ -327,7 +327,7 @@ static void build_ltree(const hash256_bytes_t in_pk[67],
adrs_set_tree_height(adrs, tree_height++);

while (len > 1) {
for (i = 0; i < len/2; i++) {
for (i = 0; i < (uint32_t)len/2; i++) {
adrs_set_tree_index(adrs, i);
randomized_hash(pk[2 * i], pk[2 * i + 1], prf_seed_ctx, adrs, pk[i]);
}
Expand Down Expand Up @@ -382,8 +382,7 @@ void sm3_xmss_derive_root(const uint8_t xmss_secret[32], int height,

// generate all the wots pk[]
for (i = 0; i < (1<<height); i++) {
HASH256_CTX prf_ctx = prf_keygen_ctx;
uint8_t wots_secret[32];
//HASH256_CTX prf_ctx = prf_keygen_ctx;
hash256_bytes_t wots_sk[67];
hash256_bytes_t wots_pk[67];

Expand Down Expand Up @@ -612,7 +611,7 @@ int sm3_xmss_key_from_bytes(SM3_XMSS_KEY *key, const uint8_t *in, size_t inlen)
memcpy(key->prf_key, p, 32); p += 32;

key->index = uint32_from_bytes(p); p += 4;
if (key->index >= (1 << height)) {
if (key->index >= (uint32_t)(1 << height)) {
error_print();
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/sm4_ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ int sm4_ccm_decrypt(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 All @@ -181,7 +181,7 @@ int sm4_ccm_decrypt(const SM4_KEY *sm4_key, const uint8_t *iv, size_t ivlen,
if (aadlen < ((1<<16) - (1<<8))) {
length_to_bytes(aadlen, 2, block);
alen = 2;
} else if (aadlen < ((size_t)1<<32)) {
} else if ((uint64_t)aadlen < ((uint64_t)1<<32)) {
block[0] = 0xff;
block[1] = 0xfe;
length_to_bytes(aadlen, 4, block + 2);
Expand Down
25 changes: 12 additions & 13 deletions src/sm9_z256.c
Original file line number Diff line number Diff line change
Expand Up @@ -2864,15 +2864,15 @@ void sm9_z256_fp12_line_mul(sm9_z256_fp12_t r, const sm9_z256_fp12_t a, const sm
{
sm9_z256_fp4_t r0, r1, r2;
sm9_z256_fp2_t t;

sm9_z256_fp4_t lw4;
sm9_z256_fp2_copy(lw4[0], lw[0]);
sm9_z256_fp2_copy(lw4[1], lw[2]);

sm9_z256_fp4_mul(r0, a[0], lw4);
sm9_z256_fp4_mul(r1, a[1], lw4);
sm9_z256_fp4_mul(r2, a[2], lw4);

sm9_z256_fp2_mul (t, a[0][0], lw[1]);
sm9_z256_fp2_add (r2[0], r2[0], t);
sm9_z256_fp2_mul (t, a[0][1], lw[1]);
Expand All @@ -2885,7 +2885,7 @@ void sm9_z256_fp12_line_mul(sm9_z256_fp12_t r, const sm9_z256_fp12_t a, const sm
sm9_z256_fp2_add (r1[1], r1[1], t);
sm9_z256_fp2_mul_u(t, a[2][1], lw[1]);
sm9_z256_fp2_add (r1[0], r1[0], t);

sm9_z256_fp4_copy(r[0], r0);
sm9_z256_fp4_copy(r[1], r1);
sm9_z256_fp4_copy(r[2], r2);
Expand All @@ -2898,18 +2898,18 @@ void sm9_z256_pairing(sm9_z256_fp12_t r, const SM9_Z256_TWIST_POINT *Q, const SM
SM9_Z256_TWIST_POINT T;
SM9_Z256_TWIST_POINT Q1;
SM9_Z256_TWIST_POINT Q2;

SM9_Z256_AFFINE_POINT P_;
sm9_z256_fp2_t lw[3];
sm9_z256_fp2_t pre[5]; // same for Q and -Q
size_t i;

sm9_z256_fp2_copy(T.X, Q->X);
sm9_z256_fp2_copy(T.Y, Q->Y);
sm9_z256_fp2_copy(T.Z, Q->Z);

SM9_Z256_AFFINE_POINT P_;

sm9_z256_point_to_affine(&P_, P);
sm9_z256_twist_point_neg(&Q1, Q);

sm9_z256_fp2_t lw[3];
sm9_z256_fp2_t pre[5]; // same for Q and -Q


sm9_z256_fp2_sqr(pre[0], Q->Y);
sm9_z256_fp2_mul(pre[4], Q->X, Q->Z);
sm9_z256_fp2_dbl(pre[4], pre[4]);
Expand All @@ -2923,7 +2923,6 @@ void sm9_z256_pairing(sm9_z256_fp12_t r, const SM9_Z256_TWIST_POINT *Q, const SM

sm9_z256_fp12_set_one(r);

int i;
for (i = 0; i < strlen(abits); i++) {
sm9_z256_fp12_sqr(r, r);
sm9_z256_eval_g_tangent(&T, lw, &T, &P_);
Expand All @@ -2948,7 +2947,7 @@ void sm9_z256_pairing(sm9_z256_fp12_t r, const SM9_Z256_TWIST_POINT *Q, const SM

sm9_z256_eval_g_line_no_pre(&T, lw, &T, &Q2, &P_);
sm9_z256_fp12_line_mul(r, r, lw);

sm9_z256_final_exponent(r, r);
}

Expand Down

0 comments on commit 4f21be0

Please sign in to comment.