Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 68 lines (57 sloc) 1.565 kB
e549ccf added libtommath-0.32
Tom St Denis authored
1 #include <tommath.h>
2 #ifdef BN_MP_LSHD_C
57354e1 added libtommath-0.12
Tom St Denis authored
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4 *
c1da6aa added libtommath-0.25
Tom St Denis authored
5 * LibTomMath is a library that provides multiple-precision
57354e1 added libtommath-0.12
Tom St Denis authored
6 * integer arithmetic as well as number theoretic functionality.
7 *
c1da6aa added libtommath-0.25
Tom St Denis authored
8 * The library was designed directly after the MPI library by
57354e1 added libtommath-0.12
Tom St Denis authored
9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place.
11 *
12 * The library is free for all purposes without any express
13 * guarantee it works.
14 *
333aebc added libtommath-0.41
Tom St Denis authored
15 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
57354e1 added libtommath-0.12
Tom St Denis authored
16 */
17
18 /* shift left a certain amount of digits */
455bb4d added libtommath-0.28
Tom St Denis authored
19 int mp_lshd (mp_int * a, int b)
57354e1 added libtommath-0.12
Tom St Denis authored
20 {
b66471f added libtommath-0.13
Tom St Denis authored
21 int x, res;
57354e1 added libtommath-0.12
Tom St Denis authored
22
23 /* if its less than zero return */
24 if (b <= 0) {
25 return MP_OKAY;
26 }
27
28 /* grow to fit the new digits */
fd181cc added libtommath-0.17
Tom St Denis authored
29 if (a->alloc < a->used + b) {
30 if ((res = mp_grow (a, a->used + b)) != MP_OKAY) {
31 return res;
32 }
57354e1 added libtommath-0.12
Tom St Denis authored
33 }
34
82f4858 added libtommath-0.14
Tom St Denis authored
35 {
0ef44ce added libtommath-0.18
Tom St Denis authored
36 register mp_digit *top, *bottom;
82f4858 added libtommath-0.14
Tom St Denis authored
37
0ef44ce added libtommath-0.18
Tom St Denis authored
38 /* increment the used by the shift amount then copy upwards */
82f4858 added libtommath-0.14
Tom St Denis authored
39 a->used += b;
b1756f2 added libtommath-0.15
Tom St Denis authored
40
82f4858 added libtommath-0.14
Tom St Denis authored
41 /* top */
0ef44ce added libtommath-0.18
Tom St Denis authored
42 top = a->dp + a->used - 1;
b1756f2 added libtommath-0.15
Tom St Denis authored
43
82f4858 added libtommath-0.14
Tom St Denis authored
44 /* base */
0ef44ce added libtommath-0.18
Tom St Denis authored
45 bottom = a->dp + a->used - 1 - b;
82f4858 added libtommath-0.14
Tom St Denis authored
46
47 /* much like mp_rshd this is implemented using a sliding window
48 * except the window goes the otherway around. Copying from
49 * the bottom to the top. see bn_mp_rshd.c for more info.
50 */
51 for (x = a->used - 1; x >= b; x--) {
0ef44ce added libtommath-0.18
Tom St Denis authored
52 *top-- = *bottom--;
82f4858 added libtommath-0.14
Tom St Denis authored
53 }
57354e1 added libtommath-0.12
Tom St Denis authored
54
82f4858 added libtommath-0.14
Tom St Denis authored
55 /* zero the lower digits */
0ef44ce added libtommath-0.18
Tom St Denis authored
56 top = a->dp;
82f4858 added libtommath-0.14
Tom St Denis authored
57 for (x = 0; x < b; x++) {
0ef44ce added libtommath-0.18
Tom St Denis authored
58 *top++ = 0;
82f4858 added libtommath-0.14
Tom St Denis authored
59 }
57354e1 added libtommath-0.12
Tom St Denis authored
60 }
61 return MP_OKAY;
62 }
e549ccf added libtommath-0.32
Tom St Denis authored
63 #endif
9294e79 added libtommath-0.36
Tom St Denis authored
64
65 /* $Source$ */
66 /* $Revision$ */
67 /* $Date$ */
Something went wrong with that request. Please try again.