Merge pull request #578 from PX4/fix_mp_prime_strong_lucas_lefridge_compilation
[libtommath.git] / mp_copy.c
blobd79e2b8bf64f3a20aab3a3b155bd141c174cc409
1 #include "tommath_private.h"
2 #ifdef MP_COPY_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* copy, b = a */
7 mp_err mp_copy(const mp_int *a, mp_int *b)
9 mp_err err;
11 /* if dst == src do nothing */
12 if (a == b) {
13 return MP_OKAY;
16 /* grow dest */
17 if ((err = mp_grow(b, a->used)) != MP_OKAY) {
18 return err;
21 /* copy everything over and zero high digits */
22 s_mp_copy_digs(b->dp, a->dp, a->used);
23 s_mp_zero_digs(b->dp + a->used, b->used - a->used);
24 b->used = a->used;
25 b->sign = a->sign;
27 return MP_OKAY;
29 #endif