1 /*	$NetBSD: bn_mp_read_unsigned_bin.c,v 1.1.1.2 2014/04/24 12:45:31 pettai Exp $	*/
2 
3 #include <tommath.h>
4 #ifdef BN_MP_READ_UNSIGNED_BIN_C
5 /* LibTomMath, multiple-precision integer library -- Tom St Denis
6  *
7  * LibTomMath is a library that provides multiple-precision
8  * integer arithmetic as well as number theoretic functionality.
9  *
10  * The library was designed directly after the MPI library by
11  * Michael Fromberger but has been written from scratch with
12  * additional optimizations in place.
13  *
14  * The library is free for all purposes without any express
15  * guarantee it works.
16  *
17  * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
18  */
19 
20 /* reads a unsigned char array, assumes the msb is stored first [big endian] */
mp_read_unsigned_bin(mp_int * a,const unsigned char * b,int c)21 int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c)
22 {
23   int     res;
24 
25   /* make sure there are at least two digits */
26   if (a->alloc < 2) {
27      if ((res = mp_grow(a, 2)) != MP_OKAY) {
28         return res;
29      }
30   }
31 
32   /* zero the int */
33   mp_zero (a);
34 
35   /* read the bytes in */
36   while (c-- > 0) {
37     if ((res = mp_mul_2d (a, 8, a)) != MP_OKAY) {
38       return res;
39     }
40 
41 #ifndef MP_8BIT
42       a->dp[0] |= *b++;
43       a->used += 1;
44 #else
45       a->dp[0] = (*b & MP_MASK);
46       a->dp[1] |= ((*b++ >> 7U) & 1);
47       a->used += 2;
48 #endif
49   }
50   mp_clamp (a);
51   return MP_OKAY;
52 }
53 #endif
54 
55 /* Source: /cvs/libtom/libtommath/bn_mp_read_unsigned_bin.c,v  */
56 /* Revision: 1.5  */
57 /* Date: 2006/12/28 01:25:13  */
58