bn_mp_neg.c 482 B

123456789101112131415161718192021222324
  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. /* b = -a */
  6. mp_err mp_neg(const mp_int *a, mp_int *b)
  7. {
  8. mp_err err;
  9. if (a != b) {
  10. if ((err = mp_copy(a, b)) != MP_OKAY) {
  11. return err;
  12. }
  13. }
  14. if (!MP_IS_ZERO(b)) {
  15. b->sign = (a->sign == MP_ZPOS) ? MP_NEG : MP_ZPOS;
  16. } else {
  17. b->sign = MP_ZPOS;
  18. }
  19. return MP_OKAY;
  20. }
  21. #endif