replace BGN with SHE

dev
MITSUNARI Shigeo 7 years ago
parent 5aa2d9c1e1
commit fa809a1d70
  1. 52
      include/mcl/she.hpp
  2. 22
      test/she_test.cpp

@ -1,9 +1,9 @@
#pragma once
/**
@file
@brief somewhat homomorphic encryption
additive homomorphic encryption which supports one multiplication by lifted ElGamal and prime-order pairing
@brief somewhat homomorphic encryption with one-time multiplication, based on prime-order pairings
@author MITSUNARI Shigeo(@herumi)
see https://github.com/herumi/blob/master/she/she.pdf
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
@ -30,7 +30,7 @@
#include <cybozu/random_generator.hpp>
#endif
namespace mcl { namespace bgn {
namespace mcl { namespace she {
namespace local {
@ -271,13 +271,13 @@ int log(const G& P, const G& xP)
G::neg(negT, T);
if (xP == negT) return -i;
}
throw cybozu::Exception("BGN:log:not found");
throw cybozu::Exception("she:log:not found");
}
} // mcl::bgn::local
} // mcl::she::local
template<class BN, class Fr>
struct BGNT {
struct SHET {
typedef typename BN::G1 G1;
typedef typename BN::G2 G2;
typedef typename BN::Fp12 GT;
@ -484,7 +484,7 @@ public:
GT::unitaryInv(inv, t);
if (y == inv) return -i;
}
throw cybozu::Exception("BGN:dec:log:not found");
throw cybozu::Exception("she:dec:log:not found");
}
#endif
int dec(const CipherTextG1& c) const
@ -646,7 +646,7 @@ public:
}
void convertToCipherTextM(CipherText& cm, const CipherText& ca) const
{
if (ca.isMultiplied()) throw cybozu::Exception("bgn:PublicKey:convertCipherText:already isMultiplied");
if (ca.isMultiplied()) throw cybozu::Exception("she:PublicKey:convertCipherText:already isMultiplied");
cm.isMultiplied_ = true;
convertToCipherTextM(cm.m, ca.a);
}
@ -933,7 +933,7 @@ public:
CipherTextA::add(z.a, x.a, y.a);
return;
}
throw cybozu::Exception("bgn:CipherText:add:mixed CipherText");
throw cybozu::Exception("she:CipherText:add:mixed CipherText");
}
static void sub(CipherText& z, const CipherText& x, const CipherText& y)
{
@ -947,12 +947,12 @@ public:
CipherTextA::sub(z.a, x.a, y.a);
return;
}
throw cybozu::Exception("bgn:CipherText:sub:mixed CipherText");
throw cybozu::Exception("she:CipherText:sub:mixed CipherText");
}
static void mul(CipherText& z, const CipherText& x, const CipherText& y)
{
if (x.isMultiplied() || y.isMultiplied()) {
throw cybozu::Exception("bgn:CipherText:mul:mixed CipherText");
throw cybozu::Exception("she:CipherText:mul:mixed CipherText");
}
z.isMultiplied_ = true;
CipherTextM::mul(z.m, x.a, y.a);
@ -1020,23 +1020,23 @@ public:
};
};
template<class BN, class Fr> typename BN::G1 BGNT<BN, Fr>::P;
template<class BN, class Fr> typename BN::G2 BGNT<BN, Fr>::Q;
template<class BN, class Fr> typename BN::Fp12 BGNT<BN, Fr>::ePQ;
template<class BN, class Fr> local::HashTable<typename BN::G1> BGNT<BN, Fr>::g1HashTbl;
template<class BN, class Fr> local::HashTable<typename BN::Fp12, false> BGNT<BN, Fr>::gtHashTbl;
template<class BN, class Fr> typename BN::G1 SHET<BN, Fr>::P;
template<class BN, class Fr> typename BN::G2 SHET<BN, Fr>::Q;
template<class BN, class Fr> typename BN::Fp12 SHET<BN, Fr>::ePQ;
template<class BN, class Fr> local::HashTable<typename BN::G1> SHET<BN, Fr>::g1HashTbl;
template<class BN, class Fr> local::HashTable<typename BN::Fp12, false> SHET<BN, Fr>::gtHashTbl;
#ifdef MCL_USE_BN384
typedef mcl::bgn::BGNT<mcl::bn384::BN, mcl::bn256::Fr> BGN;
typedef mcl::she::SHET<mcl::bn384::BN, mcl::bn256::Fr> SHE;
#else
typedef mcl::bgn::BGNT<mcl::bn256::BN, mcl::bn256::Fr> BGN;
typedef mcl::she::SHET<mcl::bn256::BN, mcl::bn256::Fr> SHE;
#endif
typedef BGN::SecretKey SecretKey;
typedef BGN::PublicKey PublicKey;
typedef BGN::CipherTextG1 CipherTextG1;
typedef BGN::CipherTextG2 CipherTextG2;
typedef BGN::CipherTextA CipherTextA;
typedef BGN::CipherTextM CipherTextM;
typedef BGN::CipherText CipherText;
typedef SHE::SecretKey SecretKey;
typedef SHE::PublicKey PublicKey;
typedef SHE::CipherTextG1 CipherTextG1;
typedef SHE::CipherTextG2 CipherTextG2;
typedef SHE::CipherTextA CipherTextA;
typedef SHE::CipherTextM CipherTextM;
typedef SHE::CipherText CipherText;
} } // mcl::bgn
} } // mcl::she

@ -2,28 +2,28 @@
#include <cybozu/test.hpp>
#include <cybozu/benchmark.hpp>
#include <cybozu/xorshift.hpp>
#include <mcl/bgn.hpp>
#include <mcl/she.hpp>
using namespace mcl::bgn;
using namespace mcl::she;
using namespace mcl::bn256;
SecretKey g_sec;
CYBOZU_TEST_AUTO(log)
{
BGN::init();
SHE::init();
G1 P;
BN::hashAndMapToG1(P, "abc");
for (int i = -5; i < 5; i++) {
G1 iP;
G1::mul(iP, P, i);
CYBOZU_TEST_EQUAL(mcl::bgn::local::log(P, iP), i);
CYBOZU_TEST_EQUAL(mcl::she::local::log(P, iP), i);
}
}
CYBOZU_TEST_AUTO(HashTable)
{
mcl::bgn::local::HashTable<G1> hashTbl;
mcl::she::local::HashTable<G1> hashTbl;
G1 P;
BN::hashAndMapToG1(P, "abc");
const int maxSize = 100;
@ -43,7 +43,7 @@ CYBOZU_TEST_AUTO(HashTable)
CYBOZU_TEST_AUTO(GTHashTable)
{
mcl::bgn::local::HashTable<GT, false> hashTbl;
mcl::she::local::HashTable<GT, false> hashTbl;
GT g;
{
G1 P;
@ -71,7 +71,7 @@ CYBOZU_TEST_AUTO(enc_dec)
{
SecretKey& sec = g_sec;
sec.setByCSPRNG();
BGN::setRangeForDLP(1024);
SHE::setRangeForDLP(1024);
PublicKey pub;
sec.getPublicKey(pub);
CipherText c;
@ -196,7 +196,7 @@ T testIo(const T& x)
CYBOZU_TEST_AUTO(io)
{
BGN::setRangeForDLP(100, 2);
SHE::setRangeForDLP(100, 2);
int m;
for (int i = 0; i < 2; i++) {
if (i == 1) {
@ -247,8 +247,8 @@ CYBOZU_TEST_AUTO(bench)
CYBOZU_TEST_AUTO(saveHash)
{
mcl::bgn::local::HashTable<BGN::G1> hashTbl1, hashTbl2;
hashTbl1.init(BGN::P, 1234, 123);
mcl::she::local::HashTable<SHE::G1> hashTbl1, hashTbl2;
hashTbl1.init(SHE::P, 1234, 123);
std::stringstream ss;
hashTbl1.save(ss);
hashTbl2.load(ss);
@ -259,7 +259,7 @@ CYBOZU_TEST_AUTO(hashBench)
{
SecretKey& sec = g_sec;
sec.setByCSPRNG();
BGN::setRangeForDLP(100, 1000);
SHE::setRangeForDLP(100, 1000);
PublicKey pub;
sec.getPublicKey(pub);
int x = 100;

Loading…
Cancel
Save