diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-11-27 14:17:31 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-11-27 14:17:31 +0800 |
commit | a7efe8a6fee268f2c12da379c8fed7ef81673e84 (patch) | |
tree | b5a2db3764e360ecec66a53ced3bf3d5b7a298d0 /include | |
parent | 07372576fe5e7afb89add4ff19e642143b2444d9 (diff) | |
download | tangerine-mcl-a7efe8a6fee268f2c12da379c8fed7ef81673e84.tar.gz tangerine-mcl-a7efe8a6fee268f2c12da379c8fed7ef81673e84.tar.zst tangerine-mcl-a7efe8a6fee268f2c12da379c8fed7ef81673e84.zip |
use sha2.hpp instead of crypto.hpp
Diffstat (limited to 'include')
-rw-r--r-- | include/cybozu/sha2.hpp | 16 | ||||
-rw-r--r-- | include/mcl/elgamal.hpp | 18 |
2 files changed, 21 insertions, 13 deletions
diff --git a/include/cybozu/sha2.hpp b/include/cybozu/sha2.hpp index b3fd459..1830936 100644 --- a/include/cybozu/sha2.hpp +++ b/include/cybozu/sha2.hpp @@ -57,6 +57,10 @@ public: { update(buf.c_str(), buf.size()); } + std::string digest(const std::string& buf) + { + return digest(buf.c_str(), buf.size()); + } std::string digest(const void *buf, size_t bufSize) { std::string md(SHA256_DIGEST_LENGTH, 0); @@ -93,6 +97,10 @@ public: { update(buf.c_str(), buf.size()); } + std::string digest(const std::string& buf) + { + return digest(buf.c_str(), buf.size()); + } std::string digest(const void *buf, size_t bufSize) { std::string md(SHA512_DIGEST_LENGTH, 0); @@ -300,6 +308,10 @@ public: { update(buf.c_str(), buf.size()); } + std::string digest(const std::string& buf) + { + return digest(buf.c_str(), buf.size()); + } std::string digest(const void *buf, size_t bufSize) { std::string md(outByteSize_, 0); @@ -437,6 +449,10 @@ public: { update(buf.c_str(), buf.size()); } + std::string digest(const std::string& buf) + { + return digest(buf.c_str(), buf.size()); + } std::string digest(const void *buf, size_t bufSize) { std::string md(outByteSize_, 0); diff --git a/include/mcl/elgamal.hpp b/include/mcl/elgamal.hpp index 8bc3104..4311485 100644 --- a/include/mcl/elgamal.hpp +++ b/include/mcl/elgamal.hpp @@ -244,8 +244,7 @@ struct ElgamalT { input : m = 0 or 1 output : c (c1, c2), zkp */ - template<class Hash> - void encWithZkp(CipherText& c, Zkp& zkp, int m, Hash& hash, fp::RandGen rg = fp::RandGen()) const + void encWithZkp(CipherText& c, Zkp& zkp, int m, fp::RandGen rg = fp::RandGen()) const { if (m != 0 && m != 1) { throw cybozu::Exception("elgamal:PublicKey:encWithZkp") << m; @@ -272,10 +271,8 @@ struct ElgamalT { mulH(R12, r1); std::ostringstream os; os << R01 << R02 << R11 << R12 << c.c1 << c.c2 << f << g << h; - hash.update(os.str()); - const std::string digest = hash.digest(); Zn cc; - cc.setArrayMask(digest.c_str(), digest.size()); + cc.setHashOf(os.str()); zkp.c1 = cc - zkp.c0; zkp.s1 = r1 + zkp.c1 * u; } else { @@ -296,10 +293,8 @@ struct ElgamalT { Ec::sub(R12, t1, t2); std::ostringstream os; os << R01 << R02 << R11 << R12 << c.c1 << c.c2 << f << g << h; - hash.update(os.str()); - const std::string digest = hash.digest(); Zn cc; - cc.setArrayMask(digest.c_str(), digest.size()); + cc.setHashOf(os.str()); zkp.c0 = cc - zkp.c1; zkp.s0 = r0 + zkp.c0 * u; } @@ -307,8 +302,7 @@ struct ElgamalT { /* verify cipher text with ZKP */ - template<class Hash> - bool verify(const CipherText& c, const Zkp& zkp, Hash& hash) const + bool verify(const CipherText& c, const Zkp& zkp) const { Ec R01, R02, R11, R12; Ec t1, t2; @@ -327,10 +321,8 @@ struct ElgamalT { Ec::sub(R12, t1, t2); std::ostringstream os; os << R01 << R02 << R11 << R12 << c.c1 << c.c2 << f << g << h; - hash.update(os.str()); - const std::string digest = hash.digest(); Zn cc; - cc.setArrayMask(digest.c_str(), digest.size()); + cc.setHashOf(os.str()); return cc == zkp.c0 + zkp.c1; } /* |