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

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

@ -26,13 +26,14 @@ namespace mcl {
byte string(not zero terminated, fixed size)
IoArray | IoArrayRaw
IoArray = IoFixedSizeByteSeq
// for Ec
affine(0) | IoEcCompY | IoComp
default : affine
affine and IoEcCompY are available with ioMode for Fp
IoEcComp ignores ioMode for Fp
IoFixedSizeByteSeq ignores ioMode for Fp
IoAuto
dec or hex according to ios_base::fmtflags
@ -64,7 +65,7 @@ namespace mcl {
"2 <x>" ; compressed for even 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)
[0] ; infinity
<x> ; for even y
@ -82,9 +83,8 @@ enum IoMode {
IoHexPrefix = IoHex | IoPrefix,
IoEcAffine = 0, // affine coordinate
IoEcCompY = 256, // 1-bit y representation of elliptic curve
IoEcComp = 512, // use MBS for 1-bit y
IoEcProj = 1024, // projective or jacobi coordinate
IoTight = IoEcComp // tight repr of Ec(obsolete)
IoFixedSizeByteSeq = 512, // use MBS for 1-bit y
IoEcProj = 1024 // projective or jacobi coordinate
};
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)
{
return (ioMode & (IoArray | IoArrayRaw | IoEcComp)) ? "" : " ";
return (ioMode & (IoArray | IoArrayRaw | IoFixedSizeByteSeq)) ? "" : " ";
}
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)
{
std::string str;
if (ioMode & (IoArray | IoArrayRaw | IoEcComp)) {
if (ioMode & (IoArray | IoArrayRaw | IoFixedSizeByteSeq)) {
str.resize(byteSize);
is.read(&str[0], byteSize);
*pIsMinus = false;

@ -277,7 +277,7 @@ void testTrivial(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 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 j = 0; j < CYBOZU_NUM_OF_ARRAY(EcTbl); j++) {
G1 P2 = P, P3;

@ -280,28 +280,28 @@ struct Test {
ss >> Q;
CYBOZU_TEST_EQUAL(P, Q);
}
// IoEcComp
if (!Ec::isIoEcCompSupported()) return;
// IoFixedSizeByteSeq
if (!Ec::isFixedSizeByteSeq()) return;
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());
Q.setStr(s, mcl::IoEcComp);
Q.setStr(s, mcl::IoFixedSizeByteSeq);
CYBOZU_TEST_EQUAL(P, Q);
}
{
P = -P;
std::string s = P.getStr(mcl::IoEcComp);
std::string s = P.getStr(mcl::IoFixedSizeByteSeq);
CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize());
Q.setStr(s, mcl::IoEcComp);
Q.setStr(s, mcl::IoFixedSizeByteSeq);
CYBOZU_TEST_EQUAL(P, Q);
}
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_ASSERT(mcl::fp::isZeroArray(s.c_str(), s.size()));
Q.setStr(s, mcl::IoEcComp);
Q.setStr(s, mcl::IoFixedSizeByteSeq);
CYBOZU_TEST_EQUAL(P, Q);
}
}

Loading…
Cancel
Save