LCOV - code coverage report
Current view: top level - source4/heimdal/lib/hcrypto/libtommath - bn_mp_rshd.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 12 14 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_RSHD_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             : /* shift right a certain amount of digits */
      19        1634 : void mp_rshd (mp_int * a, int b)
      20             : {
      21             :   /* if b <= 0 then ignore it */
      22        1634 :   if (b <= 0) {
      23          26 :     return;
      24             :   }
      25             : 
      26             :   /* if b > used then simply zero it and return */
      27        1606 :   if (a->used <= b) {
      28           0 :     mp_zero (a);
      29           0 :     return;
      30             :   }
      31             : 
      32             :   {
      33             :     register mp_digit *bottom, *top;
      34             :     unsigned x, y;
      35             : 
      36             :     /* shift the digits down */
      37             : 
      38             :     /* bottom */
      39        1606 :     bottom = a->dp;
      40             : 
      41             :     /* top [offset into digits] */
      42        1606 :     top = a->dp + b;
      43             : 
      44             :     /* this is implemented as a sliding window where
      45             :      * the window is b-digits long and digits from
      46             :      * the top of the window are copied to the bottom
      47             :      *
      48             :      * e.g.
      49             : 
      50             :      b-2 | b-1 | b0 | b1 | b2 | ... | bb |   ---->
      51             :                  /\                   |      ---->
      52             :                   \-------------------/      ---->
      53             :      */
      54        1606 :     y = a->used - b;         /* a->used>=b checked above */
      55       73252 :     for (x = 0; x < y; x++) {
      56       71646 :       *bottom++ = *top++;
      57             :     }
      58             : 
      59             :     /* zero the top digits */
      60       72846 :     for (; x < (unsigned)a->used; x++) {
      61       71312 :       *bottom++ = 0;
      62             :     }
      63             :   }
      64             : 
      65             :   /* remove excess digits */
      66        1606 :   a->used -= b;
      67             : }
      68             : #endif
      69             : 
      70             : /* $Source: /cvs/libtom/libtommath/bn_mp_rshd.c,v $ */
      71             : /* $Revision: 1.4 $ */
      72             : /* $Date: 2006/12/28 01:25:13 $ */

Generated by: LCOV version 1.13