diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-11-22 04:50:16 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-11-22 04:50:16 +0800 |
commit | db9488e0613a2013ad7235722884198c57785f26 (patch) | |
tree | 7026d6239004b76c748b4b23bc811500d5861086 | |
parent | c6080baafd7244aa30164dd632614bab1659b254 (diff) | |
download | tangerine-mcl-db9488e0613a2013ad7235722884198c57785f26.tar.gz tangerine-mcl-db9488e0613a2013ad7235722884198c57785f26.tar.zst tangerine-mcl-db9488e0613a2013ad7235722884198c57785f26.zip |
[she] rename CipherTextM to CipherTextGT
-rw-r--r-- | include/mcl/she.hpp | 88 | ||||
-rw-r--r-- | sample/she_smpl.cpp | 6 | ||||
-rw-r--r-- | src/she_c_impl.hpp | 2 | ||||
-rw-r--r-- | test/she_test.cpp | 74 |
4 files changed, 85 insertions, 85 deletions
diff --git a/include/mcl/she.hpp b/include/mcl/she.hpp index 0eb751d..a98e56f 100644 --- a/include/mcl/she.hpp +++ b/include/mcl/she.hpp @@ -333,8 +333,8 @@ struct SHET { class PrecomputedPublicKey; // additive HE class CipherTextA; // = CipherTextG1 + CipherTextG2 - class CipherTextM; // multiplicative HE - class CipherText; // CipherTextA + CipherTextM + class CipherTextGT; // multiplicative HE + class CipherText; // CipherTextA + CipherTextGT static G1 P_; static G2 Q_; @@ -353,7 +353,7 @@ private: friend class PublicKey; friend class PrecomputedPublicKey; friend class CipherTextA; - friend class CipherTextM; + friend class CipherTextGT; public: void clear() { @@ -562,7 +562,7 @@ public: { return dec(c.c1_); } - int64_t dec(const CipherTextM& c) const + int64_t dec(const CipherTextGT& c) const { /* (s, t, u, v) := (e(S, S'), e(S, T'), e(T, S'), e(T, T')) @@ -673,7 +673,7 @@ public: enc(c.c2_, m, rg); } template<class RG> - void enc(CipherTextM& c, int64_t m, RG& rg) const + void enc(CipherTextGT& c, int64_t m, RG& rg) const { /* (s, t, u, v) = ((e^x)^a (e^y)^b (e^-xy)^c e^m, e^b, e^a, e^c) @@ -724,12 +724,12 @@ public: void enc(CipherTextG1& c, int64_t m) const { return enc(c, m, local::g_rg); } void enc(CipherTextG2& c, int64_t m) const { return enc(c, m, local::g_rg); } void enc(CipherTextA& c, int64_t m) const { return enc(c, m, local::g_rg); } - void enc(CipherTextM& c, int64_t m) const { return enc(c, m, local::g_rg); } + void enc(CipherTextGT& c, int64_t m) const { return enc(c, m, local::g_rg); } void enc(CipherText& c, int64_t m, bool multiplied = false) const { return enc(c, m, local::g_rg, multiplied); } /* - convert from CipherTextG1 to CipherTextM + convert from CipherTextG1 to CipherTextGT */ - void convertToCipherTextM(CipherTextM& cm, const CipherTextG1& c1) const + void convertToCipherTextGT(CipherTextGT& cm, const CipherTextG1& c1) const { /* Enc(1) = (S, T) = (Q + r yQ, rQ) = (Q, 0) if r = 0 @@ -745,9 +745,9 @@ public: cm.g_[3] = 1; } /* - convert from CipherTextG2 to CipherTextM + convert from CipherTextG2 to CipherTextGT */ - void convertToCipherTextM(CipherTextM& cm, const CipherTextG2& c2) const + void convertToCipherTextGT(CipherTextGT& cm, const CipherTextG2& c2) const { /* Enc(1) = (S, T) = (P + r xP, rP) = (P, 0) if r = 0 @@ -756,15 +756,15 @@ public: G1 zero; zero.clear(); tensorProduct(cm.g_, P_, zero, c2.S_, c2.T_); } - void convertToCipherTextM(CipherTextM& cm, const CipherTextA& ca) const + void convertToCipherTextGT(CipherTextGT& cm, const CipherTextA& ca) const { - convertToCipherTextM(cm, ca.c1_); + convertToCipherTextGT(cm, ca.c1_); } - void convertToCipherTextM(CipherText& cm, const CipherText& ca) const + void convertToCipherTextGT(CipherText& cm, const CipherText& ca) const { if (ca.isMultiplied()) throw cybozu::Exception("she:PublicKey:convertCipherText:already isMultiplied"); cm.isMultiplied_ = true; - convertToCipherTextM(cm.m_, ca.a_); + convertToCipherTextGT(cm.m_, ca.a_); } /* c += Enc(0) @@ -791,12 +791,12 @@ public: CipherTextA::add(c, c, c0); } template<class RG> - void reRand(CipherTextM& c, RG& rg) const + void reRand(CipherTextGT& c, RG& rg) const { #if 1 // for circuit security : 3.58Mclk -> 5.4Mclk - CipherTextM c0; + CipherTextGT c0; enc(c0, 0, rg); - CipherTextM::add(c, c, c0); + CipherTextGT::add(c, c, c0); #else /* add Enc(0) * Enc(0) @@ -828,7 +828,7 @@ public: void reRand(CipherTextG1& c) const { reRand(c, local::g_rg); } void reRand(CipherTextG2& c) const { reRand(c, local::g_rg); } void reRand(CipherTextA& c) const { reRand(c, local::g_rg); } - void reRand(CipherTextM& c) const { reRand(c, local::g_rg); } + void reRand(CipherTextGT& c) const { reRand(c, local::g_rg); } void reRand(CipherText& c) const { reRand(c, local::g_rg); } std::istream& readStream(std::istream& is, int ioMode) @@ -925,7 +925,7 @@ public: enc1(c.S_, c.T_, m, rg, QhashTbl_.getWM(), yQwm_); } template<class RG> - void enc(CipherTextM& c, int64_t m, RG& rg) const + void enc(CipherTextGT& c, int64_t m, RG& rg) const { /* (s, t, u, v) = (e^m e^(xya), (e^x)^b, (e^y)^c, e^(b + c - a)) @@ -952,13 +952,13 @@ public: } template<class RG> void reRand(CipherTextG1& c, RG& rg) const { reRandT(c, rg); } template<class RG> void reRand(CipherTextG2& c, RG& rg) const { reRandT(c, rg); } - template<class RG> void reRand(CipherTextM& c, RG& rg) const { reRandT(c, rg); } + template<class RG> void reRand(CipherTextGT& c, RG& rg) const { reRandT(c, rg); } void enc(CipherTextG1& c, int64_t m) const { return enc(c, m, local::g_rg); } void enc(CipherTextG2& c, int64_t m) const { return enc(c, m, local::g_rg); } - void enc(CipherTextM& c, int64_t m) const { return enc(c, m, local::g_rg); } + void enc(CipherTextGT& c, int64_t m) const { return enc(c, m, local::g_rg); } void reRand(CipherTextG1& c) const { reRand(c, local::g_rg); } void reRand(CipherTextG2& c) const { reRand(c, local::g_rg); } - void reRand(CipherTextM& c) const { reRand(c, local::g_rg); } + void reRand(CipherTextGT& c) const { reRand(c, local::g_rg); } }; class CipherTextA { @@ -966,7 +966,7 @@ public: CipherTextG2 c2_; friend class SecretKey; friend class PublicKey; - friend class CipherTextM; + friend class CipherTextGT; public: void clear() { @@ -1034,7 +1034,7 @@ public: bool operator!=(const CipherTextA& rhs) const { return !operator==(rhs); } }; - class CipherTextM { + class CipherTextGT { GT g_[4]; friend class SecretKey; friend class PublicKey; @@ -1047,7 +1047,7 @@ public: g_[i].setOne(); } } - static void add(CipherTextM& z, const CipherTextM& x, const CipherTextM& y) + static void add(CipherTextGT& z, const CipherTextGT& x, const CipherTextGT& y) { /* (g[i]) + (g'[i]) = (g[i] * g'[i]) @@ -1056,7 +1056,7 @@ public: GT::mul(z.g_[i], x.g_[i], y.g_[i]); } } - static void sub(CipherTextM& z, const CipherTextM& x, const CipherTextM& y) + static void sub(CipherTextGT& z, const CipherTextGT& x, const CipherTextGT& y) { /* (g[i]) - (g'[i]) = (g[i] / g'[i]) @@ -1067,25 +1067,25 @@ public: GT::mul(z.g_[i], x.g_[i], t); } } - static void mul(CipherTextM& z, const CipherTextG1& x, const CipherTextG2& y) + static void mul(CipherTextGT& z, const CipherTextG1& x, const CipherTextG2& y) { /* (S1, T1) * (S2, T2) = (e(S1, S2), e(S1, T2), e(T1, S2), e(T1, T2)) */ tensorProduct(z.g_, x.S_, x.T_, y.S_, y.T_); } - static void mul(CipherTextM& z, const CipherTextA& x, const CipherTextA& y) + static void mul(CipherTextGT& z, const CipherTextA& x, const CipherTextA& y) { mul(z, x.c1_, y.c2_); } - static void mul(CipherTextM& z, const CipherTextM& x, int64_t y) + static void mul(CipherTextGT& z, const CipherTextGT& x, int64_t y) { for (int i = 0; i < 4; i++) { GT::pow(z.g_[i], x.g_[i], y); } } - void add(const CipherTextM& c) { add(*this, *this, c); } - void sub(const CipherTextM& c) { sub(*this, *this, c); } + void add(const CipherTextGT& c) { add(*this, *this, c); } + void sub(const CipherTextGT& c) { sub(*this, *this, c); } std::istream& readStream(std::istream& is, int ioMode) { for (int i = 0; i < 4; i++) { @@ -1113,28 +1113,28 @@ public: getStr(str, ioMode); return str; } - friend std::istream& operator>>(std::istream& is, CipherTextM& self) + friend std::istream& operator>>(std::istream& is, CipherTextGT& self) { return self.readStream(is, fp::detectIoMode(G1::getIoMode(), is)); } - friend std::ostream& operator<<(std::ostream& os, const CipherTextM& self) + friend std::ostream& operator<<(std::ostream& os, const CipherTextGT& self) { return os << self.getStr(fp::detectIoMode(G1::getIoMode(), os)); } - bool operator==(const CipherTextM& rhs) const + bool operator==(const CipherTextGT& rhs) const { for (int i = 0; i < 4; i++) { if (g_[i] != rhs.g_[i]) return false; } return true; } - bool operator!=(const CipherTextM& rhs) const { return !operator==(rhs); } + bool operator!=(const CipherTextGT& rhs) const { return !operator==(rhs); } }; class CipherText { bool isMultiplied_; CipherTextA a_; - CipherTextM m_; + CipherTextGT m_; friend class SecretKey; friend class PublicKey; public: @@ -1154,7 +1154,7 @@ public: { if (x.isMultiplied() && y.isMultiplied()) { z.isMultiplied_ = true; - CipherTextM::add(z.m_, x.m_, y.m_); + CipherTextGT::add(z.m_, x.m_, y.m_); return; } if (!x.isMultiplied() && !y.isMultiplied()) { @@ -1168,7 +1168,7 @@ public: { if (x.isMultiplied() && y.isMultiplied()) { z.isMultiplied_ = true; - CipherTextM::sub(z.m_, x.m_, y.m_); + CipherTextGT::sub(z.m_, x.m_, y.m_); return; } if (!x.isMultiplied() && !y.isMultiplied()) { @@ -1184,12 +1184,12 @@ public: throw cybozu::Exception("she:CipherText:mul:mixed CipherText"); } z.isMultiplied_ = true; - CipherTextM::mul(z.m_, x.a_, y.a_); + CipherTextGT::mul(z.m_, x.a_, y.a_); } static void mul(CipherText& z, const CipherText& x, int64_t y) { if (x.isMultiplied()) { - CipherTextM::mul(z.m_, x.m_, y); + CipherTextGT::mul(z.m_, x.m_, y); } else { CipherTextA::mul(z.a_, x.a_, y); } @@ -1237,7 +1237,7 @@ public: { return os << self.getStr(fp::detectIoMode(G1::getIoMode(), os)); } - bool operator==(const CipherTextM& rhs) const + bool operator==(const CipherTextGT& rhs) const { if (isMultiplied() != rhs.isMultiplied()) return false; if (isMultiplied()) { @@ -1245,7 +1245,7 @@ public: } return a_ == rhs.a_; } - bool operator!=(const CipherTextM& rhs) const { return !operator==(rhs); } + bool operator!=(const CipherTextGT& rhs) const { return !operator==(rhs); } }; }; @@ -1262,9 +1262,9 @@ typedef SHE::PublicKey PublicKey; typedef SHE::PrecomputedPublicKey PrecomputedPublicKey; typedef SHE::CipherTextG1 CipherTextG1; typedef SHE::CipherTextG2 CipherTextG2; -typedef SHE::CipherTextM CipherTextM; +typedef SHE::CipherTextGT CipherTextGT; typedef SHE::CipherTextA CipherTextA; -typedef CipherTextM CipherTextGT; +typedef CipherTextGT CipherTextGM; // old class typedef SHE::CipherText CipherText; } } // mcl::she diff --git a/sample/she_smpl.cpp b/sample/she_smpl.cpp index cd5a4c1..ab60684 100644 --- a/sample/she_smpl.cpp +++ b/sample/she_smpl.cpp @@ -85,8 +85,8 @@ void usePrimitiveCipherText() pub.enc(d2, b2); c1.add(c2); // CipherTextG1 is additive HE d1.add(d2); // CipherTextG2 is additive HE - CipherTextM cm; // size of CipherTextM = N * 12 * 4 - CipherTextM::mul(cm, c1, d1); // cm = c1 * d1 + CipherTextGT cm; // size of CipherTextGT = N * 12 * 4 + CipherTextGT::mul(cm, c1, d1); // cm = c1 * d1 cm.add(cm); // 2cm int m = sec.dec(cm); int ok = (a1 + a2) * (b1 + b2) * 2; @@ -109,7 +109,7 @@ void usePrimitiveCipherText() s = cm.getStr(mcl::IoFixedSizeByteSeq); // serialize printf("cm data size %d byte\n", (int)s.size()); - CipherTextM cm2; + CipherTextGT cm2; cm2.setStr(s, mcl::IoFixedSizeByteSeq); printf("deserialize %s\n", cm == cm2 ? "ok" : "ng"); } diff --git a/src/she_c_impl.hpp b/src/she_c_impl.hpp index 5b17198..f7ea627 100644 --- a/src/she_c_impl.hpp +++ b/src/she_c_impl.hpp @@ -402,7 +402,7 @@ template<class CT> int convertTo(sheCipherTextGT *y, const shePublicKey *pub, const CT *x) try { - cast(pub)->convertToCipherTextM(*cast(y), *cast(x)); + cast(pub)->convertToCipherTextGT(*cast(y), *cast(x)); return 0; } catch (std::exception& e) { printf("err %s\n", e.what()); diff --git a/test/she_test.cpp b/test/she_test.cpp index c9cbbab..5de1a93 100644 --- a/test/she_test.cpp +++ b/test/she_test.cpp @@ -96,12 +96,12 @@ CYBOZU_TEST_AUTO(enc_dec) ppub.init(pub); CipherTextG1 c1; CipherTextG1 c2; - CipherTextM cm1, cm2; + CipherTextGT ct1, ct2; for (int i = -5; i < 5; i++) { - pub.enc(cm1, i); - CYBOZU_TEST_EQUAL(sec.dec(cm1), i); - ppub.enc(cm2, i); - CYBOZU_TEST_EQUAL(sec.dec(cm2), i); + pub.enc(ct1, i); + CYBOZU_TEST_EQUAL(sec.dec(ct1), i); + ppub.enc(ct2, i); + CYBOZU_TEST_EQUAL(sec.dec(ct2), i); ppub.enc(c1, i); CYBOZU_TEST_EQUAL(sec.dec(c1), i); ppub.enc(c2, i); @@ -163,7 +163,7 @@ CYBOZU_TEST_AUTO(add_mul_add_sub) CYBOZU_TEST_EQUAL(sec.dec(c[i]), m[i]); CYBOZU_TEST_ASSERT(!c[i].isMultiplied()); CipherText mc; - pub.convertToCipherTextM(mc, c[i]); + pub.convertToCipherTextGT(mc, c[i]); CYBOZU_TEST_ASSERT(mc.isMultiplied()); CYBOZU_TEST_EQUAL(sec.dec(mc), m[i]); } @@ -252,9 +252,9 @@ CYBOZU_TEST_AUTO(io) pub.enc(ca, -4); m = sec.dec(testIo(ca)); CYBOZU_TEST_EQUAL(m, -4); - CipherTextM cm; - CipherTextM::mul(cm, g1, g2); - m = sec.dec(testIo(cm)); + CipherTextGT ct; + CipherTextGT::mul(ct, g1, g2); + m = sec.dec(testIo(ct)); CYBOZU_TEST_EQUAL(m, 15); } } @@ -387,9 +387,9 @@ CYBOZU_TEST_AUTO(hashBench) CYBOZU_BENCH_C("finalExp", C, BN::finalExp, e, e); CYBOZU_BENCH_C("precomML", C, BN::precomputedMillerLoop, e, P, SHE::Qcoeff_); - CipherTextG1 ca1; - CipherTextG2 ca2; - CipherTextM cm; + CipherTextG1 c1; + CipherTextG2 c2; + CipherTextGT ct; int m = int(hashSize - 1); printf("small m = %d\n", m); @@ -401,30 +401,30 @@ CYBOZU_TEST_AUTO(hashBench) CYBOZU_BENCH_C("GTwindow", C, SHE::ePQhashTbl_.mulByWindowMethod, e, m); // CYBOZU_BENCH_C("GTwindow", C, wm.mul, static_cast<AG&>(e), m); - CYBOZU_BENCH_C("encG1 ", C, pub.enc, ca1, m); - CYBOZU_BENCH_C("encG2 ", C, pub.enc, ca2, m); - CYBOZU_BENCH_C("encGT ", C, pub.enc, cm, m); - CYBOZU_BENCH_C("encG1pre", C, ppub.enc, ca1, m); - CYBOZU_BENCH_C("encG2pre", C, ppub.enc, ca2, m); - CYBOZU_BENCH_C("encGTpre", C, ppub.enc, cm, m); - - CYBOZU_BENCH_C("decG1 ", C, sec.dec, ca1); - CYBOZU_BENCH_C("decG2 ", C, sec.dec, ca2); - CYBOZU_BENCH_C("degGT ", C, sec.dec, cm); - - CYBOZU_BENCH_C("mul ", C, CipherTextM::mul, cm, ca1, ca2); - - CYBOZU_BENCH_C("addG1 ", C, CipherTextG1::add, ca1, ca1, ca1); - CYBOZU_BENCH_C("addG2 ", C, CipherTextG2::add, ca2, ca2, ca2); - CYBOZU_BENCH_C("addGT ", C, CipherTextM::add, cm, cm, cm); - CYBOZU_BENCH_C("reRandG1", C, pub.reRand, ca1); - CYBOZU_BENCH_C("reRandG2", C, pub.reRand, ca2); - CYBOZU_BENCH_C("reRandGT", C, pub.reRand, cm); - CYBOZU_BENCH_C("reRandG1pre", C, ppub.reRand, ca1); - CYBOZU_BENCH_C("reRandG2pre", C, ppub.reRand, ca2); - CYBOZU_BENCH_C("reRandGTpre", C, ppub.reRand, cm); - CYBOZU_BENCH_C("mulG1 ", C, CipherTextG1::mul, ca1, ca1, m); - CYBOZU_BENCH_C("mulG2 ", C, CipherTextG2::mul, ca2, ca2, m); - CYBOZU_BENCH_C("mulGT ", C, CipherTextM::mul, cm, cm, m); + CYBOZU_BENCH_C("encG1 ", C, pub.enc, c1, m); + CYBOZU_BENCH_C("encG2 ", C, pub.enc, c2, m); + CYBOZU_BENCH_C("encGT ", C, pub.enc, ct, m); + CYBOZU_BENCH_C("encG1pre", C, ppub.enc, c1, m); + CYBOZU_BENCH_C("encG2pre", C, ppub.enc, c2, m); + CYBOZU_BENCH_C("encGTpre", C, ppub.enc, ct, m); + + CYBOZU_BENCH_C("decG1 ", C, sec.dec, c1); + CYBOZU_BENCH_C("decG2 ", C, sec.dec, c2); + CYBOZU_BENCH_C("degGT ", C, sec.dec, ct); + + CYBOZU_BENCH_C("mul ", C, CipherTextGT::mul, ct, c1, c2); + + CYBOZU_BENCH_C("addG1 ", C, CipherTextG1::add, c1, c1, c1); + CYBOZU_BENCH_C("addG2 ", C, CipherTextG2::add, c2, c2, c2); + CYBOZU_BENCH_C("addGT ", C, CipherTextGT::add, ct, ct, ct); + CYBOZU_BENCH_C("reRandG1", C, pub.reRand, c1); + CYBOZU_BENCH_C("reRandG2", C, pub.reRand, c2); + CYBOZU_BENCH_C("reRandGT", C, pub.reRand, ct); + CYBOZU_BENCH_C("reRandG1pre", C, ppub.reRand, c1); + CYBOZU_BENCH_C("reRandG2pre", C, ppub.reRand, c2); + CYBOZU_BENCH_C("reRandGTpre", C, ppub.reRand, ct); + CYBOZU_BENCH_C("mulG1 ", C, CipherTextG1::mul, c1, c1, m); + CYBOZU_BENCH_C("mulG2 ", C, CipherTextG2::mul, c2, c2, m); + CYBOZU_BENCH_C("mulGT ", C, CipherTextGT::mul, ct, ct, m); } |