From 08e560e0a75151986b2a7fb25885526f149025d5 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Tue, 29 Jun 2021 11:07:47 +1000 Subject: [PATCH 1/2] SP: Don't cast number to sp_digit rather than declare as long mingw64 has numbers as 32-bit type when declarted long. Fixup some line lengths. --- wolfcrypt/src/sp_arm32.c | 206 +++++++++----- wolfcrypt/src/sp_arm64.c | 167 +++++++---- wolfcrypt/src/sp_armthumb.c | 206 +++++++++----- wolfcrypt/src/sp_c32.c | 551 +++++++++++++++++++++--------------- wolfcrypt/src/sp_c64.c | 493 ++++++++++++++++++-------------- wolfcrypt/src/sp_cortexm.c | 206 +++++++++----- wolfcrypt/src/sp_x86_64.c | 239 ++++++++++------ 7 files changed, 1293 insertions(+), 775 deletions(-) diff --git a/wolfcrypt/src/sp_arm32.c b/wolfcrypt/src/sp_arm32.c index 331e454ae..d0a850577 100644 --- a/wolfcrypt/src/sp_arm32.c +++ b/wolfcrypt/src/sp_arm32.c @@ -126,7 +126,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -8621,7 +8621,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -20282,7 +20282,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -28385,19 +28385,22 @@ static const sp_point_256 p256_base = { { 0xd898c296,0xf4a13945,0x2deb33a0,0x77037d81,0x63a440f2,0xf8bce6e5, 0xe12c4247,0x6b17d1f2, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0x37bf51f5,0xcbb64068,0x6b315ece,0x2bce3357,0x7c0f9e16,0x8ee7eb4a, 0xfe1a7f9b,0x4fe342e2, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -29814,7 +29817,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -32183,8 +32186,9 @@ static void sp_256_proj_point_dbl_8(sp_point_256* r, const sp_point_256* p, sp_d */ static int sp_256_cmp_equal_8(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7])) == 0; } /* Add two Montgomery form projective points. @@ -36321,7 +36325,8 @@ static int sp_256_calc_s_8(sp_digit* s, const sp_digit* r, sp_digit* k, sp_256_cond_sub_8(s, s, p256_order, 0 - carry); sp_256_norm_8(s); c = sp_256_cmp_8(s, p256_order); - sp_256_cond_sub_8(s, s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(s, s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(s); /* s = s * k^-1 mod order */ @@ -36414,7 +36419,8 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 8U); sp_256_norm_8(ctx->r); c = sp_256_cmp_8(ctx->r, p256_order); - sp_256_cond_sub_8(ctx->r, ctx->r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(ctx->r, ctx->r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(ctx->r); sp_256_from_mp(ctx->x, 8, priv); @@ -36460,10 +36466,12 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int32_t c; sp_256_norm_8(ctx->x); carry = sp_256_add_8(ctx->s, ctx->e, ctx->x); - sp_256_cond_sub_8(ctx->s, ctx->s, p256_order, 0 - carry); + sp_256_cond_sub_8(ctx->s, ctx->s, + p256_order, 0 - carry); sp_256_norm_8(ctx->s); c = sp_256_cmp_8(ctx->s, p256_order); - sp_256_cond_sub_8(ctx->s, ctx->s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(ctx->s, ctx->s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(ctx->s); /* s = s * k^-1 mod order */ @@ -36576,7 +36584,8 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 8U); sp_256_norm_8(r); c = sp_256_cmp_8(r, p256_order); - sp_256_cond_sub_8(r, r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(r, r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(r); sp_256_from_mp(x, 8, priv); @@ -37877,19 +37886,25 @@ static const sp_point_384 p384_base = { { 0x72760ab7,0x3a545e38,0xbf55296c,0x5502f25d,0x82542a38,0x59f741e0, 0x8ba79b98,0x6e1d3b62,0xf320ad74,0x8eb1c71e,0xbe8b0537,0xaa87ca22, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0x90ea0e5f,0x7a431d7c,0x1d7e819d,0x0a60b1ce,0xb5f0b8c0,0xe9da3113, 0x289a147c,0xf8f41dbd,0x9292dc29,0x5d9e98bf,0x96262c6f,0x3617de4a, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -40095,7 +40110,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -41312,9 +41327,10 @@ static void sp_384_proj_point_dbl_12(sp_point_384* r, const sp_point_384* p, sp_ */ static int sp_384_cmp_equal_12(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11])) == 0; } /* Add two Montgomery form projective points. @@ -45539,7 +45555,8 @@ static int sp_384_calc_s_12(sp_digit* s, const sp_digit* r, sp_digit* k, sp_384_cond_sub_12(s, s, p384_order, 0 - carry); sp_384_norm_12(s); c = sp_384_cmp_12(s, p384_order); - sp_384_cond_sub_12(s, s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(s, s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(s); /* s = s * k^-1 mod order */ @@ -45632,7 +45649,8 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 12U); sp_384_norm_12(ctx->r); c = sp_384_cmp_12(ctx->r, p384_order); - sp_384_cond_sub_12(ctx->r, ctx->r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(ctx->r, ctx->r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(ctx->r); sp_384_from_mp(ctx->x, 12, priv); @@ -45678,10 +45696,12 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int32_t c; sp_384_norm_12(ctx->x); carry = sp_384_add_12(ctx->s, ctx->e, ctx->x); - sp_384_cond_sub_12(ctx->s, ctx->s, p384_order, 0 - carry); + sp_384_cond_sub_12(ctx->s, ctx->s, + p384_order, 0 - carry); sp_384_norm_12(ctx->s); c = sp_384_cmp_12(ctx->s, p384_order); - sp_384_cond_sub_12(ctx->s, ctx->s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(ctx->s, ctx->s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(ctx->s); /* s = s * k^-1 mod order */ @@ -45794,7 +45814,8 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 12U); sp_384_norm_12(r); c = sp_384_cmp_12(r, p384_order); - sp_384_cond_sub_12(r, r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(r, r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(r); sp_384_from_mp(x, 12, priv); @@ -50689,7 +50710,13 @@ static const sp_point_1024 p1024_base = { 0xdb9dfa55,0x43d5f22c,0x30b09e10,0xab10db90,0xf6ce2308,0xb5edb6c0, 0xb6ff7cbf,0x98b2f204,0x0aec69c6,0x2b1a2fd6,0x3ed9b52a,0x0a799005, 0x332c29ad,0x53fc09ee, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { @@ -50699,7 +50726,13 @@ static const sp_point_1024 p1024_base = { 0x9a140b2e,0x6b598ccf,0xf0de55f6,0xe7f7f5e5,0x654ec2b9,0xf5ea69f4, 0x1e141178,0x3d778d82,0x02990696,0xd3e82016,0x3634a135,0xf9f1f053, 0x3f6009f1,0x0a824906, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { @@ -50709,7 +50742,13 @@ static const sp_point_1024 p1024_base = { 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -51942,7 +51981,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -54105,14 +54144,17 @@ static sp_digit sp_1024_sub_32(sp_digit* r, const sp_digit* a, */ static int sp_1024_cmp_equal_32(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | - (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | (a[15] ^ b[15]) | - (a[16] ^ b[16]) | (a[17] ^ b[17]) | (a[18] ^ b[18]) | (a[19] ^ b[19]) | - (a[20] ^ b[20]) | (a[21] ^ b[21]) | (a[22] ^ b[22]) | (a[23] ^ b[23]) | - (a[24] ^ b[24]) | (a[25] ^ b[25]) | (a[26] ^ b[26]) | (a[27] ^ b[27]) | - (a[28] ^ b[28]) | (a[29] ^ b[29]) | (a[30] ^ b[30]) | (a[31] ^ b[31])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | + (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | + (a[15] ^ b[15]) | (a[16] ^ b[16]) | (a[17] ^ b[17]) | + (a[18] ^ b[18]) | (a[19] ^ b[19]) | (a[20] ^ b[20]) | + (a[21] ^ b[21]) | (a[22] ^ b[22]) | (a[23] ^ b[23]) | + (a[24] ^ b[24]) | (a[25] ^ b[25]) | (a[26] ^ b[26]) | + (a[27] ^ b[27]) | (a[28] ^ b[28]) | (a[29] ^ b[29]) | + (a[30] ^ b[30]) | (a[31] ^ b[31])) == 0; } /* Add two Montgomery form projective points. @@ -55499,8 +55541,12 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, */ static const sp_table_entry_1024 p1024_table[16] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* 1 */ { { 0xe0162bc2,0xbf9c7ec6,0x10a89289,0xddecc6e3,0x9e499d81,0x5d599df0, 0x6d358218,0x9a96ea28,0x70c5f8db,0x01aec7d3,0x8cf5d066,0xe72e4995, @@ -55727,8 +55773,12 @@ static int sp_1024_ecc_mulmod_base_32(sp_point_1024* r, const sp_digit* k, */ static const sp_table_entry_1024 p1024_table[256] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* 1 */ { { 0xe0162bc2,0xbf9c7ec6,0x10a89289,0xddecc6e3,0x9e499d81,0x5d599df0, 0x6d358218,0x9a96ea28,0x70c5f8db,0x01aec7d3,0x8cf5d066,0xe72e4995, @@ -59429,7 +59479,8 @@ static void sp_1024_proj_sqr_32(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -59448,7 +59499,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -59457,7 +59509,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 32 * 2; ty = td + 5 * 32 * 2; @@ -59500,7 +59553,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -61324,7 +61378,8 @@ static const sp_digit sp_1024_g_table[256][32] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -61342,7 +61397,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -61351,7 +61407,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 32 * 2; ty = td + 5 * 32 * 2; @@ -61394,7 +61451,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -61664,7 +61722,8 @@ static void sp_1024_accumulate_line_add_one_32(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -61693,7 +61752,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -61704,7 +61764,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 32 * 2; vy = td + 7 * 32 * 2; @@ -61760,7 +61821,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -62038,7 +62100,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -62074,7 +62137,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -62085,7 +62149,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 32 * 2; vy = td + 7 * 32 * 2; @@ -62183,7 +62248,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -62425,7 +62491,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -62464,7 +62531,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_32(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -62475,7 +62543,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; pre_p = (sp_point_1024*)(td + 6 * 32 * 2); #endif @@ -62547,7 +62616,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -62581,7 +62651,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -62623,7 +62694,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -62634,7 +62706,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 32 * 2; vy = td + 7 * 32 * 2; @@ -62738,7 +62811,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } diff --git a/wolfcrypt/src/sp_arm64.c b/wolfcrypt/src/sp_arm64.c index 9e262d35f..88b0fc90c 100644 --- a/wolfcrypt/src/sp_arm64.c +++ b/wolfcrypt/src/sp_arm64.c @@ -137,7 +137,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -6125,7 +6125,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -14254,7 +14254,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -19486,19 +19486,19 @@ static const sp_point_256 p256_base = { { 0xf4a13945d898c296L,0x77037d812deb33a0L,0xf8bce6e563a440f2L, 0x6b17d1f2e12c4247L, - 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0xcbb6406837bf51f5L,0x2bce33576b315eceL,0x8ee7eb4a7c0f9e16L, 0x4fe342e2fe1a7f9bL, - 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x0000000000000001L,0x0000000000000000L,0x0000000000000000L, 0x0000000000000000L, - 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -19925,7 +19925,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -21433,7 +21433,8 @@ static void sp_256_proj_point_dbl_n_4(sp_point_256* p, int n, */ static int sp_256_cmp_equal_4(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3])) == 0; } /* Add two Montgomery form projective points. @@ -37883,7 +37884,8 @@ static int sp_256_calc_s_4(sp_digit* s, const sp_digit* r, sp_digit* k, sp_256_cond_sub_4(s, s, p256_order, 0 - carry); sp_256_norm_4(s); c = sp_256_cmp_4(s, p256_order); - sp_256_cond_sub_4(s, s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_4(s, s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_4(s); /* s = s * k^-1 mod order */ @@ -37976,7 +37978,8 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 4U); sp_256_norm_4(ctx->r); c = sp_256_cmp_4(ctx->r, p256_order); - sp_256_cond_sub_4(ctx->r, ctx->r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_4(ctx->r, ctx->r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_4(ctx->r); sp_256_from_mp(ctx->x, 4, priv); @@ -38022,10 +38025,12 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int64_t c; sp_256_norm_4(ctx->x); carry = sp_256_add_4(ctx->s, ctx->e, ctx->x); - sp_256_cond_sub_4(ctx->s, ctx->s, p256_order, 0 - carry); + sp_256_cond_sub_4(ctx->s, ctx->s, + p256_order, 0 - carry); sp_256_norm_4(ctx->s); c = sp_256_cmp_4(ctx->s, p256_order); - sp_256_cond_sub_4(ctx->s, ctx->s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_4(ctx->s, ctx->s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_4(ctx->s); /* s = s * k^-1 mod order */ @@ -38138,7 +38143,8 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 4U); sp_256_norm_4(r); c = sp_256_cmp_4(r, p256_order); - sp_256_cond_sub_4(r, r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_4(r, r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_4(r); sp_256_from_mp(x, 4, priv); @@ -39436,19 +39442,22 @@ static const sp_point_384 p384_base = { { 0x3a545e3872760ab7L,0x5502f25dbf55296cL,0x59f741e082542a38L, 0x6e1d3b628ba79b98L,0x8eb1c71ef320ad74L,0xaa87ca22be8b0537L, - 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* Y ordinate */ { 0x7a431d7c90ea0e5fL,0x0a60b1ce1d7e819dL,0xe9da3113b5f0b8c0L, 0xf8f41dbd289a147cL,0x5d9e98bf9292dc29L,0x3617de4a96262c6fL, - 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* Z ordinate */ { 0x0000000000000001L,0x0000000000000000L,0x0000000000000000L, 0x0000000000000000L,0x0000000000000000L,0x0000000000000000L, - 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* infinity */ 0 @@ -40200,7 +40209,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -41286,8 +41295,8 @@ static void sp_384_proj_point_dbl_n_6(sp_point_384* p, int n, */ static int sp_384_cmp_equal_6(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5])) == 0; } /* Add two Montgomery form projective points. @@ -63626,7 +63635,8 @@ static int sp_384_calc_s_6(sp_digit* s, const sp_digit* r, sp_digit* k, sp_384_cond_sub_6(s, s, p384_order, 0 - carry); sp_384_norm_6(s); c = sp_384_cmp_6(s, p384_order); - sp_384_cond_sub_6(s, s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_6(s, s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_6(s); /* s = s * k^-1 mod order */ @@ -63719,7 +63729,8 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 6U); sp_384_norm_6(ctx->r); c = sp_384_cmp_6(ctx->r, p384_order); - sp_384_cond_sub_6(ctx->r, ctx->r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_6(ctx->r, ctx->r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_6(ctx->r); sp_384_from_mp(ctx->x, 6, priv); @@ -63765,10 +63776,12 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int64_t c; sp_384_norm_6(ctx->x); carry = sp_384_add_6(ctx->s, ctx->e, ctx->x); - sp_384_cond_sub_6(ctx->s, ctx->s, p384_order, 0 - carry); + sp_384_cond_sub_6(ctx->s, ctx->s, + p384_order, 0 - carry); sp_384_norm_6(ctx->s); c = sp_384_cmp_6(ctx->s, p384_order); - sp_384_cond_sub_6(ctx->s, ctx->s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_6(ctx->s, ctx->s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_6(ctx->s); /* s = s * k^-1 mod order */ @@ -63881,7 +63894,8 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 6U); sp_384_norm_6(r); c = sp_384_cmp_6(r, p384_order); - sp_384_cond_sub_6(r, r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_6(r, r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_6(r); sp_384_from_mp(x, 6, priv); @@ -66211,7 +66225,10 @@ static const sp_point_1024 p1024_base = { 0x43d5f22cdb9dfa55L,0xab10db9030b09e10L,0xb5edb6c0f6ce2308L, 0x98b2f204b6ff7cbfL,0x2b1a2fd60aec69c6L,0x0a7990053ed9b52aL, 0x53fc09ee332c29adL, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* Y ordinate */ { @@ -66221,7 +66238,10 @@ static const sp_point_1024 p1024_base = { 0x6b598ccf9a140b2eL,0xe7f7f5e5f0de55f6L,0xf5ea69f4654ec2b9L, 0x3d778d821e141178L,0xd3e8201602990696L,0xf9f1f0533634a135L, 0x0a8249063f6009f1L, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* Z ordinate */ { @@ -66231,7 +66251,10 @@ static const sp_point_1024 p1024_base = { 0x0000000000000000L,0x0000000000000000L,0x0000000000000000L, 0x0000000000000000L,0x0000000000000000L,0x0000000000000000L, 0x0000000000000000L, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* infinity */ 0 @@ -67006,7 +67029,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -68651,10 +68674,12 @@ static sp_digit sp_1024_sub_16(sp_digit* r, const sp_digit* a, */ static int sp_1024_cmp_equal_16(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | - (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | (a[15] ^ b[15])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | + (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | + (a[15] ^ b[15])) == 0; } /* Add two Montgomery form projective points. @@ -69845,8 +69870,10 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, */ static const sp_table_entry_1024 p1024_table[256] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 } }, /* 1 */ { { 0xbf9c7ec6e0162bc2L,0xddecc6e310a89289L,0x5d599df09e499d81L, 0x9a96ea286d358218L,0x01aec7d370c5f8dbL,0xe72e49958cf5d066L, @@ -73545,7 +73572,8 @@ static void sp_1024_proj_sqr_16(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -73564,7 +73592,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -73573,7 +73602,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 16 * 2; ty = td + 5 * 16 * 2; @@ -73616,7 +73646,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -75184,7 +75215,8 @@ static const sp_digit sp_1024_g_table[256][16] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -75202,7 +75234,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -75211,7 +75244,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 16 * 2; ty = td + 5 * 16 * 2; @@ -75254,7 +75288,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -75524,7 +75559,8 @@ static void sp_1024_accumulate_line_add_one_16(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -75553,7 +75589,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -75564,7 +75601,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 16 * 2; vy = td + 7 * 16 * 2; @@ -75620,7 +75658,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -75898,7 +75937,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -75934,7 +75974,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -75945,7 +75986,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 16 * 2; vy = td + 7 * 16 * 2; @@ -76043,7 +76085,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -76285,7 +76328,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -76324,7 +76368,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_16(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -76335,7 +76380,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; pre_p = (sp_point_1024*)(td + 6 * 16 * 2); #endif @@ -76407,7 +76453,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -76441,7 +76488,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -76483,7 +76531,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -76494,7 +76543,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 16 * 2; vy = td + 7 * 16 * 2; @@ -76598,7 +76648,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } diff --git a/wolfcrypt/src/sp_armthumb.c b/wolfcrypt/src/sp_armthumb.c index 0d21a2975..752e99546 100644 --- a/wolfcrypt/src/sp_armthumb.c +++ b/wolfcrypt/src/sp_armthumb.c @@ -126,7 +126,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -5476,7 +5476,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -11539,7 +11539,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -15593,19 +15593,22 @@ static const sp_point_256 p256_base = { { 0xd898c296,0xf4a13945,0x2deb33a0,0x77037d81,0x63a440f2,0xf8bce6e5, 0xe12c4247,0x6b17d1f2, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0x37bf51f5,0xcbb64068,0x6b315ece,0x2bce3357,0x7c0f9e16,0x8ee7eb4a, 0xfe1a7f9b,0x4fe342e2, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -16163,7 +16166,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -17478,8 +17481,9 @@ static void sp_256_proj_point_dbl_8(sp_point_256* r, const sp_point_256* p, sp_d */ static int sp_256_cmp_equal_8(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7])) == 0; } /* Add two Montgomery form projective points. @@ -21661,7 +21665,8 @@ static int sp_256_calc_s_8(sp_digit* s, const sp_digit* r, sp_digit* k, sp_256_cond_sub_8(s, s, p256_order, 0 - carry); sp_256_norm_8(s); c = sp_256_cmp_8(s, p256_order); - sp_256_cond_sub_8(s, s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(s, s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(s); /* s = s * k^-1 mod order */ @@ -21754,7 +21759,8 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 8U); sp_256_norm_8(ctx->r); c = sp_256_cmp_8(ctx->r, p256_order); - sp_256_cond_sub_8(ctx->r, ctx->r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(ctx->r, ctx->r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(ctx->r); sp_256_from_mp(ctx->x, 8, priv); @@ -21800,10 +21806,12 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int32_t c; sp_256_norm_8(ctx->x); carry = sp_256_add_8(ctx->s, ctx->e, ctx->x); - sp_256_cond_sub_8(ctx->s, ctx->s, p256_order, 0 - carry); + sp_256_cond_sub_8(ctx->s, ctx->s, + p256_order, 0 - carry); sp_256_norm_8(ctx->s); c = sp_256_cmp_8(ctx->s, p256_order); - sp_256_cond_sub_8(ctx->s, ctx->s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(ctx->s, ctx->s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(ctx->s); /* s = s * k^-1 mod order */ @@ -21916,7 +21924,8 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 8U); sp_256_norm_8(r); c = sp_256_cmp_8(r, p256_order); - sp_256_cond_sub_8(r, r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(r, r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(r); sp_256_from_mp(x, 8, priv); @@ -23506,19 +23515,25 @@ static const sp_point_384 p384_base = { { 0x72760ab7,0x3a545e38,0xbf55296c,0x5502f25d,0x82542a38,0x59f741e0, 0x8ba79b98,0x6e1d3b62,0xf320ad74,0x8eb1c71e,0xbe8b0537,0xaa87ca22, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0x90ea0e5f,0x7a431d7c,0x1d7e819d,0x0a60b1ce,0xb5f0b8c0,0xe9da3113, 0x289a147c,0xf8f41dbd,0x9292dc29,0x5d9e98bf,0x96262c6f,0x3617de4a, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -24139,7 +24154,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -25092,9 +25107,10 @@ static void sp_384_proj_point_dbl_12(sp_point_384* r, const sp_point_384* p, sp_ */ static int sp_384_cmp_equal_12(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11])) == 0; } /* Add two Montgomery form projective points. @@ -29336,7 +29352,8 @@ static int sp_384_calc_s_12(sp_digit* s, const sp_digit* r, sp_digit* k, sp_384_cond_sub_12(s, s, p384_order, 0 - carry); sp_384_norm_12(s); c = sp_384_cmp_12(s, p384_order); - sp_384_cond_sub_12(s, s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(s, s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(s); /* s = s * k^-1 mod order */ @@ -29429,7 +29446,8 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 12U); sp_384_norm_12(ctx->r); c = sp_384_cmp_12(ctx->r, p384_order); - sp_384_cond_sub_12(ctx->r, ctx->r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(ctx->r, ctx->r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(ctx->r); sp_384_from_mp(ctx->x, 12, priv); @@ -29475,10 +29493,12 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int32_t c; sp_384_norm_12(ctx->x); carry = sp_384_add_12(ctx->s, ctx->e, ctx->x); - sp_384_cond_sub_12(ctx->s, ctx->s, p384_order, 0 - carry); + sp_384_cond_sub_12(ctx->s, ctx->s, + p384_order, 0 - carry); sp_384_norm_12(ctx->s); c = sp_384_cmp_12(ctx->s, p384_order); - sp_384_cond_sub_12(ctx->s, ctx->s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(ctx->s, ctx->s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(ctx->s); /* s = s * k^-1 mod order */ @@ -29591,7 +29611,8 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 12U); sp_384_norm_12(r); c = sp_384_cmp_12(r, p384_order); - sp_384_cond_sub_12(r, r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(r, r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(r); sp_384_from_mp(x, 12, priv); @@ -32399,7 +32420,13 @@ static const sp_point_1024 p1024_base = { 0xdb9dfa55,0x43d5f22c,0x30b09e10,0xab10db90,0xf6ce2308,0xb5edb6c0, 0xb6ff7cbf,0x98b2f204,0x0aec69c6,0x2b1a2fd6,0x3ed9b52a,0x0a799005, 0x332c29ad,0x53fc09ee, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { @@ -32409,7 +32436,13 @@ static const sp_point_1024 p1024_base = { 0x9a140b2e,0x6b598ccf,0xf0de55f6,0xe7f7f5e5,0x654ec2b9,0xf5ea69f4, 0x1e141178,0x3d778d82,0x02990696,0xd3e82016,0x3634a135,0xf9f1f053, 0x3f6009f1,0x0a824906, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { @@ -32419,7 +32452,13 @@ static const sp_point_1024 p1024_base = { 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -32990,7 +33029,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -35668,14 +35707,17 @@ SP_NOINLINE static sp_digit sp_1024_sub_32(sp_digit* r, const sp_digit* a, */ static int sp_1024_cmp_equal_32(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | - (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | (a[15] ^ b[15]) | - (a[16] ^ b[16]) | (a[17] ^ b[17]) | (a[18] ^ b[18]) | (a[19] ^ b[19]) | - (a[20] ^ b[20]) | (a[21] ^ b[21]) | (a[22] ^ b[22]) | (a[23] ^ b[23]) | - (a[24] ^ b[24]) | (a[25] ^ b[25]) | (a[26] ^ b[26]) | (a[27] ^ b[27]) | - (a[28] ^ b[28]) | (a[29] ^ b[29]) | (a[30] ^ b[30]) | (a[31] ^ b[31])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | + (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | + (a[15] ^ b[15]) | (a[16] ^ b[16]) | (a[17] ^ b[17]) | + (a[18] ^ b[18]) | (a[19] ^ b[19]) | (a[20] ^ b[20]) | + (a[21] ^ b[21]) | (a[22] ^ b[22]) | (a[23] ^ b[23]) | + (a[24] ^ b[24]) | (a[25] ^ b[25]) | (a[26] ^ b[26]) | + (a[27] ^ b[27]) | (a[28] ^ b[28]) | (a[29] ^ b[29]) | + (a[30] ^ b[30]) | (a[31] ^ b[31])) == 0; } /* Add two Montgomery form projective points. @@ -37062,8 +37104,12 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, */ static const sp_table_entry_1024 p1024_table[16] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* 1 */ { { 0xe0162bc2,0xbf9c7ec6,0x10a89289,0xddecc6e3,0x9e499d81,0x5d599df0, 0x6d358218,0x9a96ea28,0x70c5f8db,0x01aec7d3,0x8cf5d066,0xe72e4995, @@ -37290,8 +37336,12 @@ static int sp_1024_ecc_mulmod_base_32(sp_point_1024* r, const sp_digit* k, */ static const sp_table_entry_1024 p1024_table[256] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* 1 */ { { 0xe0162bc2,0xbf9c7ec6,0x10a89289,0xddecc6e3,0x9e499d81,0x5d599df0, 0x6d358218,0x9a96ea28,0x70c5f8db,0x01aec7d3,0x8cf5d066,0xe72e4995, @@ -40992,7 +41042,8 @@ static void sp_1024_proj_sqr_32(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -41011,7 +41062,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -41020,7 +41072,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 32 * 2; ty = td + 5 * 32 * 2; @@ -41063,7 +41116,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -42887,7 +42941,8 @@ static const sp_digit sp_1024_g_table[256][32] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -42905,7 +42960,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -42914,7 +42970,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 32 * 2; ty = td + 5 * 32 * 2; @@ -42957,7 +43014,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -43227,7 +43285,8 @@ static void sp_1024_accumulate_line_add_one_32(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -43256,7 +43315,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -43267,7 +43327,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 32 * 2; vy = td + 7 * 32 * 2; @@ -43323,7 +43384,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -43601,7 +43663,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -43637,7 +43700,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -43648,7 +43712,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 32 * 2; vy = td + 7 * 32 * 2; @@ -43746,7 +43811,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -43988,7 +44054,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -44027,7 +44094,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_32(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -44038,7 +44106,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; pre_p = (sp_point_1024*)(td + 6 * 32 * 2); #endif @@ -44110,7 +44179,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -44144,7 +44214,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -44186,7 +44257,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -44197,7 +44269,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 32 * 2; vy = td + 7 * 32 * 2; @@ -44301,7 +44374,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } diff --git a/wolfcrypt/src/sp_c32.c b/wolfcrypt/src/sp_c32.c index bbdf1bcb7..38312e010 100644 --- a/wolfcrypt/src/sp_c32.c +++ b/wolfcrypt/src/sp_c32.c @@ -60,7 +60,7 @@ static const size_t addr_mask[2] = { 0, (size_t)-1 }; #endif -#if defined(WOLFSSL_SP_NONBLOCK) && (!defined(WOLFSSL_SP_NO_MALLOC) || !defined(WOLFSSL_SP_SMALL)) +#if defined(WOLFSSL_SP_NONBLOCK) && (!defined(WOLFSSL_SP_NO_MALLOC) || !defined(WOLFSSL_SP_SMALL)) #error SP non-blocking requires small and no-malloc (WOLFSSL_SP_SMALL and WOLFSSL_SP_NO_MALLOC) #endif @@ -143,7 +143,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -1251,7 +1251,7 @@ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x7fffff; /* rho = -1/m mod b */ - *rho = (1L << 23) - x; + *rho = ((sp_digit)1 << 23) - x; } /* Multiply a by scalar b into r. (r = a * b) @@ -1370,25 +1370,25 @@ static sp_digit sp_2048_cmp_45(const sp_digit* a, const sp_digit* b) int i; for (i=44; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[44] - b[44]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[43] - b[43]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[42] - b[42]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[41] - b[41]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[40] - b[40]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[44] - b[44]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[43] - b[43]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[42] - b[42]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[41] - b[41]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[40] - b[40]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 32; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -1477,10 +1477,14 @@ SP_NOINLINE static void sp_2048_mul_add_45(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 23) + (t[0] & 0x7fffff)); } - t[1] = tb * a[41]; r[41] += (sp_digit)((t[0] >> 23) + (t[1] & 0x7fffff)); - t[2] = tb * a[42]; r[42] += (sp_digit)((t[1] >> 23) + (t[2] & 0x7fffff)); - t[3] = tb * a[43]; r[43] += (sp_digit)((t[2] >> 23) + (t[3] & 0x7fffff)); - t[4] = tb * a[44]; r[44] += (sp_digit)((t[3] >> 23) + (t[4] & 0x7fffff)); + t[1] = tb * a[41]; + r[41] += (sp_digit)((t[0] >> 23) + (t[1] & 0x7fffff)); + t[2] = tb * a[42]; + r[42] += (sp_digit)((t[1] >> 23) + (t[2] & 0x7fffff)); + t[3] = tb * a[43]; + r[43] += (sp_digit)((t[2] >> 23) + (t[3] & 0x7fffff)); + t[4] = tb * a[44]; + r[44] += (sp_digit)((t[3] >> 23) + (t[4] & 0x7fffff)); r[45] += (sp_digit)(t[4] >> 23); #endif /* WOLFSSL_SP_SMALL */ } @@ -1822,8 +1826,8 @@ static int sp_2048_div_45(const sp_digit* a, const sp_digit* d, t2 = t1 + 90 + 1; sd = t2 + 45 + 1; - sp_2048_mul_d_45(sd, d, 1L << 11); - sp_2048_mul_d_90(t1, a, 1L << 11); + sp_2048_mul_d_45(sd, d, (sp_digit)1 << 11); + sp_2048_mul_d_90(t1, a, (sp_digit)1 << 11); dv = sd[44]; t1[45 + 45] += t1[45 + 45 - 1] >> 23; t1[45 + 45 - 1] &= 0x7fffff; @@ -1897,8 +1901,8 @@ static int sp_2048_mod_45(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_2048_mod_exp_45(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_2048_mod_exp_45(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -2258,22 +2262,22 @@ static sp_digit sp_2048_cmp_90(const sp_digit* a, const sp_digit* b) int i; for (i=89; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[89] - b[89]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[88] - b[88]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[89] - b[89]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[88] - b[88]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 80; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -2359,7 +2363,8 @@ SP_NOINLINE static void sp_2048_mul_add_90(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 23) + (t[0] & 0x7fffff)); } - t[1] = tb * a[89]; r[89] += (sp_digit)((t[0] >> 23) + (t[1] & 0x7fffff)); + t[1] = tb * a[89]; + r[89] += (sp_digit)((t[0] >> 23) + (t[1] & 0x7fffff)); r[90] += (sp_digit)(t[1] >> 23); #endif /* WOLFSSL_SP_SMALL */ } @@ -2711,8 +2716,8 @@ static int sp_2048_div_90(const sp_digit* a, const sp_digit* d, t2 = t1 + 180 + 1; sd = t2 + 90 + 1; - sp_2048_mul_d_90(sd, d, 1L << 22); - sp_2048_mul_d_180(t1, a, 1L << 22); + sp_2048_mul_d_90(sd, d, (sp_digit)1 << 22); + sp_2048_mul_d_180(t1, a, (sp_digit)1 << 22); dv = sd[89]; t1[90 + 90] += t1[90 + 90 - 1] >> 23; t1[90 + 90 - 1] &= 0x7fffff; @@ -2788,8 +2793,8 @@ static int sp_2048_mod_90(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_2048_mod_exp_90(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_2048_mod_exp_90(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -4602,7 +4607,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -5156,7 +5161,7 @@ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x7fffff; /* rho = -1/m mod b */ - *rho = (1L << 23) - x; + *rho = ((sp_digit)1 << 23) - x; } /* Multiply a by scalar b into r. (r = a * b) @@ -5273,23 +5278,23 @@ static sp_digit sp_3072_cmp_67(const sp_digit* a, const sp_digit* b) int i; for (i=66; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[66] - b[66]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[65] - b[65]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[64] - b[64]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[66] - b[66]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[65] - b[65]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[64] - b[64]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 56; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -5376,8 +5381,10 @@ SP_NOINLINE static void sp_3072_mul_add_67(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 23) + (t[0] & 0x7fffff)); } - t[1] = tb * a[65]; r[65] += (sp_digit)((t[0] >> 23) + (t[1] & 0x7fffff)); - t[2] = tb * a[66]; r[66] += (sp_digit)((t[1] >> 23) + (t[2] & 0x7fffff)); + t[1] = tb * a[65]; + r[65] += (sp_digit)((t[0] >> 23) + (t[1] & 0x7fffff)); + t[2] = tb * a[66]; + r[66] += (sp_digit)((t[1] >> 23) + (t[2] & 0x7fffff)); r[67] += (sp_digit)(t[2] >> 23); #endif /* WOLFSSL_SP_SMALL */ } @@ -5766,8 +5773,8 @@ static int sp_3072_mod_67(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_3072_mod_exp_67(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_3072_mod_exp_67(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -6131,26 +6138,26 @@ static sp_digit sp_3072_cmp_134(const sp_digit* a, const sp_digit* b) int i; for (i=133; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[133] - b[133]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[132] - b[132]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[131] - b[131]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[130] - b[130]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[129] - b[129]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[128] - b[128]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[133] - b[133]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[132] - b[132]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[131] - b[131]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[130] - b[130]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[129] - b[129]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[128] - b[128]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 120; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -6240,11 +6247,16 @@ SP_NOINLINE static void sp_3072_mul_add_134(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 23) + (t[0] & 0x7fffff)); } - t[1] = tb * a[129]; r[129] += (sp_digit)((t[0] >> 23) + (t[1] & 0x7fffff)); - t[2] = tb * a[130]; r[130] += (sp_digit)((t[1] >> 23) + (t[2] & 0x7fffff)); - t[3] = tb * a[131]; r[131] += (sp_digit)((t[2] >> 23) + (t[3] & 0x7fffff)); - t[4] = tb * a[132]; r[132] += (sp_digit)((t[3] >> 23) + (t[4] & 0x7fffff)); - t[5] = tb * a[133]; r[133] += (sp_digit)((t[4] >> 23) + (t[5] & 0x7fffff)); + t[1] = tb * a[129]; + r[129] += (sp_digit)((t[0] >> 23) + (t[1] & 0x7fffff)); + t[2] = tb * a[130]; + r[130] += (sp_digit)((t[1] >> 23) + (t[2] & 0x7fffff)); + t[3] = tb * a[131]; + r[131] += (sp_digit)((t[2] >> 23) + (t[3] & 0x7fffff)); + t[4] = tb * a[132]; + r[132] += (sp_digit)((t[3] >> 23) + (t[4] & 0x7fffff)); + t[5] = tb * a[133]; + r[133] += (sp_digit)((t[4] >> 23) + (t[5] & 0x7fffff)); r[134] += (sp_digit)(t[5] >> 23); #endif /* WOLFSSL_SP_SMALL */ } @@ -6612,8 +6624,8 @@ static int sp_3072_div_134(const sp_digit* a, const sp_digit* d, t2 = t1 + 268 + 1; sd = t2 + 134 + 1; - sp_3072_mul_d_134(sd, d, 1L << 10); - sp_3072_mul_d_268(t1, a, 1L << 10); + sp_3072_mul_d_134(sd, d, (sp_digit)1 << 10); + sp_3072_mul_d_268(t1, a, (sp_digit)1 << 10); dv = sd[133]; t1[134 + 134] += t1[134 + 134 - 1] >> 23; t1[134 + 134 - 1] &= 0x7fffff; @@ -6689,8 +6701,8 @@ static int sp_3072_mod_134(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_3072_mod_exp_134(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_3072_mod_exp_134(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -8591,7 +8603,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -9210,7 +9222,7 @@ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1fffff; /* rho = -1/m mod b */ - *rho = (1L << 21) - x; + *rho = ((sp_digit)1 << 21) - x; } /* Multiply a by scalar b into r. (r = a * b) @@ -9321,22 +9333,22 @@ static sp_digit sp_4096_cmp_98(const sp_digit* a, const sp_digit* b) int i; for (i=97; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[97] - b[97]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[96] - b[96]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[97] - b[97]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[96] - b[96]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 88; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -9422,7 +9434,8 @@ SP_NOINLINE static void sp_4096_mul_add_98(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 21) + (t[0] & 0x1fffff)); } - t[1] = tb * a[97]; r[97] += (sp_digit)((t[0] >> 21) + (t[1] & 0x1fffff)); + t[1] = tb * a[97]; + r[97] += (sp_digit)((t[0] >> 21) + (t[1] & 0x1fffff)); r[98] += (sp_digit)(t[1] >> 21); #endif /* WOLFSSL_SP_SMALL */ } @@ -9755,8 +9768,8 @@ static int sp_4096_div_98(const sp_digit* a, const sp_digit* d, t2 = t1 + 196 + 1; sd = t2 + 98 + 1; - sp_4096_mul_d_98(sd, d, 1L << 10); - sp_4096_mul_d_196(t1, a, 1L << 10); + sp_4096_mul_d_98(sd, d, (sp_digit)1 << 10); + sp_4096_mul_d_196(t1, a, (sp_digit)1 << 10); dv = sd[97]; t1[98 + 98] += t1[98 + 98 - 1] >> 21; t1[98 + 98 - 1] &= 0x1fffff; @@ -9830,8 +9843,8 @@ static int sp_4096_mod_98(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_4096_mod_exp_98(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_4096_mod_exp_98(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -10194,24 +10207,24 @@ static sp_digit sp_4096_cmp_196(const sp_digit* a, const sp_digit* b) int i; for (i=195; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[195] - b[195]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[194] - b[194]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[193] - b[193]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[192] - b[192]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[195] - b[195]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[194] - b[194]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[193] - b[193]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[192] - b[192]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 184; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -10299,9 +10312,12 @@ SP_NOINLINE static void sp_4096_mul_add_196(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 21) + (t[0] & 0x1fffff)); } - t[1] = tb * a[193]; r[193] += (sp_digit)((t[0] >> 21) + (t[1] & 0x1fffff)); - t[2] = tb * a[194]; r[194] += (sp_digit)((t[1] >> 21) + (t[2] & 0x1fffff)); - t[3] = tb * a[195]; r[195] += (sp_digit)((t[2] >> 21) + (t[3] & 0x1fffff)); + t[1] = tb * a[193]; + r[193] += (sp_digit)((t[0] >> 21) + (t[1] & 0x1fffff)); + t[2] = tb * a[194]; + r[194] += (sp_digit)((t[1] >> 21) + (t[2] & 0x1fffff)); + t[3] = tb * a[195]; + r[195] += (sp_digit)((t[2] >> 21) + (t[3] & 0x1fffff)); r[196] += (sp_digit)(t[3] >> 21); #endif /* WOLFSSL_SP_SMALL */ } @@ -10661,8 +10677,8 @@ static int sp_4096_div_196(const sp_digit* a, const sp_digit* d, t2 = t1 + 392 + 1; sd = t2 + 196 + 1; - sp_4096_mul_d_196(sd, d, 1L << 20); - sp_4096_mul_d_392(t1, a, 1L << 20); + sp_4096_mul_d_196(sd, d, (sp_digit)1 << 20); + sp_4096_mul_d_392(t1, a, (sp_digit)1 << 20); dv = sd[195]; t1[196 + 196] += t1[196 + 196 - 1] >> 21; t1[196 + 196 - 1] &= 0x1fffff; @@ -10738,8 +10754,8 @@ static int sp_4096_mod_196(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_4096_mod_exp_196(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_4096_mod_exp_196(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -12602,19 +12618,22 @@ static const sp_point_256 p256_base = { { 0x098c296,0x04e5176,0x33a0f4a,0x204b7ac,0x277037d,0x0e9103c,0x3ce6e56, 0x1091fe2,0x1f2e12c,0x01ac5f4, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0x3bf51f5,0x1901a0d,0x1ececbb,0x15dacc5,0x22bce33,0x303e785,0x27eb4a7, 0x1fe6e3b,0x2e2fe1a,0x013f8d0, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x0000001,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000, 0x0000000,0x0000000,0x0000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -13052,7 +13071,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -13218,19 +13237,19 @@ static sp_digit sp_256_cmp_10(const sp_digit* a, const sp_digit* b) int i; for (i=9; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else - r |= (a[ 9] - b[ 9]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 8] - b[ 8]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 7] - b[ 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 6] - b[ 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 5] - b[ 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 4] - b[ 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 3] - b[ 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 2] - b[ 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 1] - b[ 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 0] - b[ 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[ 9] - b[ 9]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 8] - b[ 8]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 7] - b[ 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 6] - b[ 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 5] - b[ 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 4] - b[ 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 3] - b[ 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 2] - b[ 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 1] - b[ 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 0] - b[ 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); #endif /* WOLFSSL_SP_SMALL */ return r; @@ -13943,9 +13962,10 @@ static void sp_256_proj_point_dbl_10(sp_point_256* r, const sp_point_256* p, sp_ */ static int sp_256_cmp_equal_10(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9])) == 0; } /* Add two Montgomery form projective points. @@ -18037,7 +18057,8 @@ static int sp_256_calc_s_10(sp_digit* s, const sp_digit* r, sp_digit* k, sp_256_cond_sub_10(s, s, p256_order, 0 - carry); sp_256_norm_10(s); c = sp_256_cmp_10(s, p256_order); - sp_256_cond_sub_10(s, s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_10(s, s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_10(s); /* s = s * k^-1 mod order */ @@ -18130,7 +18151,8 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 10U); sp_256_norm_10(ctx->r); c = sp_256_cmp_10(ctx->r, p256_order); - sp_256_cond_sub_10(ctx->r, ctx->r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_10(ctx->r, ctx->r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_10(ctx->r); sp_256_from_mp(ctx->x, 10, priv); @@ -18176,10 +18198,12 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int32_t c; sp_256_norm_10(ctx->x); carry = sp_256_add_10(ctx->s, ctx->e, ctx->x); - sp_256_cond_sub_10(ctx->s, ctx->s, p256_order, 0 - carry); + sp_256_cond_sub_10(ctx->s, ctx->s, + p256_order, 0 - carry); sp_256_norm_10(ctx->s); c = sp_256_cmp_10(ctx->s, p256_order); - sp_256_cond_sub_10(ctx->s, ctx->s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_10(ctx->s, ctx->s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_10(ctx->s); /* s = s * k^-1 mod order */ @@ -18292,7 +18316,8 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 10U); sp_256_norm_10(r); c = sp_256_cmp_10(r, p256_order); - sp_256_cond_sub_10(r, r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_10(r, r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_10(r); sp_256_from_mp(x, 10, priv); @@ -19466,21 +19491,27 @@ static const sp_point_384 p384_base = { 0x2760ab7,0x1178e1c,0x296c3a5,0x176fd54,0x05502f2,0x0950a8e,0x3741e08, 0x26e6167,0x3628ba7,0x11b874e,0x3320ad7,0x2c71c7b,0x305378e,0x288afa2, 0x00aa87c, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0x0ea0e5f,0x0c75f24,0x019d7a4,0x33875fa,0x00a60b1,0x17c2e30,0x1a3113b, 0x051f3a7,0x1bd289a,0x27e3d07,0x1292dc2,0x27a62fe,0x22c6f5d,0x392a589, 0x003617d, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x0000001,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000, 0x0000000,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000, 0x0000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -20139,7 +20170,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -20305,24 +20336,24 @@ static sp_digit sp_384_cmp_15(const sp_digit* a, const sp_digit* b) int i; for (i=14; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else - r |= (a[14] - b[14]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[13] - b[13]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[12] - b[12]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[11] - b[11]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[10] - b[10]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 9] - b[ 9]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 8] - b[ 8]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 7] - b[ 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 6] - b[ 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 5] - b[ 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 4] - b[ 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 3] - b[ 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 2] - b[ 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 1] - b[ 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 0] - b[ 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[14] - b[14]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[13] - b[13]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[12] - b[12]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[11] - b[11]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[10] - b[10]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 9] - b[ 9]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 8] - b[ 8]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 7] - b[ 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 6] - b[ 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 5] - b[ 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 4] - b[ 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 3] - b[ 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 2] - b[ 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 1] - b[ 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 0] - b[ 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); #endif /* WOLFSSL_SP_SMALL */ return r; @@ -21059,9 +21090,10 @@ static void sp_384_proj_point_dbl_15(sp_point_384* r, const sp_point_384* p, sp_ */ static int sp_384_cmp_equal_15(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14])) == 0; } @@ -23086,8 +23118,10 @@ static int sp_384_ecc_mulmod_base_15(sp_point_384* r, const sp_digit* k, */ static const sp_table_entry_384 p384_table[256] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00 } }, /* 1 */ { { 0x1c0b528,0x01d5992,0x0e383dd,0x38a835b,0x220e378,0x106d35b, 0x1c3afc5,0x03bfe1e,0x28459a3,0x2d91521,0x214ede2,0x0bfdc8d, @@ -25747,7 +25781,8 @@ static int sp_384_calc_s_15(sp_digit* s, const sp_digit* r, sp_digit* k, sp_384_cond_sub_15(s, s, p384_order, 0 - carry); sp_384_norm_15(s); c = sp_384_cmp_15(s, p384_order); - sp_384_cond_sub_15(s, s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_15(s, s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_15(s); /* s = s * k^-1 mod order */ @@ -25840,7 +25875,8 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 15U); sp_384_norm_15(ctx->r); c = sp_384_cmp_15(ctx->r, p384_order); - sp_384_cond_sub_15(ctx->r, ctx->r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_15(ctx->r, ctx->r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_15(ctx->r); sp_384_from_mp(ctx->x, 15, priv); @@ -25886,10 +25922,12 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int32_t c; sp_384_norm_15(ctx->x); carry = sp_384_add_15(ctx->s, ctx->e, ctx->x); - sp_384_cond_sub_15(ctx->s, ctx->s, p384_order, 0 - carry); + sp_384_cond_sub_15(ctx->s, ctx->s, + p384_order, 0 - carry); sp_384_norm_15(ctx->s); c = sp_384_cmp_15(ctx->s, p384_order); - sp_384_cond_sub_15(ctx->s, ctx->s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_15(ctx->s, ctx->s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_15(ctx->s); /* s = s * k^-1 mod order */ @@ -26002,7 +26040,8 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 15U); sp_384_norm_15(r); c = sp_384_cmp_15(r, p384_order); - sp_384_cond_sub_15(r, r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_15(r, r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_15(r); sp_384_from_mp(x, 15, priv); @@ -27702,7 +27741,15 @@ static const sp_point_1024 p1024_base = { 0x13a0367,0x1c62f67,0x13bf4aa,0x1f22cdb,0x10821ea,0x00c2c27,0x1621b72, 0x0e2308a,0x1b607b6,0x0fed7b6,0x16dfef9,0x0b2f204,0x034e34c,0x1f582bb, 0x1456345,0x1ed9b52,0x1cc8029,0x0a6b429,0x1dc6658,0x053fc09,0x0000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { @@ -27712,7 +27759,15 @@ static const sp_point_1024 p1024_base = { 0x0654f01,0x105b3fc,0x028165c,0x18ccf9a,0x0fb35ac,0x17c3795,0x0fefebc, 0x0ec2b9e,0x14fa32a,0x1e3d7a9,0x03c2822,0x1778d82,0x0834b1e,0x00580a6, 0x0ba7d04,0x1634a13,0x18f8299,0x027c7e7,0x00c7ec0,0x00a8249,0x0000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { @@ -27722,7 +27777,15 @@ static const sp_point_1024 p1024_base = { 0x0000000,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000, 0x0000000,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000, 0x0000000,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000,0x0000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -28158,7 +28221,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -28322,22 +28385,22 @@ static sp_digit sp_1024_cmp_42(const sp_digit* a, const sp_digit* b) int i; for (i=41; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[41] - b[41]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[40] - b[40]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[41] - b[41]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[40] - b[40]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 32; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -28423,7 +28486,8 @@ SP_NOINLINE static void sp_1024_mul_add_42(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 25) + (t[0] & 0x1ffffff)); } - t[1] = tb * a[41]; r[41] += (sp_digit)((t[0] >> 25) + (t[1] & 0x1ffffff)); + t[1] = tb * a[41]; + r[41] += (sp_digit)((t[0] >> 25) + (t[1] & 0x1ffffff)); r[42] += (sp_digit)(t[1] >> 25); #endif /* WOLFSSL_SP_SMALL */ } @@ -28998,17 +29062,20 @@ static void sp_1024_proj_point_dbl_42(sp_point_1024* r, const sp_point_1024* p, */ static int sp_1024_cmp_equal_42(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | - (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | (a[15] ^ b[15]) | - (a[16] ^ b[16]) | (a[17] ^ b[17]) | (a[18] ^ b[18]) | (a[19] ^ b[19]) | - (a[20] ^ b[20]) | (a[21] ^ b[21]) | (a[22] ^ b[22]) | (a[23] ^ b[23]) | - (a[24] ^ b[24]) | (a[25] ^ b[25]) | (a[26] ^ b[26]) | (a[27] ^ b[27]) | - (a[28] ^ b[28]) | (a[29] ^ b[29]) | (a[30] ^ b[30]) | (a[31] ^ b[31]) | - (a[32] ^ b[32]) | (a[33] ^ b[33]) | (a[34] ^ b[34]) | (a[35] ^ b[35]) | - (a[36] ^ b[36]) | (a[37] ^ b[37]) | (a[38] ^ b[38]) | (a[39] ^ b[39]) | - (a[40] ^ b[40]) | (a[41] ^ b[41])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | + (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | + (a[15] ^ b[15]) | (a[16] ^ b[16]) | (a[17] ^ b[17]) | + (a[18] ^ b[18]) | (a[19] ^ b[19]) | (a[20] ^ b[20]) | + (a[21] ^ b[21]) | (a[22] ^ b[22]) | (a[23] ^ b[23]) | + (a[24] ^ b[24]) | (a[25] ^ b[25]) | (a[26] ^ b[26]) | + (a[27] ^ b[27]) | (a[28] ^ b[28]) | (a[29] ^ b[29]) | + (a[30] ^ b[30]) | (a[31] ^ b[31]) | (a[32] ^ b[32]) | + (a[33] ^ b[33]) | (a[34] ^ b[34]) | (a[35] ^ b[35]) | + (a[36] ^ b[36]) | (a[37] ^ b[37]) | (a[38] ^ b[38]) | + (a[39] ^ b[39]) | (a[40] ^ b[40]) | (a[41] ^ b[41])) == 0; } /* Add two Montgomery form projective points. @@ -30649,8 +30716,14 @@ static int sp_1024_ecc_mulmod_base_42(sp_point_1024* r, const sp_digit* k, */ static const sp_table_entry_1024 p1024_table[256] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* 1 */ { { 0x0162bc2,0x03f6370,0x0a26fe7,0x0621512,0x1decc6e,0x04cec0e, 0x077c279,0x030bab3,0x06d3582,0x14b7514,0x17e36e6,0x0fa6e18, @@ -34861,7 +34934,8 @@ static void sp_1024_proj_sqr_42(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -34880,7 +34954,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 42 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -34889,7 +34964,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 42 * 2; ty = td + 5 * 42 * 2; @@ -34932,7 +35008,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -36756,7 +36833,8 @@ static const sp_digit sp_1024_g_table[256][42] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -36774,7 +36852,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 42 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -36783,7 +36862,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 42 * 2; ty = td + 5 * 42 * 2; @@ -36826,7 +36906,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -37096,7 +37177,8 @@ static void sp_1024_accumulate_line_add_one_42(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -37125,7 +37207,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_42(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 42 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -37136,7 +37219,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 42 * 2; vy = td + 7 * 42 * 2; @@ -37192,7 +37276,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -37470,7 +37555,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -37506,7 +37592,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_42(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 42 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -37517,7 +37604,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 42 * 2; vy = td + 7 * 42 * 2; @@ -37615,7 +37703,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -37857,7 +37946,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -37896,7 +37986,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_42(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 42 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -37907,7 +37998,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; pre_p = (sp_point_1024*)(td + 6 * 42 * 2); #endif @@ -37979,7 +38071,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -38013,7 +38106,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -38055,7 +38149,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_42(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 42 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -38066,7 +38161,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 42 * 2; vy = td + 7 * 42 * 2; @@ -38170,7 +38266,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } diff --git a/wolfcrypt/src/sp_c64.c b/wolfcrypt/src/sp_c64.c index df4eb4671..9f0594e78 100644 --- a/wolfcrypt/src/sp_c64.c +++ b/wolfcrypt/src/sp_c64.c @@ -60,7 +60,7 @@ static const size_t addr_mask[2] = { 0, (size_t)-1 }; #endif -#if defined(WOLFSSL_SP_NONBLOCK) && (!defined(WOLFSSL_SP_NO_MALLOC) || !defined(WOLFSSL_SP_SMALL)) +#if defined(WOLFSSL_SP_NONBLOCK) && (!defined(WOLFSSL_SP_NO_MALLOC) || !defined(WOLFSSL_SP_SMALL)) #error SP non-blocking requires small and no-malloc (WOLFSSL_SP_SMALL and WOLFSSL_SP_NO_MALLOC) #endif @@ -143,7 +143,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -890,7 +890,7 @@ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1ffffffffffffffL; /* rho = -1/m mod b */ - *rho = (1L << 57) - x; + *rho = ((sp_digit)1 << 57) - x; } /* Multiply a by scalar b into r. (r = a * b) @@ -1000,22 +1000,22 @@ static sp_digit sp_2048_cmp_18(const sp_digit* a, const sp_digit* b) int i; for (i=17; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[17] - b[17]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[16] - b[16]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[17] - b[17]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[16] - b[16]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 8; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -1101,7 +1101,8 @@ SP_NOINLINE static void sp_2048_mul_add_18(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 57) + (t[0] & 0x1ffffffffffffffL)); } - t[1] = tb * a[17]; r[17] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL)); + t[1] = tb * a[17]; + r[17] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL)); r[18] += (sp_digit)(t[1] >> 57); #endif /* WOLFSSL_SP_SMALL */ } @@ -1527,8 +1528,8 @@ static int sp_2048_mod_18(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -1890,24 +1891,24 @@ static sp_digit sp_2048_cmp_36(const sp_digit* a, const sp_digit* b) int i; for (i=35; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[35] - b[35]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[34] - b[34]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[33] - b[33]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[32] - b[32]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[35] - b[35]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[34] - b[34]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[33] - b[33]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[32] - b[32]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 24; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -1995,9 +1996,12 @@ SP_NOINLINE static void sp_2048_mul_add_36(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 57) + (t[0] & 0x1ffffffffffffffL)); } - t[1] = tb * a[33]; r[33] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL)); - t[2] = tb * a[34]; r[34] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL)); - t[3] = tb * a[35]; r[35] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL)); + t[1] = tb * a[33]; + r[33] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL)); + t[2] = tb * a[34]; + r[34] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL)); + t[3] = tb * a[35]; + r[35] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL)); r[36] += (sp_digit)(t[3] >> 57); #endif /* WOLFSSL_SP_SMALL */ } @@ -2411,8 +2415,8 @@ static int sp_2048_mod_36(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -4118,7 +4122,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -5090,7 +5094,7 @@ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1ffffffffffffffL; /* rho = -1/m mod b */ - *rho = (1L << 57) - x; + *rho = ((sp_digit)1 << 57) - x; } /* Multiply a by scalar b into r. (r = a * b) @@ -5207,23 +5211,23 @@ static sp_digit sp_3072_cmp_27(const sp_digit* a, const sp_digit* b) int i; for (i=26; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[26] - b[26]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[25] - b[25]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[24] - b[24]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[26] - b[26]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[25] - b[25]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[24] - b[24]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 16; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -5310,8 +5314,10 @@ SP_NOINLINE static void sp_3072_mul_add_27(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 57) + (t[0] & 0x1ffffffffffffffL)); } - t[1] = tb * a[25]; r[25] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL)); - t[2] = tb * a[26]; r[26] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL)); + t[1] = tb * a[25]; + r[25] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL)); + t[2] = tb * a[26]; + r[26] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL)); r[27] += (sp_digit)(t[2] >> 57); #endif /* WOLFSSL_SP_SMALL */ } @@ -5756,8 +5762,8 @@ static int sp_3072_mod_27(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -6121,26 +6127,26 @@ static sp_digit sp_3072_cmp_54(const sp_digit* a, const sp_digit* b) int i; for (i=53; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[53] - b[53]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[52] - b[52]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[51] - b[51]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[50] - b[50]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[49] - b[49]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[48] - b[48]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[53] - b[53]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[52] - b[52]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[51] - b[51]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[50] - b[50]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[49] - b[49]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[48] - b[48]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 40; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -6230,11 +6236,16 @@ SP_NOINLINE static void sp_3072_mul_add_54(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 57) + (t[0] & 0x1ffffffffffffffL)); } - t[1] = tb * a[49]; r[49] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL)); - t[2] = tb * a[50]; r[50] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL)); - t[3] = tb * a[51]; r[51] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL)); - t[4] = tb * a[52]; r[52] += (sp_digit)((t[3] >> 57) + (t[4] & 0x1ffffffffffffffL)); - t[5] = tb * a[53]; r[53] += (sp_digit)((t[4] >> 57) + (t[5] & 0x1ffffffffffffffL)); + t[1] = tb * a[49]; + r[49] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL)); + t[2] = tb * a[50]; + r[50] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL)); + t[3] = tb * a[51]; + r[51] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL)); + t[4] = tb * a[52]; + r[52] += (sp_digit)((t[3] >> 57) + (t[4] & 0x1ffffffffffffffL)); + t[5] = tb * a[53]; + r[53] += (sp_digit)((t[4] >> 57) + (t[5] & 0x1ffffffffffffffL)); r[54] += (sp_digit)(t[5] >> 57); #endif /* WOLFSSL_SP_SMALL */ } @@ -6645,8 +6656,8 @@ static int sp_3072_mod_54(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -8388,7 +8399,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -9408,7 +9419,7 @@ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho) x &= 0x1fffffffffffffL; /* rho = -1/m mod b */ - *rho = (1L << 53) - x; + *rho = ((sp_digit)1 << 53) - x; } /* Multiply a by scalar b into r. (r = a * b) @@ -9530,27 +9541,27 @@ static sp_digit sp_4096_cmp_39(const sp_digit* a, const sp_digit* b) int i; for (i=38; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[38] - b[38]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[37] - b[37]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[36] - b[36]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[35] - b[35]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[34] - b[34]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[33] - b[33]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[32] - b[32]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[38] - b[38]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[37] - b[37]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[36] - b[36]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[35] - b[35]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[34] - b[34]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[33] - b[33]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[32] - b[32]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 24; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -9641,12 +9652,18 @@ SP_NOINLINE static void sp_4096_mul_add_39(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 53) + (t[0] & 0x1fffffffffffffL)); } - t[1] = tb * a[33]; r[33] += (sp_digit)((t[0] >> 53) + (t[1] & 0x1fffffffffffffL)); - t[2] = tb * a[34]; r[34] += (sp_digit)((t[1] >> 53) + (t[2] & 0x1fffffffffffffL)); - t[3] = tb * a[35]; r[35] += (sp_digit)((t[2] >> 53) + (t[3] & 0x1fffffffffffffL)); - t[4] = tb * a[36]; r[36] += (sp_digit)((t[3] >> 53) + (t[4] & 0x1fffffffffffffL)); - t[5] = tb * a[37]; r[37] += (sp_digit)((t[4] >> 53) + (t[5] & 0x1fffffffffffffL)); - t[6] = tb * a[38]; r[38] += (sp_digit)((t[5] >> 53) + (t[6] & 0x1fffffffffffffL)); + t[1] = tb * a[33]; + r[33] += (sp_digit)((t[0] >> 53) + (t[1] & 0x1fffffffffffffL)); + t[2] = tb * a[34]; + r[34] += (sp_digit)((t[1] >> 53) + (t[2] & 0x1fffffffffffffL)); + t[3] = tb * a[35]; + r[35] += (sp_digit)((t[2] >> 53) + (t[3] & 0x1fffffffffffffL)); + t[4] = tb * a[36]; + r[36] += (sp_digit)((t[3] >> 53) + (t[4] & 0x1fffffffffffffL)); + t[5] = tb * a[37]; + r[37] += (sp_digit)((t[4] >> 53) + (t[5] & 0x1fffffffffffffL)); + t[6] = tb * a[38]; + r[38] += (sp_digit)((t[5] >> 53) + (t[6] & 0x1fffffffffffffL)); r[39] += (sp_digit)(t[6] >> 53); #endif /* WOLFSSL_SP_SMALL */ } @@ -10026,8 +10043,8 @@ static int sp_4096_div_39(const sp_digit* a, const sp_digit* d, t2 = t1 + 78 + 1; sd = t2 + 39 + 1; - sp_4096_mul_d_39(sd, d, 1L << 19); - sp_4096_mul_d_78(t1, a, 1L << 19); + sp_4096_mul_d_39(sd, d, (sp_digit)1 << 19); + sp_4096_mul_d_78(t1, a, (sp_digit)1 << 19); dv = sd[38]; t1[39 + 39] += t1[39 + 39 - 1] >> 53; t1[39 + 39 - 1] &= 0x1fffffffffffffL; @@ -10101,8 +10118,8 @@ static int sp_4096_mod_39(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -10467,26 +10484,26 @@ static sp_digit sp_4096_cmp_78(const sp_digit* a, const sp_digit* b) int i; for (i=77; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[77] - b[77]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[76] - b[76]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[75] - b[75]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[74] - b[74]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[73] - b[73]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[72] - b[72]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[77] - b[77]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[76] - b[76]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[75] - b[75]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[74] - b[74]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[73] - b[73]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[72] - b[72]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 64; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -10576,11 +10593,16 @@ SP_NOINLINE static void sp_4096_mul_add_78(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 53) + (t[0] & 0x1fffffffffffffL)); } - t[1] = tb * a[73]; r[73] += (sp_digit)((t[0] >> 53) + (t[1] & 0x1fffffffffffffL)); - t[2] = tb * a[74]; r[74] += (sp_digit)((t[1] >> 53) + (t[2] & 0x1fffffffffffffL)); - t[3] = tb * a[75]; r[75] += (sp_digit)((t[2] >> 53) + (t[3] & 0x1fffffffffffffL)); - t[4] = tb * a[76]; r[76] += (sp_digit)((t[3] >> 53) + (t[4] & 0x1fffffffffffffL)); - t[5] = tb * a[77]; r[77] += (sp_digit)((t[4] >> 53) + (t[5] & 0x1fffffffffffffL)); + t[1] = tb * a[73]; + r[73] += (sp_digit)((t[0] >> 53) + (t[1] & 0x1fffffffffffffL)); + t[2] = tb * a[74]; + r[74] += (sp_digit)((t[1] >> 53) + (t[2] & 0x1fffffffffffffL)); + t[3] = tb * a[75]; + r[75] += (sp_digit)((t[2] >> 53) + (t[3] & 0x1fffffffffffffL)); + t[4] = tb * a[76]; + r[76] += (sp_digit)((t[3] >> 53) + (t[4] & 0x1fffffffffffffL)); + t[5] = tb * a[77]; + r[77] += (sp_digit)((t[4] >> 53) + (t[5] & 0x1fffffffffffffL)); r[78] += (sp_digit)(t[5] >> 53); #endif /* WOLFSSL_SP_SMALL */ } @@ -10972,8 +10994,8 @@ static int sp_4096_div_78(const sp_digit* a, const sp_digit* d, t2 = t1 + 156 + 1; sd = t2 + 78 + 1; - sp_4096_mul_d_78(sd, d, 1L << 38); - sp_4096_mul_d_156(t1, a, 1L << 38); + sp_4096_mul_d_78(sd, d, (sp_digit)1 << 38); + sp_4096_mul_d_156(t1, a, (sp_digit)1 << 38); dv = sd[77]; t1[78 + 78] += t1[78 + 78 - 1] >> 53; t1[78 + 78 - 1] &= 0x1fffffffffffffL; @@ -11049,8 +11071,8 @@ static int sp_4096_mod_78(sp_digit* r, const sp_digit* a, const sp_digit* m) * m A single precision number that is the modulus. * returns 0 on success and MEMORY_E on dynamic memory allocation failure. */ -static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, - const sp_digit* m, int reduceA) +static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, + int bits, const sp_digit* m, int reduceA) { #ifdef WOLFSSL_SP_SMALL #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) @@ -12678,19 +12700,19 @@ static const sp_point_256 p256_base = { { 0x13945d898c296L,0x812deb33a0f4aL,0x3a440f277037dL,0x4247f8bce6e56L, 0x06b17d1f2e12cL, - 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0x6406837bf51f5L,0x576b315ececbbL,0xc0f9e162bce33L,0x7f9b8ee7eb4a7L, 0x04fe342e2fe1aL, - 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x0000000000001L,0x0000000000000L,0x0000000000000L,0x0000000000000L, 0x0000000000000L, - 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -12983,7 +13005,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -13149,14 +13171,14 @@ static sp_digit sp_256_cmp_5(const sp_digit* a, const sp_digit* b) int i; for (i=4; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else - r |= (a[ 4] - b[ 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 3] - b[ 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 2] - b[ 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 1] - b[ 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 0] - b[ 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[ 4] - b[ 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 3] - b[ 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 2] - b[ 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 1] - b[ 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 0] - b[ 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); #endif /* WOLFSSL_SP_SMALL */ return r; @@ -13821,8 +13843,8 @@ static void sp_256_proj_point_dbl_5(sp_point_256* r, const sp_point_256* p, sp_d */ static int sp_256_cmp_equal_5(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4])) == 0; } /* Add two Montgomery form projective points. @@ -17818,7 +17840,8 @@ static int sp_256_calc_s_5(sp_digit* s, const sp_digit* r, sp_digit* k, sp_256_cond_sub_5(s, s, p256_order, 0 - carry); sp_256_norm_5(s); c = sp_256_cmp_5(s, p256_order); - sp_256_cond_sub_5(s, s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_5(s, s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_5(s); /* s = s * k^-1 mod order */ @@ -17911,7 +17934,8 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 5U); sp_256_norm_5(ctx->r); c = sp_256_cmp_5(ctx->r, p256_order); - sp_256_cond_sub_5(ctx->r, ctx->r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_5(ctx->r, ctx->r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_5(ctx->r); sp_256_from_mp(ctx->x, 5, priv); @@ -17957,10 +17981,12 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int64_t c; sp_256_norm_5(ctx->x); carry = sp_256_add_5(ctx->s, ctx->e, ctx->x); - sp_256_cond_sub_5(ctx->s, ctx->s, p256_order, 0 - carry); + sp_256_cond_sub_5(ctx->s, ctx->s, + p256_order, 0 - carry); sp_256_norm_5(ctx->s); c = sp_256_cmp_5(ctx->s, p256_order); - sp_256_cond_sub_5(ctx->s, ctx->s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_5(ctx->s, ctx->s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_5(ctx->s); /* s = s * k^-1 mod order */ @@ -18073,7 +18099,8 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 5U); sp_256_norm_5(r); c = sp_256_cmp_5(r, p256_order); - sp_256_cond_sub_5(r, r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_5(r, r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_5(r); sp_256_from_mp(x, 5, priv); @@ -19241,19 +19268,22 @@ static const sp_point_384 p384_base = { { 0x545e3872760ab7L,0x64bb7eaa52d874L,0x020950a8e1540bL,0x5d3cdcc2cfba0fL, 0x0ad746e1d3b628L,0x26f1d638e3de64L,0x2aa1f288afa2c1L, - 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0x431d7c90ea0e5fL,0x639c3afd033af4L,0x4ed7c2e3002982L,0x44d0a3e74ed188L, 0x2dc29f8f41dbd2L,0x0debb3d317f252L,0x0d85f792a5898bL, - 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x00000000000001L,0x00000000000000L,0x00000000000000L,0x00000000000000L, 0x00000000000000L,0x00000000000000L,0x00000000000000L, - 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -19595,7 +19625,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -19761,16 +19791,16 @@ static sp_digit sp_384_cmp_7(const sp_digit* a, const sp_digit* b) int i; for (i=6; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else - r |= (a[ 6] - b[ 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 5] - b[ 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 4] - b[ 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 3] - b[ 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 2] - b[ 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 1] - b[ 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[ 0] - b[ 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[ 6] - b[ 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 5] - b[ 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 4] - b[ 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 3] - b[ 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 2] - b[ 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 1] - b[ 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[ 0] - b[ 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); #endif /* WOLFSSL_SP_SMALL */ return r; @@ -20453,8 +20483,9 @@ static void sp_384_proj_point_dbl_7(sp_point_384* r, const sp_point_384* p, sp_d */ static int sp_384_cmp_equal_7(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6])) == 0; } /* Add two Montgomery form projective points. @@ -25007,7 +25038,8 @@ static int sp_384_calc_s_7(sp_digit* s, const sp_digit* r, sp_digit* k, sp_384_cond_sub_7(s, s, p384_order, 0 - carry); sp_384_norm_7(s); c = sp_384_cmp_7(s, p384_order); - sp_384_cond_sub_7(s, s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_7(s, s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_7(s); /* s = s * k^-1 mod order */ @@ -25100,7 +25132,8 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 7U); sp_384_norm_7(ctx->r); c = sp_384_cmp_7(ctx->r, p384_order); - sp_384_cond_sub_7(ctx->r, ctx->r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_7(ctx->r, ctx->r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_7(ctx->r); sp_384_from_mp(ctx->x, 7, priv); @@ -25146,10 +25179,12 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int64_t c; sp_384_norm_7(ctx->x); carry = sp_384_add_7(ctx->s, ctx->e, ctx->x); - sp_384_cond_sub_7(ctx->s, ctx->s, p384_order, 0 - carry); + sp_384_cond_sub_7(ctx->s, ctx->s, + p384_order, 0 - carry); sp_384_norm_7(ctx->s); c = sp_384_cmp_7(ctx->s, p384_order); - sp_384_cond_sub_7(ctx->s, ctx->s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_7(ctx->s, ctx->s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_7(ctx->s); /* s = s * k^-1 mod order */ @@ -25262,7 +25297,8 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 7U); sp_384_norm_7(r); c = sp_384_cmp_7(r, p384_order); - sp_384_cond_sub_7(r, r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_7(r, r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_7(r); sp_384_from_mp(x, 7, priv); @@ -26839,7 +26875,10 @@ static const sp_point_1024 p1024_base = { 0x0c5ecf3a0367448L,0x17c8b36e77e955cL,0x172061613c2087aL, 0x00f6ce2308ab10dL,0x1b7fbe5fdaf6db6L,0x1b1a71a62cbc812L, 0x16a5456345fac15L,0x1ad0a7990053ed9L,0x029fe04f7199614L, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { @@ -26849,7 +26888,10 @@ static const sp_point_1024 p1024_base = { 0x0b67f8654f0195cL,0x06333e68502cb90L,0x0bcbe1bcabecd6bL, 0x14654ec2b9e7f7fL,0x0f0a08bc7af534fL,0x0641a58f5de3608L, 0x1426ba7d0402c05L,0x1f1f9f1f0533634L,0x0054124831fb004L, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { @@ -26859,7 +26901,10 @@ static const sp_point_1024 p1024_base = { 0x000000000000000L,0x000000000000000L,0x000000000000000L, 0x000000000000000L,0x000000000000000L,0x000000000000000L, 0x000000000000000L,0x000000000000000L,0x000000000000000L, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -27334,7 +27379,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -27498,22 +27543,22 @@ static sp_digit sp_1024_cmp_18(const sp_digit* a, const sp_digit* b) int i; for (i=17; i>=0; i--) { - r |= (a[i] - b[i]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i] - b[i]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #else int i; - r |= (a[17] - b[17]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[16] - b[16]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[17] - b[17]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[16] - b[16]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); for (i = 8; i >= 0; i -= 8) { - r |= (a[i + 7] - b[i + 7]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 6] - b[i + 6]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 5] - b[i + 5]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 4] - b[i + 4]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 3] - b[i + 3]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 2] - b[i + 2]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 1] - b[i + 1]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); - r |= (a[i + 0] - b[i + 0]) & (0 - ((r == 0) ? (sp_digit)1 : (sp_digit)0)); + r |= (a[i + 7] - b[i + 7]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 6] - b[i + 6]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 5] - b[i + 5]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 4] - b[i + 4]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 3] - b[i + 3]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 2] - b[i + 2]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 1] - b[i + 1]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); + r |= (a[i + 0] - b[i + 0]) & (0 - (sp_digit)((r == 0) ? 1 : 0)); } #endif /* WOLFSSL_SP_SMALL */ @@ -27599,7 +27644,8 @@ SP_NOINLINE static void sp_1024_mul_add_18(sp_digit* r, const sp_digit* a, t[0] = tb * a[i+8]; r[i+8] += (sp_digit)((t[7] >> 57) + (t[0] & 0x1ffffffffffffffL)); } - t[1] = tb * a[17]; r[17] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL)); + t[1] = tb * a[17]; + r[17] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL)); r[18] += (sp_digit)(t[1] >> 57); #endif /* WOLFSSL_SP_SMALL */ } @@ -28150,11 +28196,12 @@ static void sp_1024_proj_point_dbl_18(sp_point_1024* r, const sp_point_1024* p, */ static int sp_1024_cmp_equal_18(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | - (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | (a[15] ^ b[15]) | - (a[16] ^ b[16]) | (a[17] ^ b[17])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | + (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | + (a[15] ^ b[15]) | (a[16] ^ b[16]) | (a[17] ^ b[17])) == 0; } /* Add two Montgomery form projective points. @@ -29747,8 +29794,10 @@ static int sp_1024_ecc_mulmod_base_18(sp_point_1024* r, const sp_digit* k, */ static const sp_table_entry_1024 p1024_table[256] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* 1 */ { { 0x19c7ec6e0162bc2L,0x0637188544944dfL,0x17c27926760777bL, 0x10da6b0430bab33L,0x10c5f8db9a96ea2L,0x1ae83300d763e9bL, @@ -33449,7 +33498,8 @@ static void sp_1024_proj_sqr_18(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -33468,7 +33518,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 18 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -33477,7 +33528,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 18 * 2; ty = td + 5 * 18 * 2; @@ -33520,7 +33572,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -35088,7 +35141,8 @@ static const sp_digit sp_1024_g_table[256][18] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -35106,7 +35160,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 18 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -35115,7 +35170,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 18 * 2; ty = td + 5 * 18 * 2; @@ -35158,7 +35214,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -35428,7 +35485,8 @@ static void sp_1024_accumulate_line_add_one_18(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -35457,7 +35515,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_18(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 18 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -35468,7 +35527,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 18 * 2; vy = td + 7 * 18 * 2; @@ -35524,7 +35584,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -35802,7 +35863,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -35838,7 +35900,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_18(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 18 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -35849,7 +35912,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 18 * 2; vy = td + 7 * 18 * 2; @@ -35947,7 +36011,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -36189,7 +36254,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -36228,7 +36294,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_18(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 18 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -36239,7 +36306,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; pre_p = (sp_point_1024*)(td + 6 * 18 * 2); #endif @@ -36311,7 +36379,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -36345,7 +36414,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -36387,7 +36457,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_18(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 18 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -36398,7 +36469,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 18 * 2; vy = td + 7 * 18 * 2; @@ -36502,7 +36574,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } diff --git a/wolfcrypt/src/sp_cortexm.c b/wolfcrypt/src/sp_cortexm.c index 7092b0784..733134d63 100644 --- a/wolfcrypt/src/sp_cortexm.c +++ b/wolfcrypt/src/sp_cortexm.c @@ -135,7 +135,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -5372,7 +5372,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -10465,7 +10465,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -13912,19 +13912,22 @@ static const sp_point_256 p256_base = { { 0xd898c296,0xf4a13945,0x2deb33a0,0x77037d81,0x63a440f2,0xf8bce6e5, 0xe12c4247,0x6b17d1f2, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0x37bf51f5,0xcbb64068,0x6b315ece,0x2bce3357,0x7c0f9e16,0x8ee7eb4a, 0xfe1a7f9b,0x4fe342e2, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -15254,7 +15257,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -17608,8 +17611,9 @@ static void sp_256_proj_point_dbl_8(sp_point_256* r, const sp_point_256* p, sp_d */ static int sp_256_cmp_equal_8(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7])) == 0; } /* Add two Montgomery form projective points. @@ -21667,7 +21671,8 @@ static int sp_256_calc_s_8(sp_digit* s, const sp_digit* r, sp_digit* k, sp_256_cond_sub_8(s, s, p256_order, 0 - carry); sp_256_norm_8(s); c = sp_256_cmp_8(s, p256_order); - sp_256_cond_sub_8(s, s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(s, s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(s); /* s = s * k^-1 mod order */ @@ -21760,7 +21765,8 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 8U); sp_256_norm_8(ctx->r); c = sp_256_cmp_8(ctx->r, p256_order); - sp_256_cond_sub_8(ctx->r, ctx->r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(ctx->r, ctx->r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(ctx->r); sp_256_from_mp(ctx->x, 8, priv); @@ -21806,10 +21812,12 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int32_t c; sp_256_norm_8(ctx->x); carry = sp_256_add_8(ctx->s, ctx->e, ctx->x); - sp_256_cond_sub_8(ctx->s, ctx->s, p256_order, 0 - carry); + sp_256_cond_sub_8(ctx->s, ctx->s, + p256_order, 0 - carry); sp_256_norm_8(ctx->s); c = sp_256_cmp_8(ctx->s, p256_order); - sp_256_cond_sub_8(ctx->s, ctx->s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(ctx->s, ctx->s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(ctx->s); /* s = s * k^-1 mod order */ @@ -21922,7 +21930,8 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 8U); sp_256_norm_8(r); c = sp_256_cmp_8(r, p256_order); - sp_256_cond_sub_8(r, r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_8(r, r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_8(r); sp_256_from_mp(x, 8, priv); @@ -23221,19 +23230,25 @@ static const sp_point_384 p384_base = { { 0x72760ab7,0x3a545e38,0xbf55296c,0x5502f25d,0x82542a38,0x59f741e0, 0x8ba79b98,0x6e1d3b62,0xf320ad74,0x8eb1c71e,0xbe8b0537,0xaa87ca22, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0x90ea0e5f,0x7a431d7c,0x1d7e819d,0x0a60b1ce,0xb5f0b8c0,0xe9da3113, 0x289a147c,0xf8f41dbd,0x9292dc29,0x5d9e98bf,0x96262c6f,0x3617de4a, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -23805,7 +23820,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -24716,9 +24731,10 @@ static void sp_384_proj_point_dbl_12(sp_point_384* r, const sp_point_384* p, sp_ */ static int sp_384_cmp_equal_12(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11])) == 0; } /* Add two Montgomery form projective points. @@ -28830,7 +28846,8 @@ static int sp_384_calc_s_12(sp_digit* s, const sp_digit* r, sp_digit* k, sp_384_cond_sub_12(s, s, p384_order, 0 - carry); sp_384_norm_12(s); c = sp_384_cmp_12(s, p384_order); - sp_384_cond_sub_12(s, s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(s, s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(s); /* s = s * k^-1 mod order */ @@ -28923,7 +28940,8 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 12U); sp_384_norm_12(ctx->r); c = sp_384_cmp_12(ctx->r, p384_order); - sp_384_cond_sub_12(ctx->r, ctx->r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(ctx->r, ctx->r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(ctx->r); sp_384_from_mp(ctx->x, 12, priv); @@ -28969,10 +28987,12 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int32_t c; sp_384_norm_12(ctx->x); carry = sp_384_add_12(ctx->s, ctx->e, ctx->x); - sp_384_cond_sub_12(ctx->s, ctx->s, p384_order, 0 - carry); + sp_384_cond_sub_12(ctx->s, ctx->s, + p384_order, 0 - carry); sp_384_norm_12(ctx->s); c = sp_384_cmp_12(ctx->s, p384_order); - sp_384_cond_sub_12(ctx->s, ctx->s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(ctx->s, ctx->s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(ctx->s); /* s = s * k^-1 mod order */ @@ -29085,7 +29105,8 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 12U); sp_384_norm_12(r); c = sp_384_cmp_12(r, p384_order); - sp_384_cond_sub_12(r, r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_12(r, r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_12(r); sp_384_from_mp(x, 12, priv); @@ -31241,7 +31262,13 @@ static const sp_point_1024 p1024_base = { 0xdb9dfa55,0x43d5f22c,0x30b09e10,0xab10db90,0xf6ce2308,0xb5edb6c0, 0xb6ff7cbf,0x98b2f204,0x0aec69c6,0x2b1a2fd6,0x3ed9b52a,0x0a799005, 0x332c29ad,0x53fc09ee, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { @@ -31251,7 +31278,13 @@ static const sp_point_1024 p1024_base = { 0x9a140b2e,0x6b598ccf,0xf0de55f6,0xe7f7f5e5,0x654ec2b9,0xf5ea69f4, 0x1e141178,0x3d778d82,0x02990696,0xd3e82016,0x3634a135,0xf9f1f053, 0x3f6009f1,0x0a824906, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { @@ -31261,7 +31294,13 @@ static const sp_point_1024 p1024_base = { 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -31732,7 +31771,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -33507,14 +33546,17 @@ SP_NOINLINE static sp_digit sp_1024_sub_32(sp_digit* r, const sp_digit* a, */ static int sp_1024_cmp_equal_32(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | - (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | (a[15] ^ b[15]) | - (a[16] ^ b[16]) | (a[17] ^ b[17]) | (a[18] ^ b[18]) | (a[19] ^ b[19]) | - (a[20] ^ b[20]) | (a[21] ^ b[21]) | (a[22] ^ b[22]) | (a[23] ^ b[23]) | - (a[24] ^ b[24]) | (a[25] ^ b[25]) | (a[26] ^ b[26]) | (a[27] ^ b[27]) | - (a[28] ^ b[28]) | (a[29] ^ b[29]) | (a[30] ^ b[30]) | (a[31] ^ b[31])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | + (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | + (a[15] ^ b[15]) | (a[16] ^ b[16]) | (a[17] ^ b[17]) | + (a[18] ^ b[18]) | (a[19] ^ b[19]) | (a[20] ^ b[20]) | + (a[21] ^ b[21]) | (a[22] ^ b[22]) | (a[23] ^ b[23]) | + (a[24] ^ b[24]) | (a[25] ^ b[25]) | (a[26] ^ b[26]) | + (a[27] ^ b[27]) | (a[28] ^ b[28]) | (a[29] ^ b[29]) | + (a[30] ^ b[30]) | (a[31] ^ b[31])) == 0; } /* Add two Montgomery form projective points. @@ -34901,8 +34943,12 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, */ static const sp_table_entry_1024 p1024_table[16] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* 1 */ { { 0xe0162bc2,0xbf9c7ec6,0x10a89289,0xddecc6e3,0x9e499d81,0x5d599df0, 0x6d358218,0x9a96ea28,0x70c5f8db,0x01aec7d3,0x8cf5d066,0xe72e4995, @@ -35129,8 +35175,12 @@ static int sp_1024_ecc_mulmod_base_32(sp_point_1024* r, const sp_digit* k, */ static const sp_table_entry_1024 p1024_table[256] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* 1 */ { { 0xe0162bc2,0xbf9c7ec6,0x10a89289,0xddecc6e3,0x9e499d81,0x5d599df0, 0x6d358218,0x9a96ea28,0x70c5f8db,0x01aec7d3,0x8cf5d066,0xe72e4995, @@ -38831,7 +38881,8 @@ static void sp_1024_proj_sqr_32(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -38850,7 +38901,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -38859,7 +38911,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 32 * 2; ty = td + 5 * 32 * 2; @@ -38902,7 +38955,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -40726,7 +40780,8 @@ static const sp_digit sp_1024_g_table[256][32] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -40744,7 +40799,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -40753,7 +40809,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 32 * 2; ty = td + 5 * 32 * 2; @@ -40796,7 +40853,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -41066,7 +41124,8 @@ static void sp_1024_accumulate_line_add_one_32(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -41095,7 +41154,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -41106,7 +41166,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 32 * 2; vy = td + 7 * 32 * 2; @@ -41162,7 +41223,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -41440,7 +41502,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -41476,7 +41539,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -41487,7 +41551,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 32 * 2; vy = td + 7 * 32 * 2; @@ -41585,7 +41650,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -41827,7 +41893,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -41866,7 +41933,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_32(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -41877,7 +41945,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; pre_p = (sp_point_1024*)(td + 6 * 32 * 2); #endif @@ -41949,7 +42018,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -41983,7 +42053,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -42025,7 +42096,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -42036,7 +42108,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 32 * 2; vy = td + 7 * 32 * 2; @@ -42140,7 +42213,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } diff --git a/wolfcrypt/src/sp_x86_64.c b/wolfcrypt/src/sp_x86_64.c index 9055afbdc..19436d0f6 100644 --- a/wolfcrypt/src/sp_x86_64.c +++ b/wolfcrypt/src/sp_x86_64.c @@ -115,7 +115,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -2456,7 +2456,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -4807,7 +4807,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -6495,19 +6495,19 @@ static const sp_point_256 p256_base = { { 0xf4a13945d898c296L,0x77037d812deb33a0L,0xf8bce6e563a440f2L, 0x6b17d1f2e12c4247L, - 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Y ordinate */ { 0xcbb6406837bf51f5L,0x2bce33576b315eceL,0x8ee7eb4a7c0f9e16L, 0x4fe342e2fe1a7f9bL, - 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* Z ordinate */ { 0x0000000000000001L,0x0000000000000000L,0x0000000000000000L, 0x0000000000000000L, - 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0 }, /* infinity */ 0 @@ -6633,7 +6633,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -7234,7 +7234,8 @@ static void sp_256_proj_point_dbl_n_4(sp_point_256* p, int n, */ static int sp_256_cmp_equal_4(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3])) == 0; } /* Add two Montgomery form projective points. @@ -23604,7 +23605,8 @@ static int sp_256_calc_s_4(sp_digit* s, const sp_digit* r, sp_digit* k, sp_256_cond_sub_4(s, s, p256_order, 0 - carry); sp_256_norm_4(s); c = sp_256_cmp_4(s, p256_order); - sp_256_cond_sub_4(s, s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_4(s, s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_4(s); /* s = s * k^-1 mod order */ @@ -23702,7 +23704,8 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 4U); sp_256_norm_4(ctx->r); c = sp_256_cmp_4(ctx->r, p256_order); - sp_256_cond_sub_4(ctx->r, ctx->r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_4(ctx->r, ctx->r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_4(ctx->r); sp_256_from_mp(ctx->x, 4, priv); @@ -23748,10 +23751,12 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int64_t c; sp_256_norm_4(ctx->x); carry = sp_256_add_4(ctx->s, ctx->e, ctx->x); - sp_256_cond_sub_4(ctx->s, ctx->s, p256_order, 0 - carry); + sp_256_cond_sub_4(ctx->s, ctx->s, + p256_order, 0 - carry); sp_256_norm_4(ctx->s); c = sp_256_cmp_4(ctx->s, p256_order); - sp_256_cond_sub_4(ctx->s, ctx->s, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_4(ctx->s, ctx->s, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_4(ctx->s); /* s = s * k^-1 mod order */ @@ -23872,7 +23877,8 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 4U); sp_256_norm_4(r); c = sp_256_cmp_4(r, p256_order); - sp_256_cond_sub_4(r, r, p256_order, 0L - (sp_digit)(c >= 0)); + sp_256_cond_sub_4(r, r, p256_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_256_norm_4(r); sp_256_from_mp(x, 4, priv); @@ -25026,19 +25032,22 @@ static const sp_point_384 p384_base = { { 0x3a545e3872760ab7L,0x5502f25dbf55296cL,0x59f741e082542a38L, 0x6e1d3b628ba79b98L,0x8eb1c71ef320ad74L,0xaa87ca22be8b0537L, - 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* Y ordinate */ { 0x7a431d7c90ea0e5fL,0x0a60b1ce1d7e819dL,0xe9da3113b5f0b8c0L, 0xf8f41dbd289a147cL,0x5d9e98bf9292dc29L,0x3617de4a96262c6fL, - 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* Z ordinate */ { 0x0000000000000001L,0x0000000000000000L,0x0000000000000000L, 0x0000000000000000L,0x0000000000000000L,0x0000000000000000L, - 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* infinity */ 0 @@ -25208,7 +25217,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -25912,8 +25921,8 @@ static void sp_384_proj_point_dbl_n_6(sp_point_384* p, int n, */ static int sp_384_cmp_equal_6(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5])) == 0; } /* Add two Montgomery form projective points. @@ -48093,7 +48102,8 @@ static int sp_384_calc_s_6(sp_digit* s, const sp_digit* r, sp_digit* k, sp_384_cond_sub_6(s, s, p384_order, 0 - carry); sp_384_norm_6(s); c = sp_384_cmp_6(s, p384_order); - sp_384_cond_sub_6(s, s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_6(s, s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_6(s); /* s = s * k^-1 mod order */ @@ -48191,7 +48201,8 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 6U); sp_384_norm_6(ctx->r); c = sp_384_cmp_6(ctx->r, p384_order); - sp_384_cond_sub_6(ctx->r, ctx->r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_6(ctx->r, ctx->r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_6(ctx->r); sp_384_from_mp(ctx->x, 6, priv); @@ -48237,10 +48248,12 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W int64_t c; sp_384_norm_6(ctx->x); carry = sp_384_add_6(ctx->s, ctx->e, ctx->x); - sp_384_cond_sub_6(ctx->s, ctx->s, p384_order, 0 - carry); + sp_384_cond_sub_6(ctx->s, ctx->s, + p384_order, 0 - carry); sp_384_norm_6(ctx->s); c = sp_384_cmp_6(ctx->s, p384_order); - sp_384_cond_sub_6(ctx->s, ctx->s, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_6(ctx->s, ctx->s, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_6(ctx->s); /* s = s * k^-1 mod order */ @@ -48361,7 +48374,8 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, XMEMCPY(r, point->x, sizeof(sp_digit) * 6U); sp_384_norm_6(r); c = sp_384_cmp_6(r, p384_order); - sp_384_cond_sub_6(r, r, p384_order, 0L - (sp_digit)(c >= 0)); + sp_384_cond_sub_6(r, r, p384_order, + (sp_digit)0 - (sp_digit)(c >= 0)); sp_384_norm_6(r); sp_384_from_mp(x, 6, priv); @@ -49649,7 +49663,10 @@ static const sp_point_1024 p1024_base = { 0x43d5f22cdb9dfa55L,0xab10db9030b09e10L,0xb5edb6c0f6ce2308L, 0x98b2f204b6ff7cbfL,0x2b1a2fd60aec69c6L,0x0a7990053ed9b52aL, 0x53fc09ee332c29adL, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* Y ordinate */ { @@ -49659,7 +49676,10 @@ static const sp_point_1024 p1024_base = { 0x6b598ccf9a140b2eL,0xe7f7f5e5f0de55f6L,0xf5ea69f4654ec2b9L, 0x3d778d821e141178L,0xd3e8201602990696L,0xf9f1f0533634a135L, 0x0a8249063f6009f1L, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* Z ordinate */ { @@ -49669,7 +49689,10 @@ static const sp_point_1024 p1024_base = { 0x0000000000000000L,0x0000000000000000L,0x0000000000000000L, 0x0000000000000000L,0x0000000000000000L,0x0000000000000000L, 0x0000000000000000L, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, + (sp_digit)0 }, /* infinity */ 0 @@ -49958,7 +49981,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a) r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/ } else { - r[++j] = 0L; + r[++j] = (sp_digit)0; } } s = (word32)DIGIT_BIT - s; @@ -50546,10 +50569,12 @@ extern sp_digit sp_1024_sub_16(sp_digit* r, const sp_digit* a, const sp_digit* b */ static int sp_1024_cmp_equal_16(const sp_digit* a, const sp_digit* b) { - return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) | - (a[4] ^ b[4]) | (a[5] ^ b[5]) | (a[6] ^ b[6]) | (a[7] ^ b[7]) | - (a[8] ^ b[8]) | (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | - (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | (a[15] ^ b[15])) == 0; + return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | + (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) | + (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) | + (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) | + (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) | + (a[15] ^ b[15])) == 0; } /* Add two Montgomery form projective points. @@ -53104,8 +53129,10 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, */ static const sp_table_entry_1024 p1024_table[256] = { /* 0 */ - { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 } }, /* 1 */ { { 0xbf9c7ec6e0162bc2L,0xddecc6e310a89289L,0x5d599df09e499d81L, 0x9a96ea286d358218L,0x01aec7d370c5f8dbL,0xe72e49958cf5d066L, @@ -56872,7 +56899,8 @@ static void sp_1024_proj_sqr_16(sp_digit* px, sp_digit* py, sp_digit* t) */ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -56891,7 +56919,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -56900,7 +56929,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 16 * 2; ty = td + 5 * 16 * 2; @@ -56943,7 +56973,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -58511,7 +58542,8 @@ static const sp_digit sp_1024_g_table[256][16] = { */ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -58529,7 +58561,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -58538,7 +58571,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 16 * 2; ty = td + 5 * 16 * 2; @@ -58581,7 +58615,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -58656,7 +58691,8 @@ static void sp_1024_proj_sqr_avx2_16(sp_digit* px, sp_digit* py, sp_digit* t) */ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -58675,7 +58711,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -58684,7 +58721,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 16 * 2; ty = td + 5 * 16 * 2; @@ -58727,7 +58765,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -58752,7 +58791,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* */ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -58770,7 +58810,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -58779,7 +58820,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; tx = td + 4 * 16 * 2; ty = td + 5 * 16 * 2; @@ -58822,7 +58864,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -59121,7 +59164,8 @@ static void sp_1024_accumulate_line_add_one_16(sp_digit* vx, sp_digit* vy, static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -59150,7 +59194,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -59161,7 +59206,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 16 * 2; vy = td + 7 * 16 * 2; @@ -59217,7 +59263,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -59495,7 +59542,8 @@ static const signed char sp_1024_order_op[] = { static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -59531,7 +59579,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -59542,7 +59591,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 16 * 2; vy = td + 7 * 16 * 2; @@ -59640,7 +59690,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -59914,7 +59965,8 @@ static void sp_1024_accumulate_line_add_one_avx2_16(sp_digit* vx, sp_digit* vy, static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -59943,7 +59995,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -59954,7 +60007,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 16 * 2; vy = td + 7 * 16 * 2; @@ -60010,7 +60064,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -60261,7 +60316,8 @@ static void sp_1024_accumulate_line_dbl_n_avx2_16(sp_digit* vx, sp_digit* vy, static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -60297,7 +60353,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -60308,7 +60365,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 16 * 2; vy = td + 7 * 16 * 2; @@ -60406,7 +60464,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -60682,7 +60741,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -60721,7 +60781,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_16(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -60732,7 +60793,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; pre_p = (sp_point_1024*)(td + 6 * 16 * 2); #endif @@ -60804,7 +60866,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -60838,7 +60901,8 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -60880,7 +60944,8 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -60891,7 +60956,8 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 16 * 2; vy = td + 7 * 16 * 2; @@ -60995,7 +61061,8 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -61211,7 +61278,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -61250,7 +61318,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_16(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -61261,7 +61330,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; pre_p = (sp_point_1024*)(td + 6 * 16 * 2); #endif @@ -61333,7 +61403,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -61367,7 +61438,8 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -61409,7 +61481,8 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -61420,7 +61493,8 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) t = td; vx = td + 6 * 16 * 2; vy = td + 7 * 16 * 2; @@ -61524,7 +61598,8 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ + !defined(WOLFSSL_SP_NO_MALLOC) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } From a748b5264ee9a3bcaeadacd9249efe43379b8e18 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 29 Jun 2021 09:13:32 -0700 Subject: [PATCH 2/2] Fix for `wolfcrypt/src/sp_int.c:2720:34: error: left shift count >= width of type` with mingw64. --- wolfcrypt/src/sp_int.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index 2b4ec7542..6cee7fb50 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -2717,7 +2717,7 @@ int sp_count_bits(const sp_int* a) r *= SP_WORD_SIZE; if (d > SP_HALF_MAX) { r += SP_WORD_SIZE; - while ((d & (1UL << (SP_WORD_SIZE - 1))) == 0) { + while ((d & ((sp_digit)1 << (SP_WORD_SIZE - 1))) == 0) { r--; d <<= 1; }