fp_tower assumes p < W/4

update-fork
MITSUNARI Shigeo 4 years ago
parent 91a2ecf358
commit f9d7d40059
  1. 13
      include/mcl/fp_tower.hpp
  2. 6
      test/fp_tower_test.cpp

@ -379,11 +379,16 @@ public:
} }
static uint32_t get_xi_a() { return Fp::getOp().xi_a; } static uint32_t get_xi_a() { return Fp::getOp().xi_a; }
static void init() static void init(bool *pb)
{ {
// assert(Fp::maxSize <= 256); // assert(Fp::maxSize <= 256);
mcl::fp::Op& op = Fp::op_; mcl::fp::Op& op = Fp::op_;
assert(op.xi_a); assert(op.xi_a);
// assume p < W/4 where W = 1 << (N * sizeof(Unit) * 8)
if ((op.p[op.N - 1] >> (sizeof(fp::Unit) * 8 - 2)) != 0) {
*pb = false;
return;
}
mul_xi = 0; mul_xi = 0;
#ifdef MCL_XBYAK_DIRECT_CALL #ifdef MCL_XBYAK_DIRECT_CALL
add = fp::func_ptr_cast<void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y)>(op.fp2_addA_); add = fp::func_ptr_cast<void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y)>(op.fp2_addA_);
@ -440,6 +445,12 @@ public:
} }
} }
#ifndef CYBOZU_DONT_USE_EXCEPTION #ifndef CYBOZU_DONT_USE_EXCEPTION
static void init()
{
bool b;
init(&b);
if (!b) throw cybozu::Exception("Fp2::init");
}
template<class InputStream> template<class InputStream>
void load(InputStream& is, int ioMode = IoSerialize) void load(InputStream& is, int ioMode = IoSerialize)
{ {

@ -400,9 +400,11 @@ void test(const char *p, mcl::fp::Mode mode)
{ {
const int xi_a = 1; const int xi_a = 1;
Fp::init(xi_a, p, mode); Fp::init(xi_a, p, mode);
printf("mode=%s\n", mcl::fp::ModeToStr(mode));
if (Fp::getOp().isFullBit) return; if (Fp::getOp().isFullBit) return;
Fp2::init(); bool b;
Fp2::init(&b);
if (!b) return;
printf("mode=%s\n", mcl::fp::ModeToStr(mode));
printf("bitSize=%d\n", (int)Fp::getBitSize()); printf("bitSize=%d\n", (int)Fp::getBitSize());
#if 0 #if 0
if (Fp::getBitSize() > 256) { if (Fp::getBitSize() > 256) {

Loading…
Cancel
Save