LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_div_2.c (source / functions) Hit Total Coverage
Test: coverage report for master 98b443d9 Lines: 18 20 90.0 %
Date: 2024-05-31 13:13:24 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "tommath_private.h"
       2             : #ifdef BN_MP_DIV_2_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* b = a/2 */
       7     1375622 : mp_err mp_div_2(const mp_int *a, mp_int *b)
       8             : {
       9       92282 :    int     x, oldused;
      10       92282 :    mp_digit r, rr, *tmpa, *tmpb;
      11       92282 :    mp_err err;
      12             : 
      13             :    /* copy */
      14     1375622 :    if (b->alloc < a->used) {
      15           0 :       if ((err = mp_grow(b, a->used)) != MP_OKAY) {
      16           0 :          return err;
      17             :       }
      18             :    }
      19             : 
      20     1375622 :    oldused = b->used;
      21     1375622 :    b->used = a->used;
      22             : 
      23             :    /* source alias */
      24     1375622 :    tmpa = a->dp + b->used - 1;
      25             : 
      26             :    /* dest alias */
      27     1375622 :    tmpb = b->dp + b->used - 1;
      28             : 
      29             :    /* carry */
      30     1375622 :    r = 0;
      31    66741271 :    for (x = b->used - 1; x >= 0; x--) {
      32             :       /* get the carry for the next iteration */
      33    65365649 :       rr = *tmpa & 1u;
      34             : 
      35             :       /* shift the current digit, add in carry and store */
      36    65365649 :       *tmpb-- = (*tmpa-- >> 1) | (r << (MP_DIGIT_BIT - 1));
      37             : 
      38             :       /* forward carry to next iteration */
      39    65365649 :       r = rr;
      40             :    }
      41             : 
      42             :    /* zero excess digits */
      43     1375622 :    MP_ZERO_DIGITS(b->dp + b->used, oldused - b->used);
      44             : 
      45     1375622 :    b->sign = a->sign;
      46     1375622 :    mp_clamp(b);
      47     1375622 :    return MP_OKAY;
      48             : }
      49             : #endif

Generated by: LCOV version 1.14