mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 04:04:39 +02:00
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 is the digit count */
|
||||||
digs = 1;
|
digs = 0;
|
||||||
|
|
||||||
/* if it's negative add one for the sign */
|
/* if it's negative add one for the sign */
|
||||||
if (a->sign == MP_NEG) {
|
if (a->sign == MP_NEG) {
|
||||||
@@ -5267,6 +5267,13 @@ int mp_radix_size (mp_int *a, int radix, int *size)
|
|||||||
}
|
}
|
||||||
mp_clear (&t);
|
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. */
|
/* return digs + 1, the 1 is for the NULL byte that would be required. */
|
||||||
*size = digs + 1;
|
*size = digs + 1;
|
||||||
return MP_OKAY;
|
return MP_OKAY;
|
||||||
|
@@ -5451,7 +5451,7 @@ int mp_radix_size (mp_int *a, int radix, int *size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* digs is the digit count */
|
/* digs is the digit count */
|
||||||
digs = 1;
|
digs = 0;
|
||||||
|
|
||||||
/* if it's negative add one for the sign */
|
/* if it's negative add one for the sign */
|
||||||
if (a->sign == FP_NEG) {
|
if (a->sign == FP_NEG) {
|
||||||
@@ -5483,6 +5483,13 @@ int mp_radix_size (mp_int *a, int radix, int *size)
|
|||||||
}
|
}
|
||||||
fp_zero (t);
|
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. */
|
/* return digs + 1, the 1 is for the NULL byte that would be required. */
|
||||||
*size = digs + 1;
|
*size = digs + 1;
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
Reference in New Issue
Block a user