bn_mp_abs.c 519 B

1234567891011121314151617181920212223242526
  1. #include "tommath_private.h"
  2. #ifdef BN_MP_ABS_C
  3. /* LibTomMath, multiple-precision integer library -- Tom St Denis */
  4. /* SPDX-License-Identifier: Unlicense */
  5. /* b = |a|
  6. *
  7. * Simple function copies the input and fixes the sign to positive
  8. */
  9. mp_err mp_abs(const mp_int *a, mp_int *b)
  10. {
  11. mp_err err;
  12. /* copy a to b */
  13. if (a != b) {
  14. if ((err = mp_copy(a, b)) != MP_OKAY) {
  15. return err;
  16. }
  17. }
  18. /* force the sign of b to positive */
  19. b->sign = MP_ZPOS;
  20. return MP_OKAY;
  21. }
  22. #endif