rename IoEcComp to IoFixedSizeByteSeq

dev
MITSUNARI Shigeo 8 years ago
parent a27f9ea729
commit 49ebc4119e
  1. 10
      include/mcl/ec.hpp
  2. 2
      include/mcl/fp.hpp
  3. 12
      include/mcl/op.hpp
  4. 2
      src/fp.cpp
  5. 2
      test/bn_test.cpp
  6. 16
      test/ec_test.cpp

@ -645,7 +645,7 @@ public:
return z.isZero(); return z.isZero();
#endif #endif
} }
static inline bool isIoEcCompSupported() static inline bool isFixedSizeByteSeq()
{ {
return !b_.isZero() && (Fp::BaseFp::getBitSize() & 7) != 0; return !b_.isZero() && (Fp::BaseFp::getBitSize() & 7) != 0;
} }
@ -667,8 +667,8 @@ public:
} }
EcT P(*this); EcT P(*this);
P.normalize(); P.normalize();
if (ioMode & IoEcComp) { if (ioMode & IoFixedSizeByteSeq) {
if (!isIoEcCompSupported()) throw cybozu::Exception("EcT:getStr:not supported ioMode") << ioMode; if (!isFixedSizeByteSeq()) throw cybozu::Exception("EcT:getStr:not supported ioMode") << ioMode;
const size_t n = Fp::getByteSize(); const size_t n = Fp::getByteSize();
if (isZero()) { if (isZero()) {
str.clear(); str.clear();
@ -717,8 +717,8 @@ public:
#else #else
z = 1; z = 1;
#endif #endif
if (ioMode & IoEcComp) { if (ioMode & IoFixedSizeByteSeq) {
if (!isIoEcCompSupported()) throw cybozu::Exception("EcT:readStream:not supported ioMode") << ioMode; if (!isFixedSizeByteSeq()) throw cybozu::Exception("EcT:readStream:not supported ioMode") << ioMode;
std::string str; std::string str;
const size_t n = Fp::getByteSize(); const size_t n = Fp::getByteSize();
str.resize(n); str.resize(n);

@ -273,7 +273,7 @@ public:
getBlock(b); getBlock(b);
p = b.p; p = b.p;
} }
if (ioMode & (IoArray | IoArrayRaw | IoEcComp)) { if (ioMode & (IoArray | IoArrayRaw | IoFixedSizeByteSeq)) {
str.resize(n); str.resize(n);
fp::copyUnitToByteAsLE(reinterpret_cast<uint8_t*>(&str[0]), p, str.size()); fp::copyUnitToByteAsLE(reinterpret_cast<uint8_t*>(&str[0]), p, str.size());
return; return;

@ -26,13 +26,14 @@ namespace mcl {
byte string(not zero terminated, fixed size) byte string(not zero terminated, fixed size)
IoArray | IoArrayRaw IoArray | IoArrayRaw
IoArray = IoFixedSizeByteSeq
// for Ec // for Ec
affine(0) | IoEcCompY | IoComp affine(0) | IoEcCompY | IoComp
default : affine default : affine
affine and IoEcCompY are available with ioMode for Fp affine and IoEcCompY are available with ioMode for Fp
IoEcComp ignores ioMode for Fp IoFixedSizeByteSeq ignores ioMode for Fp
IoAuto IoAuto
dec or hex according to ios_base::fmtflags dec or hex according to ios_base::fmtflags
@ -64,7 +65,7 @@ namespace mcl {
"2 <x>" ; compressed for even y "2 <x>" ; compressed for even y
"3 <x>" ; compressed for odd y "3 <x>" ; compressed for odd y
IoComp(fixed size = Fp::getByteSize()) IoFixedSizeByteSeq(fixed size = Fp::getByteSize())
use MSB of array of x for 1-bit y for prime p where (p % 8 != 0) use MSB of array of x for 1-bit y for prime p where (p % 8 != 0)
[0] ; infinity [0] ; infinity
<x> ; for even y <x> ; for even y
@ -82,9 +83,8 @@ enum IoMode {
IoHexPrefix = IoHex | IoPrefix, IoHexPrefix = IoHex | IoPrefix,
IoEcAffine = 0, // affine coordinate IoEcAffine = 0, // affine coordinate
IoEcCompY = 256, // 1-bit y representation of elliptic curve IoEcCompY = 256, // 1-bit y representation of elliptic curve
IoEcComp = 512, // use MBS for 1-bit y IoFixedSizeByteSeq = 512, // use MBS for 1-bit y
IoEcProj = 1024, // projective or jacobi coordinate IoEcProj = 1024 // projective or jacobi coordinate
IoTight = IoEcComp // tight repr of Ec(obsolete)
}; };
namespace fp { namespace fp {
@ -306,7 +306,7 @@ void arrayToStr(std::string& str, const Unit *x, size_t n, int ioMode);
inline const char* getIoSeparator(int ioMode) inline const char* getIoSeparator(int ioMode)
{ {
return (ioMode & (IoArray | IoArrayRaw | IoEcComp)) ? "" : " "; return (ioMode & (IoArray | IoArrayRaw | IoFixedSizeByteSeq)) ? "" : " ";
} }
int detectIoMode(int ioMode, const std::ios_base& ios); int detectIoMode(int ioMode, const std::ios_base& ios);

@ -539,7 +539,7 @@ int detectIoMode(int ioMode, const std::ios_base& ios)
void streamToArray(bool *pIsMinus, Unit *x, size_t byteSize, std::istream& is, int ioMode) void streamToArray(bool *pIsMinus, Unit *x, size_t byteSize, std::istream& is, int ioMode)
{ {
std::string str; std::string str;
if (ioMode & (IoArray | IoArrayRaw | IoEcComp)) { if (ioMode & (IoArray | IoArrayRaw | IoFixedSizeByteSeq)) {
str.resize(byteSize); str.resize(byteSize);
is.read(&str[0], byteSize); is.read(&str[0], byteSize);
*pIsMinus = false; *pIsMinus = false;

@ -277,7 +277,7 @@ void testTrivial(const G1& P, const G2& Q)
void testIoAll(const G1& P, const G2& Q) void testIoAll(const G1& P, const G2& Q)
{ {
int FpTbl[] = { 0, 2, 2|mcl::IoPrefix, 10, 16, 16|mcl::IoPrefix, mcl::IoArray, mcl::IoArrayRaw }; int FpTbl[] = { 0, 2, 2|mcl::IoPrefix, 10, 16, 16|mcl::IoPrefix, mcl::IoArray, mcl::IoArrayRaw };
int EcTbl[] = { mcl::IoEcAffine, mcl::IoEcProj, mcl::IoEcCompY, mcl::IoEcComp }; int EcTbl[] = { mcl::IoEcAffine, mcl::IoEcProj, mcl::IoEcCompY, mcl::IoFixedSizeByteSeq };
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(FpTbl); i++) { for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(FpTbl); i++) {
for (size_t j = 0; j < CYBOZU_NUM_OF_ARRAY(EcTbl); j++) { for (size_t j = 0; j < CYBOZU_NUM_OF_ARRAY(EcTbl); j++) {
G1 P2 = P, P3; G1 P2 = P, P3;

@ -280,28 +280,28 @@ struct Test {
ss >> Q; ss >> Q;
CYBOZU_TEST_EQUAL(P, Q); CYBOZU_TEST_EQUAL(P, Q);
} }
// IoEcComp // IoFixedSizeByteSeq
if (!Ec::isIoEcCompSupported()) return; if (!Ec::isFixedSizeByteSeq()) return;
P.set(x, y); P.set(x, y);
{ {
std::string s = P.getStr(mcl::IoEcComp); std::string s = P.getStr(mcl::IoFixedSizeByteSeq);
CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize()); CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize());
Q.setStr(s, mcl::IoEcComp); Q.setStr(s, mcl::IoFixedSizeByteSeq);
CYBOZU_TEST_EQUAL(P, Q); CYBOZU_TEST_EQUAL(P, Q);
} }
{ {
P = -P; P = -P;
std::string s = P.getStr(mcl::IoEcComp); std::string s = P.getStr(mcl::IoFixedSizeByteSeq);
CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize()); CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize());
Q.setStr(s, mcl::IoEcComp); Q.setStr(s, mcl::IoFixedSizeByteSeq);
CYBOZU_TEST_EQUAL(P, Q); CYBOZU_TEST_EQUAL(P, Q);
} }
P.clear(); P.clear();
{ {
std::string s = P.getStr(mcl::IoEcComp); std::string s = P.getStr(mcl::IoFixedSizeByteSeq);
CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize()); CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize());
CYBOZU_TEST_ASSERT(mcl::fp::isZeroArray(s.c_str(), s.size())); CYBOZU_TEST_ASSERT(mcl::fp::isZeroArray(s.c_str(), s.size()));
Q.setStr(s, mcl::IoEcComp); Q.setStr(s, mcl::IoFixedSizeByteSeq);
CYBOZU_TEST_EQUAL(P, Q); CYBOZU_TEST_EQUAL(P, Q);
} }
} }

Loading…
Cancel
Save