LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_mul_d.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 22 23 95.7 %
Date: 2024-02-29 22:57:05 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "tommath_private.h"
       2             : #ifdef BN_MP_MUL_D_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* multiply by a digit */
       7      188042 : mp_err mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
       8             : {
       9        9689 :    mp_digit u, *tmpa, *tmpc;
      10        9689 :    mp_word  r;
      11        9689 :    mp_err   err;
      12        9689 :    int      ix, olduse;
      13             : 
      14             :    /* make sure c is big enough to hold a*b */
      15      188042 :    if (c->alloc < (a->used + 1)) {
      16        1194 :       if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
      17           0 :          return err;
      18             :       }
      19             :    }
      20             : 
      21             :    /* get the original destinations used count */
      22      188042 :    olduse = c->used;
      23             : 
      24             :    /* set the sign */
      25      188042 :    c->sign = a->sign;
      26             : 
      27             :    /* alias for a->dp [source] */
      28      188042 :    tmpa = a->dp;
      29             : 
      30             :    /* alias for c->dp [dest] */
      31      188042 :    tmpc = c->dp;
      32             : 
      33             :    /* zero carry */
      34      188042 :    u = 0;
      35             : 
      36             :    /* compute columns */
      37     5680509 :    for (ix = 0; ix < a->used; ix++) {
      38             :       /* compute product and carry sum for this term */
      39     5492467 :       r       = (mp_word)u + ((mp_word)*tmpa++ * (mp_word)b);
      40             : 
      41             :       /* mask off higher bits to get a single digit */
      42     5492467 :       *tmpc++ = (mp_digit)(r & (mp_word)MP_MASK);
      43             : 
      44             :       /* send carry into next iteration */
      45     5492467 :       u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
      46             :    }
      47             : 
      48             :    /* store final carry [if any] and increment ix offset  */
      49      188042 :    *tmpc++ = u;
      50      188042 :    ++ix;
      51             : 
      52             :    /* now zero digits above the top */
      53      188042 :    MP_ZERO_DIGITS(tmpc, olduse - ix);
      54             : 
      55             :    /* set used count */
      56      188042 :    c->used = a->used + 1;
      57      188042 :    mp_clamp(c);
      58             : 
      59      188042 :    return MP_OKAY;
      60             : }
      61             : #endif

Generated by: LCOV version 1.14