Mercurial > dropbear
comparison libtommath/bn_mp_clamp.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_CLAMP_C | 2 #ifdef BN_MP_CLAMP_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 /* trim unused digits | 6 /* trim unused digits |
19 * | 7 * |
20 * This is used to ensure that leading zero digits are | 8 * This is used to ensure that leading zero digits are |
21 * trimed and the leading "used" digit will be non-zero | 9 * trimed and the leading "used" digit will be non-zero |
22 * Typically very fast. Also fixes the sign if there | 10 * Typically very fast. Also fixes the sign if there |
23 * are no more leading digits | 11 * are no more leading digits |
24 */ | 12 */ |
25 void | 13 void mp_clamp(mp_int *a) |
26 mp_clamp (mp_int * a) | |
27 { | 14 { |
28 /* decrease used while the most significant digit is | 15 /* decrease used while the most significant digit is |
29 * zero. | 16 * zero. |
30 */ | 17 */ |
31 while ((a->used > 0) && (a->dp[a->used - 1] == 0)) { | 18 while ((a->used > 0) && (a->dp[a->used - 1] == 0u)) { |
32 --(a->used); | 19 --(a->used); |
33 } | 20 } |
34 | 21 |
35 /* reset the sign flag if used == 0 */ | 22 /* reset the sign flag if used == 0 */ |
36 if (a->used == 0) { | 23 if (a->used == 0) { |
37 a->sign = MP_ZPOS; | 24 a->sign = MP_ZPOS; |
38 } | 25 } |
39 } | 26 } |
40 #endif | 27 #endif |
41 | |
42 /* ref: $Format:%D$ */ | |
43 /* git commit: $Format:%H$ */ | |
44 /* commit time: $Format:%ai$ */ |