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

          Line data    Source code
       1             : #include <tommath.h>
       2             : #ifdef BN_MP_DIV_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     1388064 : int mp_div_2(mp_int * a, mp_int * b)
      20             : {
      21             :   int     x, res, oldused;
      22             : 
      23             :   /* copy */
      24     1388064 :   if (b->alloc < a->used) {
      25           0 :     if ((res = mp_grow (b, a->used)) != MP_OKAY) {
      26           0 :       return res;
      27             :     }
      28             :   }
      29             : 
      30     1388064 :   oldused = b->used;
      31     1388064 :   b->used = a->used;
      32             :   {
      33             :     register mp_digit r, rr, *tmpa, *tmpb;
      34             : 
      35             :     /* source alias */
      36     1388064 :     tmpa = a->dp + b->used - 1;
      37             : 
      38             :     /* dest alias */
      39     1388064 :     tmpb = b->dp + b->used - 1;
      40             : 
      41             :     /* carry */
      42     1388064 :     r = 0;
      43    61508397 :     for (x = b->used - 1; x >= 0; x--) {
      44             :       /* get the carry for the next iteration */
      45    60120333 :       rr = *tmpa & 1;
      46             : 
      47             :       /* shift the current digit, add in carry and store */
      48    60120333 :       *tmpb-- = (*tmpa-- >> 1) | (r << (DIGIT_BIT - 1));
      49             : 
      50             :       /* forward carry to next iteration */
      51    60120333 :       r = rr;
      52             :     }
      53             : 
      54             :     /* zero excess digits */
      55     1388064 :     tmpb = b->dp + b->used;
      56     1388064 :     for (x = b->used; x < oldused; x++) {
      57           0 :       *tmpb++ = 0;
      58             :     }
      59             :   }
      60     1388064 :   b->sign = a->sign;
      61     1388064 :   mp_clamp (b);
      62     1388064 :   return MP_OKAY;
      63             : }
      64             : #endif
      65             : 
      66             : /* $Source: /cvs/libtom/libtommath/bn_mp_div_2.c,v $ */
      67             : /* $Revision: 1.4 $ */
      68             : /* $Date: 2006/12/28 01:25:13 $ */

Generated by: LCOV version 1.13