/src/dropbear/libtommath/bn_mp_neg.c
Line  | Count  | Source  | 
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 */  | 
7  |  | mp_err mp_neg(const mp_int *a, mp_int *b)  | 
8  | 0  | { | 
9  | 0  |    mp_err err;  | 
10  | 0  |    if (a != b) { | 
11  | 0  |       if ((err = mp_copy(a, b)) != MP_OKAY) { | 
12  | 0  |          return err;  | 
13  | 0  |       }  | 
14  | 0  |    }  | 
15  |  |  | 
16  | 0  |    if (!MP_IS_ZERO(b)) { | 
17  | 0  |       b->sign = (a->sign == MP_ZPOS) ? MP_NEG : MP_ZPOS;  | 
18  | 0  |    } else { | 
19  | 0  |       b->sign = MP_ZPOS;  | 
20  | 0  |    }  | 
21  |  | 
  | 
22  | 0  |    return MP_OKAY;  | 
23  | 0  | }  | 
24  |  | #endif  |