comparison libtommath/bn_mp_lshd.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_LSHD_C 2 #ifdef BN_MP_LSHD_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 /* shift left a certain amount of digits */ 15 /* shift left a certain amount of digits */
19 int mp_lshd (mp_int * a, int b) 16 int mp_lshd(mp_int *a, int b)
20 { 17 {
21 int x, res; 18 int x, res;
22 19
23 /* if its less than zero return */ 20 /* if its less than zero return */
24 if (b <= 0) { 21 if (b <= 0) {
25 return MP_OKAY; 22 return MP_OKAY;
26 } 23 }
24 /* no need to shift 0 around */
25 if (mp_iszero(a) == MP_YES) {
26 return MP_OKAY;
27 }
27 28
28 /* grow to fit the new digits */ 29 /* grow to fit the new digits */
29 if (a->alloc < (a->used + b)) { 30 if (a->alloc < (a->used + b)) {
30 if ((res = mp_grow (a, a->used + b)) != MP_OKAY) { 31 if ((res = mp_grow(a, a->used + b)) != MP_OKAY) {
31 return res; 32 return res;
32 } 33 }
33 } 34 }
34 35
35 { 36 {
36 mp_digit *top, *bottom; 37 mp_digit *top, *bottom;
37 38
38 /* increment the used by the shift amount then copy upwards */ 39 /* increment the used by the shift amount then copy upwards */
39 a->used += b; 40 a->used += b;
40 41
41 /* top */ 42 /* top */
42 top = a->dp + a->used - 1; 43 top = a->dp + a->used - 1;
43 44
44 /* base */ 45 /* base */
45 bottom = (a->dp + a->used - 1) - b; 46 bottom = (a->dp + a->used - 1) - b;
46 47
47 /* much like mp_rshd this is implemented using a sliding window 48 /* much like mp_rshd this is implemented using a sliding window
48 * except the window goes the otherway around. Copying from 49 * except the window goes the otherway around. Copying from
49 * the bottom to the top. see bn_mp_rshd.c for more info. 50 * the bottom to the top. see bn_mp_rshd.c for more info.
50 */ 51 */
51 for (x = a->used - 1; x >= b; x--) { 52 for (x = a->used - 1; x >= b; x--) {
52 *top-- = *bottom--; 53 *top-- = *bottom--;
53 } 54 }
54 55
55 /* zero the lower digits */ 56 /* zero the lower digits */
56 top = a->dp; 57 top = a->dp;
57 for (x = 0; x < b; x++) { 58 for (x = 0; x < b; x++) {
58 *top++ = 0; 59 *top++ = 0;
59 } 60 }
60 } 61 }
61 return MP_OKAY; 62 return MP_OKAY;
62 } 63 }
63 #endif 64 #endif
64 65
65 /* ref: $Format:%D$ */ 66 /* ref: HEAD -> master, tag: v1.1.0 */
66 /* git commit: $Format:%H$ */ 67 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
67 /* commit time: $Format:%ai$ */ 68 /* commit time: 2019-01-28 20:32:32 +0100 */