From 932513a41eae070da18193e5c54c2083bac30744 Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Thu, 6 Mar 2025 16:08:38 -0600 Subject: [PATCH] fixes for various -W*conversions in sp_int.c, asn.c, fe_operations.c, fe_448.c, ge_448.c. also, add support for NO_INT128, and add .github/workflows/wolfCrypt-Wconversion.yml. --- .github/workflows/wolfCrypt-Wconversion.yml | 41 ++ wolfcrypt/src/asn.c | 26 +- wolfcrypt/src/fe_448.c | 16 +- wolfcrypt/src/fe_operations.c | 2 +- wolfcrypt/src/ge_448.c | 437 ++++++++++++-------- wolfcrypt/src/sp_int.c | 29 +- wolfssl/wolfcrypt/fe_448.h | 3 +- wolfssl/wolfcrypt/sp_int.h | 2 +- 8 files changed, 342 insertions(+), 214 deletions(-) create mode 100644 .github/workflows/wolfCrypt-Wconversion.yml diff --git a/.github/workflows/wolfCrypt-Wconversion.yml b/.github/workflows/wolfCrypt-Wconversion.yml new file mode 100644 index 000000000..a6541320a --- /dev/null +++ b/.github/workflows/wolfCrypt-Wconversion.yml @@ -0,0 +1,41 @@ +name: wolfCrypt conversion warnings + +# START OF COMMON SECTION +on: + push: + branches: [ 'master', 'main', 'release/**' ] + pull_request: + branches: [ '*' ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +# END OF COMMON SECTION + +jobs: + make_check: + strategy: + matrix: + config: [ + # Add new configs here + '--disable-asm --enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion"', + '--enable-intelasm --enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion"', + '--enable-smallstack --disable-asm --enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion"', + '--enable-smallstack --enable-intelasm --enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion"', + '--enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion -DNO_INT128"', + '--enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion" --enable-32bit CFLAGS=-m32' + ] + name: build library + if: github.repository_owner == 'wolfssl' + runs-on: ubuntu-22.04 + # This should be a safe limit for the tests to run. + timeout-minutes: 6 + steps: + - uses: actions/checkout@v4 + name: Checkout wolfSSL + + - name: Build wolfCrypt with extra type conversion warnings + run: | + ./autogen.sh || $(exit 2) + ./configure ${{ matrix.config }} || $(exit 3) + make -j 4 || $(exit 4) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index ebb0a8369..224f8819a 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -25321,8 +25321,8 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz, char header[MAX_X509_HEADER_SZ + HEADER_ENCRYPTED_KEY_SIZE]; char footer[MAX_X509_HEADER_SZ]; #endif - int headerLen = MAX_X509_HEADER_SZ + HEADER_ENCRYPTED_KEY_SIZE; - int footerLen = MAX_X509_HEADER_SZ; + size_t headerLen = MAX_X509_HEADER_SZ + HEADER_ENCRYPTED_KEY_SIZE; + size_t footerLen = MAX_X509_HEADER_SZ; int i; int err; int outLen; /* return length or error */ @@ -25349,9 +25349,9 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz, #endif /* build header and footer based on type */ - XSTRNCPY(header, headerStr, (size_t)headerLen - 1); + XSTRNCPY(header, headerStr, headerLen - 1); header[headerLen - 2] = 0; - XSTRNCPY(footer, footerStr, (size_t)footerLen - 1); + XSTRNCPY(footer, footerStr, footerLen - 1); footer[footerLen - 2] = 0; /* add new line to end */ @@ -25359,7 +25359,7 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz, XSTRNCAT(footer, "\n", 2); #ifdef WOLFSSL_ENCRYPTED_KEYS - err = wc_EncryptedInfoAppend(header, headerLen, (char*)cipher_info); + err = wc_EncryptedInfoAppend(header, (int)headerLen, (char*)cipher_info); if (err != 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -25369,8 +25369,8 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz, } #endif - headerLen = (int)XSTRLEN(header); - footerLen = (int)XSTRLEN(footer); + headerLen = XSTRLEN(header); + footerLen = XSTRLEN(footer); /* if null output and 0 size passed in then return size needed */ if (!output && outSz == 0) { @@ -25384,7 +25384,7 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz, WOLFSSL_ERROR_VERBOSE(err); return err; } - return headerLen + footerLen + outLen; + return (int)headerLen + (int)footerLen + outLen; } if (!der || !output) { @@ -25406,14 +25406,14 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz, /* header */ XMEMCPY(output, header, (size_t)headerLen); - i = headerLen; + i = (int)headerLen; #ifdef WOLFSSL_SMALL_STACK XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif /* body */ - outLen = (int)outSz - (headerLen + footerLen); /* input to Base64_Encode */ + outLen = (int)outSz - (int)(headerLen + footerLen); /* input to Base64_Encode */ if ( (err = Base64_Encode(der, derSz, output + i, (word32*)&outLen)) < 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(footer, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -25424,7 +25424,7 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz, i += outLen; /* footer */ - if ( (i + footerLen) > (int)outSz) { + if ( (i + (int)footerLen) > (int)outSz) { #ifdef WOLFSSL_SMALL_STACK XFREE(footer, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -25436,7 +25436,7 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz, XFREE(footer, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif - return outLen + headerLen + footerLen; + return outLen + (int)headerLen + (int)footerLen; } #endif /* WOLFSSL_DER_TO_PEM */ @@ -25757,7 +25757,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type, } #ifdef WOLFSSL_SMALL_STACK - password = (char*)XMALLOC(passwordSz, heap, DYNAMIC_TYPE_STRING); + password = (char*)XMALLOC((size_t)passwordSz, heap, DYNAMIC_TYPE_STRING); if (password == NULL) { return MEMORY_E; } diff --git a/wolfcrypt/src/fe_448.c b/wolfcrypt/src/fe_448.c index 17db5fd71..d375735e2 100644 --- a/wolfcrypt/src/fe_448.c +++ b/wolfcrypt/src/fe_448.c @@ -1437,56 +1437,56 @@ void fe448_to_bytes(unsigned char* b, const sword32* a) b[ 0] = (byte)(in0 >> 0); b[ 1] = (byte)(in0 >> 8); b[ 2] = (byte)(in0 >> 16); - b[ 3] = (byte)(in0 >> 24) + (byte)((in1 >> 0) << 4); + b[ 3] = (byte)((byte)(in0 >> 24) + (byte)((in1 >> 0) << 4)); b[ 4] = (byte)(in1 >> 4); b[ 5] = (byte)(in1 >> 12); b[ 6] = (byte)(in1 >> 20); b[ 7] = (byte)(in2 >> 0); b[ 8] = (byte)(in2 >> 8); b[ 9] = (byte)(in2 >> 16); - b[10] = (byte)(in2 >> 24) + (byte)((in3 >> 0) << 4); + b[10] = (byte)((byte)(in2 >> 24) + (byte)((in3 >> 0) << 4)); b[11] = (byte)(in3 >> 4); b[12] = (byte)(in3 >> 12); b[13] = (byte)(in3 >> 20); b[14] = (byte)(in4 >> 0); b[15] = (byte)(in4 >> 8); b[16] = (byte)(in4 >> 16); - b[17] = (byte)(in4 >> 24) + (byte)((in5 >> 0) << 4); + b[17] = (byte)((byte)(in4 >> 24) + (byte)((in5 >> 0) << 4)); b[18] = (byte)(in5 >> 4); b[19] = (byte)(in5 >> 12); b[20] = (byte)(in5 >> 20); b[21] = (byte)(in6 >> 0); b[22] = (byte)(in6 >> 8); b[23] = (byte)(in6 >> 16); - b[24] = (byte)(in6 >> 24) + (byte)((in7 >> 0) << 4); + b[24] = (byte)((byte)(in6 >> 24) + (byte)((in7 >> 0) << 4)); b[25] = (byte)(in7 >> 4); b[26] = (byte)(in7 >> 12); b[27] = (byte)(in7 >> 20); b[28] = (byte)(in8 >> 0); b[29] = (byte)(in8 >> 8); b[30] = (byte)(in8 >> 16); - b[31] = (byte)(in8 >> 24) + (byte)((in9 >> 0) << 4); + b[31] = (byte)((byte)(in8 >> 24) + (byte)((in9 >> 0) << 4)); b[32] = (byte)(in9 >> 4); b[33] = (byte)(in9 >> 12); b[34] = (byte)(in9 >> 20); b[35] = (byte)(in10 >> 0); b[36] = (byte)(in10 >> 8); b[37] = (byte)(in10 >> 16); - b[38] = (byte)(in10 >> 24) + (byte)((in11 >> 0) << 4); + b[38] = (byte)((byte)(in10 >> 24) + (byte)((in11 >> 0) << 4)); b[39] = (byte)(in11 >> 4); b[40] = (byte)(in11 >> 12); b[41] = (byte)(in11 >> 20); b[42] = (byte)(in12 >> 0); b[43] = (byte)(in12 >> 8); b[44] = (byte)(in12 >> 16); - b[45] = (byte)(in12 >> 24) + (byte)((in13 >> 0) << 4); + b[45] = (byte)((byte)(in12 >> 24) + (byte)((in13 >> 0) << 4)); b[46] = (byte)(in13 >> 4); b[47] = (byte)(in13 >> 12); b[48] = (byte)(in13 >> 20); b[49] = (byte)(in14 >> 0); b[50] = (byte)(in14 >> 8); b[51] = (byte)(in14 >> 16); - b[52] = (byte)(in14 >> 24) + (byte)((in15 >> 0) << 4); + b[52] = (byte)((byte)(in14 >> 24) + (byte)((in15 >> 0) << 4)); b[53] = (byte)(in15 >> 4); b[54] = (byte)(in15 >> 12); b[55] = (byte)(in15 >> 20); diff --git a/wolfcrypt/src/fe_operations.c b/wolfcrypt/src/fe_operations.c index 384095162..e129618a7 100644 --- a/wolfcrypt/src/fe_operations.c +++ b/wolfcrypt/src/fe_operations.c @@ -150,7 +150,7 @@ int curve25519(byte* q, const byte* n, const byte* p) swap = 0; for (pos = 254;pos >= 0;--pos) { unsigned int b; - b = n[pos / 8] >> (pos & 7); + b = (unsigned int)(n[pos / 8]) >> (pos & 7); b &= 1; swap ^= b; fe_cswap(x2,x3,(int)swap); diff --git a/wolfcrypt/src/ge_448.c b/wolfcrypt/src/ge_448.c index e234ae234..e36f1e1ee 100644 --- a/wolfcrypt/src/ge_448.c +++ b/wolfcrypt/src/ge_448.c @@ -5143,136 +5143,169 @@ void sc448_reduce(byte* b) word32 o; /* Load from bytes */ - t[ 0] = (((sword32)((b[ 0] ) >> 0)) << 0) + t[ 0] = (word64)( + (((sword32)((b[ 0] ) >> 0)) << 0) | (((sword32)((b[ 1] ) >> 0)) << 8) | (((sword32)((b[ 2] ) >> 0)) << 16) - | ((((sword32)((b[ 3] & 0xf )) >> 0)) << 24); - t[ 1] = (((sword32)((b[ 3] ) >> 4)) << 0) + | ((((sword32)((b[ 3] & 0xf )) >> 0)) << 24)); + t[ 1] = (word64)( + (((sword32)((b[ 3] ) >> 4)) << 0) | (((sword32)((b[ 4] ) >> 0)) << 4) | (((sword32)((b[ 5] ) >> 0)) << 12) - | (((sword32)((b[ 6] ) >> 0)) << 20); - t[ 2] = (((sword32)((b[ 7] ) >> 0)) << 0) + | (((sword32)((b[ 6] ) >> 0)) << 20)); + t[ 2] = (word64)( + (((sword32)((b[ 7] ) >> 0)) << 0) | (((sword32)((b[ 8] ) >> 0)) << 8) | (((sword32)((b[ 9] ) >> 0)) << 16) - | ((((sword32)((b[10] & 0xf )) >> 0)) << 24); - t[ 3] = (((sword32)((b[10] ) >> 4)) << 0) + | ((((sword32)((b[10] & 0xf )) >> 0)) << 24)); + t[ 3] = (word64)( + (((sword32)((b[10] ) >> 4)) << 0) | (((sword32)((b[11] ) >> 0)) << 4) | (((sword32)((b[12] ) >> 0)) << 12) - | (((sword32)((b[13] ) >> 0)) << 20); - t[ 4] = (((sword32)((b[14] ) >> 0)) << 0) + | (((sword32)((b[13] ) >> 0)) << 20)); + t[ 4] = (word64)( + (((sword32)((b[14] ) >> 0)) << 0) | (((sword32)((b[15] ) >> 0)) << 8) | (((sword32)((b[16] ) >> 0)) << 16) - | ((((sword32)((b[17] & 0xf )) >> 0)) << 24); - t[ 5] = (((sword32)((b[17] ) >> 4)) << 0) + | ((((sword32)((b[17] & 0xf )) >> 0)) << 24)); + t[ 5] = (word64)( + (((sword32)((b[17] ) >> 4)) << 0) | (((sword32)((b[18] ) >> 0)) << 4) | (((sword32)((b[19] ) >> 0)) << 12) - | (((sword32)((b[20] ) >> 0)) << 20); - t[ 6] = (((sword32)((b[21] ) >> 0)) << 0) + | (((sword32)((b[20] ) >> 0)) << 20)); + t[ 6] = (word64)( + (((sword32)((b[21] ) >> 0)) << 0) | (((sword32)((b[22] ) >> 0)) << 8) | (((sword32)((b[23] ) >> 0)) << 16) - | ((((sword32)((b[24] & 0xf )) >> 0)) << 24); - t[ 7] = (((sword32)((b[24] ) >> 4)) << 0) + | ((((sword32)((b[24] & 0xf )) >> 0)) << 24)); + t[ 7] = (word64)( + (((sword32)((b[24] ) >> 4)) << 0) | (((sword32)((b[25] ) >> 0)) << 4) | (((sword32)((b[26] ) >> 0)) << 12) - | (((sword32)((b[27] ) >> 0)) << 20); - t[ 8] = (((sword32)((b[28] ) >> 0)) << 0) + | (((sword32)((b[27] ) >> 0)) << 20)); + t[ 8] = (word64)( + (((sword32)((b[28] ) >> 0)) << 0) | (((sword32)((b[29] ) >> 0)) << 8) | (((sword32)((b[30] ) >> 0)) << 16) - | ((((sword32)((b[31] & 0xf )) >> 0)) << 24); - t[ 9] = (((sword32)((b[31] ) >> 4)) << 0) + | ((((sword32)((b[31] & 0xf )) >> 0)) << 24)); + t[ 9] = (word64)( + (((sword32)((b[31] ) >> 4)) << 0) | (((sword32)((b[32] ) >> 0)) << 4) | (((sword32)((b[33] ) >> 0)) << 12) - | (((sword32)((b[34] ) >> 0)) << 20); - t[10] = (((sword32)((b[35] ) >> 0)) << 0) + | (((sword32)((b[34] ) >> 0)) << 20)); + t[10] = (word64)( + (((sword32)((b[35] ) >> 0)) << 0) | (((sword32)((b[36] ) >> 0)) << 8) | (((sword32)((b[37] ) >> 0)) << 16) - | ((((sword32)((b[38] & 0xf )) >> 0)) << 24); - t[11] = (((sword32)((b[38] ) >> 4)) << 0) + | ((((sword32)((b[38] & 0xf )) >> 0)) << 24)); + t[11] = (word64)( + (((sword32)((b[38] ) >> 4)) << 0) | (((sword32)((b[39] ) >> 0)) << 4) | (((sword32)((b[40] ) >> 0)) << 12) - | (((sword32)((b[41] ) >> 0)) << 20); - t[12] = (((sword32)((b[42] ) >> 0)) << 0) + | (((sword32)((b[41] ) >> 0)) << 20)); + t[12] = (word64)( + (((sword32)((b[42] ) >> 0)) << 0) | (((sword32)((b[43] ) >> 0)) << 8) | (((sword32)((b[44] ) >> 0)) << 16) - | ((((sword32)((b[45] & 0xf )) >> 0)) << 24); - t[13] = (((sword32)((b[45] ) >> 4)) << 0) + | ((((sword32)((b[45] & 0xf )) >> 0)) << 24)); + t[13] = (word64)( + (((sword32)((b[45] ) >> 4)) << 0) | (((sword32)((b[46] ) >> 0)) << 4) | (((sword32)((b[47] ) >> 0)) << 12) - | (((sword32)((b[48] ) >> 0)) << 20); - t[14] = (((sword32)((b[49] ) >> 0)) << 0) + | (((sword32)((b[48] ) >> 0)) << 20)); + t[14] = (word64)( + (((sword32)((b[49] ) >> 0)) << 0) | (((sword32)((b[50] ) >> 0)) << 8) | (((sword32)((b[51] ) >> 0)) << 16) - | ((((sword32)((b[52] & 0xf )) >> 0)) << 24); - t[15] = (((sword32)((b[52] ) >> 4)) << 0) + | ((((sword32)((b[52] & 0xf )) >> 0)) << 24)); + t[15] = (word64)( + (((sword32)((b[52] ) >> 4)) << 0) | (((sword32)((b[53] ) >> 0)) << 4) | (((sword32)((b[54] ) >> 0)) << 12) - | (((sword32)((b[55] ) >> 0)) << 20); - t[16] = (((sword32)((b[56] ) >> 0)) << 0) + | (((sword32)((b[55] ) >> 0)) << 20)); + t[16] = (word64)( + (((sword32)((b[56] ) >> 0)) << 0) | (((sword32)((b[57] ) >> 0)) << 8) | (((sword32)((b[58] ) >> 0)) << 16) - | ((((sword32)((b[59] & 0xf )) >> 0)) << 24); - t[17] = (((sword32)((b[59] ) >> 4)) << 0) + | ((((sword32)((b[59] & 0xf )) >> 0)) << 24)); + t[17] = (word64)( + (((sword32)((b[59] ) >> 4)) << 0) | (((sword32)((b[60] ) >> 0)) << 4) | (((sword32)((b[61] ) >> 0)) << 12) - | (((sword32)((b[62] ) >> 0)) << 20); - t[18] = (((sword32)((b[63] ) >> 0)) << 0) + | (((sword32)((b[62] ) >> 0)) << 20)); + t[18] = (word64)( + (((sword32)((b[63] ) >> 0)) << 0) | (((sword32)((b[64] ) >> 0)) << 8) | (((sword32)((b[65] ) >> 0)) << 16) - | ((((sword32)((b[66] & 0xf )) >> 0)) << 24); - t[19] = (((sword32)((b[66] ) >> 4)) << 0) + | ((((sword32)((b[66] & 0xf )) >> 0)) << 24)); + t[19] = (word64)( + (((sword32)((b[66] ) >> 4)) << 0) | (((sword32)((b[67] ) >> 0)) << 4) | (((sword32)((b[68] ) >> 0)) << 12) - | (((sword32)((b[69] ) >> 0)) << 20); - t[20] = (((sword32)((b[70] ) >> 0)) << 0) + | (((sword32)((b[69] ) >> 0)) << 20)); + t[20] = (word64)( + (((sword32)((b[70] ) >> 0)) << 0) | (((sword32)((b[71] ) >> 0)) << 8) | (((sword32)((b[72] ) >> 0)) << 16) - | ((((sword32)((b[73] & 0xf )) >> 0)) << 24); - t[21] = (((sword32)((b[73] ) >> 4)) << 0) + | ((((sword32)((b[73] & 0xf )) >> 0)) << 24)); + t[21] = (word64)( + (((sword32)((b[73] ) >> 4)) << 0) | (((sword32)((b[74] ) >> 0)) << 4) | (((sword32)((b[75] ) >> 0)) << 12) - | (((sword32)((b[76] ) >> 0)) << 20); - t[22] = (((sword32)((b[77] ) >> 0)) << 0) + | (((sword32)((b[76] ) >> 0)) << 20)); + t[22] = (word64)( + (((sword32)((b[77] ) >> 0)) << 0) | (((sword32)((b[78] ) >> 0)) << 8) | (((sword32)((b[79] ) >> 0)) << 16) - | ((((sword32)((b[80] & 0xf )) >> 0)) << 24); - t[23] = (((sword32)((b[80] ) >> 4)) << 0) + | ((((sword32)((b[80] & 0xf )) >> 0)) << 24)); + t[23] = (word64)( + (((sword32)((b[80] ) >> 4)) << 0) | (((sword32)((b[81] ) >> 0)) << 4) | (((sword32)((b[82] ) >> 0)) << 12) - | (((sword32)((b[83] ) >> 0)) << 20); - t[24] = (((sword32)((b[84] ) >> 0)) << 0) + | (((sword32)((b[83] ) >> 0)) << 20)); + t[24] = (word64)( + (((sword32)((b[84] ) >> 0)) << 0) | (((sword32)((b[85] ) >> 0)) << 8) | (((sword32)((b[86] ) >> 0)) << 16) - | ((((sword32)((b[87] & 0xf )) >> 0)) << 24); - t[25] = (((sword32)((b[87] ) >> 4)) << 0) + | ((((sword32)((b[87] & 0xf )) >> 0)) << 24)); + t[25] = (word64)( + (((sword32)((b[87] ) >> 4)) << 0) | (((sword32)((b[88] ) >> 0)) << 4) | (((sword32)((b[89] ) >> 0)) << 12) - | (((sword32)((b[90] ) >> 0)) << 20); - t[26] = (((sword32)((b[91] ) >> 0)) << 0) + | (((sword32)((b[90] ) >> 0)) << 20)); + t[26] = (word64)( + (((sword32)((b[91] ) >> 0)) << 0) | (((sword32)((b[92] ) >> 0)) << 8) | (((sword32)((b[93] ) >> 0)) << 16) - | ((((sword32)((b[94] & 0xf )) >> 0)) << 24); - t[27] = (((sword32)((b[94] ) >> 4)) << 0) + | ((((sword32)((b[94] & 0xf )) >> 0)) << 24)); + t[27] = (word64)( + (((sword32)((b[94] ) >> 4)) << 0) | (((sword32)((b[95] ) >> 0)) << 4) | (((sword32)((b[96] ) >> 0)) << 12) - | (((sword32)((b[97] ) >> 0)) << 20); - t[28] = (((sword32)((b[98] ) >> 0)) << 0) + | (((sword32)((b[97] ) >> 0)) << 20)); + t[28] = (word64)( + (((sword32)((b[98] ) >> 0)) << 0) | (((sword32)((b[99] ) >> 0)) << 8) | (((sword32)((b[100] ) >> 0)) << 16) - | ((((sword32)((b[101] & 0xf )) >> 0)) << 24); - t[29] = (((sword32)((b[101] ) >> 4)) << 0) + | ((((sword32)((b[101] & 0xf )) >> 0)) << 24)); + t[29] = (word64)( + (((sword32)((b[101] ) >> 4)) << 0) | (((sword32)((b[102] ) >> 0)) << 4) | (((sword32)((b[103] ) >> 0)) << 12) - | (((sword32)((b[104] ) >> 0)) << 20); - t[30] = (((sword32)((b[105] ) >> 0)) << 0) + | (((sword32)((b[104] ) >> 0)) << 20)); + t[30] = (word64)( + (((sword32)((b[105] ) >> 0)) << 0) | (((sword32)((b[106] ) >> 0)) << 8) | (((sword32)((b[107] ) >> 0)) << 16) - | ((((sword32)((b[108] & 0xf )) >> 0)) << 24); - t[31] = (((sword32)((b[108] ) >> 4)) << 0) + | ((((sword32)((b[108] & 0xf )) >> 0)) << 24)); + t[31] = (word64)( + (((sword32)((b[108] ) >> 4)) << 0) | (((sword32)((b[109] ) >> 0)) << 4) | (((sword32)((b[110] ) >> 0)) << 12) - | (((sword32)((b[111] ) >> 0)) << 20); - t[32] = (((sword32)((b[112] ) >> 0)) << 0) - | (((sword32)((b[113] ) >> 0)) << 8); + | (((sword32)((b[111] ) >> 0)) << 20)); + t[32] = (word64)( + (((sword32)((b[112] ) >> 0)) << 0) + | (((sword32)((b[113] ) >> 0)) << 8)); /* Mod curve order */ /* 2^446 - 0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d */ @@ -5514,56 +5547,56 @@ void sc448_reduce(byte* b) b[ 0] = (byte)(d[0 ] >> 0); b[ 1] = (byte)(d[0 ] >> 8); b[ 2] = (byte)(d[0 ] >> 16); - b[ 3] = (byte)(d[0 ] >> 24) + (byte)((d[1 ] >> 0) << 4); + b[ 3] = (byte)((byte)(d[0 ] >> 24) + (byte)((d[1 ] >> 0) << 4)); b[ 4] = (byte)(d[1 ] >> 4); b[ 5] = (byte)(d[1 ] >> 12); b[ 6] = (byte)(d[1 ] >> 20); b[ 7] = (byte)(d[2 ] >> 0); b[ 8] = (byte)(d[2 ] >> 8); b[ 9] = (byte)(d[2 ] >> 16); - b[10] = (byte)(d[2 ] >> 24) + (byte)((d[3 ] >> 0) << 4); + b[10] = (byte)((byte)(d[2 ] >> 24) + (byte)((d[3 ] >> 0) << 4)); b[11] = (byte)(d[3 ] >> 4); b[12] = (byte)(d[3 ] >> 12); b[13] = (byte)(d[3 ] >> 20); b[14] = (byte)(d[4 ] >> 0); b[15] = (byte)(d[4 ] >> 8); b[16] = (byte)(d[4 ] >> 16); - b[17] = (byte)(d[4 ] >> 24) + (byte)((d[5 ] >> 0) << 4); + b[17] = (byte)((byte)(d[4 ] >> 24) + (byte)((d[5 ] >> 0) << 4)); b[18] = (byte)(d[5 ] >> 4); b[19] = (byte)(d[5 ] >> 12); b[20] = (byte)(d[5 ] >> 20); b[21] = (byte)(d[6 ] >> 0); b[22] = (byte)(d[6 ] >> 8); b[23] = (byte)(d[6 ] >> 16); - b[24] = (byte)(d[6 ] >> 24) + (byte)((d[7 ] >> 0) << 4); + b[24] = (byte)((byte)(d[6 ] >> 24) + (byte)((d[7 ] >> 0) << 4)); b[25] = (byte)(d[7 ] >> 4); b[26] = (byte)(d[7 ] >> 12); b[27] = (byte)(d[7 ] >> 20); b[28] = (byte)(d[8 ] >> 0); b[29] = (byte)(d[8 ] >> 8); b[30] = (byte)(d[8 ] >> 16); - b[31] = (byte)(d[8 ] >> 24) + (byte)((d[9 ] >> 0) << 4); + b[31] = (byte)((byte)(d[8 ] >> 24) + (byte)((d[9 ] >> 0) << 4)); b[32] = (byte)(d[9 ] >> 4); b[33] = (byte)(d[9 ] >> 12); b[34] = (byte)(d[9 ] >> 20); b[35] = (byte)(d[10] >> 0); b[36] = (byte)(d[10] >> 8); b[37] = (byte)(d[10] >> 16); - b[38] = (byte)(d[10] >> 24) + (byte)((d[11] >> 0) << 4); + b[38] = (byte)((byte)(d[10] >> 24) + (byte)((d[11] >> 0) << 4)); b[39] = (byte)(d[11] >> 4); b[40] = (byte)(d[11] >> 12); b[41] = (byte)(d[11] >> 20); b[42] = (byte)(d[12] >> 0); b[43] = (byte)(d[12] >> 8); b[44] = (byte)(d[12] >> 16); - b[45] = (byte)(d[12] >> 24) + (byte)((d[13] >> 0) << 4); + b[45] = (byte)((byte)(d[12] >> 24) + (byte)((d[13] >> 0) << 4)); b[46] = (byte)(d[13] >> 4); b[47] = (byte)(d[13] >> 12); b[48] = (byte)(d[13] >> 20); b[49] = (byte)(d[14] >> 0); b[50] = (byte)(d[14] >> 8); b[51] = (byte)(d[14] >> 16); - b[52] = (byte)(d[14] >> 24) + (byte)((d[15] >> 0) << 4); + b[52] = (byte)((byte)(d[14] >> 24) + (byte)((d[15] >> 0) << 4)); b[53] = (byte)(d[15] >> 4); b[54] = (byte)(d[15] >> 12); b[55] = (byte)(d[15] >> 20); @@ -5586,200 +5619,248 @@ void sc448_muladd(byte* r, const byte* a, const byte* b, const byte* d) sword32 u; /* Load from bytes */ - ad[ 0] = (((sword32)((a[ 0] ) >> 0)) << 0) + ad[ 0] = (word32)( + (((sword32)((a[ 0] ) >> 0)) << 0) | (((sword32)((a[ 1] ) >> 0)) << 8) | (((sword32)((a[ 2] ) >> 0)) << 16) - | ((((sword32)((a[ 3] & 0xf )) >> 0)) << 24); - ad[ 1] = (((sword32)((a[ 3] ) >> 4)) << 0) + | ((((sword32)((a[ 3] & 0xf )) >> 0)) << 24)); + ad[ 1] = (word32)( + (((sword32)((a[ 3] ) >> 4)) << 0) | (((sword32)((a[ 4] ) >> 0)) << 4) | (((sword32)((a[ 5] ) >> 0)) << 12) - | (((sword32)((a[ 6] ) >> 0)) << 20); - ad[ 2] = (((sword32)((a[ 7] ) >> 0)) << 0) + | (((sword32)((a[ 6] ) >> 0)) << 20)); + ad[ 2] = (word32)( + (((sword32)((a[ 7] ) >> 0)) << 0) | (((sword32)((a[ 8] ) >> 0)) << 8) | (((sword32)((a[ 9] ) >> 0)) << 16) - | ((((sword32)((a[10] & 0xf )) >> 0)) << 24); - ad[ 3] = (((sword32)((a[10] ) >> 4)) << 0) + | ((((sword32)((a[10] & 0xf )) >> 0)) << 24)); + ad[ 3] = (word32)( + (((sword32)((a[10] ) >> 4)) << 0) | (((sword32)((a[11] ) >> 0)) << 4) | (((sword32)((a[12] ) >> 0)) << 12) - | (((sword32)((a[13] ) >> 0)) << 20); - ad[ 4] = (((sword32)((a[14] ) >> 0)) << 0) + | (((sword32)((a[13] ) >> 0)) << 20)); + ad[ 4] = (word32)( + (((sword32)((a[14] ) >> 0)) << 0) | (((sword32)((a[15] ) >> 0)) << 8) | (((sword32)((a[16] ) >> 0)) << 16) - | ((((sword32)((a[17] & 0xf )) >> 0)) << 24); - ad[ 5] = (((sword32)((a[17] ) >> 4)) << 0) + | ((((sword32)((a[17] & 0xf )) >> 0)) << 24)); + ad[ 5] = (word32)( + (((sword32)((a[17] ) >> 4)) << 0) | (((sword32)((a[18] ) >> 0)) << 4) | (((sword32)((a[19] ) >> 0)) << 12) - | (((sword32)((a[20] ) >> 0)) << 20); - ad[ 6] = (((sword32)((a[21] ) >> 0)) << 0) + | (((sword32)((a[20] ) >> 0)) << 20)); + ad[ 6] = (word32)( + (((sword32)((a[21] ) >> 0)) << 0) | (((sword32)((a[22] ) >> 0)) << 8) | (((sword32)((a[23] ) >> 0)) << 16) - | ((((sword32)((a[24] & 0xf )) >> 0)) << 24); - ad[ 7] = (((sword32)((a[24] ) >> 4)) << 0) + | ((((sword32)((a[24] & 0xf )) >> 0)) << 24)); + ad[ 7] = (word32)( + (((sword32)((a[24] ) >> 4)) << 0) | (((sword32)((a[25] ) >> 0)) << 4) | (((sword32)((a[26] ) >> 0)) << 12) - | (((sword32)((a[27] ) >> 0)) << 20); - ad[ 8] = (((sword32)((a[28] ) >> 0)) << 0) + | (((sword32)((a[27] ) >> 0)) << 20)); + ad[ 8] = (word32)( + (((sword32)((a[28] ) >> 0)) << 0) | (((sword32)((a[29] ) >> 0)) << 8) | (((sword32)((a[30] ) >> 0)) << 16) - | ((((sword32)((a[31] & 0xf )) >> 0)) << 24); - ad[ 9] = (((sword32)((a[31] ) >> 4)) << 0) + | ((((sword32)((a[31] & 0xf )) >> 0)) << 24)); + ad[ 9] = (word32)( + (((sword32)((a[31] ) >> 4)) << 0) | (((sword32)((a[32] ) >> 0)) << 4) | (((sword32)((a[33] ) >> 0)) << 12) - | (((sword32)((a[34] ) >> 0)) << 20); - ad[10] = (((sword32)((a[35] ) >> 0)) << 0) + | (((sword32)((a[34] ) >> 0)) << 20)); + ad[10] = (word32)( + (((sword32)((a[35] ) >> 0)) << 0) | (((sword32)((a[36] ) >> 0)) << 8) | (((sword32)((a[37] ) >> 0)) << 16) - | ((((sword32)((a[38] & 0xf )) >> 0)) << 24); - ad[11] = (((sword32)((a[38] ) >> 4)) << 0) + | ((((sword32)((a[38] & 0xf )) >> 0)) << 24)); + ad[11] = (word32)( + (((sword32)((a[38] ) >> 4)) << 0) | (((sword32)((a[39] ) >> 0)) << 4) | (((sword32)((a[40] ) >> 0)) << 12) - | (((sword32)((a[41] ) >> 0)) << 20); - ad[12] = (((sword32)((a[42] ) >> 0)) << 0) + | (((sword32)((a[41] ) >> 0)) << 20)); + ad[12] = (word32)( + (((sword32)((a[42] ) >> 0)) << 0) | (((sword32)((a[43] ) >> 0)) << 8) | (((sword32)((a[44] ) >> 0)) << 16) - | ((((sword32)((a[45] & 0xf )) >> 0)) << 24); - ad[13] = (((sword32)((a[45] ) >> 4)) << 0) + | ((((sword32)((a[45] & 0xf )) >> 0)) << 24)); + ad[13] = (word32)( + (((sword32)((a[45] ) >> 4)) << 0) | (((sword32)((a[46] ) >> 0)) << 4) | (((sword32)((a[47] ) >> 0)) << 12) - | (((sword32)((a[48] ) >> 0)) << 20); - ad[14] = (((sword32)((a[49] ) >> 0)) << 0) + | (((sword32)((a[48] ) >> 0)) << 20)); + ad[14] = (word32)( + (((sword32)((a[49] ) >> 0)) << 0) | (((sword32)((a[50] ) >> 0)) << 8) | (((sword32)((a[51] ) >> 0)) << 16) - | ((((sword32)((a[52] & 0xf )) >> 0)) << 24); - ad[15] = (((sword32)((a[52] ) >> 4)) << 0) + | ((((sword32)((a[52] & 0xf )) >> 0)) << 24)); + ad[15] = (word32)( + (((sword32)((a[52] ) >> 4)) << 0) | (((sword32)((a[53] ) >> 0)) << 4) | (((sword32)((a[54] ) >> 0)) << 12) - | (((sword32)((a[55] ) >> 0)) << 20); + | (((sword32)((a[55] ) >> 0)) << 20)); /* Load from bytes */ - bd[ 0] = (((sword32)((b[ 0] ) >> 0)) << 0) + bd[ 0] = (word32)( + (((sword32)((b[ 0] ) >> 0)) << 0) | (((sword32)((b[ 1] ) >> 0)) << 8) | (((sword32)((b[ 2] ) >> 0)) << 16) - | ((((sword32)((b[ 3] & 0xf )) >> 0)) << 24); - bd[ 1] = (((sword32)((b[ 3] ) >> 4)) << 0) + | ((((sword32)((b[ 3] & 0xf )) >> 0)) << 24)); + bd[ 1] = (word32)( + (((sword32)((b[ 3] ) >> 4)) << 0) | (((sword32)((b[ 4] ) >> 0)) << 4) | (((sword32)((b[ 5] ) >> 0)) << 12) - | (((sword32)((b[ 6] ) >> 0)) << 20); - bd[ 2] = (((sword32)((b[ 7] ) >> 0)) << 0) + | (((sword32)((b[ 6] ) >> 0)) << 20)); + bd[ 2] = (word32)( + (((sword32)((b[ 7] ) >> 0)) << 0) | (((sword32)((b[ 8] ) >> 0)) << 8) | (((sword32)((b[ 9] ) >> 0)) << 16) - | ((((sword32)((b[10] & 0xf )) >> 0)) << 24); - bd[ 3] = (((sword32)((b[10] ) >> 4)) << 0) + | ((((sword32)((b[10] & 0xf )) >> 0)) << 24)); + bd[ 3] = (word32)( + (((sword32)((b[10] ) >> 4)) << 0) | (((sword32)((b[11] ) >> 0)) << 4) | (((sword32)((b[12] ) >> 0)) << 12) - | (((sword32)((b[13] ) >> 0)) << 20); - bd[ 4] = (((sword32)((b[14] ) >> 0)) << 0) + | (((sword32)((b[13] ) >> 0)) << 20)); + bd[ 4] = (word32)( + (((sword32)((b[14] ) >> 0)) << 0) | (((sword32)((b[15] ) >> 0)) << 8) | (((sword32)((b[16] ) >> 0)) << 16) - | ((((sword32)((b[17] & 0xf )) >> 0)) << 24); - bd[ 5] = (((sword32)((b[17] ) >> 4)) << 0) + | ((((sword32)((b[17] & 0xf )) >> 0)) << 24)); + bd[ 5] = (word32)( + (((sword32)((b[17] ) >> 4)) << 0) | (((sword32)((b[18] ) >> 0)) << 4) | (((sword32)((b[19] ) >> 0)) << 12) - | (((sword32)((b[20] ) >> 0)) << 20); - bd[ 6] = (((sword32)((b[21] ) >> 0)) << 0) + | (((sword32)((b[20] ) >> 0)) << 20)); + bd[ 6] = (word32)( + (((sword32)((b[21] ) >> 0)) << 0) | (((sword32)((b[22] ) >> 0)) << 8) | (((sword32)((b[23] ) >> 0)) << 16) - | ((((sword32)((b[24] & 0xf )) >> 0)) << 24); - bd[ 7] = (((sword32)((b[24] ) >> 4)) << 0) + | ((((sword32)((b[24] & 0xf )) >> 0)) << 24)); + bd[ 7] = (word32)( + (((sword32)((b[24] ) >> 4)) << 0) | (((sword32)((b[25] ) >> 0)) << 4) | (((sword32)((b[26] ) >> 0)) << 12) - | (((sword32)((b[27] ) >> 0)) << 20); - bd[ 8] = (((sword32)((b[28] ) >> 0)) << 0) + | (((sword32)((b[27] ) >> 0)) << 20)); + bd[ 8] = (word32)( + (((sword32)((b[28] ) >> 0)) << 0) | (((sword32)((b[29] ) >> 0)) << 8) | (((sword32)((b[30] ) >> 0)) << 16) - | ((((sword32)((b[31] & 0xf )) >> 0)) << 24); - bd[ 9] = (((sword32)((b[31] ) >> 4)) << 0) + | ((((sword32)((b[31] & 0xf )) >> 0)) << 24)); + bd[ 9] = (word32)( + (((sword32)((b[31] ) >> 4)) << 0) | (((sword32)((b[32] ) >> 0)) << 4) | (((sword32)((b[33] ) >> 0)) << 12) - | (((sword32)((b[34] ) >> 0)) << 20); - bd[10] = (((sword32)((b[35] ) >> 0)) << 0) + | (((sword32)((b[34] ) >> 0)) << 20)); + bd[10] = (word32)( + (((sword32)((b[35] ) >> 0)) << 0) | (((sword32)((b[36] ) >> 0)) << 8) | (((sword32)((b[37] ) >> 0)) << 16) - | ((((sword32)((b[38] & 0xf )) >> 0)) << 24); - bd[11] = (((sword32)((b[38] ) >> 4)) << 0) + | ((((sword32)((b[38] & 0xf )) >> 0)) << 24)); + bd[11] = (word32)( + (((sword32)((b[38] ) >> 4)) << 0) | (((sword32)((b[39] ) >> 0)) << 4) | (((sword32)((b[40] ) >> 0)) << 12) - | (((sword32)((b[41] ) >> 0)) << 20); - bd[12] = (((sword32)((b[42] ) >> 0)) << 0) + | (((sword32)((b[41] ) >> 0)) << 20)); + bd[12] = (word32)( + (((sword32)((b[42] ) >> 0)) << 0) | (((sword32)((b[43] ) >> 0)) << 8) | (((sword32)((b[44] ) >> 0)) << 16) - | ((((sword32)((b[45] & 0xf )) >> 0)) << 24); - bd[13] = (((sword32)((b[45] ) >> 4)) << 0) + | ((((sword32)((b[45] & 0xf )) >> 0)) << 24)); + bd[13] = (word32)( + (((sword32)((b[45] ) >> 4)) << 0) | (((sword32)((b[46] ) >> 0)) << 4) | (((sword32)((b[47] ) >> 0)) << 12) - | (((sword32)((b[48] ) >> 0)) << 20); - bd[14] = (((sword32)((b[49] ) >> 0)) << 0) + | (((sword32)((b[48] ) >> 0)) << 20)); + bd[14] = (word32)( + (((sword32)((b[49] ) >> 0)) << 0) | (((sword32)((b[50] ) >> 0)) << 8) | (((sword32)((b[51] ) >> 0)) << 16) - | ((((sword32)((b[52] & 0xf )) >> 0)) << 24); - bd[15] = (((sword32)((b[52] ) >> 4)) << 0) + | ((((sword32)((b[52] & 0xf )) >> 0)) << 24)); + bd[15] = (word32)( + (((sword32)((b[52] ) >> 4)) << 0) | (((sword32)((b[53] ) >> 0)) << 4) | (((sword32)((b[54] ) >> 0)) << 12) - | (((sword32)((b[55] ) >> 0)) << 20); + | (((sword32)((b[55] ) >> 0)) << 20)); /* Load from bytes */ - dd[ 0] = (((sword32)((d[ 0] ) >> 0)) << 0) + dd[ 0] = (word32)( + (((sword32)((d[ 0] ) >> 0)) << 0) | (((sword32)((d[ 1] ) >> 0)) << 8) | (((sword32)((d[ 2] ) >> 0)) << 16) - | ((((sword32)((d[ 3] & 0xf )) >> 0)) << 24); - dd[ 1] = (((sword32)((d[ 3] ) >> 4)) << 0) + | ((((sword32)((d[ 3] & 0xf )) >> 0)) << 24)); + dd[ 1] = (word32)( + (((sword32)((d[ 3] ) >> 4)) << 0) | (((sword32)((d[ 4] ) >> 0)) << 4) | (((sword32)((d[ 5] ) >> 0)) << 12) - | (((sword32)((d[ 6] ) >> 0)) << 20); - dd[ 2] = (((sword32)((d[ 7] ) >> 0)) << 0) + | (((sword32)((d[ 6] ) >> 0)) << 20)); + dd[ 2] = (word32)( + (((sword32)((d[ 7] ) >> 0)) << 0) | (((sword32)((d[ 8] ) >> 0)) << 8) | (((sword32)((d[ 9] ) >> 0)) << 16) - | ((((sword32)((d[10] & 0xf )) >> 0)) << 24); - dd[ 3] = (((sword32)((d[10] ) >> 4)) << 0) + | ((((sword32)((d[10] & 0xf )) >> 0)) << 24)); + dd[ 3] = (word32)( + (((sword32)((d[10] ) >> 4)) << 0) | (((sword32)((d[11] ) >> 0)) << 4) | (((sword32)((d[12] ) >> 0)) << 12) - | (((sword32)((d[13] ) >> 0)) << 20); - dd[ 4] = (((sword32)((d[14] ) >> 0)) << 0) + | (((sword32)((d[13] ) >> 0)) << 20)); + dd[ 4] = (word32)( + (((sword32)((d[14] ) >> 0)) << 0) | (((sword32)((d[15] ) >> 0)) << 8) | (((sword32)((d[16] ) >> 0)) << 16) - | ((((sword32)((d[17] & 0xf )) >> 0)) << 24); - dd[ 5] = (((sword32)((d[17] ) >> 4)) << 0) + | ((((sword32)((d[17] & 0xf )) >> 0)) << 24)); + dd[ 5] = (word32)( + (((sword32)((d[17] ) >> 4)) << 0) | (((sword32)((d[18] ) >> 0)) << 4) | (((sword32)((d[19] ) >> 0)) << 12) - | (((sword32)((d[20] ) >> 0)) << 20); - dd[ 6] = (((sword32)((d[21] ) >> 0)) << 0) + | (((sword32)((d[20] ) >> 0)) << 20)); + dd[ 6] = (word32)( + (((sword32)((d[21] ) >> 0)) << 0) | (((sword32)((d[22] ) >> 0)) << 8) | (((sword32)((d[23] ) >> 0)) << 16) - | ((((sword32)((d[24] & 0xf )) >> 0)) << 24); - dd[ 7] = (((sword32)((d[24] ) >> 4)) << 0) + | ((((sword32)((d[24] & 0xf )) >> 0)) << 24)); + dd[ 7] = (word32)( + (((sword32)((d[24] ) >> 4)) << 0) | (((sword32)((d[25] ) >> 0)) << 4) | (((sword32)((d[26] ) >> 0)) << 12) - | (((sword32)((d[27] ) >> 0)) << 20); - dd[ 8] = (((sword32)((d[28] ) >> 0)) << 0) + | (((sword32)((d[27] ) >> 0)) << 20)); + dd[ 8] = (word32)( + (((sword32)((d[28] ) >> 0)) << 0) | (((sword32)((d[29] ) >> 0)) << 8) | (((sword32)((d[30] ) >> 0)) << 16) - | ((((sword32)((d[31] & 0xf )) >> 0)) << 24); - dd[ 9] = (((sword32)((d[31] ) >> 4)) << 0) + | ((((sword32)((d[31] & 0xf )) >> 0)) << 24)); + dd[ 9] = (word32)( + (((sword32)((d[31] ) >> 4)) << 0) | (((sword32)((d[32] ) >> 0)) << 4) | (((sword32)((d[33] ) >> 0)) << 12) - | (((sword32)((d[34] ) >> 0)) << 20); - dd[10] = (((sword32)((d[35] ) >> 0)) << 0) + | (((sword32)((d[34] ) >> 0)) << 20)); + dd[10] = (word32)( + (((sword32)((d[35] ) >> 0)) << 0) | (((sword32)((d[36] ) >> 0)) << 8) | (((sword32)((d[37] ) >> 0)) << 16) - | ((((sword32)((d[38] & 0xf )) >> 0)) << 24); - dd[11] = (((sword32)((d[38] ) >> 4)) << 0) + | ((((sword32)((d[38] & 0xf )) >> 0)) << 24)); + dd[11] = (word32)( + (((sword32)((d[38] ) >> 4)) << 0) | (((sword32)((d[39] ) >> 0)) << 4) | (((sword32)((d[40] ) >> 0)) << 12) - | (((sword32)((d[41] ) >> 0)) << 20); - dd[12] = (((sword32)((d[42] ) >> 0)) << 0) + | (((sword32)((d[41] ) >> 0)) << 20)); + dd[12] = (word32)( + (((sword32)((d[42] ) >> 0)) << 0) | (((sword32)((d[43] ) >> 0)) << 8) | (((sword32)((d[44] ) >> 0)) << 16) - | ((((sword32)((d[45] & 0xf )) >> 0)) << 24); - dd[13] = (((sword32)((d[45] ) >> 4)) << 0) + | ((((sword32)((d[45] & 0xf )) >> 0)) << 24)); + dd[13] = (word32)( + (((sword32)((d[45] ) >> 4)) << 0) | (((sword32)((d[46] ) >> 0)) << 4) | (((sword32)((d[47] ) >> 0)) << 12) - | (((sword32)((d[48] ) >> 0)) << 20); - dd[14] = (((sword32)((d[49] ) >> 0)) << 0) + | (((sword32)((d[48] ) >> 0)) << 20)); + dd[14] = (word32)( + (((sword32)((d[49] ) >> 0)) << 0) | (((sword32)((d[50] ) >> 0)) << 8) | (((sword32)((d[51] ) >> 0)) << 16) - | ((((sword32)((d[52] & 0xf )) >> 0)) << 24); - dd[15] = (((sword32)((d[52] ) >> 4)) << 0) + | ((((sword32)((d[52] & 0xf )) >> 0)) << 24)); + dd[15] = (word32)( + (((sword32)((d[52] ) >> 4)) << 0) | (((sword32)((d[53] ) >> 0)) << 4) | (((sword32)((d[54] ) >> 0)) << 12) - | (((sword32)((d[55] ) >> 0)) << 20); + | (((sword32)((d[55] ) >> 0)) << 20)); /* a * b + d */ t[ 0] = (word64)(dd[ 0] + (word64)((sword64)ad[ 0] * bd[ 0])); @@ -6335,56 +6416,56 @@ void sc448_muladd(byte* r, const byte* a, const byte* b, const byte* d) r[ 0] = (byte)(rd[0 ] >> 0); r[ 1] = (byte)(rd[0 ] >> 8); r[ 2] = (byte)(rd[0 ] >> 16); - r[ 3] = (byte)(rd[0 ] >> 24) + (byte)((rd[1 ] >> 0) << 4); + r[ 3] = (byte)((byte)(rd[0 ] >> 24) + (byte)((rd[1 ] >> 0) << 4)); r[ 4] = (byte)(rd[1 ] >> 4); r[ 5] = (byte)(rd[1 ] >> 12); r[ 6] = (byte)(rd[1 ] >> 20); r[ 7] = (byte)(rd[2 ] >> 0); r[ 8] = (byte)(rd[2 ] >> 8); r[ 9] = (byte)(rd[2 ] >> 16); - r[10] = (byte)(rd[2 ] >> 24) + (byte)((rd[3 ] >> 0) << 4); + r[10] = (byte)((byte)(rd[2 ] >> 24) + (byte)((rd[3 ] >> 0) << 4)); r[11] = (byte)(rd[3 ] >> 4); r[12] = (byte)(rd[3 ] >> 12); r[13] = (byte)(rd[3 ] >> 20); r[14] = (byte)(rd[4 ] >> 0); r[15] = (byte)(rd[4 ] >> 8); r[16] = (byte)(rd[4 ] >> 16); - r[17] = (byte)(rd[4 ] >> 24) + (byte)((rd[5 ] >> 0) << 4); + r[17] = (byte)((byte)(rd[4 ] >> 24) + (byte)((rd[5 ] >> 0) << 4)); r[18] = (byte)(rd[5 ] >> 4); r[19] = (byte)(rd[5 ] >> 12); r[20] = (byte)(rd[5 ] >> 20); r[21] = (byte)(rd[6 ] >> 0); r[22] = (byte)(rd[6 ] >> 8); r[23] = (byte)(rd[6 ] >> 16); - r[24] = (byte)(rd[6 ] >> 24) + (byte)((rd[7 ] >> 0) << 4); + r[24] = (byte)((byte)(rd[6 ] >> 24) + (byte)((rd[7 ] >> 0) << 4)); r[25] = (byte)(rd[7 ] >> 4); r[26] = (byte)(rd[7 ] >> 12); r[27] = (byte)(rd[7 ] >> 20); r[28] = (byte)(rd[8 ] >> 0); r[29] = (byte)(rd[8 ] >> 8); r[30] = (byte)(rd[8 ] >> 16); - r[31] = (byte)(rd[8 ] >> 24) + (byte)((rd[9 ] >> 0) << 4); + r[31] = (byte)((byte)(rd[8 ] >> 24) + (byte)((rd[9 ] >> 0) << 4)); r[32] = (byte)(rd[9 ] >> 4); r[33] = (byte)(rd[9 ] >> 12); r[34] = (byte)(rd[9 ] >> 20); r[35] = (byte)(rd[10] >> 0); r[36] = (byte)(rd[10] >> 8); r[37] = (byte)(rd[10] >> 16); - r[38] = (byte)(rd[10] >> 24) + (byte)((rd[11] >> 0) << 4); + r[38] = (byte)((byte)(rd[10] >> 24) + (byte)((rd[11] >> 0) << 4)); r[39] = (byte)(rd[11] >> 4); r[40] = (byte)(rd[11] >> 12); r[41] = (byte)(rd[11] >> 20); r[42] = (byte)(rd[12] >> 0); r[43] = (byte)(rd[12] >> 8); r[44] = (byte)(rd[12] >> 16); - r[45] = (byte)(rd[12] >> 24) + (byte)((rd[13] >> 0) << 4); + r[45] = (byte)((byte)(rd[12] >> 24) + (byte)((rd[13] >> 0) << 4)); r[46] = (byte)(rd[13] >> 4); r[47] = (byte)(rd[13] >> 12); r[48] = (byte)(rd[13] >> 20); r[49] = (byte)(rd[14] >> 0); r[50] = (byte)(rd[14] >> 8); r[51] = (byte)(rd[14] >> 16); - r[52] = (byte)(rd[14] >> 24) + (byte)((rd[15] >> 0) << 4); + r[52] = (byte)((byte)(rd[14] >> 24) + (byte)((rd[15] >> 0) << 4)); r[53] = (byte)(rd[15] >> 4); r[54] = (byte)(rd[15] >> 12); r[55] = (byte)(rd[15] >> 20); diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index 9eb8ecaaf..39de4a594 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -8025,10 +8025,12 @@ static void sp_clamp_ct(sp_int* a) ((SP_WORD_SIZE == 32) && defined(NO_64BIT)) sp_int_digit negVal = ~a->dp[i]; sp_int_digit minusOne = a->dp[i] - 1; - sp_int_digit zeroMask = (sp_int_sdigit)(negVal & minusOne) >> - (SP_WORD_SIZE - 1); + sp_int_digit zeroMask = + (sp_int_digit)((sp_int_sdigit)(negVal & minusOne) >> + (SP_WORD_SIZE - 1)); #else - sp_int_digit zeroMask = (((sp_int_sword)a->dp[i]) - 1) >> SP_WORD_SIZE; + sp_int_digit zeroMask = + (sp_int_digit)((((sp_int_sword)a->dp[i]) - 1) >> SP_WORD_SIZE); #endif mask &= (sp_size_t)zeroMask; used = (sp_size_t)(used + mask); @@ -8879,7 +8881,7 @@ static int _sp_div(const sp_int* a, const sp_int* d, sp_int* r, sp_int* rem, if ((!done) && (err == MP_OKAY)) { #if (defined(WOLFSSL_SMALL_STACK) || defined(SP_ALLOC)) && \ !defined(WOLFSSL_SP_NO_MALLOC) - int cnt = 4; + unsigned int cnt = 4; /* Reuse remainder sp_int where possible. */ if ((rem != NULL) && (rem != d) && (rem->size > a->used)) { sa = rem; @@ -8908,7 +8910,7 @@ static int _sp_div(const sp_int* a, const sp_int* d, sp_int* r, sp_int* rem, } if (tr == NULL) { tr = td[i]; - _sp_init_size(tr, a->used - d->used + 2); + _sp_init_size(tr, (unsigned int)(a->used - d->used + 2)); } #else sa = td[2]; @@ -9255,8 +9257,9 @@ static int _sp_mul(const sp_int* a, const sp_int* b, sp_int* r) #endif #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_int_digit*)XMALLOC(sizeof(sp_int_digit) * (a->used + b->used), NULL, - DYNAMIC_TYPE_BIGINT); + t = (sp_int_digit*)XMALLOC(sizeof(sp_int_digit) * + (size_t)(a->used + b->used), NULL, + DYNAMIC_TYPE_BIGINT); if (t == NULL) { err = MP_MEM; } @@ -9331,8 +9334,9 @@ static int _sp_mul(const sp_int* a, const sp_int* b, sp_int* r) #endif #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_int_digit*)XMALLOC(sizeof(sp_int_digit) * (a->used + b->used), NULL, - DYNAMIC_TYPE_BIGINT); + t = (sp_int_digit*)XMALLOC(sizeof(sp_int_digit) * + (size_t)(a->used + b->used), NULL, + DYNAMIC_TYPE_BIGINT); if (t == NULL) { err = MP_MEM; } @@ -14881,7 +14885,7 @@ static int _sp_sqr(const sp_int* a, sp_int* r) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) t = (sp_int_digit*)XMALLOC( - sizeof(sp_int_digit) * (((a->used + 1) / 2) * 2 + 1), NULL, + sizeof(sp_int_digit) * (size_t)(((a->used + 1) / 2) * 2 + 1), NULL, DYNAMIC_TYPE_BIGINT); if (t == NULL) { err = MP_MEM; @@ -14995,8 +14999,9 @@ static int _sp_sqr(const sp_int* a, sp_int* r) #endif #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_int_digit*)XMALLOC(sizeof(sp_int_digit) * (a->used * 2), NULL, - DYNAMIC_TYPE_BIGINT); + t = (sp_int_digit*)XMALLOC(sizeof(sp_int_digit) * + (size_t)(a->used * 2), NULL, + DYNAMIC_TYPE_BIGINT); if (t == NULL) { err = MP_MEM; } diff --git a/wolfssl/wolfcrypt/fe_448.h b/wolfssl/wolfcrypt/fe_448.h index 088c1f1a3..fef9d177b 100644 --- a/wolfssl/wolfcrypt/fe_448.h +++ b/wolfssl/wolfcrypt/fe_448.h @@ -29,7 +29,8 @@ #include -#if defined(HAVE___UINT128_T) && !defined(NO_CURVED448_128BIT) +#if defined(HAVE___UINT128_T) && !defined(NO_CURVED448_128BIT) && \ + !defined(NO_INT128) #define CURVED448_128BIT #endif diff --git a/wolfssl/wolfcrypt/sp_int.h b/wolfssl/wolfcrypt/sp_int.h index f78a4de0f..7c5fdd1ab 100644 --- a/wolfssl/wolfcrypt/sp_int.h +++ b/wolfssl/wolfcrypt/sp_int.h @@ -262,7 +262,7 @@ extern "C" { #define SP_WORD_SIZEOF (SP_WORD_SIZE / 8) /* Define the types used. */ -#ifdef HAVE___UINT128_T +#if defined(HAVE___UINT128_T) && !defined(NO_INT128) #ifdef __SIZEOF_INT128__ typedef __uint128_t sp_uint128; typedef __int128_t sp_int128;