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