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

          Line data    Source code
       1             : #include <tommath.h>
       2             : #ifdef BN_S_MP_MUL_HIGH_DIGS_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             : /* multiplies |a| * |b| and does not compute the lower digs digits
      19             :  * [meant to get the higher part of the product]
      20             :  */
      21             : int
      22           0 : s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
      23             : {
      24             :   mp_int  t;
      25             :   int     res, pa, pb, ix, iy;
      26             :   mp_digit u;
      27             :   mp_word r;
      28             :   mp_digit tmpx, *tmpt, *tmpy;
      29             : 
      30             :   /* can we use the fast multiplier? */
      31             : #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
      32           0 :   if (((a->used + b->used + 1) < MP_WARRAY)
      33           0 :       && MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
      34           0 :     return fast_s_mp_mul_high_digs (a, b, c, digs);
      35             :   }
      36             : #endif
      37             : 
      38           0 :   if ((res = mp_init_size (&t, a->used + b->used + 1)) != MP_OKAY) {
      39           0 :     return res;
      40             :   }
      41           0 :   t.used = a->used + b->used + 1;
      42             : 
      43           0 :   pa = a->used;
      44           0 :   pb = b->used;
      45           0 :   for (ix = 0; ix < pa; ix++) {
      46             :     /* clear the carry */
      47           0 :     u = 0;
      48             : 
      49             :     /* left hand side of A[ix] * B[iy] */
      50           0 :     tmpx = a->dp[ix];
      51             : 
      52             :     /* alias to the address of where the digits will be stored */
      53           0 :     tmpt = &(t.dp[digs]);
      54             : 
      55             :     /* alias for where to read the right hand side from */
      56           0 :     tmpy = b->dp + (digs - ix);
      57             : 
      58           0 :     for (iy = digs - ix; iy < pb; iy++) {
      59             :       /* calculate the double precision result */
      60           0 :       r       = ((mp_word)*tmpt) +
      61           0 :                 ((mp_word)tmpx) * ((mp_word)*tmpy++) +
      62           0 :                 ((mp_word) u);
      63             : 
      64             :       /* get the lower part */
      65           0 :       *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
      66             : 
      67             :       /* carry the carry */
      68           0 :       u       = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
      69             :     }
      70           0 :     *tmpt = u;
      71             :   }
      72           0 :   mp_clamp (&t);
      73           0 :   mp_exch (&t, c);
      74           0 :   mp_clear (&t);
      75           0 :   return MP_OKAY;
      76             : }
      77             : #endif
      78             : 
      79             : /* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_high_digs.c,v $ */
      80             : /* $Revision: 1.4 $ */
      81             : /* $Date: 2006/12/28 01:25:13 $ */

Generated by: LCOV version 1.13