LCOV - code coverage report
Current view: top level - source4/heimdal/lib/hcrypto/libtommath - bn_s_mp_sqr.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_SQR_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             : /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
      19           0 : int s_mp_sqr (mp_int * a, mp_int * b)
      20             : {
      21             :   mp_int  t;
      22             :   int     res, ix, iy, pa;
      23             :   mp_word r;
      24             :   mp_digit u, tmpx, *tmpt;
      25             : 
      26           0 :   pa = a->used;
      27           0 :   if ((res = mp_init_size (&t, 2*pa + 1)) != MP_OKAY) {
      28           0 :     return res;
      29             :   }
      30             : 
      31             :   /* default used is maximum possible size */
      32           0 :   t.used = 2*pa + 1;
      33             : 
      34           0 :   for (ix = 0; ix < pa; ix++) {
      35             :     /* first calculate the digit at 2*ix */
      36             :     /* calculate double precision result */
      37           0 :     r = ((mp_word) t.dp[2*ix]) +
      38           0 :         ((mp_word)a->dp[ix])*((mp_word)a->dp[ix]);
      39             : 
      40             :     /* store lower part in result */
      41           0 :     t.dp[ix+ix] = (mp_digit) (r & ((mp_word) MP_MASK));
      42             : 
      43             :     /* get the carry */
      44           0 :     u           = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
      45             : 
      46             :     /* left hand side of A[ix] * A[iy] */
      47           0 :     tmpx        = a->dp[ix];
      48             : 
      49             :     /* alias for where to store the results */
      50           0 :     tmpt        = t.dp + (2*ix + 1);
      51             : 
      52           0 :     for (iy = ix + 1; iy < pa; iy++) {
      53             :       /* first calculate the product */
      54           0 :       r       = ((mp_word)tmpx) * ((mp_word)a->dp[iy]);
      55             : 
      56             :       /* now calculate the double precision result, note we use
      57             :        * addition instead of *2 since it's easier to optimize
      58             :        */
      59           0 :       r       = ((mp_word) *tmpt) + r + r + ((mp_word) u);
      60             : 
      61             :       /* store lower part */
      62           0 :       *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
      63             : 
      64             :       /* get carry */
      65           0 :       u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
      66             :     }
      67             :     /* propagate upwards */
      68           0 :     while (u != ((mp_digit) 0)) {
      69           0 :       r       = ((mp_word) *tmpt) + ((mp_word) u);
      70           0 :       *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
      71           0 :       u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
      72             :     }
      73             :   }
      74             : 
      75           0 :   mp_clamp (&t);
      76           0 :   mp_exch (&t, b);
      77           0 :   mp_clear (&t);
      78           0 :   return MP_OKAY;
      79             : }
      80             : #endif
      81             : 
      82             : /* $Source: /cvs/libtom/libtommath/bn_s_mp_sqr.c,v $ */
      83             : /* $Revision: 1.4 $ */
      84             : /* $Date: 2006/12/28 01:25:13 $ */

Generated by: LCOV version 1.13