#include #include #include #include #include CYBOZU_TEST_AUTO(ArrayIterator) { const uint32_t in[2] = { 0x12345678, 0xabcdef89 }; const size_t bitSize = 64; for (size_t w = 1; w <= 32; w++) { const uint32_t mask = uint32_t((uint64_t(1) << w) - 1); mpz_class x; mcl::gmp::setArray(x, in, 2); mcl::fp::ArrayIterator ai(in, bitSize, w); size_t n = (bitSize + w - 1) / w; for (size_t j = 0; j < n; j++) { CYBOZU_TEST_ASSERT(ai.hasNext()); uint32_t v = ai.getNext(); CYBOZU_TEST_EQUAL(v, x & mask); x >>= w; } CYBOZU_TEST_ASSERT(!ai.hasNext()); } } CYBOZU_TEST_AUTO(int) { typedef mcl::FpT<> Fp; typedef mcl::EcT Ec; const struct mcl::EcParam& para = mcl::ecparam::secp192k1; Fp::setModulo(para.p); Ec::init(para.a, para.b); const Fp x(para.gx); const Fp y(para.gy); const Ec P(x, y); typedef mcl::fp::WindowMethod PW; const size_t bitSize = 13; Ec Q, R; for (size_t winSize = 10; winSize <= bitSize; winSize++) { PW pw(P, bitSize, winSize); for (int i = 0; i < (1 << bitSize); i++) { pw.mul(Q, i); Ec::mul(R, P, i); CYBOZU_TEST_EQUAL(Q, R); } } PW pw(P, para.bitSize, 10); pw.mul(Q, -12345); Ec::mul(R, P, -12345); CYBOZU_TEST_EQUAL(Q, R); mpz_class t(para.gx); pw.mul(Q, t); Ec::mul(R, P, t); CYBOZU_TEST_EQUAL(Q, R); t = -t; pw.mul(Q, t); Ec::mul(R, P, t); CYBOZU_TEST_EQUAL(Q, R); pw.mul(Q, x); Ec::mul(R, P, x); CYBOZU_TEST_EQUAL(Q, R); pw.mul(Q, y); Ec::mul(R, P, y); CYBOZU_TEST_EQUAL(Q, R); }