aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2018-02-06 15:23:08 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2018-02-06 15:23:08 +0800
commit199ed712d3056c85369a7e330a779e14feca5cc7 (patch)
tree2ea9c4ffbd5e4ab49de9ff8f3fda131d95998c64 /src
parent8c665543ad4115efcb619db7c977137882635cfd (diff)
downloadtangerine-mcl-199ed712d3056c85369a7e330a779e14feca5cc7.tar.gz
tangerine-mcl-199ed712d3056c85369a7e330a779e14feca5cc7.tar.zst
tangerine-mcl-199ed712d3056c85369a7e330a779e14feca5cc7.zip
[she] add ZkpBin api for c
Diffstat (limited to 'src')
-rw-r--r--src/she_c_impl.hpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/she_c_impl.hpp b/src/she_c_impl.hpp
index 9d29c67..d9a6593 100644
--- a/src/she_c_impl.hpp
+++ b/src/she_c_impl.hpp
@@ -39,6 +39,9 @@ static const CipherTextG2 *cast(const sheCipherTextG2 *p) { return reinterpret_c
static CipherTextGT *cast(sheCipherTextGT *p) { return reinterpret_cast<CipherTextGT*>(p); }
static const CipherTextGT *cast(const sheCipherTextGT *p) { return reinterpret_cast<const CipherTextGT*>(p); }
+static ZkpBin *cast(sheZkpBin *p) { return reinterpret_cast<ZkpBin*>(p); }
+static const ZkpBin *cast(const sheZkpBin *p) { return reinterpret_cast<const ZkpBin*>(p); }
+
int sheInit(int curve, int maxUnitSize)
try
{
@@ -278,6 +281,37 @@ int sheEncGT(sheCipherTextGT *c, const shePublicKey *pub, mclInt m)
return encT(c, pub, m);
}
+template<class CT, class PK>
+int encWithZkpBinT(CT *c, sheZkpBin *zkp, const PK *pub, int m)
+ try
+{
+ cast(pub)->encWithZkpBin(*cast(c), *cast(zkp), m);
+ return 0;
+} catch (std::exception& e) {
+ fprintf(stderr, "err %s\n", e.what());
+ return -1;
+}
+
+int sheEncWithZkpBinG1(sheCipherTextG1 *c, sheZkpBin *zkp, const shePublicKey *pub, int m)
+{
+ return encWithZkpBinT(c, zkp, pub, m);
+}
+
+int sheEncWithZkpBinG2(sheCipherTextG2 *c, sheZkpBin *zkp, const shePublicKey *pub, int m)
+{
+ return encWithZkpBinT(c, zkp, pub, m);
+}
+
+int shePrecomputedPublicKeyEncWithZkpBinG1(sheCipherTextG1 *c, sheZkpBin *zkp, const shePrecomputedPublicKey *pub, int m)
+{
+ return encWithZkpBinT(c, zkp, pub, m);
+}
+
+int shePrecomputedPublicKeyEncWithZkpBinG2(sheCipherTextG2 *c, sheZkpBin *zkp, const shePrecomputedPublicKey *pub, int m)
+{
+ return encWithZkpBinT(c, zkp, pub, m);
+}
+
template<class CT>
int decT(mclInt *m, const sheSecretKey *sec, const CT *c)
try
@@ -547,3 +581,30 @@ int shePrecomputedPublicKeyEncGT(sheCipherTextGT *c, const shePrecomputedPublicK
{
return pEncT(c, pub, m);
}
+
+template<class PK, class CT>
+int verifyT(const PK& pub, const CT& c, const ZkpBin& zkp)
+ try
+{
+ return pub.verify(c, zkp);
+} catch (std::exception& e) {
+ fprintf(stderr, "err %s\n", e.what());
+ return 0;
+}
+
+int sheVerifyZkpBinG1(const shePublicKey *pub, const sheCipherTextG1 *c, const sheZkpBin *zkp)
+{
+ return verifyT(*cast(pub), *cast(c), *cast(zkp));
+}
+int sheVerifyZkpBinG2(const shePublicKey *pub, const sheCipherTextG2 *c, const sheZkpBin *zkp)
+{
+ return verifyT(*cast(pub), *cast(c), *cast(zkp));
+}
+int shePrecomputedPublicKeyVerifyZkpBinG1(const shePrecomputedPublicKey *pub, const sheCipherTextG1 *c, const sheZkpBin *zkp)
+{
+ return verifyT(*cast(pub), *cast(c), *cast(zkp));
+}
+int shePrecomputedPublicKeyVerifyZkpBinG2(const shePrecomputedPublicKey *pub, const sheCipherTextG2 *c, const sheZkpBin *zkp)
+{
+ return verifyT(*cast(pub), *cast(c), *cast(zkp));
+}