SP: mod_exp with exponent of 0 is invalid

Don't allow exponenetiation by 0 as it is cryptographically invalid and
not supported by the implementation.
Also check for even modulus in mod_exp.
This commit is contained in:
Sean Parkinson
2021-11-09 11:53:24 +10:00
parent dd833807d8
commit 8606788198
9 changed files with 2908 additions and 1488 deletions

View File

@ -3897,14 +3897,14 @@ SP_NOINLINE static void sp_2048_mont_reduce_32(sp_digit* a, const sp_digit* m,
sp_2048_cond_sub_32(a - 32, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_mul_32(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -3916,9 +3916,9 @@ static void sp_2048_mont_mul_32(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_sqr_32(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -4721,7 +4721,9 @@ static WC_INLINE int sp_2048_mod_32(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -4741,11 +4743,20 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -4861,7 +4872,9 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -4881,11 +4894,20 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -6006,14 +6028,14 @@ SP_NOINLINE static void sp_2048_mont_reduce_64(sp_digit* a, const sp_digit* m,
sp_2048_cond_sub_64(a - 64, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_mul_64(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -6025,9 +6047,9 @@ static void sp_2048_mont_mul_64(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_sqr_64(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -7331,7 +7353,9 @@ static WC_INLINE int sp_2048_mod_64(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -7351,11 +7375,20 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -7462,7 +7495,9 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -7482,11 +7517,20 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -8644,7 +8688,9 @@ static void sp_2048_lshift_64(sp_digit* r, sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -8665,11 +8711,17 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -14518,14 +14570,14 @@ SP_NOINLINE static void sp_3072_mont_reduce_48(sp_digit* a, const sp_digit* m,
sp_3072_cond_sub_48(a - 48, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_mul_48(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -14537,9 +14589,9 @@ static void sp_3072_mont_mul_48(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_sqr_48(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -15630,7 +15682,9 @@ static WC_INLINE int sp_3072_mod_48(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -15650,11 +15704,20 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -15770,7 +15833,9 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -15790,11 +15855,20 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -17363,14 +17437,14 @@ SP_NOINLINE static void sp_3072_mont_reduce_96(sp_digit* a, const sp_digit* m,
sp_3072_cond_sub_96(a - 96, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_mul_96(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -17382,9 +17456,9 @@ static void sp_3072_mont_mul_96(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_sqr_96(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -19168,7 +19242,9 @@ static WC_INLINE int sp_3072_mod_96(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -19188,11 +19264,20 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -19299,7 +19384,9 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -19319,11 +19406,20 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -20753,7 +20849,9 @@ static void sp_3072_lshift_96(sp_digit* r, sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -20774,11 +20872,17 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 289, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 289, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -25362,14 +25466,14 @@ SP_NOINLINE static void sp_4096_mont_reduce_128(sp_digit* a, const sp_digit* m,
sp_4096_cond_sub_128(a - 128, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_4096_mont_mul_128(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -25381,9 +25485,9 @@ static void sp_4096_mont_mul_128(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_4096_mont_sqr_128(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -27647,7 +27751,9 @@ static WC_INLINE int sp_4096_mod_128(sp_digit* r, const sp_digit* a, const sp_di
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -27667,11 +27773,20 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -27778,7 +27893,9 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -27798,11 +27915,20 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -29504,7 +29630,9 @@ static void sp_4096_lshift_128(sp_digit* r, sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -29525,11 +29653,17 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 385, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 385, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -29704,12 +29838,12 @@ static const sp_digit p256_mod[8] = {
0xffffffff,0xffffffff,0xffffffff,0x00000000,0x00000000,0x00000000,
0x00000001,0xffffffff
};
/* The Montogmery normalizer for modulus of the curve P256. */
/* The Montgomery normalizer for modulus of the curve P256. */
static const sp_digit p256_norm_mod[8] = {
0x00000001,0x00000000,0x00000000,0xffffffff,0xffffffff,0xffffffff,
0xfffffffe,0x00000000
};
/* The Montogmery multiplier for modulus of the curve P256. */
/* The Montgomery multiplier for modulus of the curve P256. */
static const sp_digit p256_mp_mod = 0x00000001;
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
@ -29725,14 +29859,14 @@ static const sp_digit p256_order2[8] = {
0x00000000,0xffffffff
};
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery normalizer for order of the curve P256. */
/* The Montgomery normalizer for order of the curve P256. */
static const sp_digit p256_norm_order[8] = {
0x039cdaaf,0x0c46353d,0x58e8617b,0x43190552,0x00000000,0x00000000,
0xffffffff,0x00000000
};
#endif
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery multiplier for order of the curve P256. */
/* The Montgomery multiplier for order of the curve P256. */
static const sp_digit p256_mp_order = 0xee00bc4f;
#endif
/* The base point of curve P256. */
@ -30896,7 +31030,7 @@ static sp_digit sp_256_sub_8(sp_digit* r, const sp_digit* a,
}
#endif /* WOLFSSL_SP_SMALL */
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -31323,14 +31457,14 @@ static int sp_256_point_to_ecc_point_8(const sp_point_256* p, ecc_point* pm)
return err;
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
SP_NOINLINE static void sp_256_mont_mul_8(sp_digit* r, const sp_digit* a, const sp_digit* b,
const sp_digit* m, sp_digit mp)
@ -31985,9 +32119,9 @@ SP_NOINLINE static void sp_256_mont_mul_8(sp_digit* r, const sp_digit* a, const
/* Square the Montgomery form number mod the modulus (prime). (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
SP_NOINLINE static void sp_256_mont_sqr_8(sp_digit* r, const sp_digit* a, const sp_digit* m,
sp_digit mp)
@ -32502,10 +32636,10 @@ SP_NOINLINE static void sp_256_mont_sqr_8(sp_digit* r, const sp_digit* a, const
/* Square the Montgomery form number a number of times. (r = a ^ n mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* n Number of times to square.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_256_mont_sqr_n_8(sp_digit* r, const sp_digit* a, int n,
const sp_digit* m, sp_digit mp)
@ -32979,8 +33113,8 @@ static void sp_256_map_8(sp_point_256* r, const sp_point_256* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
static void sp_256_mont_add_8(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -33050,7 +33184,7 @@ static void sp_256_mont_add_8(sp_digit* r, const sp_digit* a, const sp_digit* b,
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
static void sp_256_mont_dbl_8(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -33103,7 +33237,7 @@ static void sp_256_mont_dbl_8(sp_digit* r, const sp_digit* a, const sp_digit* m)
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
static void sp_256_mont_tpl_8(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -33200,8 +33334,8 @@ static void sp_256_mont_tpl_8(sp_digit* r, const sp_digit* a, const sp_digit* m)
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
static void sp_256_mont_sub_8(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -35172,7 +35306,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r,
* km Scalar to multiply by.
* p Point to multiply.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -36721,7 +36855,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -39212,12 +39346,12 @@ static const sp_digit p384_mod[12] = {
0xffffffff,0x00000000,0x00000000,0xffffffff,0xfffffffe,0xffffffff,
0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff
};
/* The Montogmery normalizer for modulus of the curve P384. */
/* The Montgomery normalizer for modulus of the curve P384. */
static const sp_digit p384_norm_mod[12] = {
0x00000001,0xffffffff,0xffffffff,0x00000000,0x00000001,0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
};
/* The Montogmery multiplier for modulus of the curve P384. */
/* The Montgomery multiplier for modulus of the curve P384. */
static sp_digit p384_mp_mod = 0x00000001;
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
@ -39233,14 +39367,14 @@ static const sp_digit p384_order2[12] = {
0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff
};
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery normalizer for order of the curve P384. */
/* The Montgomery normalizer for order of the curve P384. */
static const sp_digit p384_norm_order[12] = {
0x333ad68d,0x1313e695,0xb74f5885,0xa7e5f24d,0x0bc8d220,0x389cb27e,
0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
};
#endif
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery multiplier for order of the curve P384. */
/* The Montgomery multiplier for order of the curve P384. */
static sp_digit p384_mp_order = 0xe88fdc45;
#endif
/* The base point of curve P384. */
@ -41329,7 +41463,7 @@ static sp_digit sp_384_sub_12(sp_digit* r, const sp_digit* a,
}
#endif /* WOLFSSL_SP_SMALL */
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -41873,14 +42007,14 @@ SP_NOINLINE static void sp_384_mont_reduce_12(sp_digit* a, const sp_digit* m,
sp_384_cond_sub_12(a - 12, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_mul_12(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -41892,9 +42026,9 @@ static void sp_384_mont_mul_12(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_sqr_12(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -41907,10 +42041,10 @@ static void sp_384_mont_sqr_12(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number a number of times. (r = a ^ n mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* n Number of times to square.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_sqr_n_12(sp_digit* r, const sp_digit* a, int n,
const sp_digit* m, sp_digit mp)
@ -42250,8 +42384,8 @@ static void sp_384_map_12(sp_point_384* r, const sp_point_384* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
static void sp_384_mont_add_12(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -42266,7 +42400,7 @@ static void sp_384_mont_add_12(sp_digit* r, const sp_digit* a, const sp_digit* b
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
static void sp_384_mont_dbl_12(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -42280,7 +42414,7 @@ static void sp_384_mont_dbl_12(sp_digit* r, const sp_digit* a, const sp_digit* m
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
static void sp_384_mont_tpl_12(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -42402,8 +42536,8 @@ static sp_digit sp_384_cond_add_12(sp_digit* r, const sp_digit* a, const sp_digi
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
static void sp_384_mont_sub_12(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -44377,7 +44511,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r,
* km Scalar to multiply by.
* p Point to multiply.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -45926,7 +46060,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -52048,7 +52182,7 @@ static const sp_digit p1024_mod[32] = {
0xb3e01a2e,0xbe9ae358,0x9cb48261,0x416c0ce1,0xdad0657a,0x65c61198,
0x0a563fda,0x997abb1f
};
/* The Montogmery normalizer for modulus of the curve P1024. */
/* The Montgomery normalizer for modulus of the curve P1024. */
static const sp_digit p1024_norm_mod[32] = {
0x0157a015,0x99927f85,0x53853178,0x7f3a20ef,0x767a824f,0x031c17dc,
0xa968e0e0,0x606b2950,0xe3c3f655,0x5830c3ad,0xce7ad57d,0x49500b57,
@ -52057,7 +52191,7 @@ static const sp_digit p1024_norm_mod[32] = {
0x4c1fe5d1,0x41651ca7,0x634b7d9e,0xbe93f31e,0x252f9a85,0x9a39ee67,
0xf5a9c025,0x668544e0
};
/* The Montogmery multiplier for modulus of the curve P1024. */
/* The Montgomery multiplier for modulus of the curve P1024. */
static sp_digit p1024_mp_mod = 0x7c8f2f3d;
#if defined(WOLFSSL_SP_SMALL) || defined(HAVE_ECC_CHECK_KEY)
/* The order of the curve P1024. */
@ -53234,7 +53368,7 @@ static WC_INLINE int sp_1024_mod_32(sp_digit* r, const sp_digit* a, const sp_dig
return sp_1024_div_32(a, m, NULL, r);
}
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -53828,14 +53962,14 @@ SP_NOINLINE static void sp_1024_mont_reduce_32(sp_digit* a, const sp_digit* m,
sp_1024_cond_sub_32(a - 32, a, m, ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_1024_mont_mul_32(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -53847,9 +53981,9 @@ static void sp_1024_mont_mul_32(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_1024_mont_sqr_32(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -53968,8 +54102,8 @@ static void sp_1024_map_32(sp_point_1024* r, const sp_point_1024* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
static void sp_1024_mont_add_32(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -54138,7 +54272,7 @@ static void sp_1024_mont_add_32(sp_digit* r, const sp_digit* a, const sp_digit*
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
static void sp_1024_mont_dbl_32(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -54290,7 +54424,7 @@ static void sp_1024_mont_dbl_32(sp_digit* r, const sp_digit* a, const sp_digit*
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
static void sp_1024_mont_tpl_32(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -54597,8 +54731,8 @@ static void sp_1024_mont_tpl_32(sp_digit* r, const sp_digit* a, const sp_digit*
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
static void sp_1024_mont_sub_32(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -60547,7 +60681,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.

View File

@ -2637,14 +2637,14 @@ SP_NOINLINE static void sp_2048_mont_reduce_16(sp_digit* a, const sp_digit* m,
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_mul_16(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -2656,9 +2656,9 @@ static void sp_2048_mont_mul_16(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_sqr_16(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -3223,7 +3223,9 @@ static WC_INLINE int sp_2048_mod_16(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -3243,11 +3245,20 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 32), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 32), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -3363,7 +3374,9 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -3383,11 +3396,20 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 32), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 32), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -3981,14 +4003,14 @@ SP_NOINLINE static void sp_2048_mont_reduce_32(sp_digit* a, const sp_digit* m,
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_mul_32(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -4000,9 +4022,9 @@ static void sp_2048_mont_mul_32(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_sqr_32(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -4788,7 +4810,9 @@ static WC_INLINE int sp_2048_mod_32(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -4808,11 +4832,20 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -4919,7 +4952,9 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -4939,11 +4974,20 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -5806,7 +5850,9 @@ static void sp_2048_lshift_32(sp_digit* r, sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -5827,11 +5873,17 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 97, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 97, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -10056,14 +10108,14 @@ SP_NOINLINE static void sp_3072_mont_reduce_24(sp_digit* a, const sp_digit* m,
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_mul_24(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -10075,9 +10127,9 @@ static void sp_3072_mont_mul_24(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_sqr_24(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -10794,7 +10846,9 @@ static WC_INLINE int sp_3072_mod_24(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -10814,11 +10868,20 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 48), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 48), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -10934,7 +10997,9 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -10954,11 +11019,20 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 48), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 48), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -11768,14 +11842,14 @@ SP_NOINLINE static void sp_3072_mont_reduce_48(sp_digit* a, const sp_digit* m,
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_mul_48(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -11787,9 +11861,9 @@ static void sp_3072_mont_mul_48(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_sqr_48(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -12783,7 +12857,9 @@ static WC_INLINE int sp_3072_mod_48(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -12803,11 +12879,20 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -12914,7 +12999,9 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -12934,11 +13021,20 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -13925,7 +14021,9 @@ static void sp_3072_lshift_48(sp_digit* r, sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -13946,11 +14044,17 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 145, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 145, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -16740,14 +16844,14 @@ SP_NOINLINE static void sp_4096_mont_reduce_64(sp_digit* a, const sp_digit* m,
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_4096_mont_mul_64(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -16759,9 +16863,9 @@ static void sp_4096_mont_mul_64(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_4096_mont_sqr_64(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -17963,7 +18067,9 @@ static WC_INLINE int sp_4096_mod_64(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -17983,11 +18089,20 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -18094,7 +18209,9 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -18114,11 +18231,20 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -19229,7 +19355,9 @@ static void sp_4096_lshift_64(sp_digit* r, sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -19250,11 +19378,17 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -19430,12 +19564,12 @@ static const sp_digit p256_mod[4] = {
0xffffffffffffffffL,0x00000000ffffffffL,0x0000000000000000L,
0xffffffff00000001L
};
/* The Montogmery normalizer for modulus of the curve P256. */
/* The Montgomery normalizer for modulus of the curve P256. */
static const sp_digit p256_norm_mod[4] = {
0x0000000000000001L,0xffffffff00000000L,0xffffffffffffffffL,
0x00000000fffffffeL
};
/* The Montogmery multiplier for modulus of the curve P256. */
/* The Montgomery multiplier for modulus of the curve P256. */
static const sp_digit p256_mp_mod = 0x0000000000000001;
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
@ -19451,14 +19585,14 @@ static const sp_digit p256_order2[4] = {
0xffffffff00000000L
};
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery normalizer for order of the curve P256. */
/* The Montgomery normalizer for order of the curve P256. */
static const sp_digit p256_norm_order[4] = {
0x0c46353d039cdaafL,0x4319055258e8617bL,0x0000000000000000L,
0x00000000ffffffffL
};
#endif
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery multiplier for order of the curve P256. */
/* The Montgomery multiplier for order of the curve P256. */
static const sp_digit p256_mp_order = 0xccd1c8aaee00bc4fL;
#endif
#ifdef WOLFSSL_SP_SMALL
@ -19798,7 +19932,7 @@ static sp_digit sp_256_sub_4(sp_digit* r, const sp_digit* a,
return (sp_digit)r;
}
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -20091,14 +20225,14 @@ static void sp_256_cond_copy_4(sp_digit* r, const sp_digit* a, sp_digit m)
);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
SP_NOINLINE static void sp_256_mont_mul_4(sp_digit* r, const sp_digit* a, const sp_digit* b,
const sp_digit* m, sp_digit mp)
@ -20285,9 +20419,9 @@ SP_NOINLINE static void sp_256_mont_mul_4(sp_digit* r, const sp_digit* a, const
/* Square the Montgomery form number mod the modulus (prime). (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
SP_NOINLINE static void sp_256_mont_sqr_4(sp_digit* r, const sp_digit* a, const sp_digit* m,
sp_digit mp)
@ -20438,10 +20572,10 @@ SP_NOINLINE static void sp_256_mont_sqr_4(sp_digit* r, const sp_digit* a, const
/* Square the Montgomery form number a number of times. (r = a ^ n mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* n Number of times to square.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_256_mont_sqr_n_4(sp_digit* r, const sp_digit* a, int n,
const sp_digit* m, sp_digit mp)
@ -20850,8 +20984,8 @@ static void sp_256_map_4(sp_point_256* r, const sp_point_256* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
static void sp_256_mont_add_4(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -20885,7 +21019,7 @@ static void sp_256_mont_add_4(sp_digit* r, const sp_digit* a, const sp_digit* b,
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
static void sp_256_mont_dbl_4(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -20918,7 +21052,7 @@ static void sp_256_mont_dbl_4(sp_digit* r, const sp_digit* a, const sp_digit* m)
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
static void sp_256_mont_tpl_4(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -20964,8 +21098,8 @@ static void sp_256_mont_tpl_4(sp_digit* r, const sp_digit* a, const sp_digit* m)
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
static void sp_256_mont_sub_4(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -21231,8 +21365,8 @@ static void sp_256_proj_point_dbl_4(sp_point_256* r, const sp_point_256* p, sp_d
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
static void sp_256_mont_sub_dbl_4(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -21278,8 +21412,8 @@ static void sp_256_mont_sub_dbl_4(sp_digit* r, const sp_digit* a, const sp_digit
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
static void sp_256_mont_dbl_sub_4(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -23082,7 +23216,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r,
* km Scalar to multiply by.
* p Point to multiply.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -37065,7 +37199,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -39393,12 +39527,12 @@ static const sp_digit p384_mod[6] = {
0x00000000ffffffffL,0xffffffff00000000L,0xfffffffffffffffeL,
0xffffffffffffffffL,0xffffffffffffffffL,0xffffffffffffffffL
};
/* The Montogmery normalizer for modulus of the curve P384. */
/* The Montgomery normalizer for modulus of the curve P384. */
static const sp_digit p384_norm_mod[6] = {
0xffffffff00000001L,0x00000000ffffffffL,0x0000000000000001L,
0x0000000000000000L,0x0000000000000000L,0x0000000000000000L
};
/* The Montogmery multiplier for modulus of the curve P384. */
/* The Montgomery multiplier for modulus of the curve P384. */
static sp_digit p384_mp_mod = 0x0000000100000001;
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
@ -39414,14 +39548,14 @@ static const sp_digit p384_order2[6] = {
0xffffffffffffffffL,0xffffffffffffffffL,0xffffffffffffffffL
};
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery normalizer for order of the curve P384. */
/* The Montgomery normalizer for order of the curve P384. */
static const sp_digit p384_norm_order[6] = {
0x1313e695333ad68dL,0xa7e5f24db74f5885L,0x389cb27e0bc8d220L,
0x0000000000000000L,0x0000000000000000L,0x0000000000000000L
};
#endif
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery multiplier for order of the curve P384. */
/* The Montgomery multiplier for order of the curve P384. */
static sp_digit p384_mp_order = 0x6ed46089e88fdc45L;
#endif
#ifdef WOLFSSL_SP_SMALL
@ -40045,7 +40179,7 @@ static sp_digit sp_384_sub_6(sp_digit* r, const sp_digit* a,
return (sp_digit)r;
}
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -40499,14 +40633,14 @@ SP_NOINLINE static void sp_384_mont_reduce_6(sp_digit* a, const sp_digit* m,
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_mul_6(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -40518,9 +40652,9 @@ static void sp_384_mont_mul_6(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_sqr_6(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -40533,10 +40667,10 @@ static void sp_384_mont_sqr_6(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number a number of times. (r = a ^ n mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* n Number of times to square.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_sqr_n_6(sp_digit* r, const sp_digit* a, int n,
const sp_digit* m, sp_digit mp)
@ -40824,8 +40958,8 @@ static void sp_384_map_6(sp_point_384* r, const sp_point_384* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
static void sp_384_mont_add_6(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -40840,7 +40974,7 @@ static void sp_384_mont_add_6(sp_digit* r, const sp_digit* a, const sp_digit* b,
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
static void sp_384_mont_dbl_6(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -40854,7 +40988,7 @@ static void sp_384_mont_dbl_6(sp_digit* r, const sp_digit* a, const sp_digit* m)
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
static void sp_384_mont_tpl_6(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -40937,8 +41071,8 @@ static sp_digit sp_384_cond_add_6(sp_digit* r, const sp_digit* a, const sp_digit
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
static void sp_384_mont_sub_6(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -42979,7 +43113,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r,
* km Scalar to multiply by.
* p Point to multiply.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -62784,7 +62918,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -66189,7 +66323,7 @@ static const sp_digit p1024_mod[16] = {
0xbe9ae358b3e01a2eL,0x416c0ce19cb48261L,0x65c61198dad0657aL,
0x997abb1f0a563fdaL
};
/* The Montogmery normalizer for modulus of the curve P1024. */
/* The Montgomery normalizer for modulus of the curve P1024. */
static const sp_digit p1024_norm_mod[16] = {
0x99927f850157a015L,0x7f3a20ef53853178L,0x031c17dc767a824fL,
0x606b2950a968e0e0L,0x5830c3ade3c3f655L,0x49500b57ce7ad57dL,
@ -66198,7 +66332,7 @@ static const sp_digit p1024_norm_mod[16] = {
0x41651ca74c1fe5d1L,0xbe93f31e634b7d9eL,0x9a39ee67252f9a85L,
0x668544e0f5a9c025L
};
/* The Montogmery multiplier for modulus of the curve P1024. */
/* The Montgomery multiplier for modulus of the curve P1024. */
static sp_digit p1024_mp_mod = 0x290420077c8f2f3d;
#if defined(WOLFSSL_SP_SMALL) || defined(HAVE_ECC_CHECK_KEY)
/* The order of the curve P1024. */
@ -66908,7 +67042,7 @@ static WC_INLINE int sp_1024_mod_16(sp_digit* r, const sp_digit* a, const sp_dig
return sp_1024_div_16(a, m, NULL, r);
}
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -67500,14 +67634,14 @@ SP_NOINLINE static void sp_1024_mont_reduce_16(sp_digit* a, const sp_digit* m,
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_1024_mont_mul_16(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -67519,9 +67653,9 @@ static void sp_1024_mont_mul_16(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_1024_mont_sqr_16(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -67640,8 +67774,8 @@ static void sp_1024_map_16(sp_point_1024* r, const sp_point_1024* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
static void sp_1024_mont_add_16(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -67742,7 +67876,7 @@ static void sp_1024_mont_add_16(sp_digit* r, const sp_digit* a, const sp_digit*
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
static void sp_1024_mont_dbl_16(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -67834,7 +67968,7 @@ static void sp_1024_mont_dbl_16(sp_digit* r, const sp_digit* a, const sp_digit*
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
static void sp_1024_mont_tpl_16(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -67995,8 +68129,8 @@ static void sp_1024_mont_tpl_16(sp_digit* r, const sp_digit* a, const sp_digit*
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
static void sp_1024_mont_sub_16(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -73266,7 +73400,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.

View File

@ -22895,14 +22895,14 @@ SP_NOINLINE static void sp_2048_mont_reduce_32(sp_digit* a, const sp_digit* m,
);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_mul_32(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -22914,9 +22914,9 @@ static void sp_2048_mont_mul_32(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_sqr_32(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -23780,7 +23780,9 @@ static WC_INLINE int sp_2048_mod_32(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -23800,11 +23802,20 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -23920,7 +23931,9 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -23940,11 +23953,20 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -25777,14 +25799,14 @@ SP_NOINLINE static void sp_2048_mont_reduce_64(sp_digit* a, const sp_digit* m,
);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_mul_64(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -25796,9 +25818,9 @@ static void sp_2048_mont_mul_64(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_sqr_64(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -27211,7 +27233,9 @@ static WC_INLINE int sp_2048_mod_64(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -27231,11 +27255,20 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -27342,7 +27375,9 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -27362,11 +27397,20 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -29583,7 +29627,9 @@ static void sp_2048_lshift_64(sp_digit* r, const sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -29604,11 +29650,17 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -73895,14 +73947,14 @@ SP_NOINLINE static void sp_3072_mont_reduce_48(sp_digit* a, const sp_digit* m,
);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_mul_48(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -73914,9 +73966,9 @@ static void sp_3072_mont_mul_48(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_sqr_48(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -74780,7 +74832,9 @@ static WC_INLINE int sp_3072_mod_48(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -74800,11 +74854,20 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -74920,7 +74983,9 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -74940,11 +75005,20 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -77331,14 +77405,14 @@ SP_NOINLINE static void sp_3072_mont_reduce_96(sp_digit* a, const sp_digit* m,
);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_mul_96(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -77350,9 +77424,9 @@ static void sp_3072_mont_mul_96(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_sqr_96(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -79042,7 +79116,9 @@ static WC_INLINE int sp_3072_mod_96(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -79062,11 +79138,20 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -79173,7 +79258,9 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -79193,11 +79280,20 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -82212,7 +82308,9 @@ static void sp_3072_lshift_96(sp_digit* r, const sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -82233,11 +82331,17 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 289, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 289, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -89402,14 +89506,14 @@ SP_NOINLINE static void sp_4096_mont_reduce_128(sp_digit* a, const sp_digit* m,
);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_4096_mont_mul_128(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -89421,9 +89525,9 @@ static void sp_4096_mont_mul_128(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_4096_mont_sqr_128(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -91386,7 +91490,9 @@ static WC_INLINE int sp_4096_mod_128(sp_digit* r, const sp_digit* a, const sp_di
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -91406,11 +91512,20 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -91517,7 +91632,9 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -91537,11 +91654,20 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -95349,7 +95475,9 @@ static void sp_4096_lshift_128(sp_digit* r, const sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -95370,11 +95498,17 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 385, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 385, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -95549,12 +95683,12 @@ static const sp_digit p256_mod[8] = {
0xffffffff,0xffffffff,0xffffffff,0x00000000,0x00000000,0x00000000,
0x00000001,0xffffffff
};
/* The Montogmery normalizer for modulus of the curve P256. */
/* The Montgomery normalizer for modulus of the curve P256. */
static const sp_digit p256_norm_mod[8] = {
0x00000001,0x00000000,0x00000000,0xffffffff,0xffffffff,0xffffffff,
0xfffffffe,0x00000000
};
/* The Montogmery multiplier for modulus of the curve P256. */
/* The Montgomery multiplier for modulus of the curve P256. */
static const sp_digit p256_mp_mod = 0x00000001;
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
@ -95570,14 +95704,14 @@ static const sp_digit p256_order2[8] = {
0x00000000,0xffffffff
};
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery normalizer for order of the curve P256. */
/* The Montgomery normalizer for order of the curve P256. */
static const sp_digit p256_norm_order[8] = {
0x039cdaaf,0x0c46353d,0x58e8617b,0x43190552,0x00000000,0x00000000,
0xffffffff,0x00000000
};
#endif
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery multiplier for order of the curve P256. */
/* The Montgomery multiplier for order of the curve P256. */
static const sp_digit p256_mp_order = 0xee00bc4f;
#endif
/* The base point of curve P256. */
@ -96607,7 +96741,7 @@ SP_NOINLINE static sp_digit sp_256_sub_8(sp_digit* r, const sp_digit* a,
}
#endif /* WOLFSSL_SP_SMALL */
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -97911,14 +98045,14 @@ SP_NOINLINE static void sp_256_mont_reduce_order_8(sp_digit* a,
);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_256_mont_mul_8(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -97930,9 +98064,9 @@ static void sp_256_mont_mul_8(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_256_mont_sqr_8(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -97945,10 +98079,10 @@ static void sp_256_mont_sqr_8(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number a number of times. (r = a ^ n mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* n Number of times to square.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_256_mont_sqr_n_8(sp_digit* r, const sp_digit* a, int n,
const sp_digit* m, sp_digit mp)
@ -98199,8 +98333,8 @@ static void sp_256_map_8(sp_point_256* r, const sp_point_256* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_256_mont_add_8(sp_digit* r, const sp_digit* a,
@ -98385,7 +98519,7 @@ SP_NOINLINE static void sp_256_mont_add_8(sp_digit* r, const sp_digit* a,
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_256_mont_dbl_8(sp_digit* r, const sp_digit* a,
@ -98562,7 +98696,7 @@ SP_NOINLINE static void sp_256_mont_dbl_8(sp_digit* r, const sp_digit* a,
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_256_mont_tpl_8(sp_digit* r, const sp_digit* a,
@ -98895,8 +99029,8 @@ SP_NOINLINE static void sp_256_mont_tpl_8(sp_digit* r, const sp_digit* a,
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_256_mont_sub_8(sp_digit* r, const sp_digit* a,
@ -101178,7 +101312,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r,
* km Scalar to multiply by.
* p Point to multiply.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -102727,7 +102861,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -106836,12 +106970,12 @@ static const sp_digit p384_mod[12] = {
0xffffffff,0x00000000,0x00000000,0xffffffff,0xfffffffe,0xffffffff,
0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff
};
/* The Montogmery normalizer for modulus of the curve P384. */
/* The Montgomery normalizer for modulus of the curve P384. */
static const sp_digit p384_norm_mod[12] = {
0x00000001,0xffffffff,0xffffffff,0x00000000,0x00000001,0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
};
/* The Montogmery multiplier for modulus of the curve P384. */
/* The Montgomery multiplier for modulus of the curve P384. */
static sp_digit p384_mp_mod = 0x00000001;
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
@ -106857,14 +106991,14 @@ static const sp_digit p384_order2[12] = {
0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff
};
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery normalizer for order of the curve P384. */
/* The Montgomery normalizer for order of the curve P384. */
static const sp_digit p384_norm_order[12] = {
0x333ad68d,0x1313e695,0xb74f5885,0xa7e5f24d,0x0bc8d220,0x389cb27e,
0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
};
#endif
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery multiplier for order of the curve P384. */
/* The Montgomery multiplier for order of the curve P384. */
static sp_digit p384_mp_order = 0xe88fdc45;
#endif
/* The base point of curve P384. */
@ -107965,7 +108099,7 @@ SP_NOINLINE static sp_digit sp_384_sub_12(sp_digit* r, const sp_digit* a,
}
#endif /* WOLFSSL_SP_SMALL */
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -109050,14 +109184,14 @@ SP_NOINLINE static void sp_384_mont_reduce_12(sp_digit* a, const sp_digit* m,
);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_mul_12(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -109069,9 +109203,9 @@ static void sp_384_mont_mul_12(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_sqr_12(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -109084,10 +109218,10 @@ static void sp_384_mont_sqr_12(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number a number of times. (r = a ^ n mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* n Number of times to square.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_sqr_n_12(sp_digit* r, const sp_digit* a, int n,
const sp_digit* m, sp_digit mp)
@ -109354,8 +109488,8 @@ static void sp_384_map_12(sp_point_384* r, const sp_point_384* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_384_mont_add_12(sp_digit* r, const sp_digit* a,
@ -109370,7 +109504,7 @@ SP_NOINLINE static void sp_384_mont_add_12(sp_digit* r, const sp_digit* a,
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_384_mont_dbl_12(sp_digit* r, const sp_digit* a,
@ -109385,7 +109519,7 @@ SP_NOINLINE static void sp_384_mont_dbl_12(sp_digit* r, const sp_digit* a,
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_384_mont_tpl_12(sp_digit* r, const sp_digit* a,
@ -109471,8 +109605,8 @@ SP_NOINLINE static sp_digit sp_384_cond_add_12(sp_digit* r, const sp_digit* a,
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_384_mont_sub_12(sp_digit* r, const sp_digit* a,
@ -111621,7 +111755,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r,
* km Scalar to multiply by.
* p Point to multiply.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -113170,7 +113304,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -182255,7 +182389,7 @@ static const sp_digit p1024_mod[32] = {
0xb3e01a2e,0xbe9ae358,0x9cb48261,0x416c0ce1,0xdad0657a,0x65c61198,
0x0a563fda,0x997abb1f
};
/* The Montogmery normalizer for modulus of the curve P1024. */
/* The Montgomery normalizer for modulus of the curve P1024. */
static const sp_digit p1024_norm_mod[32] = {
0x0157a015,0x99927f85,0x53853178,0x7f3a20ef,0x767a824f,0x031c17dc,
0xa968e0e0,0x606b2950,0xe3c3f655,0x5830c3ad,0xce7ad57d,0x49500b57,
@ -182264,7 +182398,7 @@ static const sp_digit p1024_norm_mod[32] = {
0x4c1fe5d1,0x41651ca7,0x634b7d9e,0xbe93f31e,0x252f9a85,0x9a39ee67,
0xf5a9c025,0x668544e0
};
/* The Montogmery multiplier for modulus of the curve P1024. */
/* The Montgomery multiplier for modulus of the curve P1024. */
static sp_digit p1024_mp_mod = 0x7c8f2f3d;
#if defined(WOLFSSL_SP_SMALL) || defined(HAVE_ECC_CHECK_KEY)
/* The order of the curve P1024. */
@ -183419,7 +183553,7 @@ static WC_INLINE int sp_1024_mod_32(sp_digit* r, const sp_digit* a, const sp_dig
return sp_1024_div_32(a, m, NULL, r);
}
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -184772,14 +184906,14 @@ SP_NOINLINE static void sp_1024_mont_reduce_32(sp_digit* a, const sp_digit* m,
);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_1024_mont_mul_32(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -184791,9 +184925,9 @@ static void sp_1024_mont_mul_32(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_1024_mont_sqr_32(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -184912,8 +185046,8 @@ static void sp_1024_map_32(sp_point_1024* r, const sp_point_1024* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_1024_mont_add_32(sp_digit* r, const sp_digit* a,
@ -185822,7 +185956,7 @@ SP_NOINLINE static void sp_1024_mont_add_32(sp_digit* r, const sp_digit* a,
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_1024_mont_dbl_32(sp_digit* r, const sp_digit* a,
@ -186699,7 +186833,7 @@ SP_NOINLINE static void sp_1024_mont_dbl_32(sp_digit* r, const sp_digit* a,
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_1024_mont_tpl_32(sp_digit* r, const sp_digit* a,
@ -188469,8 +188603,8 @@ SP_NOINLINE static void sp_1024_mont_tpl_32(sp_digit* r, const sp_digit* a,
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_1024_mont_sub_32(sp_digit* r, const sp_digit* a,
@ -196196,7 +196330,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2953,14 +2953,14 @@ SP_NOINLINE static void sp_2048_mont_reduce_32(sp_digit* a, const sp_digit* m,
sp_2048_cond_sub_32(a - 32, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_mul_32(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -2972,9 +2972,9 @@ static void sp_2048_mont_mul_32(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_sqr_32(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -3183,7 +3183,9 @@ static WC_INLINE int sp_2048_mod_32(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -3203,11 +3205,20 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -3323,7 +3334,9 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -3343,11 +3356,20 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 64), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -3636,14 +3658,14 @@ SP_NOINLINE static void sp_2048_mont_reduce_64(sp_digit* a, const sp_digit* m,
sp_2048_cond_sub_64(a - 64, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_mul_64(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -3655,9 +3677,9 @@ static void sp_2048_mont_mul_64(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_2048_mont_sqr_64(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -4244,7 +4266,9 @@ static WC_INLINE int sp_2048_mod_64(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -4264,11 +4288,20 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -4375,7 +4408,9 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -4395,11 +4430,20 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -5400,7 +5444,9 @@ static void sp_2048_lshift_64(sp_digit* r, sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -5421,11 +5467,17 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -8172,14 +8224,14 @@ SP_NOINLINE static void sp_3072_mont_reduce_48(sp_digit* a, const sp_digit* m,
sp_3072_cond_sub_48(a - 48, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_mul_48(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -8191,9 +8243,9 @@ static void sp_3072_mont_mul_48(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_sqr_48(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -8402,7 +8454,9 @@ static WC_INLINE int sp_3072_mod_48(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -8422,11 +8476,20 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -8542,7 +8605,9 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -8562,11 +8627,20 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 96), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -8856,14 +8930,14 @@ SP_NOINLINE static void sp_3072_mont_reduce_96(sp_digit* a, const sp_digit* m,
sp_3072_cond_sub_96(a - 96, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_mul_96(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -8875,9 +8949,9 @@ static void sp_3072_mont_mul_96(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_3072_mont_sqr_96(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -9601,7 +9675,9 @@ static WC_INLINE int sp_3072_mod_96(sp_digit* r, const sp_digit* a, const sp_dig
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -9621,11 +9697,20 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -9732,7 +9817,9 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -9752,11 +9839,20 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 192), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -10953,7 +11049,9 @@ static void sp_3072_lshift_96(sp_digit* r, sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -10974,11 +11072,17 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 289, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 289, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -12638,14 +12742,14 @@ SP_NOINLINE static void sp_4096_mont_reduce_128(sp_digit* a, const sp_digit* m,
sp_4096_cond_sub_128(a - 128, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_4096_mont_mul_128(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -12657,9 +12761,9 @@ static void sp_4096_mont_mul_128(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_4096_mont_sqr_128(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -13516,7 +13620,9 @@ static WC_INLINE int sp_4096_mod_128(sp_digit* r, const sp_digit* a, const sp_di
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -13536,11 +13642,20 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -13647,7 +13762,9 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even or exponent is 0.
*/
static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e,
int bits, const sp_digit* m, int reduceA)
@ -13667,11 +13784,20 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
else if (bits == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -15065,7 +15191,9 @@ static void sp_4096_lshift_128(sp_digit* r, sp_digit* a, byte n)
* e A single precision number that is the exponent.
* bits The number of bits in the exponent.
* m A single precision number that is the modulus.
* returns 0 on success and MEMORY_E on dynamic memory allocation failure.
* returns 0 on success.
* returns MEMORY_E on dynamic memory allocation failure.
* returns MP_VAL when base is even.
*/
static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits,
const sp_digit* m)
@ -15086,11 +15214,17 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits,
byte y;
int err = MP_OKAY;
if ((m[0] & 1) == 0) {
err = MP_VAL;
}
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 385, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
if (err == MP_OKAY) {
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 385, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (td == NULL)
err = MEMORY_E;
}
#endif
if (err == MP_OKAY) {
@ -15265,12 +15399,12 @@ static const sp_digit p256_mod[8] = {
0xffffffff,0xffffffff,0xffffffff,0x00000000,0x00000000,0x00000000,
0x00000001,0xffffffff
};
/* The Montogmery normalizer for modulus of the curve P256. */
/* The Montgomery normalizer for modulus of the curve P256. */
static const sp_digit p256_norm_mod[8] = {
0x00000001,0x00000000,0x00000000,0xffffffff,0xffffffff,0xffffffff,
0xfffffffe,0x00000000
};
/* The Montogmery multiplier for modulus of the curve P256. */
/* The Montgomery multiplier for modulus of the curve P256. */
static const sp_digit p256_mp_mod = 0x00000001;
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
@ -15286,14 +15420,14 @@ static const sp_digit p256_order2[8] = {
0x00000000,0xffffffff
};
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery normalizer for order of the curve P256. */
/* The Montgomery normalizer for order of the curve P256. */
static const sp_digit p256_norm_order[8] = {
0x039cdaaf,0x0c46353d,0x58e8617b,0x43190552,0x00000000,0x00000000,
0xffffffff,0x00000000
};
#endif
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery multiplier for order of the curve P256. */
/* The Montgomery multiplier for order of the curve P256. */
static const sp_digit p256_mp_order = 0xee00bc4f;
#endif
/* The base point of curve P256. */
@ -16370,7 +16504,7 @@ SP_NOINLINE static sp_digit sp_256_sub_8(sp_digit* r, const sp_digit* a,
}
#endif /* WOLFSSL_SP_SMALL */
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -16797,14 +16931,14 @@ static int sp_256_point_to_ecc_point_8(const sp_point_256* p, ecc_point* pm)
return err;
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
SP_NOINLINE static void sp_256_mont_mul_8(sp_digit* r, const sp_digit* a, const sp_digit* b,
const sp_digit* m, sp_digit mp)
@ -17459,9 +17593,9 @@ SP_NOINLINE static void sp_256_mont_mul_8(sp_digit* r, const sp_digit* a, const
/* Square the Montgomery form number mod the modulus (prime). (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
SP_NOINLINE static void sp_256_mont_sqr_8(sp_digit* r, const sp_digit* a, const sp_digit* m,
sp_digit mp)
@ -17976,10 +18110,10 @@ SP_NOINLINE static void sp_256_mont_sqr_8(sp_digit* r, const sp_digit* a, const
/* Square the Montgomery form number a number of times. (r = a ^ n mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* n Number of times to square.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_256_mont_sqr_n_8(sp_digit* r, const sp_digit* a, int n,
const sp_digit* m, sp_digit mp)
@ -18434,8 +18568,8 @@ static void sp_256_map_8(sp_point_256* r, const sp_point_256* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_256_mont_add_8(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -18505,7 +18639,7 @@ SP_NOINLINE static void sp_256_mont_add_8(sp_digit* r, const sp_digit* a, const
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_256_mont_dbl_8(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -18558,7 +18692,7 @@ SP_NOINLINE static void sp_256_mont_dbl_8(sp_digit* r, const sp_digit* a, const
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_256_mont_tpl_8(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -18643,8 +18777,8 @@ SP_NOINLINE static void sp_256_mont_tpl_8(sp_digit* r, const sp_digit* a, const
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_256_mont_sub_8(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -20631,7 +20765,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r,
* km Scalar to multiply by.
* p Point to multiply.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -22180,7 +22314,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -24590,12 +24724,12 @@ static const sp_digit p384_mod[12] = {
0xffffffff,0x00000000,0x00000000,0xffffffff,0xfffffffe,0xffffffff,
0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff
};
/* The Montogmery normalizer for modulus of the curve P384. */
/* The Montgomery normalizer for modulus of the curve P384. */
static const sp_digit p384_norm_mod[12] = {
0x00000001,0xffffffff,0xffffffff,0x00000000,0x00000001,0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
};
/* The Montogmery multiplier for modulus of the curve P384. */
/* The Montgomery multiplier for modulus of the curve P384. */
static sp_digit p384_mp_mod = 0x00000001;
#if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
defined(HAVE_ECC_VERIFY)
@ -24611,14 +24745,14 @@ static const sp_digit p384_order2[12] = {
0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff
};
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery normalizer for order of the curve P384. */
/* The Montgomery normalizer for order of the curve P384. */
static const sp_digit p384_norm_order[12] = {
0x333ad68d,0x1313e695,0xb74f5885,0xa7e5f24d,0x0bc8d220,0x389cb27e,
0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
};
#endif
#if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
/* The Montogmery multiplier for order of the curve P384. */
/* The Montgomery multiplier for order of the curve P384. */
static sp_digit p384_mp_order = 0xe88fdc45;
#endif
/* The base point of curve P384. */
@ -25073,7 +25207,7 @@ SP_NOINLINE static sp_digit sp_384_sub_12(sp_digit* r, const sp_digit* a,
}
#endif /* WOLFSSL_SP_SMALL */
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -25512,14 +25646,14 @@ SP_NOINLINE static void sp_384_mont_reduce_12(sp_digit* a, const sp_digit* m,
sp_384_cond_sub_12(a - 12, a, m, (sp_digit)0 - ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_mul_12(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -25531,9 +25665,9 @@ static void sp_384_mont_mul_12(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_sqr_12(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -25546,10 +25680,10 @@ static void sp_384_mont_sqr_12(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number a number of times. (r = a ^ n mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* n Number of times to square.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_384_mont_sqr_n_12(sp_digit* r, const sp_digit* a, int n,
const sp_digit* m, sp_digit mp)
@ -25753,8 +25887,8 @@ static void sp_384_map_12(sp_point_384* r, const sp_point_384* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_384_mont_add_12(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -25769,7 +25903,7 @@ SP_NOINLINE static void sp_384_mont_add_12(sp_digit* r, const sp_digit* a, const
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_384_mont_dbl_12(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -25783,7 +25917,7 @@ SP_NOINLINE static void sp_384_mont_dbl_12(sp_digit* r, const sp_digit* a, const
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_384_mont_tpl_12(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -25840,8 +25974,8 @@ SP_NOINLINE static sp_digit sp_384_cond_add_12(sp_digit* r, const sp_digit* a, c
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_384_mont_sub_12(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -27815,7 +27949,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r,
* km Scalar to multiply by.
* p Point to multiply.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -29364,7 +29498,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.
@ -32634,7 +32768,7 @@ static const sp_digit p1024_mod[32] = {
0xb3e01a2e,0xbe9ae358,0x9cb48261,0x416c0ce1,0xdad0657a,0x65c61198,
0x0a563fda,0x997abb1f
};
/* The Montogmery normalizer for modulus of the curve P1024. */
/* The Montgomery normalizer for modulus of the curve P1024. */
static const sp_digit p1024_norm_mod[32] = {
0x0157a015,0x99927f85,0x53853178,0x7f3a20ef,0x767a824f,0x031c17dc,
0xa968e0e0,0x606b2950,0xe3c3f655,0x5830c3ad,0xce7ad57d,0x49500b57,
@ -32643,7 +32777,7 @@ static const sp_digit p1024_norm_mod[32] = {
0x4c1fe5d1,0x41651ca7,0x634b7d9e,0xbe93f31e,0x252f9a85,0x9a39ee67,
0xf5a9c025,0x668544e0
};
/* The Montogmery multiplier for modulus of the curve P1024. */
/* The Montgomery multiplier for modulus of the curve P1024. */
static sp_digit p1024_mp_mod = 0x7c8f2f3d;
#if defined(WOLFSSL_SP_SMALL) || defined(HAVE_ECC_CHECK_KEY)
/* The order of the curve P1024. */
@ -33058,7 +33192,7 @@ static WC_INLINE int sp_1024_mod_32(sp_digit* r, const sp_digit* a, const sp_dig
return sp_1024_div_32(a, m, NULL, r);
}
/* Multiply a number by Montogmery normalizer mod modulus (prime).
/* Multiply a number by Montgomery normalizer mod modulus (prime).
*
* r The resulting Montgomery form number.
* a The number to convert.
@ -33432,14 +33566,14 @@ SP_NOINLINE static void sp_1024_mont_reduce_32(sp_digit* a, const sp_digit* m,
sp_1024_cond_sub_32(a - 32, a, m, ca);
}
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_1024_mont_mul_32(sp_digit* r, const sp_digit* a,
const sp_digit* b, const sp_digit* m, sp_digit mp)
@ -33451,9 +33585,9 @@ static void sp_1024_mont_mul_32(sp_digit* r, const sp_digit* a,
/* Square the Montgomery form number. (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
static void sp_1024_mont_sqr_32(sp_digit* r, const sp_digit* a,
const sp_digit* m, sp_digit mp)
@ -33572,8 +33706,8 @@ static void sp_1024_map_32(sp_point_1024* r, const sp_point_1024* p,
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_1024_mont_add_32(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -33742,7 +33876,7 @@ SP_NOINLINE static void sp_1024_mont_add_32(sp_digit* r, const sp_digit* a, cons
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_1024_mont_dbl_32(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -33894,7 +34028,7 @@ SP_NOINLINE static void sp_1024_mont_dbl_32(sp_digit* r, const sp_digit* a, cons
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_1024_mont_tpl_32(sp_digit* r, const sp_digit* a, const sp_digit* m)
@ -34201,8 +34335,8 @@ SP_NOINLINE static void sp_1024_mont_tpl_32(sp_digit* r, const sp_digit* a, cons
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
SP_NOINLINE static void sp_1024_mont_sub_32(sp_digit* r, const sp_digit* a, const sp_digit* b,
@ -39983,7 +40117,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap)
*
* km Scalar to multiply by.
* am Point to add to scalar mulitply result.
* inMont Point to add is in montogmery form.
* inMont Point to add is in montgomery form.
* r Resulting point.
* map Indicates whether to convert result to affine.
* heap Heap to use for allocation.

File diff suppressed because it is too large Load Diff

View File

@ -39026,14 +39026,14 @@ _sp_256_cond_copy_4:
#ifndef __APPLE__
.size sp_256_cond_copy_4,.-sp_256_cond_copy_4
#endif /* __APPLE__ */
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
#ifndef __APPLE__
.text
@ -39234,9 +39234,9 @@ _sp_256_mont_mul_4:
/* Square the Montgomery form number mod the modulus (prime). (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
#ifndef __APPLE__
.text
@ -39637,8 +39637,8 @@ L_mont_loop_4:
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -39689,7 +39689,7 @@ _sp_256_mont_add_4:
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of doubling.
* a Number to double in Montogmery form.
* a Number to double in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -39740,7 +39740,7 @@ _sp_256_mont_dbl_4:
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of Tripling.
* a Number to triple in Montogmery form.
* a Number to triple in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -39812,8 +39812,8 @@ _sp_256_mont_tpl_4:
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of subtration.
* a Number to subtract from in Montogmery form.
* b Number to subtract with in Montogmery form.
* a Number to subtract from in Montgomery form.
* b Number to subtract with in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -40033,14 +40033,14 @@ L_256_get_point_33_avx2_4_start:
#endif /* HAVE_INTEL_AVX2 */
#endif /* !WC_NO_CACHE_RESISTANT */
#ifdef HAVE_INTEL_AVX2
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
#ifndef __APPLE__
.text
@ -40223,9 +40223,9 @@ _sp_256_mont_mul_avx2_4:
/* Square the Montgomery form number mod the modulus (prime). (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
* m Modulus (prime).
* mp Montogmery mulitplier.
* mp Montgomery mulitplier.
*/
#ifndef __APPLE__
.text
@ -41424,12 +41424,12 @@ _div_256_word_asm_4:
#endif /* __APPLE__ */
#endif /* _WIN64 */
#ifdef HAVE_INTEL_AVX2
/* Multiply two Montogmery form numbers mod the modulus (prime).
/* Multiply two Montgomery form numbers mod the modulus (prime).
* (r = a * b mod m)
*
* r Result of multiplication.
* a First number to multiply in Montogmery form.
* b Second number to multiply in Montogmery form.
* a First number to multiply in Montgomery form.
* b Second number to multiply in Montgomery form.
*/
#ifndef __APPLE__
.text
@ -41658,7 +41658,7 @@ _sp_256_mont_mul_order_avx2_4:
/* Square the Montgomery form number mod the modulus (prime). (r = a * a mod m)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
*/
#ifndef __APPLE__
.text
@ -44409,7 +44409,7 @@ L_mont_loop_order_avx2_6:
/* Square a and put result in r. (r = a * a)
*
* r Result of squaring.
* a Number to square in Montogmery form.
* a Number to square in Montgomery form.
*/
#ifndef __APPLE__
.text
@ -52230,8 +52230,8 @@ L_1024_mont_loop_16:
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -52405,7 +52405,7 @@ _sp_1024_mont_add_16:
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of addition.
* a Number to souble in Montogmery form.
* a Number to souble in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -52579,7 +52579,7 @@ _sp_1024_mont_dbl_16:
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of addition.
* a Number to souble in Montogmery form.
* a Number to souble in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -52903,8 +52903,8 @@ _sp_1024_mont_tpl_16:
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -53646,8 +53646,8 @@ L_1024_mont_loop_avx2_16:
/* Add two Montgomery form numbers (r = a + b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -53805,7 +53805,7 @@ _sp_1024_mont_add_avx2_16:
/* Double a Montgomery form number (r = a + a % m).
*
* r Result of addition.
* a Number to souble in Montogmery form.
* a Number to souble in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -53963,7 +53963,7 @@ _sp_1024_mont_dbl_avx2_16:
/* Triple a Montgomery form number (r = a + a + a % m).
*
* r Result of addition.
* a Number to souble in Montogmery form.
* a Number to souble in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__
@ -54255,8 +54255,8 @@ _sp_1024_mont_tpl_avx2_16:
/* Subtract two Montgomery form numbers (r = a - b % m).
*
* r Result of addition.
* a First number to add in Montogmery form.
* b Second number to add in Montogmery form.
* a First number to add in Montgomery form.
* b Second number to add in Montgomery form.
* m Modulus (prime).
*/
#ifndef __APPLE__

View File

@ -37856,14 +37856,14 @@ sp_256_cond_copy_4 PROC
ret
sp_256_cond_copy_4 ENDP
_text ENDS
; /* Multiply two Montogmery form numbers mod the modulus (prime).
; /* Multiply two Montgomery form numbers mod the modulus (prime).
; * (r = a * b mod m)
; *
; * r Result of multiplication.
; * a First number to multiply in Montogmery form.
; * b Second number to multiply in Montogmery form.
; * a First number to multiply in Montgomery form.
; * b Second number to multiply in Montgomery form.
; * m Modulus (prime).
; * mp Montogmery mulitplier.
; * mp Montgomery mulitplier.
; */
_text SEGMENT READONLY PARA
sp_256_mont_mul_4 PROC
@ -38057,9 +38057,9 @@ _text ENDS
; /* Square the Montgomery form number mod the modulus (prime). (r = a * a mod m)
; *
; * r Result of squaring.
; * a Number to square in Montogmery form.
; * a Number to square in Montgomery form.
; * m Modulus (prime).
; * mp Montogmery mulitplier.
; * mp Montgomery mulitplier.
; */
_text SEGMENT READONLY PARA
sp_256_mont_sqr_4 PROC
@ -38431,8 +38431,8 @@ _text ENDS
; /* Add two Montgomery form numbers (r = a + b % m).
; *
; * r Result of addition.
; * a First number to add in Montogmery form.
; * b Second number to add in Montogmery form.
; * a First number to add in Montgomery form.
; * b Second number to add in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -38476,7 +38476,7 @@ _text ENDS
; /* Double a Montgomery form number (r = a + a % m).
; *
; * r Result of doubling.
; * a Number to double in Montogmery form.
; * a Number to double in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -38520,7 +38520,7 @@ _text ENDS
; /* Triple a Montgomery form number (r = a + a + a % m).
; *
; * r Result of Tripling.
; * a Number to triple in Montogmery form.
; * a Number to triple in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -38585,8 +38585,8 @@ _text ENDS
; /* Subtract two Montgomery form numbers (r = a - b % m).
; *
; * r Result of subtration.
; * a Number to subtract from in Montogmery form.
; * b Number to subtract with in Montogmery form.
; * a Number to subtract from in Montgomery form.
; * b Number to subtract with in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -38770,14 +38770,14 @@ _text ENDS
ENDIF
ENDIF
IFDEF HAVE_INTEL_AVX2
; /* Multiply two Montogmery form numbers mod the modulus (prime).
; /* Multiply two Montgomery form numbers mod the modulus (prime).
; * (r = a * b mod m)
; *
; * r Result of multiplication.
; * a First number to multiply in Montogmery form.
; * b Second number to multiply in Montogmery form.
; * a First number to multiply in Montgomery form.
; * b Second number to multiply in Montgomery form.
; * m Modulus (prime).
; * mp Montogmery mulitplier.
; * mp Montgomery mulitplier.
; */
_text SEGMENT READONLY PARA
sp_256_mont_mul_avx2_4 PROC
@ -38954,9 +38954,9 @@ IFDEF HAVE_INTEL_AVX2
; /* Square the Montgomery form number mod the modulus (prime). (r = a * a mod m)
; *
; * r Result of squaring.
; * a Number to square in Montogmery form.
; * a Number to square in Montgomery form.
; * m Modulus (prime).
; * mp Montogmery mulitplier.
; * mp Montgomery mulitplier.
; */
_text SEGMENT READONLY PARA
sp_256_mont_sqr_avx2_4 PROC
@ -39995,12 +39995,12 @@ div_256_word_asm_4 ENDP
_text ENDS
ENDIF
IFDEF HAVE_INTEL_AVX2
; /* Multiply two Montogmery form numbers mod the modulus (prime).
; /* Multiply two Montgomery form numbers mod the modulus (prime).
; * (r = a * b mod m)
; *
; * r Result of multiplication.
; * a First number to multiply in Montogmery form.
; * b Second number to multiply in Montogmery form.
; * a First number to multiply in Montgomery form.
; * b Second number to multiply in Montgomery form.
; */
_text SEGMENT READONLY PARA
sp_256_mont_mul_order_avx2_4 PROC
@ -40223,7 +40223,7 @@ IFDEF HAVE_INTEL_AVX2
; /* Square the Montgomery form number mod the modulus (prime). (r = a * a mod m)
; *
; * r Result of squaring.
; * a Number to square in Montogmery form.
; * a Number to square in Montgomery form.
; */
_text SEGMENT READONLY PARA
sp_256_mont_sqr_order_avx2_4 PROC
@ -42789,7 +42789,7 @@ IFDEF HAVE_INTEL_AVX2
; /* Square a and put result in r. (r = a * a)
; *
; * r Result of squaring.
; * a Number to square in Montogmery form.
; * a Number to square in Montgomery form.
; */
_text SEGMENT READONLY PARA
sp_384_sqr_avx2_6 PROC
@ -50309,8 +50309,8 @@ _text ENDS
; /* Add two Montgomery form numbers (r = a + b % m).
; *
; * r Result of addition.
; * a First number to add in Montogmery form.
; * b Second number to add in Montogmery form.
; * a First number to add in Montgomery form.
; * b Second number to add in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -50477,7 +50477,7 @@ _text ENDS
; /* Double a Montgomery form number (r = a + a % m).
; *
; * r Result of addition.
; * a Number to souble in Montogmery form.
; * a Number to souble in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -50642,7 +50642,7 @@ _text ENDS
; /* Triple a Montgomery form number (r = a + a + a % m).
; *
; * r Result of addition.
; * a Number to souble in Montogmery form.
; * a Number to souble in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -50957,8 +50957,8 @@ _text ENDS
; /* Subtract two Montgomery form numbers (r = a - b % m).
; *
; * r Result of addition.
; * a First number to add in Montogmery form.
; * b Second number to add in Montogmery form.
; * a First number to add in Montgomery form.
; * b Second number to add in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -51669,8 +51669,8 @@ IFDEF HAVE_INTEL_AVX2
; /* Add two Montgomery form numbers (r = a + b % m).
; *
; * r Result of addition.
; * a First number to add in Montogmery form.
; * b Second number to add in Montogmery form.
; * a First number to add in Montgomery form.
; * b Second number to add in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -51821,7 +51821,7 @@ IFDEF HAVE_INTEL_AVX2
; /* Double a Montgomery form number (r = a + a % m).
; *
; * r Result of addition.
; * a Number to souble in Montogmery form.
; * a Number to souble in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -51970,7 +51970,7 @@ IFDEF HAVE_INTEL_AVX2
; /* Triple a Montgomery form number (r = a + a + a % m).
; *
; * r Result of addition.
; * a Number to souble in Montogmery form.
; * a Number to souble in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA
@ -52253,8 +52253,8 @@ IFDEF HAVE_INTEL_AVX2
; /* Subtract two Montgomery form numbers (r = a - b % m).
; *
; * r Result of addition.
; * a First number to add in Montogmery form.
; * b Second number to add in Montogmery form.
; * a First number to add in Montgomery form.
; * b Second number to add in Montgomery form.
; * m Modulus (prime).
; */
_text SEGMENT READONLY PARA