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

          Line data    Source code
       1             : #include <tommath.h>
       2             : #ifdef BN_MP_GROW_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             : /* grow as required */
      19       37096 : int mp_grow (mp_int * a, int size)
      20             : {
      21             :   int     i;
      22             :   mp_digit *tmp;
      23             : 
      24             :   /* if the alloc size is smaller alloc more ram */
      25       37096 :   if (a->alloc < size) {
      26             :     /* ensure there are always at least MP_PREC digits extra on top */
      27       36818 :     size += (MP_PREC * 2) - (size % MP_PREC);
      28             : 
      29             :     /* reallocate the array a->dp
      30             :      *
      31             :      * We store the return in a temporary variable
      32             :      * in case the operation failed we don't want
      33             :      * to overwrite the dp member of a.
      34             :      */
      35       36818 :     tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * size);
      36       36818 :     if (tmp == NULL) {
      37             :       /* reallocation failed but "a" is still valid [can be freed] */
      38           0 :       return MP_MEM;
      39             :     }
      40             : 
      41             :     /* reallocation succeeded so set a->dp */
      42       36818 :     a->dp = tmp;
      43             : 
      44             :     /* zero excess digits */
      45       36818 :     i        = a->alloc;
      46       36818 :     a->alloc = size;
      47     3329650 :     for (; i < a->alloc; i++) {
      48     3292832 :       a->dp[i] = 0;
      49             :     }
      50             :   }
      51       35454 :   return MP_OKAY;
      52             : }
      53             : #endif
      54             : 
      55             : /* $Source: /cvs/libtom/libtommath/bn_mp_grow.c,v $ */
      56             : /* $Revision: 1.4 $ */
      57             : /* $Date: 2006/12/28 01:25:13 $ */

Generated by: LCOV version 1.13