/*************************************************
* MP Multiplication Source File                  *
* (C) 1999-2003 The Botan Project                *
*************************************************/

#include <botan/mp_core.h>
#include <botan/mp_mul.h>
#include <gmp.h>

#define __GNU_MP_VERSION_CODE_FOR(a,b,c) ((a << 16) | (b << 8) | (c))

#define __GNU_MP_VERSION_CODE \
__GNU_MP_VERSION_CODE_FOR(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, \
                          __GNU_MP_VERSION_PATCHLEVEL)

#if __GNU_MP_VERSION_CODE < __GNU_MP_VERSION_CODE_FOR(4,1,0)
  #error Your version of GNU MP is too old, upgrade to 4.1 or later
#endif

namespace Botan {

/*************************************************
* Multiply using GNU MP                          *
*************************************************/
void bigint_mul3(word* const z, u32bit,
                 const word* x, u32bit, u32bit x_sw,
                 const word* y, u32bit, u32bit y_sw)
   {
   mpz_t gmp_x, gmp_y;

   mpz_init(gmp_x);
   mpz_init(gmp_y);

   mpz_import(gmp_x, x_sw, -1, sizeof(word), 0, 0, x);
   mpz_import(gmp_y, y_sw, -1, sizeof(word), 0, 0, y);

   mpz_mul(gmp_y, gmp_x, gmp_y);

   size_t dummy = 0;
   mpz_export(z, &dummy, -1, sizeof(word), 0, 0, gmp_y);

   mpz_clear(gmp_x);
   mpz_clear(gmp_y);
   }

}
