aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-04-28 14:33:55 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-04-28 14:33:55 +0800
commitfdba8219522b3c1f0c74761c46f9cf0eded65122 (patch)
treef54893065e32aa254d56f4c572abd11e5902e40c /include
parentce5f10297e943efec0d6c32757569af35b159947 (diff)
downloadtangerine-mcl-fdba8219522b3c1f0c74761c46f9cf0eded65122.tar.gz
tangerine-mcl-fdba8219522b3c1f0c74761c46f9cf0eded65122.tar.zst
tangerine-mcl-fdba8219522b3c1f0c74761c46f9cf0eded65122.zip
change compressedExpression_ to ioMode_
Diffstat (limited to 'include')
-rw-r--r--include/mcl/ec.hpp40
-rw-r--r--include/mcl/fp.hpp1
-rw-r--r--include/mcl/op.hpp14
3 files changed, 34 insertions, 21 deletions
diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp
index 3788b5b..ab4d2bc 100644
--- a/include/mcl/ec.hpp
+++ b/include/mcl/ec.hpp
@@ -54,7 +54,7 @@ public:
static Fp a_;
static Fp b_;
static int specialA_;
- static bool compressedExpression_;
+ static int ioMode_;
/*
order_ is the order of G2 which is the subgroup of EcT<Fp2>.
check the order of the elements if verifyOrder_ is true
@@ -648,21 +648,13 @@ public:
return !b_.isZero() && (Fp::getBitSize() & 7) != 0;
}
/*
- "0" ; infinity
- "1 <x> <y>" ; not compressed
- "2 <x>" ; compressed for even y
- "3 <x>" ; compressed for odd y
-
- tight repl of EC over a prime
- the size of str must be equal to Fp::getByteSize()
- [0] ; infinity
- <x> ; for even y
- <x>|1 ; for odd y ; |1 means set MSB of x
+ see mcl/op.hpp for the format of ioMode
*/
void getStr(std::string& str, int ioMode = 0) const
{
- EcT P(*this); P.normalize();
- if (ioMode & IoTight) {
+ EcT P(*this);
+ P.normalize();
+ if (ioMode & IoEcComp) {
if (!isIoEcCompSupported()) throw cybozu::Exception("EcT:getStr:not supported ioMode") << ioMode;
const size_t n = Fp::getByteSize();
if (isZero()) {
@@ -681,7 +673,7 @@ public:
return;
}
const char *sep = Fp::BaseFp::getIoSeparator();
- if (compressedExpression_) {
+ if (ioMode & IoEcCompY) {
str = P.y.isOdd() ? '3' : '2';
str += sep;
str += P.x.getStr(ioMode);
@@ -702,6 +694,7 @@ public:
friend inline std::ostream& operator<<(std::ostream& os, const EcT& self)
{
int ioMode = fp::detectIoMode(Fp::BaseFp::getIoMode(), os);
+ ioMode |= ioMode_;
return os << self.getStr(ioMode);
}
void readStream(std::istream& is, int ioMode)
@@ -760,9 +753,22 @@ public:
std::istringstream is(str);
readStream(is, ioMode);
}
- static inline void setCompressedExpression(bool compressedExpression = true)
+ // deplicated
+ static void setCompressedExpression(bool compressedExpression = true)
+ {
+ if (compressedExpression) {
+ ioMode_ |= IoEcCompY;
+ } else {
+ ioMode_ &= ~IoEcCompY;
+ }
+ }
+ /*
+ set IoMode for operator<<(), or operator>>()
+ */
+ static void setIoMode(int ioMode)
{
- compressedExpression_ = compressedExpression;
+ if (ioMode & 0xff) throw cybozu::Exception("EcT:setIoMode:use Fp::setIomode") << ioMode;
+ ioMode_ = ioMode;
}
static inline void getWeierstrass(Fp& yy, const Fp& x)
{
@@ -833,7 +839,7 @@ public:
template<class Fp> Fp EcT<Fp>::a_;
template<class Fp> Fp EcT<Fp>::b_;
template<class Fp> int EcT<Fp>::specialA_;
-template<class Fp> bool EcT<Fp>::compressedExpression_;
+template<class Fp> int EcT<Fp>::ioMode_;
template<class Fp> bool EcT<Fp>::verifyOrder_;
template<class Fp> mpz_class EcT<Fp>::order_;
template<class Fp> void (*EcT<Fp>::mulArrayGLV)(EcT& z, const EcT& x, const fp::Unit *y, size_t yn, bool isNegative, bool constTime);
diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp
index f50b74d..b1706a4 100644
--- a/include/mcl/fp.hpp
+++ b/include/mcl/fp.hpp
@@ -410,6 +410,7 @@ public:
*/
static inline void setIoMode(IoMode ioMode)
{
+ if (ioMode_ & ~0xff) throw cybozu::Exception("FpT:setIoMode:bad mode") << ioMode;
ioMode_ = ioMode;
}
static inline IoMode getIoMode() { return ioMode_; }
diff --git a/include/mcl/op.hpp b/include/mcl/op.hpp
index 7b2ec14..de64b75 100644
--- a/include/mcl/op.hpp
+++ b/include/mcl/op.hpp
@@ -18,8 +18,8 @@
namespace mcl {
/*
- specifies available string format mode.
- // for Fp
+ specifies available string format mode for X::setIoMode()
+ // for Fp, Fp2, Fp6, Fp12
default(0) : IoDec
printable string(zero terminated, variable size)
IoBin(2) | IoDec(10) | IoHex(16) | IoBinPrefix | IoHexPrefix
@@ -51,15 +51,19 @@ namespace mcl {
IoArrayRaw
array of Unit(fixed size = Fp::getByteSize()) without Montgomery convresion
- // for Ec
- // affine coordinate(default)
+ // for Ec::setIoMode()
+ IoEcAffine(default)
"0" ; infinity
"1 <x> <y>" ; affine coordinate
+ IoEcProj
+ "4" <x> <y> <z> ; projective or jacobi coordinate
+
IoEcCompY
1-bit y prepresentation of elliptic curve
"2 <x>" ; compressed for even y
"3 <x>" ; compressed for odd y
+
IoComp(fixed size = Fp::getByteSize())
use MSB of array of x for 1-bit y for prime p where (p % 8 != 0)
[0] ; infinity
@@ -76,8 +80,10 @@ enum IoMode {
IoHexPrefix = IoHex | IoPrefix,
IoArray = 32, // array of Unit(fixed size)
IoArrayRaw = 64, // raw array of Unit without Montgomery conversion
+ IoEcAffine = 0, // affine coordinate
IoEcCompY = 128, // 1-bit y representation of elliptic curve
IoEcComp = 256, // use MBS for 1-bit y
+ IoEcProj = 512, // projective or jacobi coordinate
IoTight = IoEcComp // tight repr of Ec(obsolete)
};