mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-05 15:30:49 +02:00
Merge pull request #10564 from SparkiDev/sp_fixes_8
Improvements to SP code
This commit is contained in:
+167
-167
File diff suppressed because it is too large
Load Diff
+142
-142
@@ -265,7 +265,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -300,7 +300,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -2911,10 +2911,10 @@ static void sp_2048_sqr_16(sp_digit* r, const sp_digit* a)
|
||||
*/
|
||||
static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
{
|
||||
sp_digit x;
|
||||
sp_digit b;
|
||||
sp_uint64 x;
|
||||
sp_uint64 b;
|
||||
|
||||
b = a[0];
|
||||
b = (sp_uint64)a[0];
|
||||
x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**8 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**16 */
|
||||
@@ -2922,7 +2922,7 @@ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**64 */
|
||||
|
||||
/* rho = -1/m mod b */
|
||||
*rho = (sp_digit)0 - x;
|
||||
*rho = (sp_digit)((sp_int64)0 - (sp_int64)x);
|
||||
}
|
||||
|
||||
/* Mul a by digit b into r. (r = a * b)
|
||||
@@ -4151,10 +4151,10 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -4163,14 +4163,14 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
XMEMCPY(r, t[y], sizeof(sp_digit) * 16);
|
||||
for (; i>=0 || c>=4; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 60);
|
||||
n <<= 4;
|
||||
n = (sp_uint64)n << 4;
|
||||
c = 60;
|
||||
}
|
||||
else if (c < 4) {
|
||||
@@ -4178,12 +4178,12 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
n = e[i--];
|
||||
c = 4 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 60) & 0xf);
|
||||
n <<= 4;
|
||||
n = (sp_uint64)n << 4;
|
||||
c -= 4;
|
||||
}
|
||||
|
||||
@@ -4304,10 +4304,10 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -4316,14 +4316,14 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
XMEMCPY(r, t[y], sizeof(sp_digit) * 16);
|
||||
for (; i>=0 || c>=5; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 59);
|
||||
n <<= 5;
|
||||
n = (sp_uint64)n << 5;
|
||||
c = 59;
|
||||
}
|
||||
else if (c < 5) {
|
||||
@@ -4331,12 +4331,12 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
n = e[i--];
|
||||
c = 5 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 59) & 0x1f);
|
||||
n <<= 5;
|
||||
n = (sp_uint64)n << 5;
|
||||
c -= 5;
|
||||
}
|
||||
|
||||
@@ -5746,10 +5746,10 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -5758,14 +5758,14 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
XMEMCPY(r, t[y], sizeof(sp_digit) * 32);
|
||||
for (; i>=0 || c>=5; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 59);
|
||||
n <<= 5;
|
||||
n = (sp_uint64)n << 5;
|
||||
c = 59;
|
||||
}
|
||||
else if (c < 5) {
|
||||
@@ -5773,12 +5773,12 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
n = e[i--];
|
||||
c = 5 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 59) & 0x1f);
|
||||
n <<= 5;
|
||||
n = (sp_uint64)n << 5;
|
||||
c -= 5;
|
||||
}
|
||||
|
||||
@@ -5932,10 +5932,10 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -5944,14 +5944,14 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
XMEMCPY(r, t[y], sizeof(sp_digit) * 32);
|
||||
for (; i>=0 || c>=6; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 58);
|
||||
n <<= 6;
|
||||
n = (sp_uint64)n << 6;
|
||||
c = 58;
|
||||
}
|
||||
else if (c < 6) {
|
||||
@@ -5959,12 +5959,12 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
n = e[i--];
|
||||
c = 6 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 58) & 0x3f);
|
||||
n <<= 6;
|
||||
n = (sp_uint64)n << 6;
|
||||
c -= 6;
|
||||
}
|
||||
|
||||
@@ -6039,7 +6039,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em,
|
||||
#else
|
||||
e[0] = em->dp[0];
|
||||
if (em->used > 1) {
|
||||
e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
|
||||
e[0] |= ((sp_uint64)em->dp[1]) << DIGIT_BIT;
|
||||
}
|
||||
#endif
|
||||
if (e[0] == 0) {
|
||||
@@ -6352,7 +6352,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 32; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -6377,7 +6377,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 32; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -6703,10 +6703,10 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -6715,14 +6715,14 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
sp_2048_lshift_32(r, norm, y);
|
||||
for (; i>=0 || c>=6; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 58);
|
||||
n <<= 6;
|
||||
n = (sp_uint64)n << 6;
|
||||
c = 58;
|
||||
}
|
||||
else if (c < 6) {
|
||||
@@ -6730,12 +6730,12 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits,
|
||||
n = e[i--];
|
||||
c = 6 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 58) & 0x3f);
|
||||
n <<= 6;
|
||||
n = (sp_uint64)n << 6;
|
||||
c -= 6;
|
||||
}
|
||||
|
||||
@@ -7028,7 +7028,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -7063,7 +7063,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -11584,10 +11584,10 @@ static void sp_3072_sqr_24(sp_digit* r, const sp_digit* a)
|
||||
*/
|
||||
static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
{
|
||||
sp_digit x;
|
||||
sp_digit b;
|
||||
sp_uint64 x;
|
||||
sp_uint64 b;
|
||||
|
||||
b = a[0];
|
||||
b = (sp_uint64)a[0];
|
||||
x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**8 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**16 */
|
||||
@@ -11595,7 +11595,7 @@ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**64 */
|
||||
|
||||
/* rho = -1/m mod b */
|
||||
*rho = (sp_digit)0 - x;
|
||||
*rho = (sp_digit)((sp_int64)0 - (sp_int64)x);
|
||||
}
|
||||
|
||||
/* Mul a by digit b into r. (r = a * b)
|
||||
@@ -13212,10 +13212,10 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -13224,14 +13224,14 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
XMEMCPY(r, t[y], sizeof(sp_digit) * 24);
|
||||
for (; i>=0 || c>=4; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 60);
|
||||
n <<= 4;
|
||||
n = (sp_uint64)n << 4;
|
||||
c = 60;
|
||||
}
|
||||
else if (c < 4) {
|
||||
@@ -13239,12 +13239,12 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
n = e[i--];
|
||||
c = 4 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 60) & 0xf);
|
||||
n <<= 4;
|
||||
n = (sp_uint64)n << 4;
|
||||
c -= 4;
|
||||
}
|
||||
|
||||
@@ -13365,10 +13365,10 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -13377,14 +13377,14 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
XMEMCPY(r, t[y], sizeof(sp_digit) * 24);
|
||||
for (; i>=0 || c>=5; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 59);
|
||||
n <<= 5;
|
||||
n = (sp_uint64)n << 5;
|
||||
c = 59;
|
||||
}
|
||||
else if (c < 5) {
|
||||
@@ -13392,12 +13392,12 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
n = e[i--];
|
||||
c = 5 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 59) & 0x1f);
|
||||
n <<= 5;
|
||||
n = (sp_uint64)n << 5;
|
||||
c -= 5;
|
||||
}
|
||||
|
||||
@@ -15175,10 +15175,10 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -15187,14 +15187,14 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
XMEMCPY(r, t[y], sizeof(sp_digit) * 48);
|
||||
for (; i>=0 || c>=3; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 61);
|
||||
n <<= 3;
|
||||
n = (sp_uint64)n << 3;
|
||||
c = 61;
|
||||
}
|
||||
else if (c < 3) {
|
||||
@@ -15202,12 +15202,12 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
n = e[i--];
|
||||
c = 3 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 61) & 0x7);
|
||||
n <<= 3;
|
||||
n = (sp_uint64)n << 3;
|
||||
c -= 3;
|
||||
}
|
||||
|
||||
@@ -15311,10 +15311,10 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -15323,14 +15323,14 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
XMEMCPY(r, t[y], sizeof(sp_digit) * 48);
|
||||
for (; i>=0 || c>=4; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 60);
|
||||
n <<= 4;
|
||||
n = (sp_uint64)n << 4;
|
||||
c = 60;
|
||||
}
|
||||
else if (c < 4) {
|
||||
@@ -15338,12 +15338,12 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
n = e[i--];
|
||||
c = 4 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 60) & 0xf);
|
||||
n <<= 4;
|
||||
n = (sp_uint64)n << 4;
|
||||
c -= 4;
|
||||
}
|
||||
|
||||
@@ -15416,7 +15416,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em,
|
||||
#else
|
||||
e[0] = em->dp[0];
|
||||
if (em->used > 1) {
|
||||
e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
|
||||
e[0] |= ((sp_uint64)em->dp[1]) << DIGIT_BIT;
|
||||
}
|
||||
#endif
|
||||
if (e[0] == 0) {
|
||||
@@ -15729,7 +15729,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 48; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -15754,7 +15754,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 48; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -16176,10 +16176,10 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -16188,14 +16188,14 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
sp_3072_lshift_48(r, norm, y);
|
||||
for (; i>=0 || c>=6; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 58);
|
||||
n <<= 6;
|
||||
n = (sp_uint64)n << 6;
|
||||
c = 58;
|
||||
}
|
||||
else if (c < 6) {
|
||||
@@ -16203,12 +16203,12 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits,
|
||||
n = e[i--];
|
||||
c = 6 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 58) & 0x3f);
|
||||
n <<= 6;
|
||||
n = (sp_uint64)n << 6;
|
||||
c -= 6;
|
||||
}
|
||||
|
||||
@@ -16501,7 +16501,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -16536,7 +16536,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -17444,10 +17444,10 @@ static void sp_4096_sqr_64(sp_digit* r, const sp_digit* a)
|
||||
*/
|
||||
static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
{
|
||||
sp_digit x;
|
||||
sp_digit b;
|
||||
sp_uint64 x;
|
||||
sp_uint64 b;
|
||||
|
||||
b = a[0];
|
||||
b = (sp_uint64)a[0];
|
||||
x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**8 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**16 */
|
||||
@@ -17455,7 +17455,7 @@ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**64 */
|
||||
|
||||
/* rho = -1/m mod b */
|
||||
*rho = (sp_digit)0 - x;
|
||||
*rho = (sp_digit)((sp_int64)0 - (sp_int64)x);
|
||||
}
|
||||
|
||||
/* Mul a by digit b into r. (r = a * b)
|
||||
@@ -20186,10 +20186,10 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -20198,14 +20198,14 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
XMEMCPY(r, t[y], sizeof(sp_digit) * 64);
|
||||
for (; i>=0 || c>=3; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 61);
|
||||
n <<= 3;
|
||||
n = (sp_uint64)n << 3;
|
||||
c = 61;
|
||||
}
|
||||
else if (c < 3) {
|
||||
@@ -20213,12 +20213,12 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
n = e[i--];
|
||||
c = 3 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 61) & 0x7);
|
||||
n <<= 3;
|
||||
n = (sp_uint64)n << 3;
|
||||
c -= 3;
|
||||
}
|
||||
|
||||
@@ -20322,10 +20322,10 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -20334,14 +20334,14 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
XMEMCPY(r, t[y], sizeof(sp_digit) * 64);
|
||||
for (; i>=0 || c>=4; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 60);
|
||||
n <<= 4;
|
||||
n = (sp_uint64)n << 4;
|
||||
c = 60;
|
||||
}
|
||||
else if (c < 4) {
|
||||
@@ -20349,12 +20349,12 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
n = e[i--];
|
||||
c = 4 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 60) & 0xf);
|
||||
n <<= 4;
|
||||
n = (sp_uint64)n << 4;
|
||||
c -= 4;
|
||||
}
|
||||
|
||||
@@ -20427,7 +20427,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em,
|
||||
#else
|
||||
e[0] = em->dp[0];
|
||||
if (em->used > 1) {
|
||||
e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
|
||||
e[0] |= ((sp_uint64)em->dp[1]) << DIGIT_BIT;
|
||||
}
|
||||
#endif
|
||||
if (e[0] == 0) {
|
||||
@@ -20740,7 +20740,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 64; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -20765,7 +20765,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 64; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -21283,10 +21283,10 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
|
||||
if (c < 0) {
|
||||
/* Number of bits in top word is less than number needed. */
|
||||
c = -c;
|
||||
y = (byte)(n << c);
|
||||
y = (byte)((sp_uint64)n << c);
|
||||
n = e[i--];
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else if (c == 0) {
|
||||
@@ -21295,14 +21295,14 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
|
||||
}
|
||||
else {
|
||||
y = (byte)(n >> c);
|
||||
n <<= 64 - c;
|
||||
n = (sp_uint64)n << (64 - c);
|
||||
}
|
||||
sp_4096_lshift_64(r, norm, y);
|
||||
for (; i>=0 || c>=6; ) {
|
||||
if (c == 0) {
|
||||
n = e[i--];
|
||||
y = (byte)(n >> 58);
|
||||
n <<= 6;
|
||||
n = (sp_uint64)n << 6;
|
||||
c = 58;
|
||||
}
|
||||
else if (c < 6) {
|
||||
@@ -21310,12 +21310,12 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
|
||||
n = e[i--];
|
||||
c = 6 - c;
|
||||
y |= (byte)(n >> (64 - c));
|
||||
n <<= c;
|
||||
n = (sp_uint64)n << c;
|
||||
c = 64 - c;
|
||||
}
|
||||
else {
|
||||
y = (byte)((n >> 58) & 0x3f);
|
||||
n <<= 6;
|
||||
n = (sp_uint64)n << 6;
|
||||
c -= 6;
|
||||
}
|
||||
|
||||
@@ -21865,10 +21865,10 @@ static int sp_256_mod_mul_norm_4(sp_digit* r, const sp_digit* a, const sp_digit*
|
||||
t[5] += t[4] >> 32; t[4] &= 0xffffffff;
|
||||
t[6] += t[5] >> 32; t[5] &= 0xffffffff;
|
||||
t[7] += t[6] >> 32; t[6] &= 0xffffffff;
|
||||
r[0] = (sp_digit)((t[1] << 32) | t[0]);
|
||||
r[1] = (sp_digit)((t[3] << 32) | t[2]);
|
||||
r[2] = (sp_digit)((t[5] << 32) | t[4]);
|
||||
r[3] = (sp_digit)((t[7] << 32) | t[6]);
|
||||
r[0] = (sp_digit)(((sp_uint64)t[1] << 32) | (sp_uint64)t[0]);
|
||||
r[1] = (sp_digit)(((sp_uint64)t[3] << 32) | (sp_uint64)t[2]);
|
||||
r[2] = (sp_digit)(((sp_uint64)t[5] << 32) | (sp_uint64)t[4]);
|
||||
r[3] = (sp_digit)(((sp_uint64)t[7] << 32) | (sp_uint64)t[6]);
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
@@ -21899,7 +21899,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -21934,7 +21934,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -22000,7 +22000,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 4; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -22025,7 +22025,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 4; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -22465,7 +22465,7 @@ static void sp_256_mont_inv_4(sp_digit* r, const sp_digit* a, sp_digit* td)
|
||||
XMEMCPY(t, a, sizeof(sp_digit) * 4);
|
||||
for (i=254; i>=0; i--) {
|
||||
sp_256_mont_sqr_4(t, t, p256_mod, p256_mp_mod);
|
||||
if (p256_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p256_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_256_mont_mul_4(t, t, a, p256_mod, p256_mp_mod);
|
||||
}
|
||||
XMEMCPY(r, t, sizeof(sp_digit) * 4);
|
||||
@@ -23959,7 +23959,7 @@ static void sp_256_ecc_recode_6_4(const sp_digit* k, ecc_recode_256* v)
|
||||
}
|
||||
else if (++j < 4) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x3f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f);
|
||||
o -= 58;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -26903,7 +26903,7 @@ static void sp_256_ecc_recode_7_4(const sp_digit* k, ecc_recode_256* v)
|
||||
}
|
||||
else if (++j < 4) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x7f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f);
|
||||
o -= 57;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -42693,12 +42693,12 @@ static int sp_384_mod_mul_norm_6(sp_digit* r, const sp_digit* a, const sp_digit*
|
||||
t[10] += t[9] >> 32; t[9] &= 0xffffffff;
|
||||
t[11] += t[10] >> 32; t[10] &= 0xffffffff;
|
||||
|
||||
r[0] = (sp_digit)((t[1] << 32) | t[0]);
|
||||
r[1] = (sp_digit)((t[3] << 32) | t[2]);
|
||||
r[2] = (sp_digit)((t[5] << 32) | t[4]);
|
||||
r[3] = (sp_digit)((t[7] << 32) | t[6]);
|
||||
r[4] = (sp_digit)((t[9] << 32) | t[8]);
|
||||
r[5] = (sp_digit)((t[11] << 32) | t[10]);
|
||||
r[0] = (sp_digit)(((sp_uint64)t[1] << 32) | (sp_uint64)t[0]);
|
||||
r[1] = (sp_digit)(((sp_uint64)t[3] << 32) | (sp_uint64)t[2]);
|
||||
r[2] = (sp_digit)(((sp_uint64)t[5] << 32) | (sp_uint64)t[4]);
|
||||
r[3] = (sp_digit)(((sp_uint64)t[7] << 32) | (sp_uint64)t[6]);
|
||||
r[4] = (sp_digit)(((sp_uint64)t[9] << 32) | (sp_uint64)t[8]);
|
||||
r[5] = (sp_digit)(((sp_uint64)t[11] << 32) | (sp_uint64)t[10]);
|
||||
}
|
||||
|
||||
SP_FREE_VAR(t, NULL, DYNAMIC_TYPE_ECC);
|
||||
@@ -42732,7 +42732,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -42767,7 +42767,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -42833,7 +42833,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 6; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -42858,7 +42858,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 6; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -43247,7 +43247,7 @@ static void sp_384_mont_inv_6(sp_digit* r, const sp_digit* a, sp_digit* td)
|
||||
XMEMCPY(t, a, sizeof(sp_digit) * 6);
|
||||
for (i=382; i>=0; i--) {
|
||||
sp_384_mont_sqr_6(t, t, p384_mod, p384_mp_mod);
|
||||
if (p384_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p384_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_384_mont_mul_6(t, t, a, p384_mod, p384_mp_mod);
|
||||
}
|
||||
XMEMCPY(r, t, sizeof(sp_digit) * 6);
|
||||
@@ -44497,7 +44497,7 @@ static void sp_384_ecc_recode_6_6(const sp_digit* k, ecc_recode_384* v)
|
||||
}
|
||||
else if (++j < 6) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x3f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f);
|
||||
o -= 58;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -47405,7 +47405,7 @@ static void sp_384_ecc_recode_7_6(const sp_digit* k, ecc_recode_384* v)
|
||||
}
|
||||
else if (++j < 6) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x7f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f);
|
||||
o -= 57;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -69713,7 +69713,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -69748,7 +69748,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -69814,7 +69814,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 9; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -69839,7 +69839,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 9; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -71004,7 +71004,7 @@ static void sp_521_mont_inv_9(sp_digit* r, const sp_digit* a, sp_digit* td)
|
||||
XMEMCPY(t, a, sizeof(sp_digit) * 9);
|
||||
for (i=519; i>=0; i--) {
|
||||
sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod);
|
||||
if (p521_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p521_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_521_mont_mul_9(t, t, a, p521_mod, p521_mp_mod);
|
||||
}
|
||||
XMEMCPY(r, t, sizeof(sp_digit) * 9);
|
||||
@@ -72442,7 +72442,7 @@ static void sp_521_ecc_recode_6_9(const sp_digit* k, ecc_recode_521* v)
|
||||
}
|
||||
else if (++j < 9) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x3f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f);
|
||||
o -= 58;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -76049,7 +76049,7 @@ static void sp_521_ecc_recode_7_9(const sp_digit* k, ecc_recode_521* v)
|
||||
}
|
||||
else if (++j < 9) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x7f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f);
|
||||
o -= 57;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -111994,7 +111994,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y)
|
||||
XMEMCPY(t, y, sizeof(sp_digit) * 9);
|
||||
for (i=518; i>=0; i--) {
|
||||
sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod);
|
||||
if (p521_sqrt_power[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p521_sqrt_power[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_521_mont_mul_9(t, t, y, p521_mod, p521_mp_mod);
|
||||
}
|
||||
XMEMCPY(y, t, sizeof(sp_digit) * 9);
|
||||
@@ -114032,7 +114032,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -114067,7 +114067,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -114133,7 +114133,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -114158,7 +114158,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -116114,7 +116114,7 @@ static void sp_1024_ecc_recode_7_16(const sp_digit* k, ecc_recode_1024* v)
|
||||
}
|
||||
else if (++j < 16) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x7f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f);
|
||||
o -= 57;
|
||||
n >>= o;
|
||||
}
|
||||
|
||||
+166
-166
File diff suppressed because it is too large
Load Diff
+629
-629
File diff suppressed because it is too large
Load Diff
+618
-618
File diff suppressed because it is too large
Load Diff
+167
-167
File diff suppressed because it is too large
Load Diff
+65
-65
@@ -188,7 +188,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -223,7 +223,7 @@ static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -397,10 +397,10 @@ extern sp_digit sp_2048_sub_in_place_16(sp_digit* a, const sp_digit* b);
|
||||
*/
|
||||
static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
{
|
||||
sp_digit x;
|
||||
sp_digit b;
|
||||
sp_uint64 x;
|
||||
sp_uint64 b;
|
||||
|
||||
b = a[0];
|
||||
b = (sp_uint64)a[0];
|
||||
x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**8 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**16 */
|
||||
@@ -408,7 +408,7 @@ static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**64 */
|
||||
|
||||
/* rho = -1/m mod b */
|
||||
*rho = (sp_digit)0 - x;
|
||||
*rho = (sp_digit)((sp_int64)0 - (sp_int64)x);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -2361,7 +2361,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 32; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -2386,7 +2386,7 @@ static int sp_2048_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 32; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -2958,7 +2958,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -2993,7 +2993,7 @@ static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -3206,10 +3206,10 @@ extern void sp_3072_sqr_avx2_48(sp_digit* r, const sp_digit* a);
|
||||
*/
|
||||
static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
{
|
||||
sp_digit x;
|
||||
sp_digit b;
|
||||
sp_uint64 x;
|
||||
sp_uint64 b;
|
||||
|
||||
b = a[0];
|
||||
b = (sp_uint64)a[0];
|
||||
x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**8 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**16 */
|
||||
@@ -3217,7 +3217,7 @@ static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**64 */
|
||||
|
||||
/* rho = -1/m mod b */
|
||||
*rho = (sp_digit)0 - x;
|
||||
*rho = (sp_digit)((sp_int64)0 - (sp_int64)x);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -5066,7 +5066,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 48; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -5091,7 +5091,7 @@ static int sp_3072_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 48; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -5663,7 +5663,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -5698,7 +5698,7 @@ static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -5827,10 +5827,10 @@ extern void sp_4096_sqr_avx2_64(sp_digit* r, const sp_digit* a);
|
||||
*/
|
||||
static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
{
|
||||
sp_digit x;
|
||||
sp_digit b;
|
||||
sp_uint64 x;
|
||||
sp_uint64 b;
|
||||
|
||||
b = a[0];
|
||||
b = (sp_uint64)a[0];
|
||||
x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**8 */
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**16 */
|
||||
@@ -5838,7 +5838,7 @@ static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho)
|
||||
x *= 2 - b * x; /* here x*a==1 mod 2**64 */
|
||||
|
||||
/* rho = -1/m mod b */
|
||||
*rho = (sp_digit)0 - x;
|
||||
*rho = (sp_digit)((sp_int64)0 - (sp_int64)x);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -7027,7 +7027,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 64; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -7052,7 +7052,7 @@ static int sp_4096_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 64; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -7697,10 +7697,10 @@ static int sp_256_mod_mul_norm_4(sp_digit* r, const sp_digit* a, const sp_digit*
|
||||
t[5] += t[4] >> 32; t[4] &= 0xffffffff;
|
||||
t[6] += t[5] >> 32; t[5] &= 0xffffffff;
|
||||
t[7] += t[6] >> 32; t[6] &= 0xffffffff;
|
||||
r[0] = (sp_digit)((t[1] << 32) | t[0]);
|
||||
r[1] = (sp_digit)((t[3] << 32) | t[2]);
|
||||
r[2] = (sp_digit)((t[5] << 32) | t[4]);
|
||||
r[3] = (sp_digit)((t[7] << 32) | t[6]);
|
||||
r[0] = (sp_digit)(((sp_uint64)t[1] << 32) | (sp_uint64)t[0]);
|
||||
r[1] = (sp_digit)(((sp_uint64)t[3] << 32) | (sp_uint64)t[2]);
|
||||
r[2] = (sp_digit)(((sp_uint64)t[5] << 32) | (sp_uint64)t[4]);
|
||||
r[3] = (sp_digit)(((sp_uint64)t[7] << 32) | (sp_uint64)t[6]);
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
@@ -7731,7 +7731,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -7766,7 +7766,7 @@ static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -7832,7 +7832,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 4; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -7857,7 +7857,7 @@ static int sp_256_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 4; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -7964,7 +7964,7 @@ static void sp_256_mont_inv_4(sp_digit* r, const sp_digit* a, sp_digit* td)
|
||||
XMEMCPY(t, a, sizeof(sp_digit) * 4);
|
||||
for (i=254; i>=0; i--) {
|
||||
sp_256_mont_sqr_4(t, t, p256_mod, p256_mp_mod);
|
||||
if (p256_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p256_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_256_mont_mul_4(t, t, a, p256_mod, p256_mp_mod);
|
||||
}
|
||||
XMEMCPY(r, t, sizeof(sp_digit) * 4);
|
||||
@@ -8935,7 +8935,7 @@ static void sp_256_ecc_recode_6_4(const sp_digit* k, ecc_recode_256* v)
|
||||
}
|
||||
else if (++j < 4) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x3f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f);
|
||||
o -= 58;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -9138,7 +9138,7 @@ static void sp_256_mont_inv_avx2_4(sp_digit* r, const sp_digit* a, sp_digit* td)
|
||||
XMEMCPY(t, a, sizeof(sp_digit) * 4);
|
||||
for (i=254; i>=0; i--) {
|
||||
sp_256_mont_sqr_avx2_4(t, t, p256_mod, p256_mp_mod);
|
||||
if (p256_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p256_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_256_mont_mul_avx2_4(t, t, a, p256_mod, p256_mp_mod);
|
||||
}
|
||||
XMEMCPY(r, t, sizeof(sp_digit) * 4);
|
||||
@@ -11459,7 +11459,7 @@ static void sp_256_ecc_recode_7_4(const sp_digit* k, ecc_recode_256* v)
|
||||
}
|
||||
else if (++j < 4) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x7f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f);
|
||||
o -= 57;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -26383,12 +26383,12 @@ static int sp_384_mod_mul_norm_6(sp_digit* r, const sp_digit* a, const sp_digit*
|
||||
t[10] += t[9] >> 32; t[9] &= 0xffffffff;
|
||||
t[11] += t[10] >> 32; t[10] &= 0xffffffff;
|
||||
|
||||
r[0] = (sp_digit)((t[1] << 32) | t[0]);
|
||||
r[1] = (sp_digit)((t[3] << 32) | t[2]);
|
||||
r[2] = (sp_digit)((t[5] << 32) | t[4]);
|
||||
r[3] = (sp_digit)((t[7] << 32) | t[6]);
|
||||
r[4] = (sp_digit)((t[9] << 32) | t[8]);
|
||||
r[5] = (sp_digit)((t[11] << 32) | t[10]);
|
||||
r[0] = (sp_digit)(((sp_uint64)t[1] << 32) | (sp_uint64)t[0]);
|
||||
r[1] = (sp_digit)(((sp_uint64)t[3] << 32) | (sp_uint64)t[2]);
|
||||
r[2] = (sp_digit)(((sp_uint64)t[5] << 32) | (sp_uint64)t[4]);
|
||||
r[3] = (sp_digit)(((sp_uint64)t[7] << 32) | (sp_uint64)t[6]);
|
||||
r[4] = (sp_digit)(((sp_uint64)t[9] << 32) | (sp_uint64)t[8]);
|
||||
r[5] = (sp_digit)(((sp_uint64)t[11] << 32) | (sp_uint64)t[10]);
|
||||
}
|
||||
|
||||
SP_FREE_VAR(t, NULL, DYNAMIC_TYPE_ECC);
|
||||
@@ -26422,7 +26422,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -26457,7 +26457,7 @@ static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -26523,7 +26523,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 6; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -26548,7 +26548,7 @@ static int sp_384_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 6; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -26692,7 +26692,7 @@ static void sp_384_mont_inv_6(sp_digit* r, const sp_digit* a, sp_digit* td)
|
||||
XMEMCPY(t, a, sizeof(sp_digit) * 6);
|
||||
for (i=382; i>=0; i--) {
|
||||
sp_384_mont_sqr_6(t, t, p384_mod, p384_mp_mod);
|
||||
if (p384_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p384_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_384_mont_mul_6(t, t, a, p384_mod, p384_mp_mod);
|
||||
}
|
||||
XMEMCPY(r, t, sizeof(sp_digit) * 6);
|
||||
@@ -27669,7 +27669,7 @@ static void sp_384_ecc_recode_6_6(const sp_digit* k, ecc_recode_384* v)
|
||||
}
|
||||
else if (++j < 6) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x3f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f);
|
||||
o -= 58;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -27900,7 +27900,7 @@ static void sp_384_mont_inv_avx2_6(sp_digit* r, const sp_digit* a, sp_digit* td)
|
||||
XMEMCPY(t, a, sizeof(sp_digit) * 6);
|
||||
for (i=382; i>=0; i--) {
|
||||
sp_384_mont_sqr_avx2_6(t, t, p384_mod, p384_mp_mod);
|
||||
if (p384_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p384_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_384_mont_mul_avx2_6(t, t, a, p384_mod, p384_mp_mod);
|
||||
}
|
||||
XMEMCPY(r, t, sizeof(sp_digit) * 6);
|
||||
@@ -30252,7 +30252,7 @@ static void sp_384_ecc_recode_7_6(const sp_digit* k, ecc_recode_384* v)
|
||||
}
|
||||
else if (++j < 6) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x7f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f);
|
||||
o -= 57;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -50953,7 +50953,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -50988,7 +50988,7 @@ static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -51054,7 +51054,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 9; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -51079,7 +51079,7 @@ static int sp_521_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 9; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -51187,7 +51187,7 @@ static void sp_521_mont_inv_9(sp_digit* r, const sp_digit* a, sp_digit* td)
|
||||
XMEMCPY(t, a, sizeof(sp_digit) * 9);
|
||||
for (i=519; i>=0; i--) {
|
||||
sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod);
|
||||
if (p521_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p521_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_521_mont_mul_9(t, t, a, p521_mod, p521_mp_mod);
|
||||
}
|
||||
XMEMCPY(r, t, sizeof(sp_digit) * 9);
|
||||
@@ -52183,7 +52183,7 @@ static void sp_521_ecc_recode_6_9(const sp_digit* k, ecc_recode_521* v)
|
||||
}
|
||||
else if (++j < 9) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x3f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x3f);
|
||||
o -= 58;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -52386,7 +52386,7 @@ static void sp_521_mont_inv_avx2_9(sp_digit* r, const sp_digit* a, sp_digit* td)
|
||||
XMEMCPY(t, a, sizeof(sp_digit) * 9);
|
||||
for (i=519; i>=0; i--) {
|
||||
sp_521_mont_sqr_avx2_9(t, t, p521_mod, p521_mp_mod);
|
||||
if (p521_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p521_mod_minus_2[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_521_mont_mul_avx2_9(t, t, a, p521_mod, p521_mp_mod);
|
||||
}
|
||||
XMEMCPY(r, t, sizeof(sp_digit) * 9);
|
||||
@@ -54869,7 +54869,7 @@ static void sp_521_ecc_recode_7_9(const sp_digit* k, ecc_recode_521* v)
|
||||
}
|
||||
else if (++j < 9) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x7f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f);
|
||||
o -= 57;
|
||||
n >>= o;
|
||||
}
|
||||
@@ -91333,7 +91333,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y)
|
||||
XMEMCPY(t, y, sizeof(sp_digit) * 9);
|
||||
for (i=518; i>=0; i--) {
|
||||
sp_521_mont_sqr_avx2_9(t, t, p521_mod, p521_mp_mod);
|
||||
if (p521_sqrt_power[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p521_sqrt_power[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_521_mont_mul_avx2_9(t, t, y, p521_mod, p521_mp_mod);
|
||||
}
|
||||
XMEMCPY(y, t, sizeof(sp_digit) * 9);
|
||||
@@ -91347,7 +91347,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y)
|
||||
XMEMCPY(t, y, sizeof(sp_digit) * 9);
|
||||
for (i=518; i>=0; i--) {
|
||||
sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod);
|
||||
if (p521_sqrt_power[i / 64] & ((sp_digit)1 << (i % 64)))
|
||||
if (p521_sqrt_power[i / 64] & ((sp_uint64)1 << (i % 64)))
|
||||
sp_521_mont_mul_9(t, t, y, p521_mod, p521_mp_mod);
|
||||
}
|
||||
XMEMCPY(y, t, sizeof(sp_digit) * 9);
|
||||
@@ -91870,7 +91870,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i] << s);
|
||||
r[j] |= ((sp_uint64)a->dp[i] << s);
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
s = 64U - s;
|
||||
if (j + 1 >= size) {
|
||||
@@ -91905,7 +91905,7 @@ static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a)
|
||||
|
||||
r[0] = 0;
|
||||
for (i = 0; i < (unsigned int)a->used && j < size; i++) {
|
||||
r[j] |= ((sp_digit)a->dp[i]) << s;
|
||||
r[j] |= ((sp_uint64)a->dp[i]) << s;
|
||||
if (s + DIGIT_BIT >= 64) {
|
||||
r[j] &= 0xffffffffffffffffl;
|
||||
if (j + 1 >= size) {
|
||||
@@ -91971,7 +91971,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
r->dp[j] |= (mp_digit)(a[i] << s);
|
||||
r->dp[j] |= (mp_digit)((sp_uint64)a[i] << s);
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
s = DIGIT_BIT - s;
|
||||
r->dp[++j] = (mp_digit)(a[i] >> s);
|
||||
@@ -91996,7 +91996,7 @@ static int sp_1024_to_mp(const sp_digit* a, mp_int* r)
|
||||
|
||||
r->dp[0] = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
r->dp[j] |= ((mp_digit)a[i]) << s;
|
||||
r->dp[j] |= ((sp_uint64)a[i]) << s;
|
||||
if (s + 64 >= DIGIT_BIT) {
|
||||
#if DIGIT_BIT != 32 && DIGIT_BIT != 64
|
||||
r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
|
||||
@@ -93058,7 +93058,7 @@ static void sp_1024_ecc_recode_7_16(const sp_digit* k, ecc_recode_1024* v)
|
||||
}
|
||||
else if (++j < 16) {
|
||||
n = k[j];
|
||||
y |= (word8)((n << (64 - o)) & 0x7f);
|
||||
y |= (word8)(((sp_uint64)n << (64 - o)) & 0x7f);
|
||||
o -= 57;
|
||||
n >>= o;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user