bn_mp_clamp.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <tommath.h>
  2. #ifdef BN_MP_CLAMP_C
  3. /* LibTomMath, multiple-precision integer library -- Tom St Denis
  4. *
  5. * LibTomMath is a library that provides multiple-precision
  6. * integer arithmetic as well as number theoretic functionality.
  7. *
  8. * The library was designed directly after the MPI library by
  9. * Michael Fromberger but has been written from scratch with
  10. * additional optimizations in place.
  11. *
  12. * The library is free for all purposes without any express
  13. * guarantee it works.
  14. *
  15. * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
  16. */
  17. /* trim unused digits
  18. *
  19. * This is used to ensure that leading zero digits are
  20. * trimed and the leading "used" digit will be non-zero
  21. * Typically very fast. Also fixes the sign if there
  22. * are no more leading digits
  23. */
  24. void
  25. mp_clamp (mp_int * a)
  26. {
  27. /* decrease used while the most significant digit is
  28. * zero.
  29. */
  30. while (a->used > 0 && a->dp[a->used - 1] == 0) {
  31. --(a->used);
  32. }
  33. /* reset the sign flag if used == 0 */
  34. if (a->used == 0) {
  35. a->sign = MP_ZPOS;
  36. }
  37. }
  38. #endif
  39. /* $Source: /cvs/libtom/libtommath/bn_mp_clamp.c,v $ */
  40. /* $Revision: 1.3 $ */
  41. /* $Date: 2006/03/31 14:18:44 $ */