LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_mod.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 11 14 78.6 %
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_MOD_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */
       7        1895 : mp_err mp_mod(const mp_int *a, const mp_int *b, mp_int *c)
       8             : {
       9          88 :    mp_int  t;
      10          88 :    mp_err  err;
      11             : 
      12        1895 :    if ((err = mp_init_size(&t, b->used)) != MP_OKAY) {
      13           0 :       return err;
      14             :    }
      15             : 
      16        1895 :    if ((err = mp_div(a, b, NULL, &t)) != MP_OKAY) {
      17           0 :       goto LBL_ERR;
      18             :    }
      19             : 
      20        1895 :    if (MP_IS_ZERO(&t) || (t.sign == b->sign)) {
      21        1895 :       err = MP_OKAY;
      22        1895 :       mp_exch(&t, c);
      23             :    } else {
      24           0 :       err = mp_add(b, &t, c);
      25             :    }
      26             : 
      27        1895 : LBL_ERR:
      28        1895 :    mp_clear(&t);
      29        1895 :    return err;
      30             : }
      31             : #endif

Generated by: LCOV version 1.14