diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-02-18 10:30:41 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-02-18 10:30:41 +0800 |
commit | b12f64870e9e423bcbd8c17747cb0dd4c9221358 (patch) | |
tree | 2e933db188e7f61bf390671b023b41413b521fde | |
parent | a07f5a1c556a005714603366e14669dd4ee4db52 (diff) | |
download | tangerine-mcl-b12f64870e9e423bcbd8c17747cb0dd4c9221358.tar.gz tangerine-mcl-b12f64870e9e423bcbd8c17747cb0dd4c9221358.tar.zst tangerine-mcl-b12f64870e9e423bcbd8c17747cb0dd4c9221358.zip |
add random.hpp and ahe.hpp
-rw-r--r-- | include/mcl/ahe.hpp | 75 | ||||
-rw-r--r-- | include/mcl/random.hpp | 34 |
2 files changed, 109 insertions, 0 deletions
diff --git a/include/mcl/ahe.hpp b/include/mcl/ahe.hpp new file mode 100644 index 0000000..4848160 --- /dev/null +++ b/include/mcl/ahe.hpp @@ -0,0 +1,75 @@ +#pragma once +/** + @file + @brief 192/256-bit additive homomorphic encryption by lifted-ElGamal + @author MITSUNARI Shigeo(@herumi) + @license modified new BSD license + http://opensource.org/licenses/BSD-3-Clause +*/ +#include <mcl/elgamal.hpp> +#include <mcl/ecparam.hpp> +#include <mcl/random.hpp> + +namespace mcl { + +#ifdef MCL_USE_AHE192 +namespace ahe192 { + +const mcl::EcParam& para = mcl::ecparam::NIST_P192; + +typedef mcl::FpT<mcl::FpTag, 192> Fp; +typedef mcl::FpT<mcl::ZnTag, 192> Zn; +typedef mcl::EcT<Fp> Ec; +typedef mcl::ElgamalT<Ec, Zn> ElgamalEc; +typedef ElgamalEc::PrivateKey SecretKey; +typedef ElgamalEc::PublicKey PublicKey; +typedef ElgamalEc::CipherText CipherText; + +static inline void ahe192init() +{ + Fp::init(para.p); + Zn::init(para.n); + Ec::init(para.a, para.b); +// Fp::setIoMode(mcl::IoArrayRaw); +} + +static inline void initSecretKey(SecretKey& sec) +{ + const Ec P(Fp(para.gx), Fp(para.gy)); + sec.init(P, Zn::getBitSize(), mcl::getRandomGenerator()); +} + +} //mcl::ahe192 +#endif + +#ifdef MCL_USE_AHE256 +namespace ahe256 { + +const mcl::EcParam& para = mcl::ecparam::NIST_P256; + +typedef mcl::FpT<mcl::FpTag, 256> Fp; +typedef mcl::FpT<mcl::ZnTag, 256> Zn; +typedef mcl::EcT<Fp> Ec; +typedef mcl::ElgamalT<Ec, Zn> ElgamalEc; +typedef ElgamalEc::PrivateKey SecretKey; +typedef ElgamalEc::PublicKey PublicKey; +typedef ElgamalEc::CipherText CipherText; + +static inline void ahe256init() +{ + Fp::init(para.p); + Zn::init(para.n); + Ec::init(para.a, para.b); +// Fp::setIoMode(mcl::IoArrayRaw); +} + +static inline void initSecretKey(SecretKey& sec) +{ + const Ec P(Fp(para.gx), Fp(para.gy)); + sec.init(P, Zn::getBitSize(), mcl::getRandomGenerator()); +} + +} //mcl::ahe256 +#endif + +} // mcl diff --git a/include/mcl/random.hpp b/include/mcl/random.hpp new file mode 100644 index 0000000..504b3f7 --- /dev/null +++ b/include/mcl/random.hpp @@ -0,0 +1,34 @@ +#pragma once +/** + @file + @brief random generator + @author MITSUNARI Shigeo(@herumi) + @license modified new BSD license + http://opensource.org/licenses/BSD-3-Clause +*/ + +#if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 +#include <random> +#else +#include <cybozu/random_generator.hpp> +#endif + +namespace mcl { + +#if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 +inline std::random_device& getRandomGenerator() +{ + static std::random_device rd; + return rd; +} +#else + +inline cybozu::RandomGenerator& getRandomGenerator() +{ + static cybozu::RandomGenerator rg; + return rg; +} + +#endif + +} // mcl |