add test for NIST_P192

dev
MITSUNARI Shigeo 9 years ago
parent c0c098214b
commit ea957d50cb
  1. 11
      include/mcl/fp_tower.hpp
  2. 2
      src/fp.cpp
  3. 7
      test/fp_tower_test.cpp

@ -247,6 +247,7 @@ private:
/*
x = a + bi, i^2 = -1
y = x^2 = (a + bi)^2 = (a^2 - b^2) + 2abi
= (a + b)(a - b) + 2abi
*/
static inline void fp2_sqrW(Unit *y, const Unit *x)
{
@ -254,12 +255,22 @@ private:
Fp *py = reinterpret_cast<Fp*>(y);
const Fp& a = px[0];
const Fp& b = px[1];
#if 1
Fp aa, bb, t;
Fp::sqr(aa, a);
Fp::sqr(bb, b);
Fp::mul(t, a, b);
Fp::sub(py[0], aa, bb); // a^2 - b^2
Fp::add(py[1], t, t); // 2ab
#else
Fp t1, t2;
Fp::addNC(t1, b, b); // 2b
t1 *= a; // 2ab
Fp::sub(t2, a, b); // a - b
Fp::addNC(py[0], a, b); // a + b
py[0] *= t2; // (a + b)(a - b)
py[1] = t1; // 2ab
#endif
}
/*
xi = xi_c + i

@ -411,7 +411,7 @@ void Op::init(const std::string& mstr, int base, size_t maxBitSize, Mode mode)
throw cybozu::Exception("Op::init:not:support") << mstr;
}
#ifdef MCL_USE_LLVM
if (mode == FP_AUTO && mp == mpz_class("0xfffffffffffffffffffffffffffffffeffffffffffffffff")) {
if ((mode == FP_AUTO || mode == FP_LLVM) && mp == mpz_class("0xfffffffffffffffffffffffffffffffeffffffffffffffff")) {
fp_mul = &mcl_fp_mul_NIST_P192;
isMont = false;
}

@ -138,15 +138,13 @@ void testFpDbl()
"0", "1", "123456", "123456789012345668909", pstr.c_str(),
};
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
mpz_class mx(tbl[i]), my;
mpz_class mx(tbl[i]);
FpDbl x;
x.setMpz(mx);
x.getMpz(my);
CYBOZU_TEST_EQUAL(mx, my);
for (size_t j = 0; j < CYBOZU_NUM_OF_ARRAY(tbl); j++) {
FpDbl y, z;
mpz_class mz, mo;
my = tbl[j];
mpz_class my(tbl[j]);
y.setMpz(my);
FpDbl::add(z, x, y);
mcl::Gmp::addMod(mo, mx, my, mp);
@ -284,6 +282,7 @@ void testAll()
"0x30000000000000000000000000000000000000000000002b",
"0x70000000000000000000000000000000000000000000001f",
"0x800000000000000000000000000000000000000000000005",
"0xfffffffffffffffffffffffffffffffeffffffffffffffff",
"0xfffffffffffffffffffffffffffffffffffffffeffffee37",
"0xfffffffffffffffffffffffe26f2fc170f69466a74defd8d",
"0xffffffffffffffffffffffffffffffffffffffffffffff13", // max prime

Loading…
Cancel
Save