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 v4-17-test 1498b464 Lines: 9 12 75.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_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         687 : mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size)
       8             : {
       9             :    mp_err err;
      10             : 
      11             :    /* make sure there are at least two digits */
      12         687 :    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         687 :    mp_zero(a);
      20             : 
      21             :    /* read the bytes in */
      22      167311 :    while (size-- > 0u) {
      23      165937 :       if ((err = mp_mul_2d(a, 8, a)) != MP_OKAY) {
      24           0 :          return err;
      25             :       }
      26             : 
      27             : #ifndef MP_8BIT
      28      165937 :       a->dp[0] |= *buf++;
      29      165937 :       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         687 :    mp_clamp(a);
      37         687 :    return MP_OKAY;
      38             : }
      39             : #endif

Generated by: LCOV version 1.13