aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-08-11 05:21:44 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-08-11 05:21:44 +0800
commitf4e167ed1e0135fa34d0de1a1dcda7538da34f03 (patch)
tree389f6faa585ff35f91dde6a6f30d8e7bdea4ad24
parent8c3a117c544311b2e9e70c13bc6b7c626bd515ad (diff)
downloaddexon-mcl-f4e167ed1e0135fa34d0de1a1dcda7538da34f03.tar.gz
dexon-mcl-f4e167ed1e0135fa34d0de1a1dcda7538da34f03.tar.zst
dexon-mcl-f4e167ed1e0135fa34d0de1a1dcda7538da34f03.zip
add sample of innerProduct for she
-rw-r--r--test/bgn_test.cpp32
-rw-r--r--test/bn384_test.cpp9
2 files changed, 41 insertions, 0 deletions
diff --git a/test/bgn_test.cpp b/test/bgn_test.cpp
index f8a5ef5..3cf3b01 100644
--- a/test/bgn_test.cpp
+++ b/test/bgn_test.cpp
@@ -1,6 +1,7 @@
#define PUT(x) std::cout << #x << "=" << (x) << std::endl;
#include <cybozu/test.hpp>
#include <cybozu/benchmark.hpp>
+#include <cybozu/xorshift.hpp>
#include <mcl/bgn.hpp>
using namespace mcl::bgn;
@@ -151,6 +152,37 @@ CYBOZU_TEST_AUTO(add_mul_add_sub)
CYBOZU_TEST_EQUAL(sec.dec(c[0]), ok1);
}
+CYBOZU_TEST_AUTO(innerProduct)
+{
+ const SecretKey& sec = g_sec;
+ PublicKey pub;
+ sec.getPublicKey(pub);
+
+ cybozu::XorShift rg;
+ const size_t n = 1000;
+ std::vector<int> v1, v2;
+ std::vector<CipherText> c1, c2;
+ v1.resize(n);
+ v2.resize(n);
+ c1.resize(n);
+ c2.resize(n);
+ int innerProduct = 0;
+ for (size_t i = 0; i < n; i++) {
+ v1[i] = rg() % 2;
+ v2[i] = rg() % 2;
+ innerProduct += v1[i] * v2[i];
+ pub.enc(c1[i], v1[i]);
+ pub.enc(c2[i], v2[i]);
+ }
+ CipherText c, t;
+ CipherText::mul(c, c1[0], c2[0]);
+ for (size_t i = 1; i < n; i++) {
+ CipherText::mul(t, c1[i], c2[i]);
+ c.add(t);
+ }
+ CYBOZU_TEST_EQUAL(innerProduct, sec.dec(c));
+}
+
template<class T>
T testIo(const T& x)
{
diff --git a/test/bn384_test.cpp b/test/bn384_test.cpp
index cac0914..3b2fefc 100644
--- a/test/bn384_test.cpp
+++ b/test/bn384_test.cpp
@@ -39,6 +39,15 @@ void testCurve(const mcl::bn::CurveParam& cp)
CYBOZU_BENCH_C("G2::dbl", 500, G2::dbl, bQ, bQ);
CYBOZU_BENCH("pairing", BN::pairing, e1, P, Q);
CYBOZU_BENCH("finalExp", BN::finalExp, e1, e1);
+{
+#define PUT(x) std::cout << #x << "=" << x << std::endl;
+ G1 PP;
+ G1::mul(PP, P, BN::param.r);
+ PUT(BN::param.r);
+ PUT(PP);
+ G2 QQ;
+ G2::mul(QQ, Q, BN::param.r);
+}
}
CYBOZU_TEST_AUTO(pairing)