power.hpp is removed

dev
MITSUNARI Shigeo 10 years ago
parent 90415639ca
commit ae876eb842
  1. 54
      include/mcl/ec.hpp
  2. 2
      include/mcl/fp.hpp
  3. 181
      include/mcl/power.hpp
  4. 39
      include/mcl/tagmultigr.hpp
  5. 4
      include/mcl/util.hpp

@ -112,17 +112,8 @@ public:
y.clear();
}
static inline void dbl2(EcT& R, const EcT& P)
static inline void dblNoVerifyInf(EcT& R, const EcT& P)
{
dbl(R, P);
}
static inline void dbl(EcT& R, const EcT& P, bool verifyInf = true)
{
if (verifyInf) {
if (P.isZero()) {
R.clear(); return;
}
}
#if MCL_EC_COORD == MCL_EC_USE_JACOBI
Fp S, M, t, y2;
Fp::square(y2, P.y);
@ -227,6 +218,14 @@ public:
R.inf_ = false;
#endif
}
static inline void dbl(EcT& R, const EcT& P)
{
if (P.isZero()) {
R.clear();
return;
}
dblNoVerifyInf(R, P);
}
static inline void add(EcT& R, const EcT& P, const EcT& Q)
{
if (P.isZero()) { R = Q; return; }
@ -245,7 +244,7 @@ public:
r -= S1;
if (H.isZero()) {
if (r.isZero()) {
dbl(R, P, false);
dblNoVerifyInf(R, P);
} else {
R.clear();
}
@ -276,7 +275,7 @@ public:
if (vv.isZero()) {
R.clear();
} else {
dbl(R, P, false);
dblNoVerifyInf(R, P);
}
return;
}
@ -302,7 +301,7 @@ public:
if (P.y == t) { R.clear(); return; }
Fp::sub(t, Q.x, P.x);
if (t.isZero()) {
dbl(R, P, false);
dblNoVerifyInf(R, P);
return;
}
Fp s;
@ -328,7 +327,7 @@ public:
Fp t;
Fp::sub(t, Q.x, P.x);
if (t.isZero()) {
dbl(R, P, false);
dblNoVerifyInf(R, P);
return;
}
Fp s;
@ -369,8 +368,7 @@ public:
static inline void powerArray(EcT& z, const EcT& x, const fp::Unit *y, size_t yn)
{
EcT out;
out.clear();
fp::powerArray(out, x, y, yn, EcT::add, EcT::dbl2);
fp::powerArray(out, x, y, yn, EcT::add, EcT::dbl);
z = out;
}
template<class tag, size_t maxBitN>
@ -503,30 +501,6 @@ public:
bool operator!=(const EcT& rhs) const { return !operator==(rhs); }
};
template<class T>
struct TagMultiGr<EcT<T> > {
static void square(EcT<T>& z, const EcT<T>& x)
{
EcT<T>::dbl(z, x);
}
static void mul(EcT<T>& z, const EcT<T>& x, const EcT<T>& y)
{
EcT<T>::add(z, x, y);
}
static void inv(EcT<T>& z, const EcT<T>& x)
{
EcT<T>::neg(z, x);
}
static void div(EcT<T>& z, const EcT<T>& x, const EcT<T>& y)
{
EcT<T>::sub(z, x, y);
}
static void init(EcT<T>& x)
{
x.clear();
}
};
template<class _Fp> _Fp EcT<_Fp>::a_;
template<class _Fp> _Fp EcT<_Fp>::b_;
template<class _Fp> int EcT<_Fp>::specialA_;

@ -20,10 +20,8 @@
// #define USE_MONT_FP
#endif
#include <cybozu/hash.hpp>
#include <cybozu/bit_operation.hpp>
#include <mcl/op.hpp>
#include <mcl/util.hpp>
#include <mcl/power.hpp> // QQQ : removed laster
namespace mcl {

@ -1,181 +0,0 @@
#pragma once
/**
@file
@brief power
@author MITSUNARI Shigeo(@herumi)
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
#include <assert.h>
#include <cybozu/bit_operation.hpp>
#include <mcl/tagmultigr.hpp>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4616)
#pragma warning(disable : 4800)
#pragma warning(disable : 4244)
#pragma warning(disable : 4127)
#pragma warning(disable : 4512)
#pragma warning(disable : 4146)
#endif
#include <gmpxx.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
namespace mcl {
namespace power_impl {
template<class F>
struct TagInt {
typedef typename F::BlockType BlockType;
static size_t getBlockSize(const F& x)
{
return F::getBlockSize(x);
}
static BlockType getBlock(const F& x, size_t i)
{
return F::getBlock(x, i);
}
static const BlockType* getBlock(const F& x)
{
return F::getBlock(x);
}
static size_t getBitLen(const F& x)
{
return F::getBitLen(x);
}
static void shr(F& x, size_t n)
{
F::shr(x, x, n);
}
};
template<>
struct TagInt<int> {
typedef int BlockType;
static int getBlockSize(int)
{
return 1;
}
static BlockType getBlock(int x, size_t i)
{
assert(i == 0);
cybozu::disable_warning_unused_variable(i);
return x;
}
static const BlockType* getBlock(const int& x)
{
return &x;
}
static size_t getBitLen(int x)
{
return x == 0 ? 1 : cybozu::bsr(x) + 1;
}
static void shr(int& x, size_t n)
{
x >>= n;
}
};
template<>
struct TagInt<size_t> {
typedef size_t BlockType;
static size_t getBlockSize(size_t)
{
return 1;
}
static BlockType getBlock(size_t x, size_t i)
{
assert(i == 0);
cybozu::disable_warning_unused_variable(i);
return x;
}
static const BlockType* getBlock(const size_t& x)
{
return &x;
}
static size_t getBitLen(size_t x)
{
return x == 0 ? 1 : cybozu::bsr<size_t>(x) + 1;
}
static void shr(size_t& x, size_t n)
{
x >>= n;
}
};
template<>
struct TagInt<mpz_class> {
typedef mp_limb_t BlockType;
static size_t getBlockSize(const mpz_class& x)
{
return x.get_mpz_t()->_mp_size;
}
static BlockType getBlock(const mpz_class& x, size_t i)
{
return x.get_mpz_t()->_mp_d[i];
}
static const BlockType* getBlock(const mpz_class& x)
{
return x.get_mpz_t()->_mp_d;
}
static size_t getBitLen(const mpz_class& x)
{
return mpz_sizeinbase(x.get_mpz_t(), 2);
}
static void shr(mpz_class& x, size_t n)
{
x >>= n;
}
};
template<class G, class BlockType>
void powerArray(G& z, const G& x, const BlockType *y, size_t n)
{
typedef TagMultiGr<G> TagG;
G out;
TagG::init(out);
G t(x);
for (size_t i = 0; i < n; i++) {
BlockType v = y[i];
int m = (int)sizeof(BlockType) * 8;
if (i == n - 1) {
// avoid unused multiplication
while (m > 0 && (v & (BlockType(1) << (m - 1))) == 0) {
m--;
}
}
for (int j = 0; j < m; j++) {
if (v & (BlockType(1) << j)) {
TagG::mul(out, out, t);
}
TagG::square(t, t);
}
}
z = out;
}
template<class G, class F>
void power(G& z, const G& x, const F& _y)
{
typedef TagMultiGr<G> TagG;
typedef power_impl::TagInt<F> TagI;
if (_y == 0) {
TagG::init(z);
return;
}
if (_y == 1) {
z = x;
return;
}
bool isNegative = _y < 0;
const F& y = isNegative ? -_y : _y;
powerArray(z, x, TagI::getBlock(y), TagI::getBlockSize(y));
if (isNegative) {
TagG::inv(z, z);
}
}
} } // mcl::power_impl

@ -1,39 +0,0 @@
#pragma once
/**
@file
@brief TagMultiGr
@author MITSUNARI Shigeo(@herumi)
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
#include <assert.h>
namespace mcl {
// default tag is for multiplicative group
template<class G>
struct TagMultiGr {
static void square(G& z, const G& x)
{
G::mul(z, x, x);
}
static void mul(G& z, const G& x, const G& y)
{
G::mul(z, x, y);
}
static void inv(G& z, const G& x)
{
G::inv(z, x);
}
static void div(G& z, const G& x, const G& y)
{
G::div(z, x, y);
}
static void init(G& x)
{
x = 1;
}
};
} // mcl

@ -110,8 +110,8 @@ void getRandVal(T *out, RG& rg, const T *in, size_t bitLen)
@param y [in]
@param n [in] size of y[]
*/
template<class G, class T, class Mul, class Square>
void powerArray(G& out, const G& x, const T *y, size_t n, Mul mul, Square square)
template<class G, class T>
void powerArray(G& out, const G& x, const T *y, size_t n, void mul(G&, const G&, const G&), void square(G&, const G&))
{
G t(x);
for (size_t i = 0; i < n; i++) {

Loading…
Cancel
Save