1 /*	$NetBSD: bn_mp_copy.c,v 1.1.1.2 2014/04/24 12:45:31 pettai Exp $	*/
2 
3 #include <tommath.h>
4 #ifdef BN_MP_COPY_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 /* copy, b = a */
21 int
mp_copy(mp_int * a,mp_int * b)22 mp_copy (mp_int * a, mp_int * b)
23 {
24   int     res, n;
25 
26   /* if dst == src do nothing */
27   if (a == b) {
28     return MP_OKAY;
29   }
30 
31   /* grow dest */
32   if (b->alloc < a->used) {
33      if ((res = mp_grow (b, a->used)) != MP_OKAY) {
34         return res;
35      }
36   }
37 
38   /* zero b and copy the parameters over */
39   {
40     register mp_digit *tmpa, *tmpb;
41 
42     /* pointer aliases */
43 
44     /* source */
45     tmpa = a->dp;
46 
47     /* destination */
48     tmpb = b->dp;
49 
50     /* copy all the digits */
51     for (n = 0; n < a->used; n++) {
52       *tmpb++ = *tmpa++;
53     }
54 
55     /* clear high digits */
56     for (; n < b->used; n++) {
57       *tmpb++ = 0;
58     }
59   }
60 
61   /* copy used count and sign */
62   b->used = a->used;
63   b->sign = a->sign;
64   return MP_OKAY;
65 }
66 #endif
67 
68 /* Source: /cvs/libtom/libtommath/bn_mp_copy.c,v  */
69 /* Revision: 1.4  */
70 /* Date: 2006/12/28 01:25:13  */
71