LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_sub.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 11 11 100.0 %
Date: 2024-06-13 04:01:37 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "tommath_private.h"
       2             : #ifdef BN_MP_SUB_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* high level subtraction (handles signs) */
       7      347312 : mp_err mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
       8             : {
       9      347312 :    mp_sign sa = a->sign, sb = b->sign;
      10             :    mp_err err;
      11             : 
      12      347312 :    if (sa != sb) {
      13             :       /* subtract a negative from a positive, OR */
      14             :       /* subtract a positive from a negative. */
      15             :       /* In either case, ADD their magnitudes, */
      16             :       /* and use the sign of the first number. */
      17      107450 :       c->sign = sa;
      18      107450 :       err = s_mp_add(a, b, c);
      19             :    } else {
      20             :       /* subtract a positive from a positive, OR */
      21             :       /* subtract a negative from a negative. */
      22             :       /* First, take the difference between their */
      23             :       /* magnitudes, then... */
      24      239862 :       if (mp_cmp_mag(a, b) != MP_LT) {
      25             :          /* Copy the sign from the first */
      26      166169 :          c->sign = sa;
      27             :          /* The first has a larger or equal magnitude */
      28      166169 :          err = s_mp_sub(a, b, c);
      29             :       } else {
      30             :          /* The result has the *opposite* sign from */
      31             :          /* the first number. */
      32       73693 :          c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
      33             :          /* The second has a larger magnitude */
      34       73693 :          err = s_mp_sub(b, a, c);
      35             :       }
      36             :    }
      37      347312 :    return err;
      38             : }
      39             : 
      40             : #endif

Generated by: LCOV version 1.13