Add leading zero for odd number of hex digits

This commit is contained in:
Tesfa Mael
2019-10-14 16:43:45 -07:00
parent df77088d5c
commit 441f3a7f1f
2 changed files with 7 additions and 1 deletions

View File

@ -24095,7 +24095,7 @@ static void test_wolfSSL_X509_get_serialNumber(void)
X509_free(x509); /* free's a */ X509_free(x509); /* free's a */
AssertNotNull(serialHex = BN_bn2hex(bn)); AssertNotNull(serialHex = BN_bn2hex(bn));
AssertStrEQ(serialHex, "1"); AssertStrEQ(serialHex, "01");
OPENSSL_free(serialHex); OPENSSL_free(serialHex);
AssertIntEQ(BN_get_word(bn), 1); AssertIntEQ(BN_get_word(bn), 1);

View File

@ -4780,6 +4780,12 @@ int mp_toradix (mp_int *a, char *str, int radix)
++digs; ++digs;
} }
/* For hexadecimal output, add zero when number of digits is odd */
if ((digs & 1) && (radix == 16)) {
*str++ = fp_s_rmap[0];
++digs;
}
/* reverse the digits of the string. In this case _s points /* reverse the digits of the string. In this case _s points
* to the first digit [excluding the sign] of the number] * to the first digit [excluding the sign] of the number]
*/ */