Mercurial > dropbear
comparison libtommath/bn_mp_decr.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" | |
2 #ifdef BN_MP_DECR_C | |
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */ | |
4 /* SPDX-License-Identifier: Unlicense */ | |
5 | |
6 /* Decrement "a" by one like "a--". Changes input! */ | |
7 mp_err mp_decr(mp_int *a) | |
8 { | |
9 if (MP_IS_ZERO(a)) { | |
10 mp_set(a,1uL); | |
11 a->sign = MP_NEG; | |
12 return MP_OKAY; | |
13 } else if (a->sign == MP_NEG) { | |
14 mp_err err; | |
15 a->sign = MP_ZPOS; | |
16 if ((err = mp_incr(a)) != MP_OKAY) { | |
17 return err; | |
18 } | |
19 /* There is no -0 in LTM */ | |
20 if (!MP_IS_ZERO(a)) { | |
21 a->sign = MP_NEG; | |
22 } | |
23 return MP_OKAY; | |
24 } else if (a->dp[0] > 1uL) { | |
25 a->dp[0]--; | |
26 if (a->dp[0] == 0u) { | |
27 mp_zero(a); | |
28 } | |
29 return MP_OKAY; | |
30 } else { | |
31 return mp_sub_d(a, 1uL,a); | |
32 } | |
33 } | |
34 #endif |