Mercurial > dropbear
comparison libtommath/bn_mp_from_ubin.c @ 1692:1051e4eea25a
Update LibTomMath to 1.2.0 (#84)
* update C files
* update other files
* update headers
* update makefiles
* remove mp_set/get_double()
* use ltm 1.2.0 API
* update ltm_desc
* use bundled tommath if system-tommath is too old
* XMALLOC etc. were changed to MP_MALLOC etc.
author | Steffen Jaeckel <s@jaeckel.eu> |
---|---|
date | Tue, 26 May 2020 17:36:47 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1691:2d3745d58843 | 1692:1051e4eea25a |
---|---|
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 |