Mercurial > dropbear
comparison libtommath/bn_mp_rshd.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_RSHD_C | 2 #ifdef BN_MP_RSHD_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 right a certain amount of digits */ | 15 /* shift right a certain amount of digits */ |
19 void mp_rshd (mp_int * a, int b) | 16 void mp_rshd(mp_int *a, int b) |
20 { | 17 { |
21 int x; | 18 int x; |
22 | 19 |
23 /* if b <= 0 then ignore it */ | 20 /* if b <= 0 then ignore it */ |
24 if (b <= 0) { | 21 if (b <= 0) { |
25 return; | 22 return; |
26 } | 23 } |
27 | 24 |
28 /* if b > used then simply zero it and return */ | 25 /* if b > used then simply zero it and return */ |
29 if (a->used <= b) { | 26 if (a->used <= b) { |
30 mp_zero (a); | 27 mp_zero(a); |
31 return; | 28 return; |
32 } | 29 } |
33 | 30 |
34 { | 31 { |
35 mp_digit *bottom, *top; | 32 mp_digit *bottom, *top; |
36 | 33 |
37 /* shift the digits down */ | 34 /* shift the digits down */ |
38 | 35 |
39 /* bottom */ | 36 /* bottom */ |
40 bottom = a->dp; | 37 bottom = a->dp; |
41 | 38 |
42 /* top [offset into digits] */ | 39 /* top [offset into digits] */ |
43 top = a->dp + b; | 40 top = a->dp + b; |
44 | 41 |
45 /* this is implemented as a sliding window where | 42 /* this is implemented as a sliding window where |
46 * the window is b-digits long and digits from | 43 * the window is b-digits long and digits from |
47 * the top of the window are copied to the bottom | 44 * the top of the window are copied to the bottom |
48 * | 45 * |
49 * e.g. | 46 * e.g. |
50 | 47 |
51 b-2 | b-1 | b0 | b1 | b2 | ... | bb | ----> | 48 b-2 | b-1 | b0 | b1 | b2 | ... | bb | ----> |
52 /\ | ----> | 49 /\ | ----> |
53 \-------------------/ ----> | 50 \-------------------/ ----> |
54 */ | 51 */ |
55 for (x = 0; x < (a->used - b); x++) { | 52 for (x = 0; x < (a->used - b); x++) { |
56 *bottom++ = *top++; | 53 *bottom++ = *top++; |
57 } | 54 } |
58 | 55 |
59 /* zero the top digits */ | 56 /* zero the top digits */ |
60 for (; x < a->used; x++) { | 57 for (; x < a->used; x++) { |
61 *bottom++ = 0; | 58 *bottom++ = 0; |
62 } | 59 } |
63 } | 60 } |
64 | 61 |
65 /* remove excess digits */ | 62 /* remove excess digits */ |
66 a->used -= b; | 63 a->used -= b; |
67 } | 64 } |
68 #endif | 65 #endif |
69 | 66 |
70 /* ref: $Format:%D$ */ | 67 /* ref: HEAD -> master, tag: v1.1.0 */ |
71 /* git commit: $Format:%H$ */ | 68 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ |
72 /* commit time: $Format:%ai$ */ | 69 /* commit time: 2019-01-28 20:32:32 +0100 */ |