forked from wolfSSL/wolfssl
Merge pull request #4552 from SparkiDev/sp_mod_exp_zero
SP: mod_exp with exponent of 0 is invalid
This commit is contained in:
@ -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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
|
@ -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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
|
@ -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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
|
@ -2138,7 +2138,9 @@ static int sp_2048_mod_36(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
* 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_36(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
@ -2158,11 +2160,20 @@ static int sp_2048_mod_exp_36(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 36 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -2244,11 +2255,20 @@ static int sp_2048_mod_exp_36(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 36 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -2330,11 +2350,20 @@ static int sp_2048_mod_exp_36(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 72) + 72), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -3233,7 +3262,9 @@ static int sp_2048_mod_72(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
* 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_72(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
@ -3253,11 +3284,20 @@ static int sp_2048_mod_exp_72(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 72 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -3339,11 +3379,20 @@ static int sp_2048_mod_exp_72(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 72 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -3425,11 +3474,20 @@ static int sp_2048_mod_exp_72(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 144) + 144), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -4518,7 +4576,9 @@ SP_NOINLINE static void sp_2048_lshift_72(sp_digit* r, const sp_digit* a,
|
||||
* 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_72(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
|
||||
{
|
||||
@ -4537,11 +4597,17 @@ static int sp_2048_mod_exp_2_72(sp_digit* r, const sp_digit* e, int bits, const
|
||||
byte y;
|
||||
int err = MP_OKAY;
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 217, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -5867,7 +5933,9 @@ static int sp_3072_mod_53(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
* 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_53(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
@ -5887,11 +5955,20 @@ static int sp_3072_mod_exp_53(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 53 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -5973,11 +6050,20 @@ static int sp_3072_mod_exp_53(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 53 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -6059,11 +6145,20 @@ static int sp_3072_mod_exp_53(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 106) + 106), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -6742,7 +6837,9 @@ static int sp_3072_mod_106(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
* 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_106(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
@ -6762,11 +6859,20 @@ static int sp_3072_mod_exp_106(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 106 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -6848,11 +6954,20 @@ static int sp_3072_mod_exp_106(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 106 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -6934,11 +7049,20 @@ static int sp_3072_mod_exp_106(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 212) + 212), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -7875,7 +7999,9 @@ SP_NOINLINE static void sp_3072_lshift_106(sp_digit* r, const sp_digit* a,
|
||||
* 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_106(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
|
||||
{
|
||||
@ -7894,11 +8020,17 @@ static int sp_3072_mod_exp_2_106(sp_digit* r, const sp_digit* e, int bits, const
|
||||
byte y;
|
||||
int err = MP_OKAY;
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 319, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -9909,7 +10041,9 @@ static int sp_3072_mod_56(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
* 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_56(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
@ -9929,11 +10063,20 @@ static int sp_3072_mod_exp_56(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 56 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -10015,11 +10158,20 @@ static int sp_3072_mod_exp_56(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 56 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -10101,11 +10253,20 @@ static int sp_3072_mod_exp_56(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 112) + 112), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -10832,7 +10993,9 @@ static int sp_3072_mod_112(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
* 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_112(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
@ -10852,11 +11015,20 @@ static int sp_3072_mod_exp_112(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 112 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -10938,11 +11110,20 @@ static int sp_3072_mod_exp_112(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 112 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -11024,11 +11205,20 @@ static int sp_3072_mod_exp_112(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 224) + 224), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -12188,7 +12378,9 @@ SP_NOINLINE static void sp_3072_lshift_112(sp_digit* r, const sp_digit* a,
|
||||
* 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_112(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
|
||||
{
|
||||
@ -12207,11 +12399,17 @@ static int sp_3072_mod_exp_2_112(sp_digit* r, const sp_digit* e, int bits, const
|
||||
byte y;
|
||||
int err = MP_OKAY;
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 337, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -13547,7 +13745,9 @@ static int sp_4096_mod_71(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
* 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_71(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
@ -13567,11 +13767,20 @@ static int sp_4096_mod_exp_71(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 71 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -13653,11 +13862,20 @@ static int sp_4096_mod_exp_71(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 71 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -13739,11 +13957,20 @@ static int sp_4096_mod_exp_71(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 142) + 142), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -14423,7 +14650,9 @@ static int sp_4096_mod_142(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
* 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_142(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
@ -14443,11 +14672,20 @@ static int sp_4096_mod_exp_142(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 142 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -14529,11 +14767,20 @@ static int sp_4096_mod_exp_142(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 142 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -14615,11 +14862,20 @@ static int sp_4096_mod_exp_142(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 284) + 284), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -15556,7 +15812,9 @@ SP_NOINLINE static void sp_4096_lshift_142(sp_digit* r, const sp_digit* a,
|
||||
* 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_142(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
|
||||
{
|
||||
@ -15575,11 +15833,17 @@ static int sp_4096_mod_exp_2_142(sp_digit* r, const sp_digit* e, int bits, const
|
||||
byte y;
|
||||
int err = MP_OKAY;
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 427, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -17445,7 +17709,9 @@ static int sp_4096_mod_81(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
* 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_81(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
@ -17465,11 +17731,20 @@ static int sp_4096_mod_exp_81(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 81 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -17551,11 +17826,20 @@ static int sp_4096_mod_exp_81(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 81 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -17637,11 +17921,20 @@ static int sp_4096_mod_exp_81(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 162) + 162), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -18321,7 +18614,9 @@ static int sp_4096_mod_162(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
* 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_162(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
@ -18341,11 +18636,20 @@ static int sp_4096_mod_exp_162(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 162 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -18427,11 +18731,20 @@ static int sp_4096_mod_exp_162(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 162 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -18513,11 +18826,20 @@ static int sp_4096_mod_exp_162(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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 324) + 324), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -19777,7 +20099,9 @@ SP_NOINLINE static void sp_4096_lshift_162(sp_digit* r, const sp_digit* a,
|
||||
* 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_162(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
|
||||
{
|
||||
@ -19796,11 +20120,17 @@ static int sp_4096_mod_exp_2_162(sp_digit* r, const sp_digit* e, int bits, const
|
||||
byte y;
|
||||
int err = MP_OKAY;
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 487, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
@ -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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
|
@ -459,13 +459,15 @@ static WC_INLINE int sp_2048_mod_16(sp_digit* r, const sp_digit* a,
|
||||
* 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)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[(33 * 32) + 32];
|
||||
#endif
|
||||
@ -482,12 +484,21 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 * 32) + 32, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -671,13 +682,15 @@ static void sp_2048_mont_sqr_avx2_16(sp_digit* r, const sp_digit* a,
|
||||
* 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_avx2_16(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[(33 * 32) + 32];
|
||||
#endif
|
||||
@ -694,12 +707,21 @@ static int sp_2048_mod_exp_avx2_16(sp_digit* r, const sp_digit* a, const sp_digi
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 * 32) + 32, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -1138,13 +1160,15 @@ static WC_INLINE int sp_2048_mod_32(sp_digit* r, const sp_digit* a,
|
||||
* 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)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[(17 * 64) + 64];
|
||||
#endif
|
||||
@ -1161,12 +1185,21 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (17 * 64) + 64, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -1334,13 +1367,15 @@ static void sp_2048_mont_sqr_avx2_32(sp_digit* r, const sp_digit* a,
|
||||
* 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_avx2_32(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[(17 * 64) + 64];
|
||||
#endif
|
||||
@ -1357,12 +1392,21 @@ static int sp_2048_mod_exp_avx2_32(sp_digit* r, const sp_digit* a, const sp_digi
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (17 * 64) + 64, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -2069,13 +2113,15 @@ extern void sp_2048_lshift_32(sp_digit* r, const sp_digit* a, int 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_avx2_32(sp_digit* r, const sp_digit* e, int bits,
|
||||
const sp_digit* m)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[33 + 64];
|
||||
#endif
|
||||
@ -2092,12 +2138,18 @@ static int sp_2048_mod_exp_2_avx2_32(sp_digit* r, const sp_digit* e, int bits,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 + 64), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -2196,13 +2248,15 @@ static int sp_2048_mod_exp_2_avx2_32(sp_digit* r, const sp_digit* e, int bits,
|
||||
* 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)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[33 + 64];
|
||||
#endif
|
||||
@ -2219,12 +2273,18 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 + 64), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -2924,13 +2984,15 @@ static WC_INLINE int sp_3072_mod_24(sp_digit* r, const sp_digit* a,
|
||||
* 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)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[(33 * 48) + 48];
|
||||
#endif
|
||||
@ -2947,12 +3009,21 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 * 48) + 48, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -3136,13 +3207,15 @@ static void sp_3072_mont_sqr_avx2_24(sp_digit* r, const sp_digit* a,
|
||||
* 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_avx2_24(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[(33 * 48) + 48];
|
||||
#endif
|
||||
@ -3159,12 +3232,21 @@ static int sp_3072_mod_exp_avx2_24(sp_digit* r, const sp_digit* a, const sp_digi
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 * 48) + 48, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -3603,13 +3685,15 @@ static WC_INLINE int sp_3072_mod_48(sp_digit* r, const sp_digit* a,
|
||||
* 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)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[(17 * 96) + 96];
|
||||
#endif
|
||||
@ -3626,12 +3710,21 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (17 * 96) + 96, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -3799,13 +3892,15 @@ static void sp_3072_mont_sqr_avx2_48(sp_digit* r, const sp_digit* a,
|
||||
* 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_avx2_48(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[(17 * 96) + 96];
|
||||
#endif
|
||||
@ -3822,12 +3917,21 @@ static int sp_3072_mod_exp_avx2_48(sp_digit* r, const sp_digit* a, const sp_digi
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (17 * 96) + 96, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -4534,13 +4638,15 @@ extern void sp_3072_lshift_48(sp_digit* r, const sp_digit* a, int 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_avx2_48(sp_digit* r, const sp_digit* e, int bits,
|
||||
const sp_digit* m)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[49 + 96];
|
||||
#endif
|
||||
@ -4557,12 +4663,18 @@ static int sp_3072_mod_exp_2_avx2_48(sp_digit* r, const sp_digit* e, int bits,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (49 + 96), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -4661,13 +4773,15 @@ static int sp_3072_mod_exp_2_avx2_48(sp_digit* r, const sp_digit* e, int bits,
|
||||
* 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)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[49 + 96];
|
||||
#endif
|
||||
@ -4684,12 +4798,18 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (49 + 96), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -5455,13 +5575,15 @@ static WC_INLINE int sp_4096_mod_64(sp_digit* r, const sp_digit* a,
|
||||
* 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)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[(17 * 128) + 128];
|
||||
#endif
|
||||
@ -5478,12 +5600,21 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (17 * 128) + 128, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -5651,13 +5782,15 @@ static void sp_4096_mont_sqr_avx2_64(sp_digit* r, const sp_digit* a,
|
||||
* 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_avx2_64(sp_digit* r, const sp_digit* a, const sp_digit* e,
|
||||
int bits, const sp_digit* m, int reduceA)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[(17 * 128) + 128];
|
||||
#endif
|
||||
@ -5674,12 +5807,21 @@ static int sp_4096_mod_exp_avx2_64(sp_digit* r, const sp_digit* a, const sp_digi
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
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)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (17 * 128) + 128, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -6386,13 +6528,15 @@ extern void sp_4096_lshift_64(sp_digit* r, const sp_digit* a, int 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_avx2_64(sp_digit* r, const sp_digit* e, int bits,
|
||||
const sp_digit* m)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[65 + 128];
|
||||
#endif
|
||||
@ -6409,12 +6553,18 @@ static int sp_4096_mod_exp_2_avx2_64(sp_digit* r, const sp_digit* e, int bits,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (65 + 128), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -6513,13 +6663,15 @@ static int sp_4096_mod_exp_2_avx2_64(sp_digit* r, const sp_digit* e, int bits,
|
||||
* 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)
|
||||
{
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* td;
|
||||
sp_digit* td = NULL;
|
||||
#else
|
||||
sp_digit td[65 + 128];
|
||||
#endif
|
||||
@ -6536,12 +6688,18 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits,
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
if ((m[0] & 1) == 0) {
|
||||
err = MP_VAL;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (65 + 128), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
|
Reference in New Issue
Block a user