1 /* $NetBSD: bn_mp_set_int.c,v 1.2 2017/01/28 21:31:47 christos Exp $ */
2
3 #include <tommath.h>
4 #ifdef BN_MP_SET_INT_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 /* set a 32-bit const */
mp_set_int(mp_int * a,unsigned long b)21 int mp_set_int (mp_int * a, unsigned long b)
22 {
23 int x, res;
24
25 mp_zero (a);
26
27 /* set four bits at a time */
28 for (x = 0; x < 8; x++) {
29 /* shift the number up four bits */
30 if ((res = mp_mul_2d (a, 4, a)) != MP_OKAY) {
31 return res;
32 }
33
34 /* OR in the top four bits of the source */
35 a->dp[0] |= (b >> 28) & 15;
36
37 /* shift the source up to the next four bits */
38 b <<= 4;
39
40 /* ensure that digits are not clamped off */
41 a->used += 1;
42 }
43 mp_clamp (a);
44 return MP_OKAY;
45 }
46 #endif
47
48 /* Source: /cvs/libtom/libtommath/bn_mp_set_int.c,v */
49 /* Revision: 1.4 */
50 /* Date: 2006/12/28 01:25:13 */
51