From 199ed712d3056c85369a7e330a779e14feca5cc7 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 6 Feb 2018 16:23:08 +0900 Subject: [she] add ZkpBin api for c --- src/she_c_impl.hpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src') 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(p); } static const CipherTextGT *cast(const sheCipherTextGT *p) { return reinterpret_cast(p); } +static ZkpBin *cast(sheZkpBin *p) { return reinterpret_cast(p); } +static const ZkpBin *cast(const sheZkpBin *p) { return reinterpret_cast(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 +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 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 +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)); +} -- cgit