comparison libtommath/bn_mp_copy.c @ 1655:f52919ffd3b1

update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79) * make key-generation compliant to FIPS 186.4 * fix includes in tommath_class.h * update fuzzcorpus instead of error-out * fixup fuzzing make-targets * update Makefile.in * apply necessary patches to ltm sources * clean-up not required ltm files * update to vanilla ltm 1.1.0 this already only contains the required files * remove set/get double
author Steffen Jaeckel <s_jaeckel@gmx.de>
date Mon, 16 Sep 2019 15:50:38 +0200
parents 8bba51a55704
children 1051e4eea25a
comparison
equal deleted inserted replaced
1654:cc0fc5131c5c 1655:f52919ffd3b1
1 #include <tommath_private.h> 1 #include "tommath_private.h"
2 #ifdef BN_MP_COPY_C 2 #ifdef BN_MP_COPY_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4 * 4 *
5 * LibTomMath is a library that provides multiple-precision 5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality. 6 * integer arithmetic as well as number theoretic functionality.
7 * 7 *
8 * The library was designed directly after the MPI library by 8 * The library was designed directly after the MPI library by
9 * Michael Fromberger but has been written from scratch with 9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place. 10 * additional optimizations in place.
11 * 11 *
12 * The library is free for all purposes without any express 12 * SPDX-License-Identifier: Unlicense
13 * guarantee it works.
14 *
15 * Tom St Denis, [email protected], http://libtom.org
16 */ 13 */
17 14
18 /* copy, b = a */ 15 /* copy, b = a */
19 int 16 int mp_copy(const mp_int *a, mp_int *b)
20 mp_copy (mp_int * a, mp_int * b)
21 { 17 {
22 int res, n; 18 int res, n;
23 19
24 /* if dst == src do nothing */ 20 /* if dst == src do nothing */
25 if (a == b) { 21 if (a == b) {
26 return MP_OKAY; 22 return MP_OKAY;
27 } 23 }
28 24
29 /* grow dest */ 25 /* grow dest */
30 if (b->alloc < a->used) { 26 if (b->alloc < a->used) {
31 if ((res = mp_grow (b, a->used)) != MP_OKAY) { 27 if ((res = mp_grow(b, a->used)) != MP_OKAY) {
32 return res; 28 return res;
33 } 29 }
34 } 30 }
35 31
36 /* zero b and copy the parameters over */ 32 /* zero b and copy the parameters over */
37 { 33 {
38 mp_digit *tmpa, *tmpb; 34 mp_digit *tmpa, *tmpb;
39 35
40 /* pointer aliases */ 36 /* pointer aliases */
41 37
42 /* source */ 38 /* source */
43 tmpa = a->dp; 39 tmpa = a->dp;
44 40
45 /* destination */ 41 /* destination */
46 tmpb = b->dp; 42 tmpb = b->dp;
47 43
48 /* copy all the digits */ 44 /* copy all the digits */
49 for (n = 0; n < a->used; n++) { 45 for (n = 0; n < a->used; n++) {
50 *tmpb++ = *tmpa++; 46 *tmpb++ = *tmpa++;
51 } 47 }
52 48
53 /* clear high digits */ 49 /* clear high digits */
54 for (; n < b->used; n++) { 50 for (; n < b->used; n++) {
55 *tmpb++ = 0; 51 *tmpb++ = 0;
56 } 52 }
57 } 53 }
58 54
59 /* copy used count and sign */ 55 /* copy used count and sign */
60 b->used = a->used; 56 b->used = a->used;
61 b->sign = a->sign; 57 b->sign = a->sign;
62 return MP_OKAY; 58 return MP_OKAY;
63 } 59 }
64 #endif 60 #endif
65 61
66 /* ref: $Format:%D$ */ 62 /* ref: HEAD -> master, tag: v1.1.0 */
67 /* git commit: $Format:%H$ */ 63 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
68 /* commit time: $Format:%ai$ */ 64 /* commit time: 2019-01-28 20:32:32 +0100 */