diff --git a/include/mcl/she.h b/include/mcl/she.h index 6384b47..f4f94be 100644 --- a/include/mcl/she.h +++ b/include/mcl/she.h @@ -100,11 +100,11 @@ MCLSHE_DLL_API int sheEncG2(sheCipherTextG2 *c, const shePublicKey *pub, int64_t MCLSHE_DLL_API int sheEncGT(sheCipherTextGT *c, const shePublicKey *pub, int64_t m); /* - decode c and set m[2]. plaintext is int64_t(m[1] << 32) + m[0] + decode c and set m return 0 if success */ -MCLSHE_DLL_API int sheDecG1(uint32_t m[2], const sheSecretKey *sec, const sheCipherTextG1 *c); -MCLSHE_DLL_API int sheDecGT(uint32_t m[2], const sheSecretKey *sec, const sheCipherTextGT *c); +MCLSHE_DLL_API int sheDecG1(int64_t *m, const sheSecretKey *sec, const sheCipherTextG1 *c); +MCLSHE_DLL_API int sheDecGT(int64_t *m, const sheSecretKey *sec, const sheCipherTextGT *c); // return 0 if success // z = x + y diff --git a/src/she_c_impl.hpp b/src/she_c_impl.hpp index 885000f..d4d5dad 100644 --- a/src/she_c_impl.hpp +++ b/src/she_c_impl.hpp @@ -217,24 +217,22 @@ int sheEncGT(sheCipherTextGT *c, const shePublicKey *pub, int64_t m) } template -int decT(uint32_t m[2], const sheSecretKey *sec, const CT *c) +int decT(int64_t *m, const sheSecretKey *sec, const CT *c) try { - uint64_t dec = uint64_t(cast(sec)->dec(*cast(c))); - m[0] = uint32_t(dec); - m[1] = uint32_t(dec >> 32); + *m = cast(sec)->dec(*cast(c)); return 0; } catch (std::exception& e) { printf("err %s\n", e.what()); return -1; } -int sheDecG1(uint32_t m[2], const sheSecretKey *sec, const sheCipherTextG1 *c) +int sheDecG1(int64_t *m, const sheSecretKey *sec, const sheCipherTextG1 *c) { return decT(m, sec, c); } -int sheDecGT(uint32_t m[2], const sheSecretKey *sec, const sheCipherTextGT *c) +int sheDecGT(int64_t *m, const sheSecretKey *sec, const sheCipherTextGT *c) { return decT(m, sec, c); } diff --git a/test/she_c_test.hpp b/test/she_c_test.hpp index 66a8ec1..cd58dbf 100644 --- a/test/she_c_test.hpp +++ b/test/she_c_test.hpp @@ -21,11 +21,6 @@ CYBOZU_TEST_AUTO(init) CYBOZU_TEST_EQUAL(ret, 0); } -int64_t toInt(const uint32_t m[2]) -{ - return m[0] + (int64_t(m[1]) << 32); -} - CYBOZU_TEST_AUTO(encDec) { sheSecretKey sec; @@ -39,11 +34,11 @@ CYBOZU_TEST_AUTO(encDec) sheEncG1(&c1, &pub, m); sheEncGT(&ct, &pub, m); - uint32_t dec[2]; - CYBOZU_TEST_EQUAL(sheDecG1(dec, &sec, &c1), 0); - CYBOZU_TEST_EQUAL(toInt(dec), m); - CYBOZU_TEST_EQUAL(sheDecGT(dec, &sec, &ct), 0); - CYBOZU_TEST_EQUAL(toInt(dec), m); + int64_t dec; + CYBOZU_TEST_EQUAL(sheDecG1(&dec, &sec, &c1), 0); + CYBOZU_TEST_EQUAL(dec, m); + CYBOZU_TEST_EQUAL(sheDecGT(&dec, &sec, &ct), 0); + CYBOZU_TEST_EQUAL(dec, m); } CYBOZU_TEST_AUTO(addMul) @@ -62,9 +57,9 @@ CYBOZU_TEST_AUTO(addMul) sheEncG2(&c2, &pub, m2); sheMul(&ct, &c1, &c2); - uint32_t dec[2]; - CYBOZU_TEST_EQUAL(sheDecGT(dec, &sec, &ct), 0); - CYBOZU_TEST_EQUAL(toInt(dec), m1 * m2); + int64_t dec; + CYBOZU_TEST_EQUAL(sheDecGT(&dec, &sec, &ct), 0); + CYBOZU_TEST_EQUAL(dec, m1 * m2); } CYBOZU_TEST_AUTO(allOp) @@ -95,9 +90,9 @@ CYBOZU_TEST_AUTO(allOp) sheMulGT(&ct, &ct, -4); // 160 * (m1 - m2) * (m3 - m4) int64_t t = 160 * (m1 - m2) * (m3 - m4); - uint32_t dec[2]; - CYBOZU_TEST_EQUAL(sheDecGT(dec, &sec, &ct), 0); - CYBOZU_TEST_EQUAL(toInt(dec), t); + int64_t dec; + CYBOZU_TEST_EQUAL(sheDecGT(&dec, &sec, &ct), 0); + CYBOZU_TEST_EQUAL(dec, t); } CYBOZU_TEST_AUTO(rerand) @@ -126,9 +121,9 @@ CYBOZU_TEST_AUTO(rerand) sheReRandGT(&ct2, &pub); sheAddGT(&ct1, &ct1, &ct2); - uint32_t dec[2]; - CYBOZU_TEST_EQUAL(sheDecGT(dec, &sec, &ct1), 0); - CYBOZU_TEST_EQUAL(toInt(dec), m1 * m2 + m3); + int64_t dec; + CYBOZU_TEST_EQUAL(sheDecGT(&dec, &sec, &ct1), 0); + CYBOZU_TEST_EQUAL(dec, m1 * m2 + m3); } CYBOZU_TEST_AUTO(serialize)