Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 49 lines (41 sloc) 1.148 kB
e549ccf added libtommath-0.32
Tom St Denis authored
1 #include <tommath.h>
2 #ifdef BN_MP_2EXPT_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
0ef44ce added libtommath-0.18
Tom St Denis authored
18 /* computes a = 2**b
b66471f added libtommath-0.13
Tom St Denis authored
19 *
20 * Simple algorithm which zeroes the int, grows it then just sets one bit
21 * as required.
22 */
57354e1 added libtommath-0.12
Tom St Denis authored
23 int
24 mp_2expt (mp_int * a, int b)
25 {
b66471f added libtommath-0.13
Tom St Denis authored
26 int res;
57354e1 added libtommath-0.12
Tom St Denis authored
27
c1da6aa added libtommath-0.25
Tom St Denis authored
28 /* zero a as per default */
57354e1 added libtommath-0.12
Tom St Denis authored
29 mp_zero (a);
c1da6aa added libtommath-0.25
Tom St Denis authored
30
31 /* grow a to accomodate the single bit */
57354e1 added libtommath-0.12
Tom St Denis authored
32 if ((res = mp_grow (a, b / DIGIT_BIT + 1)) != MP_OKAY) {
33 return res;
34 }
c1da6aa added libtommath-0.25
Tom St Denis authored
35
36 /* set the used count of where the bit will go */
57354e1 added libtommath-0.12
Tom St Denis authored
37 a->used = b / DIGIT_BIT + 1;
c1da6aa added libtommath-0.25
Tom St Denis authored
38
39 /* put the single bit in its place */
8eaa988 added libtommath-0.31
Tom St Denis authored
40 a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT);
57354e1 added libtommath-0.12
Tom St Denis authored
41
42 return MP_OKAY;
43 }
e549ccf added libtommath-0.32
Tom St Denis authored
44 #endif
9294e79 added libtommath-0.36
Tom St Denis authored
45
46 /* $Source$ */
47 /* $Revision$ */
48 /* $Date$ */
Something went wrong with that request. Please try again.