test of addNC/subNC

dev
MITSUNARI Shigeo 9 years ago
parent 20a3d70625
commit bce3026b6d
  1. 8
      include/mcl/fp.hpp
  2. 7
      src/fp.cpp
  3. 10
      test/mont_fp_test.cpp

@ -129,6 +129,14 @@ public:
{
Gmp::getStr(pstr, op_.mp);
}
/*
binary patter of p
@note the value of p is zero
*/
static inline const FpT& getP()
{
return *reinterpret_cast<const FpT*>(op_.p);
}
static inline bool isOdd(const FpT& x)
{
fp::Block b;

@ -122,12 +122,12 @@ struct OpeFunc {
}
Gmp::getArray(z, N, mz);
}
// z = x + y
// z = x + y without carry
static inline void fp_addNCC(Unit *z, const Unit *x, const Unit *y)
{
Unit ret[N + 2]; // not N + 1
Unit ret[N + 1];
mpz_t mz, mx, my;
set_zero(mz, ret, N + 2);
set_zero(mz, ret, N + 1);
set_mpz_t(mx, x);
set_mpz_t(my, y);
mpz_add(mz, mx, my);
@ -140,6 +140,7 @@ struct OpeFunc {
set_zero(mz, ret, N + 1);
set_mpz_t(mx, x);
set_mpz_t(my, y);
assert(mx >= my);
mpz_sub(mz, mx, my);
Gmp::getArray(z, N, mz);
}

@ -459,9 +459,15 @@ struct Test {
{
Fp x(5), y(3), z;
Fp::addNC(z, x, y);
if (Fp::compareRaw(z, Fp::getP()) >= 0) {
Fp::subNC(z, z, Fp::getP());
}
CYBOZU_TEST_EQUAL(z, Fp(8));
// Fp::subNC(z, x, y);
// CYBOZU_TEST_EQUAL(z, Fp(2));
if (Fp::compareRaw(x, y) < 0) {
Fp::addNC(x, x, Fp::getP());
}
Fp::subNC(x, x, y);
CYBOZU_TEST_EQUAL(x, Fp(2));
}
}
void power()

Loading…
Cancel
Save