forked from wolfSSL/wolfssl
Handle leading zero
This commit is contained in:
@@ -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;
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user