mirror of https://github.com/wolfSSL/wolfssl
Merge pull request #3288 from embhorn/zd10901
Fix mp_radix_size off by 1 error
This commit is contained in:
commit
2f74817e32
|
@ -335,7 +335,7 @@ int mp_unitest_mul(const char* strZ, const char* strX, const char* strY, int ver
|
|||
}
|
||||
|
||||
mp_radix_size(&z, 16, &radixZ_size);
|
||||
bufZ = (char*)XMALLOC(radixZ_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
bufZ = (char*)XMALLOC(radixZ_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if(bufZ != NULL) {
|
||||
mp_toradix(&z, bufZ, 16);
|
||||
bufZ[radixZ_size] ='\0';
|
||||
|
@ -350,7 +350,7 @@ int mp_unitest_mul(const char* strZ, const char* strX, const char* strY, int ver
|
|||
mp_radix_size(&y, 16, &radixY_size);
|
||||
radixX_size = max(radixX_size, radixY_size);
|
||||
|
||||
buf = (char*)XMALLOC(radixX_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
buf = (char*)XMALLOC(radixX_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if(buf != NULL) {
|
||||
mp_toradix(&x, buf, 16);
|
||||
buf[radixX_size] ='\0';
|
||||
|
@ -410,7 +410,7 @@ int mp_unitest_mulmod(const char* strZ, const char* strX, const char* strY,
|
|||
}
|
||||
|
||||
mp_radix_size(&z, 16, &radixZ_size);
|
||||
bufZ = (char*)XMALLOC(radixZ_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
bufZ = (char*)XMALLOC(radixZ_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if(bufZ != NULL) {
|
||||
mp_toradix(&z, bufZ, 16);
|
||||
bufZ[radixZ_size] ='\0';
|
||||
|
@ -427,7 +427,7 @@ int mp_unitest_mulmod(const char* strZ, const char* strX, const char* strY,
|
|||
mp_radix_size(&m, 16, &radixM_size);
|
||||
radixX_size = max(radixX_size, max(radixY_size, radixM_size));
|
||||
|
||||
buf = (char*)XMALLOC(radixX_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
buf = (char*)XMALLOC(radixX_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if(buf != NULL) {
|
||||
mp_toradix(&x, buf, 16);
|
||||
buf[radixX_size] ='\0';
|
||||
|
@ -491,7 +491,7 @@ int mp_unitest_exptmod(const char* strZ, const char* strX, const char* strY,
|
|||
}
|
||||
|
||||
mp_radix_size(&z, 16, &radixZ_size);
|
||||
bufZ = (char*)XMALLOC(radixZ_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
bufZ = (char*)XMALLOC(radixZ_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if(bufZ != NULL) {
|
||||
mp_toradix(&z, bufZ, 16);
|
||||
bufZ[radixZ_size] ='\0';
|
||||
|
@ -508,7 +508,7 @@ int mp_unitest_exptmod(const char* strZ, const char* strX, const char* strY,
|
|||
mp_radix_size(&m, 16, &radixM_size);
|
||||
radixX_size = max(radixX_size, max(radixY_size, radixM_size));
|
||||
|
||||
buf = (char*)XMALLOC(radixX_size + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
buf = (char*)XMALLOC(radixX_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if(buf != NULL) {
|
||||
mp_toradix(&x, buf, 16);
|
||||
buf[radixX_size] ='\0';
|
||||
|
|
|
@ -46462,7 +46462,6 @@ char *wolfSSL_BN_bn2hex(const WOLFSSL_BIGNUM *bn)
|
|||
WOLFSSL_MSG("mp_radix_size failure");
|
||||
return NULL;
|
||||
}
|
||||
len += 1; /* add one for null terminator */
|
||||
|
||||
buf = (char*)XMALLOC(len, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||
if (buf == NULL) {
|
||||
|
|
|
@ -5244,11 +5244,6 @@ int mp_radix_size (mp_int *a, int radix, int *size)
|
|||
/* digs is the digit count */
|
||||
digs = 0;
|
||||
|
||||
/* if it's negative add one for the sign */
|
||||
if (a->sign == MP_NEG) {
|
||||
++digs;
|
||||
}
|
||||
|
||||
/* init a copy of the input */
|
||||
if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
|
||||
return res;
|
||||
|
@ -5267,6 +5262,18 @@ int mp_radix_size (mp_int *a, int radix, int *size)
|
|||
}
|
||||
mp_clear (&t);
|
||||
|
||||
#ifndef WC_DISABLE_RADIX_ZERO_PAD
|
||||
/* For hexadecimal output, add zero padding when number of digits is odd */
|
||||
if ((digs & 1) && (radix == 16)) {
|
||||
++digs;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* if it's negative add one for the sign */
|
||||
if (a->sign == MP_NEG) {
|
||||
++digs;
|
||||
}
|
||||
|
||||
/* return digs + 1, the 1 is for the NULL byte that would be required. */
|
||||
*size = digs + 1;
|
||||
return MP_OKAY;
|
||||
|
|
|
@ -5453,11 +5453,6 @@ int mp_radix_size (mp_int *a, int radix, int *size)
|
|||
/* digs is the digit count */
|
||||
digs = 0;
|
||||
|
||||
/* if it's negative add one for the sign */
|
||||
if (a->sign == FP_NEG) {
|
||||
++digs;
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
t = (fp_int*)XMALLOC(sizeof(fp_int), NULL, DYNAMIC_TYPE_BIGINT);
|
||||
if (t == NULL)
|
||||
|
@ -5483,6 +5478,18 @@ int mp_radix_size (mp_int *a, int radix, int *size)
|
|||
}
|
||||
fp_zero (t);
|
||||
|
||||
#ifndef WC_DISABLE_RADIX_ZERO_PAD
|
||||
/* For hexadecimal output, add zero padding when number of digits is odd */
|
||||
if ((digs & 1) && (radix == 16)) {
|
||||
++digs;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* if it's negative add one for the sign */
|
||||
if (a->sign == FP_NEG) {
|
||||
++digs;
|
||||
}
|
||||
|
||||
/* return digs + 1, the 1 is for the NULL byte that would be required. */
|
||||
*size = digs + 1;
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
|
|
Loading…
Reference in New Issue