From b3619c63b09ffedeea326fb10e5d4bfd41bb5e91 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Thu, 28 May 2015 15:52:31 +0900 Subject: [PATCH] move Block to fp --- include/mcl/fp.hpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index 1dffa2b..0581d5c 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -37,7 +37,6 @@ namespace fp { void setOp(mcl::fp::Op& op, const Unit* p, size_t pBitLen); -} // mcl::fp struct Block { typedef fp::Unit Unit; @@ -48,6 +47,8 @@ struct Block { Unit v_[maxUnitN]; }; +} // mcl::fp + template class FpT { typedef fp::Unit Unit; @@ -131,7 +132,7 @@ public: } static inline bool isYodd(const FpT& x) { - Block b; + fp::Block b; x.getBlock(b); return (b.p[0] & 1) == 1; } @@ -220,16 +221,16 @@ public: const size_t fpByteN = sizeof(Unit) * op_.N; if (byteN < fpByteN) throw cybozu::Exception("getRaw:bad n") << n << fpByteN; assert(byteN >= fpByteN); - Block b; + fp::Block b; getBlock(b); memcpy(outBuf, b.p, fpByteN); const size_t writeN = (fpByteN + sizeof(S) - 1) / sizeof(S); memset((char *)outBuf + fpByteN, 0, writeN * sizeof(S) - fpByteN); return writeN; } - void getBlock(Block& b) const + void getBlock(fp::Block& b) const { - assert(maxUnitN <= Block::maxUnitN); + assert(maxUnitN <= fp::Block::maxUnitN); b.n = op_.N; if (op_.fromMont) { op_.fromMont(b.v_, v_); @@ -266,7 +267,7 @@ public: } void toStr(std::string& str, int base = 10, bool withPrefix = false) const { - Block b; + fp::Block b; getBlock(b); toStr(str, b.p, b.n, base, withPrefix); } @@ -278,7 +279,7 @@ public: } void toGmp(mpz_class& x) const { - Block b; + fp::Block b; getBlock(b); Gmp::setRaw(x, b.p, b.n); } @@ -328,7 +329,7 @@ public: template static inline void power(FpT& z, const FpT& x, const FpT& y) { - Block b; + fp::Block b; y.getBlock(b); powerArray(z, x, b.p, b.n); } @@ -349,7 +350,7 @@ public: */ void appendToBitVec(cybozu::BitVector& bv) const { - Block b; + fp::Block b; getBlock(b); bv.append(b.p, pBitLen_); } @@ -405,7 +406,7 @@ public: bool operator<(const FpT&) const { return false; } static inline int compare(const FpT& x, const FpT& y) { - Block xb, yb; + fp::Block xb, yb; x.getBlock(xb); y.getBlock(yb); return fp::local::compareArray(xb.p, yb.p, xb.n); @@ -429,7 +430,7 @@ namespace power_impl { templateclass FpT> void power(G& z, const G& x, const FpT& y) { - Block b; + fp::Block b; y.getBlock(b); mcl::power_impl::powerArray(z, x, b.p, b.n); }