LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_fread.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 0 22 0.0 %
Date: 2024-06-13 04:01:37 Functions: 0 1 0.0 %

          Line data    Source code
       1             : #include "tommath_private.h"
       2             : #ifdef BN_MP_FREAD_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : #ifndef MP_NO_FILE
       7             : /* read a bigint from a file stream in ASCII */
       8           0 : mp_err mp_fread(mp_int *a, int radix, FILE *stream)
       9             : {
      10             :    mp_err err;
      11             :    mp_sign neg;
      12             : 
      13             :    /* if first digit is - then set negative */
      14           0 :    int ch = fgetc(stream);
      15           0 :    if (ch == (int)'-') {
      16           0 :       neg = MP_NEG;
      17           0 :       ch = fgetc(stream);
      18             :    } else {
      19           0 :       neg = MP_ZPOS;
      20             :    }
      21             : 
      22             :    /* no digits, return error */
      23           0 :    if (ch == EOF) {
      24           0 :       return MP_ERR;
      25             :    }
      26             : 
      27             :    /* clear a */
      28           0 :    mp_zero(a);
      29             : 
      30             :    do {
      31             :       int y;
      32           0 :       unsigned pos = (unsigned)(ch - (int)'(');
      33           0 :       if (mp_s_rmap_reverse_sz < pos) {
      34           0 :          break;
      35             :       }
      36             : 
      37           0 :       y = (int)mp_s_rmap_reverse[pos];
      38             : 
      39           0 :       if ((y == 0xff) || (y >= radix)) {
      40             :          break;
      41             :       }
      42             : 
      43             :       /* shift up and add */
      44           0 :       if ((err = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) {
      45           0 :          return err;
      46             :       }
      47           0 :       if ((err = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) {
      48           0 :          return err;
      49             :       }
      50           0 :    } while ((ch = fgetc(stream)) != EOF);
      51             : 
      52           0 :    if (a->used != 0) {
      53           0 :       a->sign = neg;
      54             :    }
      55             : 
      56           0 :    return MP_OKAY;
      57             : }
      58             : #endif
      59             : 
      60             : #endif

Generated by: LCOV version 1.13