aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-11-22 13:12:29 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-11-22 13:12:29 +0800
commitb7d80503d28374a5b1a22012ad9b87b5b30217ca (patch)
tree44850ad4d7913c38f520938fd54c61b850b915c6
parentcbe02b49612ddc6cd947390849abdd493798f261 (diff)
downloadtangerine-mcl-b7d80503d28374a5b1a22012ad9b87b5b30217ca.tar.gz
tangerine-mcl-b7d80503d28374a5b1a22012ad9b87b5b30217ca.tar.zst
tangerine-mcl-b7d80503d28374a5b1a22012ad9b87b5b30217ca.zip
she ; add isZero for c api
-rw-r--r--include/mcl/she.h7
-rw-r--r--src/she_c_impl.hpp24
-rw-r--r--test/she_c_test.hpp15
3 files changed, 46 insertions, 0 deletions
diff --git a/include/mcl/she.h b/include/mcl/she.h
index 093c7a0..20b88c4 100644
--- a/include/mcl/she.h
+++ b/include/mcl/she.h
@@ -119,6 +119,13 @@ MCLSHE_DLL_API int sheDecG1(int64_t *m, const sheSecretKey *sec, const sheCipher
MCLSHE_DLL_API int sheDecG2(int64_t *m, const sheSecretKey *sec, const sheCipherTextG2 *c);
MCLSHE_DLL_API int sheDecGT(int64_t *m, const sheSecretKey *sec, const sheCipherTextGT *c);
+/*
+ return 1 if dec(c) == 0
+*/
+MCLSHE_DLL_API int sheIsZeroG1(const sheSecretKey *sec, const sheCipherTextG1 *c);
+MCLSHE_DLL_API int sheIsZeroG2(const sheSecretKey *sec, const sheCipherTextG2 *c);
+MCLSHE_DLL_API int sheIsZeroGT(const sheSecretKey *sec, const sheCipherTextGT *c);
+
// return 0 if success
// z = x + y
MCLSHE_DLL_API int sheAddG1(sheCipherTextG1 *z, const sheCipherTextG1 *x, const sheCipherTextG1 *y);
diff --git a/src/she_c_impl.hpp b/src/she_c_impl.hpp
index f7ea627..1eb676f 100644
--- a/src/she_c_impl.hpp
+++ b/src/she_c_impl.hpp
@@ -275,6 +275,30 @@ int sheDecGT(int64_t *m, const sheSecretKey *sec, const sheCipherTextGT *c)
}
template<class CT>
+int isZeroT(const sheSecretKey *sec, const CT *c)
+ try
+{
+ return cast(sec)->isZero(*cast(c));
+} catch (std::exception& e) {
+ fprintf(stderr, "err %s\n", e.what());
+ return 0;
+}
+
+int sheIsZeroG1(const sheSecretKey *sec, const sheCipherTextG1 *c)
+{
+ return isZeroT(sec, c);
+}
+int sheIsZeroG2(const sheSecretKey *sec, const sheCipherTextG2 *c)
+{
+ return isZeroT(sec, c);
+}
+int sheIsZeroGT(const sheSecretKey *sec, const sheCipherTextGT *c)
+{
+ return isZeroT(sec, c);
+}
+
+
+template<class CT>
int addT(CT& z, const CT& x, const CT& y)
try
{
diff --git a/test/she_c_test.hpp b/test/she_c_test.hpp
index 84b171e..8a8a2a0 100644
--- a/test/she_c_test.hpp
+++ b/test/she_c_test.hpp
@@ -30,15 +30,30 @@ CYBOZU_TEST_AUTO(encDec)
int64_t m = 123;
sheCipherTextG1 c1;
+ sheCipherTextG2 c2;
sheCipherTextGT ct;
sheEncG1(&c1, &pub, m);
+ sheEncG2(&c2, &pub, m);
sheEncGT(&ct, &pub, m);
int64_t dec;
CYBOZU_TEST_EQUAL(sheDecG1(&dec, &sec, &c1), 0);
CYBOZU_TEST_EQUAL(dec, m);
+ dec = 0;
+ CYBOZU_TEST_EQUAL(sheDecG2(&dec, &sec, &c2), 0);
+ CYBOZU_TEST_EQUAL(dec, m);
+ dec = 0;
CYBOZU_TEST_EQUAL(sheDecGT(&dec, &sec, &ct), 0);
CYBOZU_TEST_EQUAL(dec, m);
+
+ for (int m = -3; m < 3; m++) {
+ sheEncG1(&c1, &pub, m);
+ CYBOZU_TEST_EQUAL(sheIsZeroG1(&sec, &c1), m == 0);
+ sheEncG2(&c2, &pub, m);
+ CYBOZU_TEST_EQUAL(sheIsZeroG2(&sec, &c2), m == 0);
+ sheEncGT(&ct, &pub, m);
+ CYBOZU_TEST_EQUAL(sheIsZeroGT(&sec, &ct), m == 0);
+ }
}
CYBOZU_TEST_AUTO(addMul)