From a8f5602e1033ef1ca5c734b9cdc58590aa4322fa Mon Sep 17 00:00:00 2001 From: Tesfa Mael Date: Thu, 25 Jun 2020 08:01:05 -0700 Subject: [PATCH 1/2] Correct mod calculation --- wolfcrypt/src/sp_c32.c | 10 +++++----- wolfcrypt/src/sp_c64.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wolfcrypt/src/sp_c32.c b/wolfcrypt/src/sp_c32.c index 44fbc7774..2081726a0 100644 --- a/wolfcrypt/src/sp_c32.c +++ b/wolfcrypt/src/sp_c32.c @@ -1851,7 +1851,7 @@ static int sp_2048_div_45(const sp_digit* a, const sp_digit* d, sp_digit* m, sp_2048_mul_d_45(t2, sd, r1); sp_2048_sub_45(t1, t1, t2); XMEMCPY(r, t1, sizeof(*r) * 2U * 45U); - for (i=0; i<43; i++) { + for (i=0; i<44; i++) { r[i+1] += r[i] >> 23; r[i] &= 0x7fffff; } @@ -2802,7 +2802,7 @@ static int sp_2048_div_90(const sp_digit* a, const sp_digit* d, sp_digit* m, sp_2048_mul_d_90(t2, sd, r1); sp_2048_sub_90(t1, t1, t2); XMEMCPY(r, t1, sizeof(*r) * 2U * 90U); - for (i=0; i<88; i++) { + for (i=0; i<89; i++) { r[i+1] += r[i] >> 23; r[i] &= 0x7fffff; } @@ -6679,7 +6679,7 @@ static int sp_3072_div_134(const sp_digit* a, const sp_digit* d, sp_digit* m, sp_3072_mul_d_134(t2, sd, r1); sp_3072_sub_134(t1, t1, t2); XMEMCPY(r, t1, sizeof(*r) * 2U * 134U); - for (i=0; i<132; i++) { + for (i=0; i<133; i++) { r[i+1] += r[i] >> 23; r[i] &= 0x7fffff; } @@ -9756,7 +9756,7 @@ static int sp_4096_div_98(const sp_digit* a, const sp_digit* d, sp_digit* m, sp_4096_mul_d_98(t2, sd, r1); sp_4096_sub_98(t1, t1, t2); XMEMCPY(r, t1, sizeof(*r) * 2U * 98U); - for (i=0; i<96; i++) { + for (i=0; i<97; i++) { r[i+1] += r[i] >> 21; r[i] &= 0x1fffff; } @@ -10720,7 +10720,7 @@ static int sp_4096_div_196(const sp_digit* a, const sp_digit* d, sp_digit* m, sp_4096_mul_d_196(t2, sd, r1); sp_4096_sub_196(t1, t1, t2); XMEMCPY(r, t1, sizeof(*r) * 2U * 196U); - for (i=0; i<194; i++) { + for (i=0; i<195; i++) { r[i+1] += r[i] >> 21; r[i] &= 0x1fffff; } diff --git a/wolfcrypt/src/sp_c64.c b/wolfcrypt/src/sp_c64.c index 86f8dc334..c9131f003 100644 --- a/wolfcrypt/src/sp_c64.c +++ b/wolfcrypt/src/sp_c64.c @@ -9977,7 +9977,7 @@ static int sp_4096_div_39(const sp_digit* a, const sp_digit* d, sp_digit* m, sp_4096_mul_d_39(t2, sd, r1); sp_4096_sub_39(t1, t1, t2); XMEMCPY(r, t1, sizeof(*r) * 2U * 39U); - for (i=0; i<37; i++) { + for (i=0; i<38; i++) { r[i+1] += r[i] >> 53; r[i] &= 0x1fffffffffffffL; } @@ -10989,7 +10989,7 @@ static int sp_4096_div_78(const sp_digit* a, const sp_digit* d, sp_digit* m, sp_4096_mul_d_78(t2, sd, r1); sp_4096_sub_78(t1, t1, t2); XMEMCPY(r, t1, sizeof(*r) * 2U * 78U); - for (i=0; i<76; i++) { + for (i=0; i<77; i++) { r[i+1] += r[i] >> 53; r[i] &= 0x1fffffffffffffL; } From 60d6f616c236d410af98739470e90b0ee1bc0e62 Mon Sep 17 00:00:00 2001 From: Tesfa Mael Date: Thu, 25 Jun 2020 08:06:14 -0700 Subject: [PATCH 2/2] Fix typo --- wolfcrypt/src/sp_x86_64.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/wolfcrypt/src/sp_x86_64.c b/wolfcrypt/src/sp_x86_64.c index b3af97702..435aa2234 100644 --- a/wolfcrypt/src/sp_x86_64.c +++ b/wolfcrypt/src/sp_x86_64.c @@ -320,7 +320,7 @@ extern int64_t sp_2048_cmp_16(const sp_digit* a, const sp_digit* b); /* Divide d in a and put remainder into r (m*d + r = a) * m is not calculated as it is not needed at this time. * - * a Nmber to be divided. + * a Number to be divided. * d Number to divide with. * m Multiplier result. * r Remainder from the division. @@ -850,7 +850,7 @@ extern int64_t sp_2048_cmp_32(const sp_digit* a, const sp_digit* b); /* Divide d in a and put remainder into r (m*d + r = a) * m is not calculated as it is not needed at this time. * - * a Nmber to be divided. + * a Number to be divided. * d Number to divide with. * m Multiplier result. * r Remainder from the division. @@ -922,7 +922,7 @@ extern sp_digit sp_2048_sub_32(sp_digit* r, const sp_digit* a, const sp_digit* b /* Divide d in a and put remainder into r (m*d + r = a) * m is not calculated as it is not needed at this time. * - * a Nmber to be divided. + * a Number to be divided. * d Number to divide with. * m Multiplier result. * r Remainder from the division. @@ -2516,7 +2516,7 @@ extern int64_t sp_3072_cmp_24(const sp_digit* a, const sp_digit* b); /* Divide d in a and put remainder into r (m*d + r = a) * m is not calculated as it is not needed at this time. * - * a Nmber to be divided. + * a Number to be divided. * d Number to divide with. * m Multiplier result. * r Remainder from the division. @@ -3046,7 +3046,7 @@ extern int64_t sp_3072_cmp_48(const sp_digit* a, const sp_digit* b); /* Divide d in a and put remainder into r (m*d + r = a) * m is not calculated as it is not needed at this time. * - * a Nmber to be divided. + * a Number to be divided. * d Number to divide with. * m Multiplier result. * r Remainder from the division. @@ -3118,7 +3118,7 @@ extern sp_digit sp_3072_sub_48(sp_digit* r, const sp_digit* a, const sp_digit* b /* Divide d in a and put remainder into r (m*d + r = a) * m is not calculated as it is not needed at this time. * - * a Nmber to be divided. + * a Number to be divided. * d Number to divide with. * m Multiplier result. * r Remainder from the division. @@ -4690,7 +4690,7 @@ extern int64_t sp_4096_cmp_64(const sp_digit* a, const sp_digit* b); /* Divide d in a and put remainder into r (m*d + r = a) * m is not calculated as it is not needed at this time. * - * a Nmber to be divided. + * a Number to be divided. * d Number to divide with. * m Multiplier result. * r Remainder from the division. @@ -4762,7 +4762,7 @@ extern sp_digit sp_4096_sub_64(sp_digit* r, const sp_digit* a, const sp_digit* b /* Divide d in a and put remainder into r (m*d + r = a) * m is not calculated as it is not needed at this time. * - * a Nmber to be divided. + * a Number to be divided. * d Number to divide with. * m Multiplier result. * r Remainder from the division. @@ -22495,7 +22495,7 @@ static void sp_256_mask_4(sp_digit* r, const sp_digit* a, sp_digit m) /* Divide d in a and put remainder into r (m*d + r = a) * m is not calculated as it is not needed at this time. * - * a Nmber to be divided. + * a Number to be divided. * d Number to divide with. * m Multiplier result. * r Remainder from the division. @@ -28352,7 +28352,7 @@ static void sp_384_mask_6(sp_digit* r, const sp_digit* a, sp_digit m) /* Divide d in a and put remainder into r (m*d + r = a) * m is not calculated as it is not needed at this time. * - * a Nmber to be divided. + * a Number to be divided. * d Number to divide with. * m Multiplier result. * r Remainder from the division.