Coverage Report

Created: 2023-09-25 06:08

/src/dropbear/libtommath/bn_mp_from_ubin.c
Line
Count
Source (jump to first uncovered line)
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
mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size)
8
6.43k
{
9
6.43k
   mp_err err;
10
11
   /* make sure there are at least two digits */
12
6.43k
   if (a->alloc < 2) {
13
0
      if ((err = mp_grow(a, 2)) != MP_OKAY) {
14
0
         return err;
15
0
      }
16
0
   }
17
18
   /* zero the int */
19
6.43k
   mp_zero(a);
20
21
   /* read the bytes in */
22
1.12M
   while (size-- > 0u) {
23
1.12M
      if ((err = mp_mul_2d(a, 8, a)) != MP_OKAY) {
24
0
         return err;
25
0
      }
26
27
1.12M
#ifndef MP_8BIT
28
1.12M
      a->dp[0] |= *buf++;
29
1.12M
      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
1.12M
   }
36
6.43k
   mp_clamp(a);
37
6.43k
   return MP_OKAY;
38
6.43k
}
39
#endif