comparison libtommath/bn_mp_2expt.c @ 1692:1051e4eea25a

Update LibTomMath to 1.2.0 (#84) * update C files * update other files * update headers * update makefiles * remove mp_set/get_double() * use ltm 1.2.0 API * update ltm_desc * use bundled tommath if system-tommath is too old * XMALLOC etc. were changed to MP_MALLOC etc.
author Steffen Jaeckel <s@jaeckel.eu>
date Tue, 26 May 2020 17:36:47 +0200
parents f52919ffd3b1
children
comparison
equal deleted inserted replaced
1691:2d3745d58843 1692:1051e4eea25a
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 * SPDX-License-Identifier: Unlicense
13 */
14 5
15 /* computes a = 2**b 6 /* computes a = 2**b
16 * 7 *
17 * 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
18 * as required. 9 * as required.
19 */ 10 */
20 int mp_2expt(mp_int *a, int b) 11 mp_err mp_2expt(mp_int *a, int b)
21 { 12 {
22 int res; 13 mp_err err;
23 14
24 /* zero a as per default */ 15 /* zero a as per default */
25 mp_zero(a); 16 mp_zero(a);
26 17
27 /* grow a to accomodate the single bit */ 18 /* grow a to accomodate the single bit */
28 if ((res = mp_grow(a, (b / DIGIT_BIT) + 1)) != MP_OKAY) { 19 if ((err = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
29 return res; 20 return err;
30 } 21 }
31 22
32 /* set the used count of where the bit will go */ 23 /* set the used count of where the bit will go */
33 a->used = (b / DIGIT_BIT) + 1; 24 a->used = (b / MP_DIGIT_BIT) + 1;
34 25
35 /* put the single bit in its place */ 26 /* put the single bit in its place */
36 a->dp[b / DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % DIGIT_BIT); 27 a->dp[b / MP_DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT);
37 28
38 return MP_OKAY; 29 return MP_OKAY;
39 } 30 }
40 #endif 31 #endif
41
42 /* ref: HEAD -> master, tag: v1.1.0 */
43 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
44 /* commit time: 2019-01-28 20:32:32 +0100 */