Mercurial > dropbear
comparison libtommath/bn_mp_2expt.c @ 1739:13d834efc376 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 15 Oct 2020 19:55:15 +0800 |
parents | 1051e4eea25a |
children |
comparison
equal
deleted
inserted
replaced
1562:768ebf737aa0 | 1739:13d834efc376 |
---|---|
1 #include <tommath_private.h> | 1 #include "tommath_private.h" |
2 #ifdef BN_MP_2EXPT_C | 2 #ifdef BN_MP_2EXPT_C |
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis | 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */ |
4 * | 4 /* SPDX-License-Identifier: Unlicense */ |
5 * LibTomMath is a library that provides multiple-precision | |
6 * integer arithmetic as well as number theoretic functionality. | |
7 * | |
8 * The library was designed directly after the MPI library by | |
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 * | |
15 * Tom St Denis, [email protected], http://libtom.org | |
16 */ | |
17 | 5 |
18 /* computes a = 2**b | 6 /* computes a = 2**b |
19 * | 7 * |
20 * Simple algorithm which zeroes the int, grows it then just sets one bit | 8 * Simple algorithm which zeroes the int, grows it then just sets one bit |
21 * as required. | 9 * as required. |
22 */ | 10 */ |
23 int | 11 mp_err mp_2expt(mp_int *a, int b) |
24 mp_2expt (mp_int * a, int b) | |
25 { | 12 { |
26 int res; | 13 mp_err err; |
27 | 14 |
28 /* zero a as per default */ | 15 /* zero a as per default */ |
29 mp_zero (a); | 16 mp_zero(a); |
30 | 17 |
31 /* grow a to accomodate the single bit */ | 18 /* grow a to accomodate the single bit */ |
32 if ((res = mp_grow (a, (b / DIGIT_BIT) + 1)) != MP_OKAY) { | 19 if ((err = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) { |
33 return res; | 20 return err; |
34 } | 21 } |
35 | 22 |
36 /* set the used count of where the bit will go */ | 23 /* set the used count of where the bit will go */ |
37 a->used = (b / DIGIT_BIT) + 1; | 24 a->used = (b / MP_DIGIT_BIT) + 1; |
38 | 25 |
39 /* put the single bit in its place */ | 26 /* put the single bit in its place */ |
40 a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT); | 27 a->dp[b / MP_DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT); |
41 | 28 |
42 return MP_OKAY; | 29 return MP_OKAY; |
43 } | 30 } |
44 #endif | 31 #endif |
45 | |
46 /* ref: $Format:%D$ */ | |
47 /* git commit: $Format:%H$ */ | |
48 /* commit time: $Format:%ai$ */ |