LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_copy.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 16 17 94.1 %
Date: 2024-04-21 15:09:00 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "tommath_private.h"
       2             : #ifdef BN_MP_COPY_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* copy, b = a */
       7      309080 : mp_err mp_copy(const mp_int *a, mp_int *b)
       8             : {
       9        8492 :    int n;
      10        8492 :    mp_digit *tmpa, *tmpb;
      11        8492 :    mp_err err;
      12             : 
      13             :    /* if dst == src do nothing */
      14      309080 :    if (a == b) {
      15      295425 :       return MP_OKAY;
      16             :    }
      17             : 
      18             :    /* grow dest */
      19        5397 :    if (b->alloc < a->used) {
      20         417 :       if ((err = mp_grow(b, a->used)) != MP_OKAY) {
      21           0 :          return err;
      22             :       }
      23             :    }
      24             : 
      25             :    /* zero b and copy the parameters over */
      26             :    /* pointer aliases */
      27             : 
      28             :    /* source */
      29        5397 :    tmpa = a->dp;
      30             : 
      31             :    /* destination */
      32        5397 :    tmpb = b->dp;
      33             : 
      34             :    /* copy all the digits */
      35      366606 :    for (n = 0; n < a->used; n++) {
      36      361209 :       *tmpb++ = *tmpa++;
      37             :    }
      38             : 
      39             :    /* clear high digits */
      40        5397 :    MP_ZERO_DIGITS(tmpb, b->used - n);
      41             : 
      42             :    /* copy used count and sign */
      43        5397 :    b->used = a->used;
      44        5397 :    b->sign = a->sign;
      45        5397 :    return MP_OKAY;
      46             : }
      47             : #endif

Generated by: LCOV version 1.14