diff options
| author | MITSUNARI Shigeo <herumi@nifty.com> | 2015-06-11 08:01:14 +0800 |
|---|---|---|
| committer | MITSUNARI Shigeo <herumi@nifty.com> | 2015-06-11 08:01:14 +0800 |
| commit | 31abdd0eec3cb082a455a098c388108f271d6a47 (patch) | |
| tree | bde7c4bb21248d21ca4e06db47c601c2807ab052 | |
| parent | 1fe925c26af2efe5bcf2fbd32ccaf2eef5469b9b (diff) | |
| download | tangerine-mcl-31abdd0eec3cb082a455a098c388108f271d6a47.tar.gz tangerine-mcl-31abdd0eec3cb082a455a098c388108f271d6a47.tar.zst tangerine-mcl-31abdd0eec3cb082a455a098c388108f271d6a47.zip | |
rename len to size
| -rw-r--r-- | include/mcl/ec.hpp | 6 | ||||
| -rw-r--r-- | include/mcl/elgamal.hpp | 32 | ||||
| -rw-r--r-- | include/mcl/fp.hpp | 56 | ||||
| -rw-r--r-- | include/mcl/gmp_util.hpp | 16 | ||||
| -rw-r--r-- | include/mcl/op.hpp | 22 | ||||
| -rw-r--r-- | include/mcl/util.hpp | 10 | ||||
| -rw-r--r-- | include/mcl/window_method.hpp | 64 | ||||
| -rw-r--r-- | src/fp.cpp | 38 | ||||
| -rw-r--r-- | test/base_test.cpp | 38 | ||||
| -rw-r--r-- | test/ec_test.cpp | 2 | ||||
| -rw-r--r-- | test/elgamal_test.cpp | 4 | ||||
| -rw-r--r-- | test/fp_util_test.cpp | 4 | ||||
| -rw-r--r-- | test/window_method_test.cpp | 16 |
13 files changed, 154 insertions, 154 deletions
diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index aed15ed..6a12eee 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -374,8 +374,8 @@ public: z = out; } } - template<class tag, size_t maxBitN> - static inline void power(EcT& z, const EcT& x, const FpT<tag, maxBitN>& y) + template<class tag, size_t maxBitSize> + static inline void power(EcT& z, const EcT& x, const FpT<tag, maxBitSize>& y) { fp::Block b; y.getBlock(b); @@ -513,7 +513,7 @@ struct EcParam { const char *gx; const char *gy; const char *n; - size_t bitLen; // bit length of p + size_t bitSize; // bit length of p }; } // mcl diff --git a/include/mcl/elgamal.hpp b/include/mcl/elgamal.hpp index 452b0e0..2d33201 100644 --- a/include/mcl/elgamal.hpp +++ b/include/mcl/elgamal.hpp @@ -98,11 +98,11 @@ struct ElgamalT { } void fromBitVec(const cybozu::BitVector& bv) { - size_t bitLen = G::getBitVecSize(); + size_t bitSize = G::getBitVecSize(); cybozu::BitVector t; - bv.extract(t, 0, bitLen); + bv.extract(t, 0, bitSize); c1.fromBitVec(t); - bv.extract(t, bitLen, bitLen); + bv.extract(t, bitSize, bitSize); c2.fromBitVec(t); } static inline size_t getBitVecSize() @@ -146,7 +146,7 @@ struct ElgamalT { class PublicKey { typedef _G G; - size_t bitLen; + size_t bitSize; G f; G g; G h; @@ -171,21 +171,21 @@ struct ElgamalT { void powerH(G& z, const N& n) const { powerSub(z, h, n, powh); } public: PublicKey() - : bitLen(0) + : bitSize(0) , enablePowerWindow_(false) { } void enablePowerWindow(size_t winSize = 10) { - powf.init(f, bitLen, winSize); - powg.init(g, bitLen, winSize); - powh.init(h, bitLen, winSize); + powf.init(f, bitSize, winSize); + powg.init(g, bitSize, winSize); + powh.init(h, bitSize, winSize); enablePowerWindow_ = true; } const G& getF() const { return f; } - void init(size_t bitLen, const G& f, const G& g, const G& h) + void init(size_t bitSize, const G& f, const G& g, const G& h) { - this->bitLen = bitLen; + this->bitSize = bitSize; this->f = f; this->g = g; this->h = h; @@ -343,18 +343,18 @@ struct ElgamalT { friend inline std::ostream& operator<<(std::ostream& os, const PublicKey& self) { std::ios_base::fmtflags flags = os.flags(); - os << std::dec << self.bitLen << ' ' << std::hex << self.f << ' ' << self.g << ' ' << self.h; + os << std::dec << self.bitSize << ' ' << std::hex << self.f << ' ' << self.g << ' ' << self.h; os.flags(flags); return os; } friend inline std::istream& operator>>(std::istream& is, PublicKey& self) { std::ios_base::fmtflags flags = is.flags(); - size_t bitLen; + size_t bitSize; G f, g, h; - is >> std::dec >> bitLen >> std::hex >> f >> g >> h; + is >> std::dec >> bitSize >> std::hex >> f >> g >> h; is.flags(flags); - self.init(bitLen, f, g, h); + self.init(bitSize, f, g, h); return is; } }; @@ -373,14 +373,14 @@ struct ElgamalT { h = g^z */ template<class RG> - void init(const G& f, size_t bitLen, RG& rg) + void init(const G& f, size_t bitSize, RG& rg) { G g, h; z.setRand(rg); G::power(g, f, z); z.setRand(rg); G::power(h, g, z); - pub.init(bitLen, f, g, h); + pub.init(bitSize, f, g, h); } const PublicKey& getPublicKey() const { return pub; } /* diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index d6140c8..a023708 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -35,13 +35,13 @@ void strToGmp(mpz_class& x, bool *isMinus, const std::string& str, int base); } // mcl::fp -template<class tag = fp::TagDefault, size_t maxBitN = MCL_MAX_OP_BIT_N> +template<class tag = fp::TagDefault, size_t maxBitSize = MCL_MAX_OP_BIT_SIZE> class FpT { typedef fp::Unit Unit; - static const size_t maxN = (maxBitN + fp::UnitBitN - 1) / fp::UnitBitN; + static const size_t maxSize = (maxBitSize + fp::UnitBitSize - 1) / fp::UnitBitSize; static fp::Op op_; - template<class tag2, size_t maxBitN2> friend class FpT; - Unit v_[maxN]; + template<class tag2, size_t maxBitSize2> friend class FpT; + Unit v_[maxSize]; public: // return pointer to array v_[] const Unit *getUnit() const { return v_; } @@ -56,14 +56,14 @@ public: } static inline void setModulo(const std::string& mstr, int base = 0) { - assert(maxBitN <= MCL_MAX_OP_BIT_N); + assert(maxBitSize <= MCL_MAX_OP_BIT_SIZE); assert(sizeof(mp_limb_t) == sizeof(Unit)); // set default wrapper function op_.neg = negW; op_.add = addW; op_.sub = subW; op_.mul = mulW; - op_.init(mstr, base, maxBitN); + op_.init(mstr, base, maxBitSize); } static inline void getModulo(std::string& pstr) { @@ -143,27 +143,27 @@ public: template<class S> void setArray(const S *inBuf, size_t n) { - const size_t byteN = sizeof(S) * n; - const size_t fpByteN = sizeof(Unit) * op_.N; - if (byteN > fpByteN) throw cybozu::Exception("FpT:setArray:bad n") << n << fpByteN; - assert(byteN <= fpByteN); - memcpy(v_, inBuf, byteN); - memset((char *)v_ + byteN, 0, fpByteN - byteN); + const size_t SbyteSize = sizeof(S) * n; + const size_t fpByteSize = sizeof(Unit) * op_.N; + if (SbyteSize > fpByteSize) throw cybozu::Exception("FpT:setArray:bad n") << n << fpByteSize; + assert(SbyteSize <= fpByteSize); + memcpy(v_, inBuf, SbyteSize); + memset((char *)v_ + SbyteSize, 0, fpByteSize - SbyteSize); if (!isValid()) throw cybozu::Exception("FpT:setArray:large value"); toMont(*this, *this); } template<class S> size_t getArray(S *outBuf, size_t n) const { - const size_t byteN = sizeof(S) * n; - const size_t fpByteN = sizeof(Unit) * op_.N; - if (byteN < fpByteN) throw cybozu::Exception("FpT:getArray:bad n") << n << fpByteN; - assert(byteN >= fpByteN); + const size_t SbyteSize = sizeof(S) * n; + const size_t fpByteSize = sizeof(Unit) * op_.N; + if (SbyteSize < fpByteSize) throw cybozu::Exception("FpT:getArray:bad n") << n << fpByteSize; + assert(SbyteSize >= fpByteSize); 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); + memcpy(outBuf, b.p, fpByteSize); + const size_t writeN = (fpByteSize + sizeof(S) - 1) / sizeof(S); + memset((char *)outBuf + fpByteSize, 0, writeN * sizeof(S) - fpByteSize); return writeN; } void getBlock(fp::Block& b) const @@ -179,7 +179,7 @@ public: template<class RG> void setRand(RG& rg) { - fp::getRandVal(v_, rg, op_.p, op_.bitLen); + fp::getRandVal(v_, rg, op_.p, op_.bitSize); toMont(*this, *this); } void getStr(std::string& str, int base = 10, bool withPrefix = false) const @@ -228,8 +228,8 @@ public: fp::powerArray(out, x, y, yn, FpT::mul, FpT::square); z = out; } - template<class tag2, size_t maxBitN2> - static inline void power(FpT& z, const FpT& x, const FpT<tag2, maxBitN2>& y) + template<class tag2, size_t maxBitSize2> + static inline void power(FpT& z, const FpT& x, const FpT<tag2, maxBitSize2>& y) { fp::Block b; y.getBlock(b); @@ -251,7 +251,7 @@ public: { return fp::compareArray(v_, op_.p, op_.N) < 0; } - static inline size_t getModBitLen() { return op_.bitLen; } + static inline size_t getModBitLen() { return op_.bitSize; } bool operator==(const FpT& rhs) const { return fp::isEqualArray(v_, rhs.v_, op_.N); } bool operator!=(const FpT& rhs) const { return !operator==(rhs); } inline friend FpT operator+(const FpT& x, const FpT& y) { FpT z; add(z, x, y); return z; } @@ -319,7 +319,7 @@ public: } static inline void mulW(Unit *z, const Unit *x, const Unit *y) { - Unit xy[maxN * 2]; + Unit xy[maxSize * 2]; op_.mulPreP(xy, x, y); op_.modP(z, xy, op_.p); } @@ -330,16 +330,16 @@ public: private: }; -template<class tag, size_t maxBitN> fp::Op FpT<tag, maxBitN>::op_; +template<class tag, size_t maxBitSize> fp::Op FpT<tag, maxBitSize>::op_; } // mcl namespace std { CYBOZU_NAMESPACE_TR1_BEGIN template<class T> struct hash; -template<class tag, size_t maxBitN> -struct hash<mcl::FpT<tag, maxBitN> > : public std::unary_function<mcl::FpT<tag, maxBitN>, size_t> { - size_t operator()(const mcl::FpT<tag, maxBitN>& x, uint64_t v = 0) const +template<class tag, size_t maxBitSize> +struct hash<mcl::FpT<tag, maxBitSize> > : public std::unary_function<mcl::FpT<tag, maxBitSize>, size_t> { + size_t operator()(const mcl::FpT<tag, maxBitSize>& x, uint64_t v = 0) const { return static_cast<size_t>(cybozu::hash64(x.getUnit(), x.getUnitSize(), v)); } diff --git a/include/mcl/gmp_util.hpp b/include/mcl/gmp_util.hpp index 12f7145..b1a3380 100644 --- a/include/mcl/gmp_util.hpp +++ b/include/mcl/gmp_util.hpp @@ -262,11 +262,11 @@ struct Gmp { return x.get_mpz_t()->_mp_size; } template<class RG> - static inline void getRand(mpz_class& z, size_t bitLen, RG& rg) + static inline void getRand(mpz_class& z, size_t bitSize, RG& rg) { - assert(bitLen > 1); - const size_t rem = bitLen & 31; - const size_t n = (bitLen + 31) / 32; + assert(bitSize > 1); + const size_t rem = bitSize & 31; + const size_t n = (bitSize + 31) / 32; std::vector<uint32_t> buf(n); rg.read(buf.data(), n); uint32_t v = buf[n - 1]; @@ -280,13 +280,13 @@ struct Gmp { Gmp::setArray(z, &buf[0], n); } template<class RG> - static void getRandPrime(mpz_class& z, size_t bitLen, RG& rg, bool setSecondBit = false, bool mustBe3mod4 = false) + static void getRandPrime(mpz_class& z, size_t bitSize, RG& rg, bool setSecondBit = false, bool mustBe3mod4 = false) { - assert(bitLen > 2); + assert(bitSize > 2); do { - getRand(z, bitLen, rg); + getRand(z, bitSize, rg); if (setSecondBit) { - z |= mpz_class(1) << (bitLen - 2); + z |= mpz_class(1) << (bitSize - 2); } if (mustBe3mod4) { z |= 3; diff --git a/include/mcl/op.hpp b/include/mcl/op.hpp index e336729..5abc44b 100644 --- a/include/mcl/op.hpp +++ b/include/mcl/op.hpp @@ -8,8 +8,8 @@ */ #include <mcl/gmp_util.hpp> -#ifndef MCL_MAX_OP_BIT_N - #define MCL_MAX_OP_BIT_N 521 +#ifndef MCL_MAX_OP_BIT_SIZE + #define MCL_MAX_OP_BIT_SIZE 521 #endif namespace mcl { namespace fp { @@ -19,9 +19,9 @@ typedef uint32_t Unit; #else typedef uint64_t Unit; #endif -const size_t UnitBitN = sizeof(Unit) * 8; +const size_t UnitBitSize = sizeof(Unit) * 8; -const size_t maxOpUnitN = (MCL_MAX_OP_BIT_N + UnitBitN - 1) / UnitBitN; +const size_t maxOpUnitSize = (MCL_MAX_OP_BIT_SIZE + UnitBitSize - 1) / UnitBitSize; struct FpGenerator; struct Op; @@ -36,24 +36,24 @@ typedef int (*int2u)(Unit*, const Unit*); struct Block { const Unit *p; // pointer to original FpT.v_ size_t n; - Unit v_[maxOpUnitN]; + Unit v_[maxOpUnitSize]; }; struct Op { mpz_class mp; mcl::SquareRoot sq; - Unit p[maxOpUnitN]; + Unit p[maxOpUnitSize]; /* for Montgomery one = 1 R = (1 << (N * sizeof(Unit) * 8)) % p RR = (R * R) % p */ - Unit one[maxOpUnitN]; - Unit RR[maxOpUnitN]; + Unit one[maxOpUnitSize]; + Unit RR[maxOpUnitSize]; std::vector<Unit> invTbl; size_t N; - size_t bitLen; + size_t bitSize; // independent from p bool (*isZero)(const Unit*); void1u clear; @@ -75,7 +75,7 @@ struct Op { void3u modP; FpGenerator *fg; Op() - : N(0), bitLen(0) + : N(0), bitSize(0) , isZero(0), clear(0), copy(0) , neg(0), add(0), sub(0), mul(0) , useMont(false), preInv(0) @@ -95,7 +95,7 @@ struct Op { { mul(y, x, RR); } - void init(const std::string& mstr, int base, size_t maxBitN); + void init(const std::string& mstr, int base, size_t maxBitSize); static FpGenerator* createFpGenerator(); static void destroyFpGenerator(FpGenerator *fg); private: diff --git a/include/mcl/util.hpp b/include/mcl/util.hpp index 81afbf4..bec9bf2 100644 --- a/include/mcl/util.hpp +++ b/include/mcl/util.hpp @@ -86,17 +86,17 @@ void toArray(T *y, size_t yn, const mpz_srcptr x) /* get random value less than in[] - n = (bitLen + sizeof(T) * 8) / (sizeof(T) * 8) + n = (bitSize + sizeof(T) * 8) / (sizeof(T) * 8) input in[0..n) output out[n..n) 0 <= out < in */ template<class RG, class T> -void getRandVal(T *out, RG& rg, const T *in, size_t bitLen) +void getRandVal(T *out, RG& rg, const T *in, size_t bitSize) { - const size_t TBitN = sizeof(T) * 8; - const size_t n = (bitLen + TBitN - 1) / TBitN; - const size_t rem = bitLen & (TBitN - 1); + const size_t TbitSize = sizeof(T) * 8; + const size_t n = (bitSize + TbitSize - 1) / TbitSize; + const size_t rem = bitSize & (TbitSize - 1); for (;;) { rg.read(out, n); if (rem > 0) out[n - 1] &= (T(1) << rem) - 1; diff --git a/include/mcl/window_method.hpp b/include/mcl/window_method.hpp index ad080b6..a55bb9f 100644 --- a/include/mcl/window_method.hpp +++ b/include/mcl/window_method.hpp @@ -10,57 +10,57 @@ namespace mcl { namespace fp { /* - get w-bit size from x[0, bitLen) + get w-bit size from x[0, bitSize) @param x [in] data - @param bitLen [in] data size - @param w [in] split size < UnitBitN + @param bitSize [in] data size + @param w [in] split size < UnitBitSize */ template<class T> struct ArrayIterator { static const size_t TBitN = sizeof(T) * 8; - ArrayIterator(const T *x, size_t bitLen, size_t w) + ArrayIterator(const T *x, size_t bitSize, size_t w) : x(x) - , bitLen(bitLen) + , bitSize(bitSize) , w(w) , pos(0) , mask((w == TBitN ? 0 : (T(1) << w)) - 1) { assert(w <= TBitN); } - bool hasNext() const { return bitLen > 0; } + bool hasNext() const { return bitSize > 0; } T getNext() { if (w == TBitN) { - bitLen -= w; + bitSize -= w; return *x++; } if (pos + w < TBitN) { T v = (*x >> pos) & mask; pos += w; - if (bitLen < w) { - bitLen = 0; + if (bitSize < w) { + bitSize = 0; } else { - bitLen -= w; + bitSize -= w; } return v; } - if (pos + bitLen <= TBitN) { - assert(bitLen <= w); + if (pos + bitSize <= TBitN) { + assert(bitSize <= w); T v = *x >> pos; - assert((v >> bitLen) == 0); - bitLen = 0; + assert((v >> bitSize) == 0); + bitSize = 0; return v & mask; } assert(pos > 0); T v = (x[0] >> pos) | (x[1] << (TBitN - pos)); v &= mask; pos = (pos + w) - TBitN; - bitLen -= w; + bitSize -= w; x++; return v; } const T *x; - size_t bitLen; + size_t bitSize; size_t w; size_t pos; T mask; @@ -70,28 +70,28 @@ template<class Ec> class WindowMethod { public: typedef std::vector<Ec> EcV; - size_t bitLen_; + size_t bitSize_; size_t winSize_; std::vector<EcV> tbl_; - WindowMethod(const Ec& x, size_t bitLen, size_t winSize) + WindowMethod(const Ec& x, size_t bitSize, size_t winSize) { - init(x, bitLen, winSize); + init(x, bitSize, winSize); } WindowMethod() - : bitLen_(0) + : bitSize_(0) , winSize_(0) { } /* @param x [in] base index - @param bitLen [in] exponent bit length + @param bitSize [in] exponent bit length @param winSize [in] window size */ - void init(const Ec& x, size_t bitLen, size_t winSize) + void init(const Ec& x, size_t bitSize, size_t winSize) { - bitLen_ = bitLen; + bitSize_ = bitSize; winSize_ = winSize; - const size_t tblNum = (bitLen + winSize - 1) / winSize; + const size_t tblNum = (bitSize + winSize - 1) / winSize; const size_t r = size_t(1) << winSize; tbl_.resize(tblNum); Ec t(x); @@ -110,12 +110,12 @@ public: @param z [out] x multiplied by y @param y [in] exponent */ - template<class tag2, size_t maxBitN2> - void power(Ec& z, const FpT<tag2, maxBitN2>& y) const + template<class tag2, size_t maxBitSize2> + void power(Ec& z, const FpT<tag2, maxBitSize2>& y) const { fp::Block b; y.getBlock(b); - powerArray(z, b.p, b.n * UnitBitN, false); + powerArray(z, b.p, b.n * UnitBitSize, false); } void power(Ec& z, int y) const { @@ -128,15 +128,15 @@ public: } void power(Ec& z, const mpz_class& y) const { - powerArray(z, Gmp::getUnit(y), abs(y.get_mpz_t()->_mp_size) * UnitBitN, y < 0); + powerArray(z, Gmp::getUnit(y), abs(y.get_mpz_t()->_mp_size) * UnitBitSize, y < 0); } - void powerArray(Ec& z, const Unit* y, size_t bitLen, bool isNegative) const + void powerArray(Ec& z, const Unit* y, size_t bitSize, bool isNegative) const { - if ((bitLen + winSize_ - 1) / winSize_ > tbl_.size()) throw cybozu::Exception("mcl:WindowMethod:powerArray:bad value") << bitLen << bitLen_ << winSize_; + if ((bitSize + winSize_ - 1) / winSize_ > tbl_.size()) throw cybozu::Exception("mcl:WindowMethod:powerArray:bad value") << bitSize << bitSize_ << winSize_; z.clear(); - if (bitLen == 0) return; + if (bitSize == 0) return; size_t i = 0; - ArrayIterator<Unit> ai(y, bitLen, winSize_); + ArrayIterator<Unit> ai(y, bitSize, winSize_); do { Unit v = ai.getNext(); if (v) { @@ -65,9 +65,9 @@ void strToGmp(mpz_class& x, bool *isMinus, const std::string& str, int base) } -template<size_t bitN> +template<size_t bitSize> struct OpeFunc { - static const size_t N = (bitN + UnitBitN - 1) / UnitBitN; + static const size_t N = (bitSize + UnitBitSize - 1) / UnitBitSize; static inline void set_mpz_t(mpz_t& z, const Unit* p, int n = (int)N) { z->_mp_alloc = n; @@ -173,7 +173,7 @@ struct OpeFunc { #endif #define SET_OP(n) \ - N = n / UnitBitN; \ + N = n / UnitBitSize; \ isZero = OpeFunc<n>::isZeroC; \ clear = OpeFunc<n>::clearC; \ copy = OpeFunc<n>::copyC; \ @@ -188,7 +188,7 @@ struct OpeFunc { #ifdef USE_MONT_FP inline void invOpForMont(Unit *y, const Unit *x, const Op& op) { - Unit r[maxOpUnitN]; + Unit r[maxOpUnitSize]; int k = op.preInv(r, x); /* xr = 2^k @@ -203,11 +203,11 @@ static void fromRawGmp(Unit *y, size_t n, const mpz_class& x) } static void initInvTbl(Op& op, size_t N) { - assert(N <= maxOpUnitN); + assert(N <= maxOpUnitSize); const size_t invTblN = N * sizeof(Unit) * 8 * 2; op.invTbl.resize(invTblN * N); Unit *tbl = op.invTbl.data() + (invTblN - 1) * N; - Unit t[maxOpUnitN] = {}; + Unit t[maxOpUnitSize] = {}; t[0] = 2; op.toMont(tbl, t); for (size_t i = 0; i < invTblN - 1; i++) { @@ -218,7 +218,7 @@ static void initInvTbl(Op& op, size_t N) static void initForMont(Op& op, const Unit *p) { - size_t N = (op.bitLen + sizeof(Unit) * 8 - 1) / (sizeof(Unit) * 8); + size_t N = (op.bitSize + sizeof(Unit) * 8 - 1) / (sizeof(Unit) * 8); if (N < 2) N = 2; mpz_class t = 1; fromRawGmp(op.one, N, t); @@ -242,45 +242,45 @@ static void initForMont(Op& op, const Unit *p) #endif -void Op::init(const std::string& mstr, int base, size_t maxBitN) +void Op::init(const std::string& mstr, int base, size_t maxBitSize) { - static const size_t maxN = (maxBitN + UnitBitN - 1) / UnitBitN; + static const size_t maxN = (maxBitSize + UnitBitSize - 1) / UnitBitSize; bool isMinus; strToGmp(mp, &isMinus, mstr, base); if (isMinus) throw cybozu::Exception("Op:init:mstr is minus") << mstr; - bitLen = Gmp::getBitLen(mp); - if (bitLen > maxBitN) throw cybozu::Exception("Op:init:too large bitLen") << mstr << bitLen << maxBitN; + bitSize = Gmp::getBitLen(mp); + if (bitSize > maxBitSize) throw cybozu::Exception("Op:init:too large bitSize") << mstr << bitSize << maxBitSize; const size_t n = Gmp::getArray(p, maxN, mp); if (n == 0) throw cybozu::Exception("Op:init:bad mstr") << mstr; - if (bitLen <= 128) { + if (bitSize <= 128) { SET_OP(128) } else #if CYBOZU_OS_BIT == 32 - if (bitLen <= 160) { + if (bitSize <= 160) { SET_OP(160) } else #endif - if (bitLen <= 192) { + if (bitSize <= 192) { SET_OP(192) } else #if CYBOZU_OS_BIT == 32 - if (bitLen <= 224) { + if (bitSize <= 224) { SET_OP(224) } else #endif - if (bitLen <= 256) { + if (bitSize <= 256) { SET_OP(256) } else - if (bitLen <= 384) { + if (bitSize <= 384) { SET_OP(384) } else #if CYBOZU_OS_BIT == 64 - if (bitLen <= 576) { + if (bitSize <= 576) { SET_OP(576) } #else - if (bitLen <= 544) { + if (bitSize <= 544) { SET_OP(544) } #endif diff --git a/test/base_test.cpp b/test/base_test.cpp index 8924b71..6f23dcc 100644 --- a/test/base_test.cpp +++ b/test/base_test.cpp @@ -18,9 +18,9 @@ const size_t MAX_N = 32; typedef mcl::fp::Unit Unit; -size_t getUnitSize(size_t bitLen) +size_t getUnitSize(size_t bitSize) { - return (bitLen + sizeof(Unit) * 8 - 1) / (sizeof(Unit) * 8); + return (bitSize + sizeof(Unit) * 8 - 1) / (sizeof(Unit) * 8); } void setMpz(mpz_class& mx, const Unit *x, size_t n) @@ -199,7 +199,7 @@ typedef mcl::fp::void4op void4op; typedef mcl::fp::void4Iop void4Iop; const struct FuncOp { - size_t bitLen; + size_t bitSize; void4op addS; void4op addL; void4op subS; @@ -227,7 +227,7 @@ const struct FuncOp { #endif }; -FuncOp getFuncOp(size_t bitLen) +FuncOp getFuncOp(size_t bitSize) { typedef std::map<size_t, FuncOp> Map; static Map map; @@ -235,28 +235,28 @@ FuncOp getFuncOp(size_t bitLen) if (!init) { init = true; for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(gFuncOpTbl); i++) { - map[gFuncOpTbl[i].bitLen] = gFuncOpTbl[i]; + map[gFuncOpTbl[i].bitSize] = gFuncOpTbl[i]; } } for (Map::const_iterator i = map.begin(), ie = map.end(); i != ie; ++i) { - if (bitLen <= i->second.bitLen) { + if (bitSize <= i->second.bitSize) { return i->second; } } - printf("ERR bitLen=%d\n", (int)bitLen); + printf("ERR bitSize=%d\n", (int)bitSize); exit(1); } -void test(const Unit *p, size_t bitLen) +void test(const Unit *p, size_t bitSize) { - printf("bitLen %d\n", (int)bitLen); - const size_t n = getUnitSize(bitLen); + printf("bitSize %d\n", (int)bitSize); + const size_t n = getUnitSize(bitSize); #ifdef NDEBUG bool doBench = true; #else bool doBench = false; #endif - const FuncOp funcOp = getFuncOp(bitLen); + const FuncOp funcOp = getFuncOp(bitSize); const void4op addS = funcOp.addS; const void4op addL = funcOp.addL; const void4op subS = funcOp.subS; @@ -269,8 +269,8 @@ void test(const Unit *p, size_t bitLen) mcl::fp::Unit z2[MAX_N * 2]; mcl::fp::Unit w2[MAX_N * 2]; cybozu::XorShift rg; - mcl::fp::getRandVal(x, rg, p, bitLen); - mcl::fp::getRandVal(y, rg, p, bitLen); + mcl::fp::getRandVal(x, rg, p, bitSize); + mcl::fp::getRandVal(y, rg, p, bitSize); const size_t C = 10; addC(z, x, y, p, n); @@ -298,7 +298,7 @@ void test(const Unit *p, size_t bitLen) setMpz(mp, p, n); Montgomery m(mp); #ifdef USE_XBYAK - if (bitLen > 128) fg.init(p, n); + if (bitSize > 128) fg.init(p, n); #endif /* real mont @@ -323,7 +323,7 @@ void test(const Unit *p, size_t bitLen) mont(w, x, y, p, m.r_); VERIFY_EQUAL(z, w, n); #ifdef USE_XBYAK - if (bitLen > 128) { + if (bitSize > 128) { fg.mul_(w, x, y); VERIFY_EQUAL(z, w, n); } @@ -345,7 +345,7 @@ void test(const Unit *p, size_t bitLen) CYBOZU_BENCH("modC ", modC, x, w2, p, n); } #ifdef USE_XBYAK - if (bitLen <= 128) return; + if (bitSize <= 128) return; if (doBench) { fg.init(p, n); CYBOZU_BENCH("addA ", fg.add_, x, y, x); @@ -353,7 +353,7 @@ void test(const Unit *p, size_t bitLen) // CYBOZU_BENCH("mulA", fg.mul_, x, y, x); } #endif - printf("mont test %d\n", (int)bitLen); + printf("mont test %d\n", (int)bitSize); } CYBOZU_TEST_AUTO(all) @@ -385,8 +385,8 @@ CYBOZU_TEST_AUTO(all) }; for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { const size_t n = tbl[i].n; - const size_t bitLen = (n - 1) * 64 + cybozu::bsr<uint64_t>(tbl[i].p[n - 1]) + 1; - test((const Unit*)tbl[i].p, bitLen); + const size_t bitSize = (n - 1) * 64 + cybozu::bsr<uint64_t>(tbl[i].p[n - 1]) + 1; + test((const Unit*)tbl[i].p, bitSize); } } diff --git a/test/ec_test.cpp b/test/ec_test.cpp index db2b10a..43dd948 100644 --- a/test/ec_test.cpp +++ b/test/ec_test.cpp @@ -26,7 +26,7 @@ struct Test { Fp::setModulo(para.p); Zn::setModulo(para.n); Ec::setParam(para.a, para.b); -// CYBOZU_TEST_EQUAL(para.bitLen, Fp(-1).getBitLen()); +// CYBOZU_TEST_EQUAL(para.bitSize, Fp(-1).getBitLen()); } void cstr() const { diff --git a/test/elgamal_test.cpp b/test/elgamal_test.cpp index e90c048..758937f 100644 --- a/test/elgamal_test.cpp +++ b/test/elgamal_test.cpp @@ -191,13 +191,13 @@ CYBOZU_TEST_AUTO(testEc) Ec::setParam(para.a, para.b); const Fp x0(para.gx); const Fp y0(para.gy); - const size_t bitLen = Zn(-1).getBitLen(); + const size_t bitSize = Zn(-1).getBitLen(); const Ec P(x0, y0); /* Zn = <P> */ ElgamalEc::PrivateKey prv; - prv.init(P, bitLen, rg); + prv.init(P, bitSize, rg); const ElgamalEc::PublicKey& pub = prv.getPublicKey(); const int m1 = 12345; diff --git a/test/fp_util_test.cpp b/test/fp_util_test.cpp index d32587f..dfca4df 100644 --- a/test/fp_util_test.cpp +++ b/test/fp_util_test.cpp @@ -102,7 +102,7 @@ CYBOZU_TEST_AUTO(getRandVal) const struct { uint32_t r[rn]; uint32_t mod[2]; - size_t bitLen; + size_t bitSize; int count; uint32_t expect[2]; } tbl[] = { @@ -114,7 +114,7 @@ CYBOZU_TEST_AUTO(getRandVal) for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { Rand rg(tbl[i].r, rn); uint32_t out[2]; - mcl::fp::getRandVal(out, rg, tbl[i].mod, tbl[i].bitLen); + mcl::fp::getRandVal(out, rg, tbl[i].mod, tbl[i].bitSize); CYBOZU_TEST_EQUAL(out[0], tbl[i].expect[0]); CYBOZU_TEST_EQUAL(out[1], tbl[i].expect[1]); CYBOZU_TEST_EQUAL(rg.count, tbl[i].count); diff --git a/test/window_method_test.cpp b/test/window_method_test.cpp index 26d016a..fde6064 100644 --- a/test/window_method_test.cpp +++ b/test/window_method_test.cpp @@ -7,13 +7,13 @@ CYBOZU_TEST_AUTO(ArrayIterator) { const uint32_t in[2] = { 0x12345678, 0xabcdef89 }; - const size_t bitLen = 64; + 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<uint32_t> ai(in, bitLen, w); - size_t n = (bitLen + w - 1) / w; + mcl::fp::ArrayIterator<uint32_t> 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(); @@ -36,18 +36,18 @@ CYBOZU_TEST_AUTO(int) const Ec P(x, y); typedef mcl::fp::WindowMethod<Ec> PW; - const size_t bitLen = 16; + const size_t bitSize = 16; Ec Q, R; - for (size_t winSize = 2; winSize <= bitLen; winSize += 3) { - PW pw(P, bitLen, winSize); - for (int i = 0; i < (1 << bitLen); i++) { + for (size_t winSize = 2; winSize <= bitSize; winSize += 3) { + PW pw(P, bitSize, winSize); + for (int i = 0; i < (1 << bitSize); i++) { pw.power(Q, i); Ec::power(R, P, i); CYBOZU_TEST_EQUAL(Q, R); } } - PW pw(P, para.bitLen, 10); + PW pw(P, para.bitSize, 10); pw.power(Q, -12345); Ec::power(R, P, -12345); CYBOZU_TEST_EQUAL(Q, R); |
