1 #include "tommath_private.h"
2 #ifdef BN_MP_NEG_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
5 
6 /* b = -a */
mp_neg(const mp_int * a,mp_int * b)7 mp_err mp_neg(const mp_int *a, mp_int *b)
8 {
9    mp_err err;
10    if (a != b) {
11       if ((err = mp_copy(a, b)) != MP_OKAY) {
12          return err;
13       }
14    }
15 
16    if (!MP_IS_ZERO(b)) {
17       b->sign = (a->sign == MP_ZPOS) ? MP_NEG : MP_ZPOS;
18    } else {
19       b->sign = MP_ZPOS;
20    }
21 
22    return MP_OKAY;
23 }
24 #endif
25