add sample of innerProduct for she

dev
MITSUNARI Shigeo 7 years ago
parent 8c3a117c54
commit f4e167ed1e
  1. 32
      test/bgn_test.cpp
  2. 9
      test/bn384_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)
{

@ -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)

Loading…
Cancel
Save