# BRCM_VERSION=3
[bcm963xx.git] / userapps / opensource / sshd / libtommath / bn_mp_read_unsigned_bin.c
1 /* LibTomMath, multiple-precision integer library -- Tom St Denis
2  *
3  * LibTomMath is library that provides for multiple-precision
4  * integer arithmetic as well as number theoretic functionality.
5  *
6  * The library is designed directly after the MPI library by
7  * Michael Fromberger but has been written from scratch with
8  * additional optimizations in place.
9  *
10  * The library is free for all purposes without any express
11  * guarantee it works.
12  *
13  * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
14  */
15 #include <tommath.h>
16
17 /* reads a unsigned char array, assumes the msb is stored first [big endian] */
18 int
19 mp_read_unsigned_bin (mp_int * a, unsigned char *b, int c)
20 {
21   int     res;
22   mp_zero (a);
23   while (c-- > 0) {
24     if ((res = mp_mul_2d (a, 8, a)) != MP_OKAY) {
25       return res;
26     }
27
28     if (DIGIT_BIT != 7) {
29       a->dp[0] |= *b++;
30       a->used += 1;
31     } else {
32       a->dp[0] = (*b & MP_MASK);
33       a->dp[1] |= ((*b++ >> 7U) & 1);
34       a->used += 2;
35     }
36   }
37   mp_clamp (a);
38   return MP_OKAY;
39 }