bn_mp_mulmod.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <tommath.h>
  2. #ifdef BN_MP_MULMOD_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. /* d = a * b (mod c) */
  18. int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
  19. {
  20. int res;
  21. mp_int t;
  22. if ((res = mp_init_size (&t, c->used)) != MP_OKAY) {
  23. return res;
  24. }
  25. if ((res = mp_mul (a, b, &t)) != MP_OKAY) {
  26. mp_clear (&t);
  27. return res;
  28. }
  29. res = mp_mod (&t, c, d);
  30. mp_clear (&t);
  31. return res;
  32. }
  33. #endif
  34. /* $Source: /cvs/libtom/libtommath/bn_mp_mulmod.c,v $ */
  35. /* $Revision: 1.4 $ */
  36. /* $Date: 2006/03/31 14:18:44 $ */