LCOV - code coverage report
Current view: top level - source4/heimdal/lib/hcrypto/libtommath - bn_mp_read_radix.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 0 24 0.0 %
Date: 2021-09-23 10:06:22 Functions: 0 1 0.0 %

          Line data    Source code
       1             : #include <tommath.h>
       2             : #ifdef BN_MP_READ_RADIX_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis
       4             :  *
       5             :  * LibTomMath is a library that provides multiple-precision
       6             :  * integer arithmetic as well as number theoretic functionality.
       7             :  *
       8             :  * The library was designed directly after the MPI library by
       9             :  * Michael Fromberger but has been written from scratch with
      10             :  * additional optimizations in place.
      11             :  *
      12             :  * The library is free for all purposes without any express
      13             :  * guarantee it works.
      14             :  *
      15             :  * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
      16             :  */
      17             : 
      18             : /* read a string [ASCII] in a given radix */
      19           0 : int mp_read_radix (mp_int * a, const char *str, int radix)
      20             : {
      21             :   int     y, res, neg;
      22             :   char    ch;
      23             : 
      24             :   /* zero the digit bignum */
      25           0 :   mp_zero(a);
      26             : 
      27             :   /* make sure the radix is ok */
      28           0 :   if (radix < 2 || radix > 64) {
      29           0 :     return MP_VAL;
      30             :   }
      31             : 
      32             :   /* if the leading digit is a
      33             :    * minus set the sign to negative.
      34             :    */
      35           0 :   if (*str == '-') {
      36           0 :     ++str;
      37           0 :     neg = MP_NEG;
      38             :   } else {
      39           0 :     neg = MP_ZPOS;
      40             :   }
      41             : 
      42             :   /* set the integer to the default of zero */
      43           0 :   mp_zero (a);
      44             : 
      45             :   /* process each digit of the string */
      46           0 :   while (*str) {
      47             :     /* if the radix < 36 the conversion is case insensitive
      48             :      * this allows numbers like 1AB and 1ab to represent the same  value
      49             :      * [e.g. in hex]
      50             :      */
      51           0 :     ch = (char) ((radix < 36) ? toupper (*str) : *str);
      52           0 :     for (y = 0; y < 64; y++) {
      53           0 :       if (ch == mp_s_rmap[y]) {
      54           0 :          break;
      55             :       }
      56             :     }
      57             : 
      58             :     /* if the char was found in the map
      59             :      * and is less than the given radix add it
      60             :      * to the number, otherwise exit the loop.
      61             :      */
      62           0 :     if (y < radix) {
      63           0 :       if ((res = mp_mul_d (a, (mp_digit) radix, a)) != MP_OKAY) {
      64           0 :          return res;
      65             :       }
      66           0 :       if ((res = mp_add_d (a, (mp_digit) y, a)) != MP_OKAY) {
      67           0 :          return res;
      68             :       }
      69             :     } else {
      70           0 :       break;
      71             :     }
      72           0 :     ++str;
      73             :   }
      74             : 
      75             :   /* set the sign only if a != 0 */
      76           0 :   if (mp_iszero(a) != 1) {
      77           0 :      a->sign = neg;
      78             :   }
      79           0 :   return MP_OKAY;
      80             : }
      81             : #endif
      82             : 
      83             : /* $Source: /cvs/libtom/libtommath/bn_mp_read_radix.c,v $ */
      84             : /* $Revision: 1.5 $ */
      85             : /* $Date: 2006/12/28 01:25:13 $ */

Generated by: LCOV version 1.13