summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_read_radix.c
diff options
context:
space:
mode:
Diffstat (limited to 'libtommath/bn_mp_read_radix.c')
-rw-r--r--libtommath/bn_mp_read_radix.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/libtommath/bn_mp_read_radix.c b/libtommath/bn_mp_read_radix.c
index bc31cc5..55c5ee1 100644
--- a/libtommath/bn_mp_read_radix.c
+++ b/libtommath/bn_mp_read_radix.c
@@ -19,6 +19,7 @@
int mp_read_radix(mp_int *a, const char *str, int radix)
{
int y, res, neg;
+ unsigned pos;
char ch;
/* zero the digit bignum */
@@ -49,31 +50,30 @@ int mp_read_radix(mp_int *a, const char *str, int radix)
* [e.g. in hex]
*/
ch = (radix <= 36) ? (char)toupper((int)*str) : *str;
- for (y = 0; y < 64; y++) {
- if (ch == mp_s_rmap[y]) {
- break;
- }
+ pos = (unsigned)(ch - '(');
+ if (mp_s_rmap_reverse_sz < pos) {
+ break;
}
+ y = (int)mp_s_rmap_reverse[pos];
/* if the char was found in the map
* and is less than the given radix add it
* to the number, otherwise exit the loop.
*/
- if (y < radix) {
- if ((res = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) {
- return res;
- }
- if ((res = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) {
- return res;
- }
- } else {
+ if ((y == 0xff) || (y >= radix)) {
break;
}
+ if ((res = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) {
+ return res;
+ }
+ if ((res = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) {
+ return res;
+ }
++str;
}
/* if an illegal character was found, fail. */
- if (!(*str == '\0' || *str == '\r' || *str == '\n')) {
+ if (!((*str == '\0') || (*str == '\r') || (*str == '\n'))) {
mp_zero(a);
return MP_VAL;
}