rename power to pow

dev
MITSUNARI Shigeo 9 years ago
parent d5f585ef82
commit 8417bf5f0b
  1. 26
      include/mcl/bn.hpp
  2. 2
      include/mcl/ec.hpp
  3. 2
      include/mcl/fp.hpp
  4. 16
      include/mcl/operator.hpp
  5. 2
      include/mcl/util.hpp
  6. 10
      include/mcl/window_method.hpp
  7. 2
      test/bn_test.cpp
  8. 16
      test/fp_test.cpp
  9. 4
      test/fp_tower_test.cpp
  10. 16
      test/mont_fp_test.cpp

@ -171,7 +171,7 @@ struct ParamT {
G1::init(0, b, mcl::ec::Proj);
G2::init(0, b_div_xi, mcl::ec::Proj);
power(g[0], xi, (p - 1) / 6); // g = xi^((p-1)/6)
pow(g[0], xi, (p - 1) / 6); // g = xi^((p-1)/6)
for (size_t i = 1; i < gN; i++) {
g[i] = g[i - 1] * g[0];
}
@ -181,7 +181,7 @@ struct ParamT {
g3[i] = g[i] * g2[i];
}
Fp2 tmp;
Fp2::power(tmp, xi, (p * p - 1) / 6);
Fp2::pow(tmp, xi, (p * p - 1) / 6);
assert(tmp.b.isZero());
Fp::sqr(Z, tmp.a);
@ -519,12 +519,12 @@ struct BNT {
mpz_class c1 = 1 + param.z * (-12 + param.z * (-18 - 36 * param.z));
mpz_class c2 = 6 * param.z * param.z + 1;
Fp12 t0, t1, t2, t3;
Fp12::power(t0, x, c0);
Fp12::pow(t0, x, c0);
Frobenius(t1, x);
Frobenius(t2, t1);
Frobenius(t3, t2);
Fp12::power(t1, t1, c1);
Fp12::power(t2, t2, c2);
Fp12::pow(t1, t1, c1);
Fp12::pow(t2, t2, c2);
t0 *= t1;
t0 *= t2;
Fp12::mul(y, t0, t3);
@ -532,7 +532,7 @@ struct BNT {
const mpz_class& p = param.p;
mpz_class p2 = p * p;
mpz_class p4 = p2 * p2;
Fp12::power(y, x, (p4 - p2 + 1) / param.r);
Fp12::pow(y, x, (p4 - p2 + 1) / param.r);
#endif
}
/*
@ -547,9 +547,9 @@ struct BNT {
y = x^z if z > 0
= unitaryInv(x^(-z)) if z < 0
*/
static void power_z(Fp12& y, const Fp12& x)
static void pow_z(Fp12& y, const Fp12& x)
{
Fp12::power(y, x, param.abs_z);
Fp12::pow(y, x, param.abs_z);
if (param.isNegative) {
unitaryInv(y, y);
}
@ -577,13 +577,13 @@ struct BNT {
static void exp_d1(Fp12& y, const Fp12& x)
{
Fp12 a0, a1, a2, a3;
power_z(a0, x); // x^z
pow_z(a0, x); // x^z
Fp12::sqr(a0, a0); // x^2z
Fp12::sqr(a1, a0); // x^4z
a1 *= a0; // x^6z
power_z(a2, a1); // x^(6z^2)
pow_z(a2, a1); // x^(6z^2)
Fp12::sqr(a3, a2); // x^(12z^2)
power_z(a3, a3); // x^(12z^3)
pow_z(a3, a3); // x^(12z^3)
Fp12 a, b;
Fp12::mul(a, a1, a2);
a *= a3;
@ -625,8 +625,8 @@ struct BNT {
const mpz_class& p = param.p;
mpz_class p2 = p * p;
mpz_class p4 = p2 * p2;
Fp12::power(y, x, p2 + 1);
Fp12::power(y, y, p4 * p2 - 1);
Fp12::pow(y, x, p2 + 1);
Fp12::pow(y, y, p4 * p2 - 1);
#endif
exp_d1(y, y);
}

@ -705,7 +705,7 @@ private:
px = &tmp;
}
z.clear();
fp::powerGeneric(z, *px, y, yn, EcT::add, EcT::dbl);
fp::powGeneric(z, *px, y, yn, EcT::add, EcT::dbl);
if (isNegative) {
neg(z, z);
}

@ -511,7 +511,7 @@ template<class T> void div(T& z, const T& x, const T& y) { T::div(z, x, y); }
template<class T> void neg(T& y, const T& x) { T::neg(y, x); }
template<class T> void inv(T& y, const T& x) { T::inv(y, x); }
template<class T> void sqr(T& y, const T& x) { T::sqr(y, x); }
template<class T, class S> void power(T& z, const T& x, const S& y) { T::power(z, x, y); }
template<class T, class S> void pow(T& z, const T& x, const S& y) { T::pow(z, x, y); }
} // mcl

@ -41,23 +41,23 @@ struct Operator : E {
friend MCL_FORCE_INLINE T operator/(const T& a, const T& b) { T c; T::inv(c, b); c *= a; return c; }
MCL_FORCE_INLINE T operator-() const { T c; T::neg(c, static_cast<const T&>(*this)); return c; }
template<class tag2, size_t maxBitSize2, template<class _tag, size_t _maxBitSize> class FpT>
static void power(T& z, const T& x, const FpT<tag2, maxBitSize2>& y)
static void pow(T& z, const T& x, const FpT<tag2, maxBitSize2>& y)
{
fp::Block b;
y.getBlock(b);
powerArray(z, x, b.p, b.n, false);
powArray(z, x, b.p, b.n, false);
}
static void power(T& z, const T& x, int y)
static void pow(T& z, const T& x, int y)
{
const Unit u = abs(y);
powerArray(z, x, &u, 1, y < 0);
powArray(z, x, &u, 1, y < 0);
}
static void power(T& z, const T& x, const mpz_class& y)
static void pow(T& z, const T& x, const mpz_class& y)
{
powerArray(z, x, gmp::getUnit(y), abs(y.get_mpz_t()->_mp_size), y < 0);
powArray(z, x, gmp::getUnit(y), abs(y.get_mpz_t()->_mp_size), y < 0);
}
private:
static void powerArray(T& z, const T& x, const Unit *y, size_t yn, bool isNegative)
static void powArray(T& z, const T& x, const Unit *y, size_t yn, bool isNegative)
{
T tmp;
const T *px = &x;
@ -66,7 +66,7 @@ private:
px = &tmp;
}
z = 1;
fp::powerGeneric(z, *px, y, yn, T::mul, T::sqr);
fp::powGeneric(z, *px, y, yn, T::mul, T::sqr);
if (isNegative) {
T::inv(z, z);
}

@ -174,7 +174,7 @@ void getRandVal(T *out, RG& rg, const T *in, size_t bitSize)
@note &out != x and out = the unit element of G
*/
template<class G, class T>
void powerGeneric(G& out, const G& x, const T *y, size_t n, void mul(G&, const G&, const G&) , void sqr(G&, const G&))
void powGeneric(G& out, const G& x, const T *y, size_t n, void mul(G&, const G&, const G&) , void sqr(G&, const G&))
{
#if 0
assert(&out != &x);

@ -115,18 +115,18 @@ public:
{
fp::Block b;
y.getBlock(b);
powerArray(z, b.p, b.n, false);
powArray(z, b.p, b.n, false);
}
void mul(Ec& z, int y) const
{
Unit u = std::abs(y);
powerArray(z, &u, 1, y < 0);
powArray(z, &u, 1, y < 0);
}
void mul(Ec& z, const mpz_class& y) const
{
powerArray(z, gmp::getUnit(y), abs(y.get_mpz_t()->_mp_size), y < 0);
powArray(z, gmp::getUnit(y), abs(y.get_mpz_t()->_mp_size), y < 0);
}
void powerArray(Ec& z, const Unit* y, size_t n, bool isNegative) const
void powArray(Ec& z, const Unit* y, size_t n, bool isNegative) const
{
z.clear();
while (n > 0) {
@ -134,7 +134,7 @@ public:
n--;
}
if (n == 0) return;
if (n > tbl_.size()) throw cybozu::Exception("mcl:WindowMethod:powerArray:bad n") << n << tbl_.size();
if (n > tbl_.size()) throw cybozu::Exception("mcl:WindowMethod:powArray:bad n") << n << tbl_.size();
assert(y[n - 1]);
const size_t bitSize = (n - 1) * UnitBitSize + cybozu::bsr<Unit>(y[n - 1]) + 1;
size_t i = 0;

@ -83,7 +83,7 @@ CYBOZU_TEST_AUTO(naive)
ss >> e2;
// mpz_class x = BN::param.z;
// x = 2 * x * (6 * x * x + 3 * x + 1);
// Fp12::power(e1, e1, x);
// Fp12::pow(e1, e1, x);
}
CYBOZU_TEST_EQUAL(e1, e2);
/*

@ -264,13 +264,13 @@ CYBOZU_TEST_AUTO(ope)
struct tag2;
CYBOZU_TEST_AUTO(power)
CYBOZU_TEST_AUTO(pow)
{
Fp x, y, z;
x = 12345;
z = 1;
for (int i = 0; i < 100; i++) {
Fp::power(y, x, i);
Fp::pow(y, x, i);
CYBOZU_TEST_EQUAL(y, z);
z *= x;
}
@ -279,33 +279,33 @@ CYBOZU_TEST_AUTO(power)
x = 5;
Fp2 n = 3;
z = 3;
Fp::power(x, x, z);
Fp::pow(x, x, z);
CYBOZU_TEST_EQUAL(x, 125);
x = 5;
Fp::power(x, x, n);
Fp::pow(x, x, n);
CYBOZU_TEST_EQUAL(x, 125);
}
CYBOZU_TEST_AUTO(neg_power)
CYBOZU_TEST_AUTO(neg_pow)
{
Fp x, y, z;
x = 12345;
z = 1;
Fp rx = 1 / x;
for (int i = 0; i < 100; i++) {
Fp::power(y, x, -i);
Fp::pow(y, x, -i);
CYBOZU_TEST_EQUAL(y, z);
z *= rx;
}
}
CYBOZU_TEST_AUTO(power_fp)
CYBOZU_TEST_AUTO(pow_fp)
{
Fp x, y, z;
x = 12345;
z = 1;
for (int i = 0; i < 100; i++) {
Fp::power(y, x, Fp(i));
Fp::pow(y, x, Fp(i));
CYBOZU_TEST_EQUAL(y, z);
z *= x;
}

@ -75,7 +75,7 @@ void testFp2()
}
y = 1;
for (int i = 0; i < 10; i++) {
power(z, x, i);
pow(z, x, i);
CYBOZU_TEST_EQUAL(z, y);
y *= x;
}
@ -86,7 +86,7 @@ void testFp2()
{
const mpz_class& mp = Fp::getOp().mp;
y = x;
power(z, y, mp);
pow(z, y, mp);
if ((mp % 4) == 3) {
neg(z.b, z.b);
}

@ -124,9 +124,9 @@ struct Test {
compare();
modulo();
ope();
power();
pow();
mul_Unit();
power_Zn();
pow_Zn();
setArray();
set64bit();
divBy2();
@ -486,20 +486,20 @@ struct Test {
CYBOZU_TEST_EQUAL(x, Fp(2));
}
}
void power()
void pow()
{
Fp x, y, z;
x = 12345;
z = 1;
for (int i = 0; i < 100; i++) {
Fp::power(y, x, i);
Fp::pow(y, x, i);
CYBOZU_TEST_EQUAL(y, z);
z *= x;
}
x = z;
Fp::power(z, x, Fp::getOp().mp - 1);
Fp::pow(z, x, Fp::getOp().mp - 1);
CYBOZU_TEST_EQUAL(z, 1);
Fp::power(z, x, Fp::getOp().mp);
Fp::pow(z, x, Fp::getOp().mp);
CYBOZU_TEST_EQUAL(z, x);
}
void mul_Unit()
@ -511,13 +511,13 @@ struct Test {
CYBOZU_TEST_EQUAL(y, z);
}
}
void power_Zn()
void pow_Zn()
{
Fp x, y, z;
x = 12345;
z = 1;
for (int i = 0; i < 100; i++) {
Fp::power(y, x, Zn(i));
Fp::pow(y, x, Zn(i));
CYBOZU_TEST_EQUAL(y, z);
z *= x;
}

Loading…
Cancel
Save