LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_from_ubin.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 10 13 76.9 %
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_FROM_UBIN_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* reads a unsigned char array, assumes the msb is stored first [big endian] */
       7        2766 : mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size)
       8             : {
       9          96 :    mp_err err;
      10             : 
      11             :    /* make sure there are at least two digits */
      12        2766 :    if (a->alloc < 2) {
      13           0 :       if ((err = mp_grow(a, 2)) != MP_OKAY) {
      14           0 :          return err;
      15             :       }
      16             :    }
      17             : 
      18             :    /* zero the int */
      19        2766 :    mp_zero(a);
      20             : 
      21             :    /* read the bytes in */
      22      828590 :    while (size-- > 0u) {
      23      825824 :       if ((err = mp_mul_2d(a, 8, a)) != MP_OKAY) {
      24           0 :          return err;
      25             :       }
      26             : 
      27             : #ifndef MP_8BIT
      28      825824 :       a->dp[0] |= *buf++;
      29      825824 :       a->used += 1;
      30             : #else
      31             :       a->dp[0] = (*buf & MP_MASK);
      32             :       a->dp[1] |= ((*buf++ >> 7) & 1u);
      33             :       a->used += 2;
      34             : #endif
      35             :    }
      36        2766 :    mp_clamp(a);
      37        2766 :    return MP_OKAY;
      38             : }
      39             : #endif

Generated by: LCOV version 1.14