comparison libtommath/bn_mp_get_bit.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
children
comparison
equal deleted inserted replaced
1654:cc0fc5131c5c 1655:f52919ffd3b1
1 #include "tommath_private.h"
2 #ifdef BN_MP_GET_BIT_C
3
4 /* LibTomMath, multiple-precision integer library -- Tom St Denis
5 *
6 * LibTomMath is a library that provides multiple-precision
7 * integer arithmetic as well as number theoretic functionality.
8 *
9 * The library was designed directly after the MPI library by
10 * Michael Fromberger but has been written from scratch with
11 * additional optimizations in place.
12 *
13 * SPDX-License-Identifier: Unlicense
14 */
15
16 /* Checks the bit at position b and returns MP_YES
17 if the bit is 1, MP_NO if it is 0 and MP_VAL
18 in case of error */
19 int mp_get_bit(const mp_int *a, int b)
20 {
21 int limb;
22 mp_digit bit, isset;
23
24 if (b < 0) {
25 return MP_VAL;
26 }
27
28 limb = b / DIGIT_BIT;
29
30 /*
31 * Zero is a special value with the member "used" set to zero.
32 * Needs to be tested before the check for the upper boundary
33 * otherwise (limb >= a->used) would be true for a = 0
34 */
35
36 if (mp_iszero(a) != MP_NO) {
37 return MP_NO;
38 }
39
40 if (limb >= a->used) {
41 return MP_VAL;
42 }
43
44 bit = (mp_digit)(1) << (b % DIGIT_BIT);
45
46 isset = a->dp[limb] & bit;
47 return (isset != 0u) ? MP_YES : MP_NO;
48 }
49
50 #endif
51
52 /* ref: HEAD -> master, tag: v1.1.0 */
53 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
54 /* commit time: 2019-01-28 20:32:32 +0100 */