From 71e3024f30ed8d1696461e20070a77683e4437e4 Mon Sep 17 00:00:00 2001 From: Kevin B Kenny Date: Tue, 10 May 2005 17:20:39 +0000 Subject: [PATCH 1/3] fix mp_iseven --- tommath.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tommath.h b/tommath.h index 7dda0a5..80bae69 100644 --- a/tommath.h +++ b/tommath.h @@ -203,7 +203,7 @@ int mp_init_size(mp_int *a, int size); /* ---> Basic Manipulations <--- */ #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO) -#define mp_iseven(a) ((((a)->used > 0) && (((a)->dp[0] & 1u) == 0u)) ? MP_YES : MP_NO) +#define mp_iseven(a) ((((a)->used == 0) || (((a)->dp[0] & 1u) == 0u)) ? MP_YES : MP_NO) #define mp_isodd(a) ((((a)->used > 0) && (((a)->dp[0] & 1u) == 1u)) ? MP_YES : MP_NO) #define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO) From ba95ef76e0e1c3a5228c446465766d4547c3e623 Mon Sep 17 00:00:00 2001 From: Kevin B Kenny Date: Tue, 10 May 2005 17:20:39 +0000 Subject: [PATCH 2/3] ensure string is null-terminated --- bn_mp_read_radix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bn_mp_read_radix.c b/bn_mp_read_radix.c index 5decdeb..e02f066 100644 --- a/bn_mp_read_radix.c +++ b/bn_mp_read_radix.c @@ -71,7 +71,13 @@ int mp_read_radix (mp_int * a, const char *str, int radix) } ++str; } - + + /* if an illegal character was found, fail. */ + if (*str != '\0') { + mp_zero(a); + return MP_VAL; + } + /* set the sign only if a != 0 */ if (mp_iszero(a) != MP_YES) { a->sign = neg; From b2971381e50c5421fa89201fda67a3114f815674 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 29 Aug 2017 12:02:18 +0200 Subject: [PATCH 3/3] don't be that strict regarding illegal characters in `mp_read_radix()` --- bn_mp_read_radix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bn_mp_read_radix.c b/bn_mp_read_radix.c index e02f066..12aa499 100644 --- a/bn_mp_read_radix.c +++ b/bn_mp_read_radix.c @@ -73,7 +73,7 @@ int mp_read_radix (mp_int * a, const char *str, int radix) } /* if an illegal character was found, fail. */ - if (*str != '\0') { + if (!(*str == '\0' || *str == '\r' || *str == '\n')) { mp_zero(a); return MP_VAL; }