1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
7 /* read a bigint from a file stream in ASCII */
8 mp_err mp_fread(mp_int *a, int radix, FILE *stream)
13 /* if first digit is - then set negative */
14 int ch = fgetc(stream);
22 /* no digits, return error */
32 unsigned pos = (unsigned)(ch - (int)'(');
33 if (mp_s_rmap_reverse_sz < pos) {
37 y = (int)mp_s_rmap_reverse[pos];
39 if ((y == 0xff) || (y >= radix)) {
43 /* shift up and add */
44 if ((err = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) {
47 if ((err = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) {
50 } while ((ch = fgetc(stream)) != EOF);