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
)
11 mp_sign sign
= MP_ZPOS
;
14 /* make sure the radix is ok */
15 if ((radix
< 2) || (radix
> 64)) {
19 /* if first digit is - then set negative */
26 /* no digits, return error */
37 ch
= (radix
<= 36) ? MP_TOUPPER(ch
) : ch
;
38 pos
= (unsigned)(ch
- (int)'+');
39 if (MP_RADIX_MAP_REVERSE_SIZE
<= pos
) {
43 y
= s_mp_radix_map_reverse
[pos
];
49 /* shift up and add */
50 if ((err
= mp_mul_d(a
, (mp_digit
)radix
, a
)) != MP_OKAY
) {
53 if ((err
= mp_add_d(a
, y
, a
)) != MP_OKAY
) {
56 } while ((ch
= fgetc(stream
)) != EOF
);