comparison libtommath/bn_mp_from_ubin.c @ 1733:d529a52b2f7c coverity coverity

merge coverity from main
author Matt Johnston <matt@ucc.asn.au>
date Fri, 26 Jun 2020 21:07:34 +0800
parents 1051e4eea25a
children
comparison
equal deleted inserted replaced
1643:b59623a64678 1733:d529a52b2f7c
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 {
9 mp_err err;
10
11 /* make sure there are at least two digits */
12 if (a->alloc < 2) {
13 if ((err = mp_grow(a, 2)) != MP_OKAY) {
14 return err;
15 }
16 }
17
18 /* zero the int */
19 mp_zero(a);
20
21 /* read the bytes in */
22 while (size-- > 0u) {
23 if ((err = mp_mul_2d(a, 8, a)) != MP_OKAY) {
24 return err;
25 }
26
27 #ifndef MP_8BIT
28 a->dp[0] |= *buf++;
29 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 mp_clamp(a);
37 return MP_OKAY;
38 }
39 #endif