forked from wolfSSL/wolfssl
Fix SP to build for different configurations
Was failing: --enable-sp --enable-sp-math --enable-sp --enable-sp-math --enable-smallstack
This commit is contained in:
@@ -49,6 +49,8 @@ WOLFSSL_LOCAL int sp_ModExp_2048(sp_int* base, sp_int* exp, sp_int* mod,
|
|||||||
sp_int* res);
|
sp_int* res);
|
||||||
WOLFSSL_LOCAL int sp_ModExp_3072(sp_int* base, sp_int* exp, sp_int* mod,
|
WOLFSSL_LOCAL int sp_ModExp_3072(sp_int* base, sp_int* exp, sp_int* mod,
|
||||||
sp_int* res);
|
sp_int* res);
|
||||||
|
WOLFSSL_LOCAL int sp_ModExp_4096(sp_int* base, sp_int* exp, sp_int* mod,
|
||||||
|
sp_int* res);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -718,17 +720,19 @@ static int sp_div(sp_int* a, sp_int* d, sp_int* r, sp_int* rem)
|
|||||||
#ifdef WOLFSSL_SMALL_STACK
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
if (!done && err == MP_OKAY) {
|
if (!done && err == MP_OKAY) {
|
||||||
sa = (sp_int*)XMALLOC(sizeof(sp_int) * 4, NULL, DYNAMIC_TYPE_BIGINT);
|
sa = (sp_int*)XMALLOC(sizeof(sp_int) * 4, NULL, DYNAMIC_TYPE_BIGINT);
|
||||||
if (sa == NULL)
|
if (sa == NULL) {
|
||||||
err = MP_MEM;
|
err = MP_MEM;
|
||||||
else {
|
|
||||||
sd = &sa[1];
|
|
||||||
tr = &sa[2];
|
|
||||||
trial = &sa[3];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!done && err == MP_OKAY) {
|
if (!done && err == MP_OKAY) {
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
sd = &sa[1];
|
||||||
|
tr = &sa[2];
|
||||||
|
trial = &sa[3];
|
||||||
|
#endif
|
||||||
|
|
||||||
sp_init(sa);
|
sp_init(sa);
|
||||||
sp_init(sd);
|
sp_init(sd);
|
||||||
sp_init(tr);
|
sp_init(tr);
|
||||||
@@ -1166,7 +1170,7 @@ int sp_mulmod(sp_int* a, sp_int* b, sp_int* m, sp_int* r)
|
|||||||
{
|
{
|
||||||
int err = MP_OKAY;
|
int err = MP_OKAY;
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
sp_int* t;
|
sp_int* t = NULL;
|
||||||
#else
|
#else
|
||||||
sp_int t[1];
|
sp_int t[1];
|
||||||
#endif
|
#endif
|
||||||
@@ -1357,19 +1361,20 @@ int sp_invmod(sp_int* a, sp_int* m, sp_int* r)
|
|||||||
if (u == NULL) {
|
if (u == NULL) {
|
||||||
err = MP_MEM;
|
err = MP_MEM;
|
||||||
}
|
}
|
||||||
else {
|
#endif
|
||||||
|
|
||||||
|
if (err == MP_OKAY) {
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
v = &u[1];
|
v = &u[1];
|
||||||
b = &u[2];
|
b = &u[2];
|
||||||
c = &u[3];
|
c = &u[3];
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
sp_init(v);
|
||||||
|
|
||||||
sp_init(v);
|
if (sp_cmp(a, m) != MP_LT) {
|
||||||
|
err = sp_mod(a, m, v);
|
||||||
|
a = v;
|
||||||
if ((err == MP_OKAY) && (sp_cmp(a, m) != MP_LT)) {
|
}
|
||||||
err = sp_mod(a, m, v);
|
|
||||||
a = v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 0 != n*m + 1 (+ve m), r*a mod 0 is always 0 (never 1) */
|
/* 0 != n*m + 1 (+ve m), r*a mod 0 is always 0 (never 1) */
|
||||||
@@ -1569,7 +1574,18 @@ int sp_exptmod(sp_int* b, sp_int* e, sp_int* m, sp_int* r)
|
|||||||
err = sp_ModExp_3072(b, e, m, r);
|
err = sp_ModExp_3072(b, e, m, r);
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WOLFSSL_SP_NO_4096
|
||||||
|
if ((mBits == 4096) && sp_isodd(m) && (bBits <= 4096) &&
|
||||||
|
(eBits <= 4096)) {
|
||||||
|
err = sp_ModExp_4096(b, e, m, r);
|
||||||
|
done = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#if defined(WOLFSSL_HAVE_SP_DH) && defined(WOLFSSL_KEY_GEN)
|
#if defined(WOLFSSL_HAVE_SP_DH) && defined(WOLFSSL_KEY_GEN)
|
||||||
if (!done && (err == MP_OKAY)) {
|
if (!done && (err == MP_OKAY)) {
|
||||||
@@ -1624,7 +1640,7 @@ int sp_exptmod(sp_int* b, sp_int* e, sp_int* m, sp_int* r)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{
|
if (!done && (err == MP_OKAY)) {
|
||||||
err = MP_VAL;
|
err = MP_VAL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -106,19 +106,19 @@
|
|||||||
#define SP_INT_DIGITS ((256 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
#define SP_INT_DIGITS ((256 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
||||||
#endif
|
#endif
|
||||||
#elif defined(WOLFSSL_SP_4096)
|
#elif defined(WOLFSSL_SP_4096)
|
||||||
#if defined(WOLFSSL_HAVE_SP_DH) && defined(WOLFSSL_KEY_GEN)
|
#if defined(WOLFSSL_HAVE_SP_DH)
|
||||||
#define SP_INT_DIGITS ((8192 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
#define SP_INT_DIGITS ((8192 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
||||||
#else
|
#else
|
||||||
#define SP_INT_DIGITS ((4096 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
#define SP_INT_DIGITS ((4096 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
||||||
#endif
|
#endif
|
||||||
#elif !defined(WOLFSSL_SP_NO_3072)
|
#elif !defined(WOLFSSL_SP_NO_3072)
|
||||||
#if defined(WOLFSSL_HAVE_SP_DH) && defined(WOLFSSL_KEY_GEN)
|
#if defined(WOLFSSL_HAVE_SP_DH)
|
||||||
#define SP_INT_DIGITS ((6144 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
#define SP_INT_DIGITS ((6144 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
||||||
#else
|
#else
|
||||||
#define SP_INT_DIGITS ((3072 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
#define SP_INT_DIGITS ((3072 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#if defined(WOLFSSL_HAVE_SP_DH) && defined(WOLFSSL_KEY_GEN)
|
#if defined(WOLFSSL_HAVE_SP_DH)
|
||||||
#define SP_INT_DIGITS ((4096 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
#define SP_INT_DIGITS ((4096 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
||||||
#else
|
#else
|
||||||
#define SP_INT_DIGITS ((2048 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
#define SP_INT_DIGITS ((2048 + SP_WORD_SIZE) / SP_WORD_SIZE)
|
||||||
|
Reference in New Issue
Block a user