Handle leading zero

This commit is contained in:
Eric Blankenhorn
2020-09-11 08:39:34 -05:00
parent 78a1670334
commit 4688f5fa59
2 changed files with 16 additions and 2 deletions

View File

@@ -5242,7 +5242,7 @@ int mp_radix_size (mp_int *a, int radix, int *size)
}
/* digs is the digit count */
digs = 1;
digs = 0;
/* if it's negative add one for the sign */
if (a->sign == MP_NEG) {
@@ -5267,6 +5267,13 @@ 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
/* return digs + 1, the 1 is for the NULL byte that would be required. */
*size = digs + 1;
return MP_OKAY;

View File

@@ -5451,7 +5451,7 @@ int mp_radix_size (mp_int *a, int radix, int *size)
}
/* digs is the digit count */
digs = 1;
digs = 0;
/* if it's negative add one for the sign */
if (a->sign == FP_NEG) {
@@ -5483,6 +5483,13 @@ 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
/* return digs + 1, the 1 is for the NULL byte that would be required. */
*size = digs + 1;
#ifdef WOLFSSL_SMALL_STACK