bn_mp_prime_rabin_miller_trials.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <tommath.h>
  2. #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_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. static const struct {
  18. int k, t;
  19. } sizes[] = {
  20. { 128, 28 },
  21. { 256, 16 },
  22. { 384, 10 },
  23. { 512, 7 },
  24. { 640, 6 },
  25. { 768, 5 },
  26. { 896, 4 },
  27. { 1024, 4 }
  28. };
  29. /* returns # of RM trials required for a given bit size */
  30. int mp_prime_rabin_miller_trials(int size)
  31. {
  32. int x;
  33. for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) {
  34. if (sizes[x].k == size) {
  35. return sizes[x].t;
  36. } else if (sizes[x].k > size) {
  37. return (x == 0) ? sizes[0].t : sizes[x - 1].t;
  38. }
  39. }
  40. return sizes[x-1].t + 1;
  41. }
  42. #endif
  43. /* $Source: /cvs/libtom/libtommath/bn_mp_prime_rabin_miller_trials.c,v $ */
  44. /* $Revision: 1.3 $ */
  45. /* $Date: 2006/03/31 14:18:44 $ */