forked from wolfSSL/wolfssl
smallstack reduction for PrintPubKeyRSA, PrintPubKeyDSA, PrintPubKeyDH
This commit is contained in:
@ -8242,12 +8242,26 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
int wsz;
|
int wsz;
|
||||||
word32 i;
|
word32 i;
|
||||||
unsigned long exponent = 0;
|
unsigned long exponent = 0;
|
||||||
mp_int a;
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
mp_int* a = NULL;
|
||||||
|
#else
|
||||||
|
mp_int a[1];
|
||||||
|
#endif
|
||||||
char line[32] = { 0 };
|
char line[32] = { 0 };
|
||||||
|
|
||||||
(void)pctx;
|
(void)pctx;
|
||||||
|
|
||||||
if( mp_init(&a) != 0) {
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
a = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_BIGINT);
|
||||||
|
if (a == NULL) {
|
||||||
|
return WOLFSSL_FAILURE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if( mp_init(a) != 0) {
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
|
||||||
|
#endif
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
if (indent < 0) {
|
if (indent < 0) {
|
||||||
@ -8272,10 +8286,10 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) {
|
if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mp_set_int(&a, bitlen) != 0) {
|
if (mp_set_int(a, bitlen) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mp_todecimal(&a, (char*)buff) != 0) {
|
if (mp_todecimal(a, (char*)buff) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wsz = (int)XSTRLEN((const char*)buff);
|
wsz = (int)XSTRLEN((const char*)buff);
|
||||||
@ -8315,10 +8329,10 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
}
|
}
|
||||||
|
|
||||||
XMEMSET(buff, 0, sizeof(buff));
|
XMEMSET(buff, 0, sizeof(buff));
|
||||||
if (mp_set_int(&a, exponent) != 0) {
|
if (mp_set_int(a, exponent) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mp_todecimal(&a, (char*)buff) != 0) {
|
if (mp_todecimal(a, (char*)buff) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wsz = (int)XSTRLEN((const char*)buff);
|
wsz = (int)XSTRLEN((const char*)buff);
|
||||||
@ -8331,7 +8345,7 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
XMEMSET(buff, 0, sizeof(buff));
|
XMEMSET(buff, 0, sizeof(buff));
|
||||||
if (mp_tohex(&a, (char*)buff) != 0) {
|
if (mp_tohex(a, (char*)buff) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (wolfSSL_BIO_write(out, buff, (int)XSTRLEN((char*)buff)) <= 0) {
|
if (wolfSSL_BIO_write(out, buff, (int)XSTRLEN((char*)buff)) <= 0) {
|
||||||
@ -8345,7 +8359,10 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
res = WOLFSSL_SUCCESS;
|
res = WOLFSSL_SUCCESS;
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
mp_free(&a);
|
mp_free(a);
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
|
||||||
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
#endif /* !NO_RSA */
|
#endif /* !NO_RSA */
|
||||||
@ -8574,11 +8591,26 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
int pSz, qSz, gSz, ySz;
|
int pSz, qSz, gSz, ySz;
|
||||||
int idx;
|
int idx;
|
||||||
int wsz;
|
int wsz;
|
||||||
mp_int a;
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
mp_int* a = NULL;
|
||||||
|
#else
|
||||||
|
mp_int a[1];
|
||||||
|
#endif
|
||||||
char line[32] = { 0 };
|
char line[32] = { 0 };
|
||||||
|
|
||||||
if( mp_init(&a) != 0)
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
a = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_BIGINT);
|
||||||
|
if (a == NULL) {
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if( mp_init(a) != 0) {
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
|
||||||
|
#endif
|
||||||
|
return WOLFSSL_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
inOutIdx = 0;
|
inOutIdx = 0;
|
||||||
(void)pctx;
|
(void)pctx;
|
||||||
@ -8684,10 +8716,10 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) {
|
if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mp_set_int(&a, bitlen) != 0) {
|
if (mp_set_int(a, bitlen) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mp_todecimal(&a, (char*)buff) != 0) {
|
if (mp_todecimal(a, (char*)buff) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wsz = (int)XSTRLEN((const char*)buff);
|
wsz = (int)XSTRLEN((const char*)buff);
|
||||||
@ -8738,7 +8770,10 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
res = WOLFSSL_SUCCESS;
|
res = WOLFSSL_SUCCESS;
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
mp_free(&a);
|
mp_free(a);
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
|
||||||
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
#endif /* !NO_DSA */
|
#endif /* !NO_DSA */
|
||||||
@ -8774,11 +8809,26 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
int wsz;
|
int wsz;
|
||||||
word32 outSz;
|
word32 outSz;
|
||||||
byte outHex[3];
|
byte outHex[3];
|
||||||
mp_int a;
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
mp_int* a = NULL;
|
||||||
|
#else
|
||||||
|
mp_int a[1];
|
||||||
|
#endif
|
||||||
char line[32] = { 0 };
|
char line[32] = { 0 };
|
||||||
|
|
||||||
if( mp_init(&a) != 0)
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
a = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_BIGINT);
|
||||||
|
if (a == NULL) {
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if( mp_init(a) != 0) {
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
|
||||||
|
#endif
|
||||||
|
return WOLFSSL_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
inOutIdx = 0;
|
inOutIdx = 0;
|
||||||
(void)pctx;
|
(void)pctx;
|
||||||
@ -8872,10 +8922,10 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) {
|
if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mp_set_int(&a, bitlen) != 0) {
|
if (mp_set_int(a, bitlen) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mp_todecimal(&a, (char*)buff) != 0) {
|
if (mp_todecimal(a, (char*)buff) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wsz = (int)XSTRLEN((const char*)buff);
|
wsz = (int)XSTRLEN((const char*)buff);
|
||||||
@ -8911,10 +8961,10 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) {
|
if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mp_set_int(&a, generator) != 0) {
|
if (mp_set_int(a, generator) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mp_todecimal(&a, (char*)buff) != 0) {
|
if (mp_todecimal(a, (char*)buff) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wsz = (int)XSTRLEN((const char*)buff);
|
wsz = (int)XSTRLEN((const char*)buff);
|
||||||
@ -8946,7 +8996,10 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
|
|||||||
res = WOLFSSL_SUCCESS;
|
res = WOLFSSL_SUCCESS;
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
mp_free(&a);
|
mp_free(a);
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
|
||||||
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
#endif /* WOLFSSL_DH_EXTRA */
|
#endif /* WOLFSSL_DH_EXTRA */
|
||||||
|
Reference in New Issue
Block a user