LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_add.c (source / functions) Hit Total Coverage
Test: coverage report for master 98b443d9 Lines: 14 14 100.0 %
Date: 2024-05-31 13:13:24 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "tommath_private.h"
       2             : #ifdef BN_MP_ADD_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* high level addition (handles signs) */
       7        8707 : mp_err mp_add(const mp_int *a, const mp_int *b, mp_int *c)
       8             : {
       9          18 :    mp_sign sa, sb;
      10          18 :    mp_err err;
      11             : 
      12             :    /* get sign of both inputs */
      13        8707 :    sa = a->sign;
      14        8707 :    sb = b->sign;
      15             : 
      16             :    /* handle two cases, not four */
      17        8707 :    if (sa == sb) {
      18             :       /* both positive or both negative */
      19             :       /* add their magnitudes, copy the sign */
      20        8539 :       c->sign = sa;
      21        8539 :       err = s_mp_add(a, b, c);
      22             :    } else {
      23             :       /* one positive, the other negative */
      24             :       /* subtract the one with the greater magnitude from */
      25             :       /* the one of the lesser magnitude.  The result gets */
      26             :       /* the sign of the one with the greater magnitude. */
      27         168 :       if (mp_cmp_mag(a, b) == MP_LT) {
      28         167 :          c->sign = sb;
      29         167 :          err = s_mp_sub(b, a, c);
      30             :       } else {
      31           1 :          c->sign = sa;
      32           1 :          err = s_mp_sub(a, b, c);
      33             :       }
      34             :    }
      35        8707 :    return err;
      36             : }
      37             : 
      38             : #endif

Generated by: LCOV version 1.14