bn_mp_cmp_mag.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <tommath.h>
  2. #ifdef BN_MP_CMP_MAG_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. /* compare maginitude of two ints (unsigned) */
  18. int mp_cmp_mag (mp_int * a, mp_int * b)
  19. {
  20. int n;
  21. mp_digit *tmpa, *tmpb;
  22. /* compare based on # of non-zero digits */
  23. if (a->used > b->used) {
  24. return MP_GT;
  25. }
  26. if (a->used < b->used) {
  27. return MP_LT;
  28. }
  29. /* alias for a */
  30. tmpa = a->dp + (a->used - 1);
  31. /* alias for b */
  32. tmpb = b->dp + (a->used - 1);
  33. /* compare based on digits */
  34. for (n = 0; n < a->used; ++n, --tmpa, --tmpb) {
  35. if (*tmpa > *tmpb) {
  36. return MP_GT;
  37. }
  38. if (*tmpa < *tmpb) {
  39. return MP_LT;
  40. }
  41. }
  42. return MP_EQ;
  43. }
  44. #endif
  45. /* $Source: /cvs/libtom/libtommath/bn_mp_cmp_mag.c,v $ */
  46. /* $Revision: 1.3 $ */
  47. /* $Date: 2006/03/31 14:18:44 $ */