diff --git a/src/fp.cpp b/src/fp.cpp index 040f491..6f167da 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -5,6 +5,7 @@ #include "fp_generator.hpp" #endif #include "fp_proto.hpp" +#include "low_gmp.hpp" #ifdef _MSC_VER #pragma warning(disable : 4127) @@ -108,48 +109,6 @@ Mode StrToMode(const std::string& s) } -template -Unit low_add(Unit *z, const Unit *x, const Unit *y) -{ - return mpn_add_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); -} -template -Unit low_sub(Unit *z, const Unit *x, const Unit *y) -{ - return mpn_sub_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); -} -// Z[N * 2] -template -void low_mul(Unit *z, const Unit *x, const Unit *y) -{ - return mpn_mul_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); -} -template -void low_sqr(Unit *y, const Unit *x) -{ - return mpn_sqr((mp_limb_t*)y, (const mp_limb_t*)x, N); -} -// Z[N + 1] -template -void low_mul_Unit(Unit *z, const Unit *x, Unit y) -{ - z[N] = mpn_mul_1((mp_limb_t*)z, (const mp_limb_t*)x, N, y); -} -// y[N] <- X[N + 1] mod p[N] -template -void low_N1_mod(Unit *y, const Unit *x, const Unit *p) -{ - mp_limb_t q[2]; // not used - mpn_tdiv_qr(q, (mp_limb_t*)y, 0, (const mp_limb_t*)x, N + 1, (const mp_limb_t*)p, N); -} -// y[N] <- X[N * 2] mod p[N] -template -void low_mod(Unit *y, const Unit *x, const Unit *p) -{ - mp_limb_t q[N + 1]; // not used - mpn_tdiv_qr(q, (mp_limb_t*)y, 0, (const mp_limb_t*)x, N * 2, (const mp_limb_t*)p, N); -} - template struct OpeFunc { static const size_t N = (bitSize + UnitBitSize - 1) / UnitBitSize; diff --git a/src/low_gmp.hpp b/src/low_gmp.hpp new file mode 100644 index 0000000..e14697b --- /dev/null +++ b/src/low_gmp.hpp @@ -0,0 +1,49 @@ +#pragma once +#include + +namespace mcl { namespace fp { + +template +Unit low_add(Unit *z, const Unit *x, const Unit *y) +{ + return mpn_add_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); +} +template +Unit low_sub(Unit *z, const Unit *x, const Unit *y) +{ + return mpn_sub_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); +} +// Z[N * 2] +template +void low_mul(Unit *z, const Unit *x, const Unit *y) +{ + return mpn_mul_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); +} +template +void low_sqr(Unit *y, const Unit *x) +{ + return mpn_sqr((mp_limb_t*)y, (const mp_limb_t*)x, N); +} +// Z[N + 1] +template +void low_mul_Unit(Unit *z, const Unit *x, Unit y) +{ + z[N] = mpn_mul_1((mp_limb_t*)z, (const mp_limb_t*)x, N, y); +} +// y[N] <- X[N + 1] mod p[N] +template +void low_N1_mod(Unit *y, const Unit *x, const Unit *p) +{ + mp_limb_t q[2]; // not used + mpn_tdiv_qr(q, (mp_limb_t*)y, 0, (const mp_limb_t*)x, N + 1, (const mp_limb_t*)p, N); +} +// y[N] <- X[N * 2] mod p[N] +template +void low_mod(Unit *y, const Unit *x, const Unit *p) +{ + mp_limb_t q[N + 1]; // not used + mpn_tdiv_qr(q, (mp_limb_t*)y, 0, (const mp_limb_t*)x, N * 2, (const mp_limb_t*)p, N); +} + +} } // mcl::fp +