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

          Line data    Source code
       1             : #include <tommath.h>
       2             : #ifdef BN_MP_MUL_2_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             : /* b = a*2 */
      19       43168 : int mp_mul_2(mp_int * a, mp_int * b)
      20             : {
      21             :   int     x, res, oldused;
      22             : 
      23             :   /* grow to accomodate result */
      24       43168 :   if (b->alloc < a->used + 1) {
      25           0 :     if ((res = mp_grow (b, a->used + 1)) != MP_OKAY) {
      26           0 :       return res;
      27             :     }
      28             :   }
      29             : 
      30       43168 :   oldused = b->used;
      31       43168 :   b->used = a->used;
      32             : 
      33             :   {
      34             :     register mp_digit r, rr, *tmpa, *tmpb;
      35             : 
      36             :     /* alias for source */
      37       43168 :     tmpa = a->dp;
      38             : 
      39             :     /* alias for dest */
      40       43168 :     tmpb = b->dp;
      41             : 
      42             :     /* carry */
      43       43168 :     r = 0;
      44     1876739 :     for (x = 0; x < a->used; x++) {
      45             : 
      46             :       /* get what will be the *next* carry bit from the
      47             :        * MSB of the current digit
      48             :        */
      49     1833571 :       rr = *tmpa >> ((mp_digit)(DIGIT_BIT - 1));
      50             : 
      51             :       /* now shift up this digit, add in the carry [from the previous] */
      52     1833571 :       *tmpb++ = ((*tmpa++ << ((mp_digit)1)) | r) & MP_MASK;
      53             : 
      54             :       /* copy the carry that would be from the source
      55             :        * digit into the next iteration
      56             :        */
      57     1833571 :       r = rr;
      58             :     }
      59             : 
      60             :     /* new leading digit? */
      61       43168 :     if (r != 0) {
      62             :       /* add a MSB which is always 1 at this point */
      63         514 :       *tmpb = 1;
      64         514 :       ++(b->used);
      65             :     }
      66             : 
      67             :     /* now zero any excess digits on the destination
      68             :      * that we didn't write to
      69             :      */
      70       43168 :     tmpb = b->dp + b->used;
      71       43168 :     for (x = b->used; x < oldused; x++) {
      72           0 :       *tmpb++ = 0;
      73             :     }
      74             :   }
      75       43168 :   b->sign = a->sign;
      76       43168 :   return MP_OKAY;
      77             : }
      78             : #endif
      79             : 
      80             : /* $Source: /cvs/libtom/libtommath/bn_mp_mul_2.c,v $ */
      81             : /* $Revision: 1.4 $ */
      82             : /* $Date: 2006/12/28 01:25:13 $ */

Generated by: LCOV version 1.13