From a666ae690ad548b5f357e70ed124aa3ab64afa5b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 18 Jan 2019 10:43:02 -0800 Subject: mpi: use wchar_t string for text-to-bignum. * mpi/mpi.c (mp_read_radix): Take const wchar_t * string rather than unsigned char *. (s_mp_tovalue): Take character argument as wchar_t rather than int. * mpi/mpi.h (mp_read_radix): Declaration updated. * lib.c (int_str): Avoid a malloc/free and UTF-8 conversion by passing the original wide string to mp_read_radix. This removes a TODO dating back to December 2011. --- mpi/mpi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mpi/mpi.c') diff --git a/mpi/mpi.c b/mpi/mpi.c index 198a5a86..d3e4cb05 100644 --- a/mpi/mpi.c +++ b/mpi/mpi.c @@ -156,7 +156,7 @@ int s_mp_cmp_d(mp_int *a, mp_digit d); /* magnitude digit compare */ mp_size s_mp_ispow2(mp_int *v); /* is v a power of 2? */ int s_mp_ispow2d(mp_digit d); /* is d a power of 2? */ -int s_mp_tovalue(int ch, int r); /* convert ch to value */ +int s_mp_tovalue(wchar_t ch, int r); /* convert ch to value */ char s_mp_todigit(int val, int r, int low); /* convert val to digit */ size_t s_mp_outlen(mp_size bits, int r); /* output length in bytes */ @@ -2568,7 +2568,7 @@ mp_size mp_is_pow_two(mp_int *mp) * characters are ignored, and the function reads until a non-digit * character or the end of the string. */ -mp_err mp_read_radix(mp_int *mp, unsigned char *str, int radix) +mp_err mp_read_radix(mp_int *mp, const wchar_t *str, int radix) { size_t ix = 0; int val = 0; @@ -3959,7 +3959,7 @@ int s_mp_ispow2d(mp_digit d) * The results will be odd if you use a radix < 2 or > 62, you are * expected to know what you're up to. */ -int s_mp_tovalue(int ch, int r) +int s_mp_tovalue(wchar_t ch, int r) { int val, xch; -- cgit v1.2.3