LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_reduce_is_2k.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 14 20 70.0 %
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_REDUCE_IS_2K_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* determines if mp_reduce_2k can be used */
       7         922 : mp_bool mp_reduce_is_2k(const mp_int *a)
       8             : {
       9          32 :    int ix, iy, iw;
      10          32 :    mp_digit iz;
      11             : 
      12         922 :    if (a->used == 0) {
      13           0 :       return MP_NO;
      14         922 :    } else if (a->used == 1) {
      15           0 :       return MP_YES;
      16         922 :    } else if (a->used > 1) {
      17         922 :       iy = mp_count_bits(a);
      18         922 :       iz = 1;
      19         922 :       iw = 1;
      20             : 
      21             :       /* Test every bit from the second digit up, must be 1 */
      22        2410 :       for (ix = MP_DIGIT_BIT; ix < iy; ix++) {
      23        2378 :          if ((a->dp[iw] & iz) == 0u) {
      24         890 :             return MP_NO;
      25             :          }
      26        1456 :          iz <<= 1;
      27        1456 :          if (iz > MP_DIGIT_MAX) {
      28           0 :             ++iw;
      29           0 :             iz = 1;
      30             :          }
      31             :       }
      32           0 :       return MP_YES;
      33             :    } else {
      34           0 :       return MP_YES;
      35             :    }
      36             : }
      37             : 
      38             : #endif

Generated by: LCOV version 1.14