she ; add isZero for c api

dev
MITSUNARI Shigeo 7 years ago
parent cbe02b4961
commit b7d80503d2
  1. 7
      include/mcl/she.h
  2. 24
      src/she_c_impl.hpp
  3. 15
      test/she_c_test.hpp

@ -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);

@ -274,6 +274,30 @@ int sheDecGT(int64_t *m, const sheSecretKey *sec, const sheCipherTextGT *c)
return decT(m, sec, 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

@ -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)

Loading…
Cancel
Save