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

          Line data    Source code
       1             : #include "tommath_private.h"
       2             : #ifdef BN_MP_RSHD_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* shift right a certain amount of digits */
       7         352 : void mp_rshd(mp_int *a, int b)
       8             : {
       9             :    int     x;
      10             :    mp_digit *bottom, *top;
      11             : 
      12             :    /* if b <= 0 then ignore it */
      13         352 :    if (b <= 0) {
      14          10 :       return;
      15             :    }
      16             : 
      17             :    /* if b > used then simply zero it and return */
      18         342 :    if (a->used <= b) {
      19           0 :       mp_zero(a);
      20           0 :       return;
      21             :    }
      22             : 
      23             :    /* shift the digits down */
      24             : 
      25             :    /* bottom */
      26         342 :    bottom = a->dp;
      27             : 
      28             :    /* top [offset into digits] */
      29         342 :    top = a->dp + b;
      30             : 
      31             :    /* this is implemented as a sliding window where
      32             :     * the window is b-digits long and digits from
      33             :     * the top of the window are copied to the bottom
      34             :     *
      35             :     * e.g.
      36             : 
      37             :     b-2 | b-1 | b0 | b1 | b2 | ... | bb |   ---->
      38             :                 /\                   |      ---->
      39             :                  \-------------------/      ---->
      40             :     */
      41       17480 :    for (x = 0; x < (a->used - b); x++) {
      42       17138 :       *bottom++ = *top++;
      43             :    }
      44             : 
      45             :    /* zero the top digits */
      46         342 :    MP_ZERO_DIGITS(bottom, a->used - x);
      47             : 
      48             :    /* remove excess digits */
      49         342 :    a->used -= b;
      50             : }
      51             : #endif

Generated by: LCOV version 1.13