From 398106733f1acf33e62ce545dadcea421ccb9c5a Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sun, 10 Dec 2017 15:32:34 +0900 Subject: new deserialize api --- include/bls/bls.h | 74 +++++++++++++++++++++++++----------------------- src/bls_c.cpp | 76 +++++++++++++++++++++++++------------------------- test/bls_c384_test.cpp | 60 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 73 deletions(-) diff --git a/include/bls/bls.h b/include/bls/bls.h index 2b87e1e..fbb3303 100644 --- a/include/bls/bls.h +++ b/include/bls/bls.h @@ -61,38 +61,42 @@ BLS_DLL_API int blsInit(int curve, int maxUnitSize); // not thread safe version (old blsInit) BLS_DLL_API int blsInitNotThreadSafe(int curve, int maxUnitSize); -BLS_DLL_API size_t blsGetOpUnitSize(void); +BLS_DLL_API mclSize blsGetOpUnitSize(void); // return strlen(buf) if success else 0 -BLS_DLL_API int blsGetCurveOrder(char *buf, size_t maxBufSize); -BLS_DLL_API int blsGetFieldOrder(char *buf, size_t maxBufSize); +BLS_DLL_API int blsGetCurveOrder(char *buf, mclSize maxBufSize); +BLS_DLL_API int blsGetFieldOrder(char *buf, mclSize maxBufSize); // get a generator of G2 BLS_DLL_API void blsGetGeneratorOfG2(blsPublicKey *pub); BLS_DLL_API void blsIdSetInt(blsId *id, int x); // return 0 if success -BLS_DLL_API int blsIdSetDecStr(blsId *id, const char *buf, size_t bufSize); -BLS_DLL_API int blsIdSetHexStr(blsId *id, const char *buf, size_t bufSize); +BLS_DLL_API int blsIdSetDecStr(blsId *id, const char *buf, mclSize bufSize); +BLS_DLL_API int blsIdSetHexStr(blsId *id, const char *buf, mclSize bufSize); /* return strlen(buf) if success else 0 buf is '\0' terminated */ -BLS_DLL_API size_t blsIdGetDecStr(char *buf, size_t maxBufSize, const blsId *id); -BLS_DLL_API size_t blsIdGetHexStr(char *buf, size_t maxBufSize, const blsId *id); +BLS_DLL_API mclSize blsIdGetDecStr(char *buf, mclSize maxBufSize, const blsId *id); +BLS_DLL_API mclSize blsIdGetHexStr(char *buf, mclSize maxBufSize, const blsId *id); // return written byte size if success else 0 -BLS_DLL_API size_t blsIdSerialize(void *buf, size_t maxBufSize, const blsId *id); -BLS_DLL_API size_t blsSecretKeySerialize(void *buf, size_t maxBufSize, const blsSecretKey *sec); -BLS_DLL_API size_t blsPublicKeySerialize(void *buf, size_t maxBufSize, const blsPublicKey *pub); -BLS_DLL_API size_t blsSignatureSerialize(void *buf, size_t maxBufSize, const blsSignature *sig); +BLS_DLL_API mclSize blsIdSerialize(void *buf, mclSize maxBufSize, const blsId *id); +BLS_DLL_API mclSize blsSecretKeySerialize(void *buf, mclSize maxBufSize, const blsSecretKey *sec); +BLS_DLL_API mclSize blsPublicKeySerialize(void *buf, mclSize maxBufSize, const blsPublicKey *pub); +BLS_DLL_API mclSize blsSignatureSerialize(void *buf, mclSize maxBufSize, const blsSignature *sig); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API +// return read byte size if success else 0 +#else // return 0 if success else -1 -BLS_DLL_API int blsIdDeserialize(blsId *id, const void *buf, size_t bufSize); -BLS_DLL_API int blsSecretKeyDeserialize(blsSecretKey *sec, const void *buf, size_t bufSize); -BLS_DLL_API int blsPublicKeyDeserialize(blsPublicKey *pub, const void *buf, size_t bufSize); -BLS_DLL_API int blsSignatureDeserialize(blsSignature *sig, const void *buf, size_t bufSize); +#endif +BLS_DLL_API mclRetType blsIdDeserialize(blsId *id, const void *buf, mclSize bufSize); +BLS_DLL_API mclRetType blsSecretKeyDeserialize(blsSecretKey *sec, const void *buf, mclSize bufSize); +BLS_DLL_API mclRetType blsPublicKeyDeserialize(blsPublicKey *pub, const void *buf, mclSize bufSize); +BLS_DLL_API mclRetType blsSignatureDeserialize(blsSignature *sig, const void *buf, mclSize bufSize); // return 1 if same else 0 BLS_DLL_API int blsIdIsEqual(const blsId *lhs, const blsId *rhs); @@ -106,7 +110,7 @@ BLS_DLL_API void blsPublicKeyAdd(blsPublicKey *pub, const blsPublicKey *rhs); BLS_DLL_API void blsSignatureAdd(blsSignature *sig, const blsSignature *rhs); // hash buf and set -BLS_DLL_API int blsHashToSecretKey(blsSecretKey *sec, const void *buf, size_t bufSize); +BLS_DLL_API int blsHashToSecretKey(blsSecretKey *sec, const void *buf, mclSize bufSize); /* set secretKey if system has /dev/urandom or CryptGenRandom return 0 if success else -1 @@ -117,49 +121,49 @@ BLS_DLL_API void blsGetPublicKey(blsPublicKey *pub, const blsSecretKey *sec); BLS_DLL_API void blsGetPop(blsSignature *sig, const blsSecretKey *sec); // return 0 if success -BLS_DLL_API int blsSecretKeyShare(blsSecretKey *sec, const blsSecretKey* msk, size_t k, const blsId *id); -BLS_DLL_API int blsPublicKeyShare(blsPublicKey *pub, const blsPublicKey *mpk, size_t k, const blsId *id); +BLS_DLL_API int blsSecretKeyShare(blsSecretKey *sec, const blsSecretKey* msk, mclSize k, const blsId *id); +BLS_DLL_API int blsPublicKeyShare(blsPublicKey *pub, const blsPublicKey *mpk, mclSize k, const blsId *id); -BLS_DLL_API int blsSecretKeyRecover(blsSecretKey *sec, const blsSecretKey *secVec, const blsId *idVec, size_t n); -BLS_DLL_API int blsPublicKeyRecover(blsPublicKey *pub, const blsPublicKey *pubVec, const blsId *idVec, size_t n); -BLS_DLL_API int blsSignatureRecover(blsSignature *sig, const blsSignature *sigVec, const blsId *idVec, size_t n); +BLS_DLL_API int blsSecretKeyRecover(blsSecretKey *sec, const blsSecretKey *secVec, const blsId *idVec, mclSize n); +BLS_DLL_API int blsPublicKeyRecover(blsPublicKey *pub, const blsPublicKey *pubVec, const blsId *idVec, mclSize n); +BLS_DLL_API int blsSignatureRecover(blsSignature *sig, const blsSignature *sigVec, const blsId *idVec, mclSize n); -BLS_DLL_API void blsSign(blsSignature *sig, const blsSecretKey *sec, const void *m, size_t size); +BLS_DLL_API void blsSign(blsSignature *sig, const blsSecretKey *sec, const void *m, mclSize size); // return 1 if valid -BLS_DLL_API int blsVerify(const blsSignature *sig, const blsPublicKey *pub, const void *m, size_t size); +BLS_DLL_API int blsVerify(const blsSignature *sig, const blsPublicKey *pub, const void *m, mclSize size); BLS_DLL_API int blsVerifyPop(const blsSignature *sig, const blsPublicKey *pub); ////////////////////////////////////////////////////////////////////////// // the following apis will be removed // mask buf with (1 << (bitLen(r) - 1)) - 1 if buf >= r -BLS_DLL_API int blsIdSetLittleEndian(blsId *id, const void *buf, size_t bufSize); +BLS_DLL_API int blsIdSetLittleEndian(blsId *id, const void *buf, mclSize bufSize); /* return written byte size if success else 0 */ -BLS_DLL_API size_t blsIdGetLittleEndian(void *buf, size_t maxBufSize, const blsId *id); +BLS_DLL_API mclSize blsIdGetLittleEndian(void *buf, mclSize maxBufSize, const blsId *id); // return 0 if success // mask buf with (1 << (bitLen(r) - 1)) - 1 if buf >= r -BLS_DLL_API int blsSecretKeySetLittleEndian(blsSecretKey *sec, const void *buf, size_t bufSize); -BLS_DLL_API int blsSecretKeySetDecStr(blsSecretKey *sec, const char *buf, size_t bufSize); -BLS_DLL_API int blsSecretKeySetHexStr(blsSecretKey *sec, const char *buf, size_t bufSize); +BLS_DLL_API int blsSecretKeySetLittleEndian(blsSecretKey *sec, const void *buf, mclSize bufSize); +BLS_DLL_API int blsSecretKeySetDecStr(blsSecretKey *sec, const char *buf, mclSize bufSize); +BLS_DLL_API int blsSecretKeySetHexStr(blsSecretKey *sec, const char *buf, mclSize bufSize); /* return written byte size if success else 0 */ -BLS_DLL_API size_t blsSecretKeyGetLittleEndian(void *buf, size_t maxBufSize, const blsSecretKey *sec); +BLS_DLL_API mclSize blsSecretKeyGetLittleEndian(void *buf, mclSize maxBufSize, const blsSecretKey *sec); /* return strlen(buf) if success else 0 buf is '\0' terminated */ -BLS_DLL_API size_t blsSecretKeyGetDecStr(char *buf, size_t maxBufSize, const blsSecretKey *sec); -BLS_DLL_API size_t blsSecretKeyGetHexStr(char *buf, size_t maxBufSize, const blsSecretKey *sec); -BLS_DLL_API int blsPublicKeySetHexStr(blsPublicKey *pub, const char *buf, size_t bufSize); -BLS_DLL_API size_t blsPublicKeyGetHexStr(char *buf, size_t maxBufSize, const blsPublicKey *pub); -BLS_DLL_API int blsSignatureSetHexStr(blsSignature *sig, const char *buf, size_t bufSize); -BLS_DLL_API size_t blsSignatureGetHexStr(char *buf, size_t maxBufSize, const blsSignature *sig); +BLS_DLL_API mclSize blsSecretKeyGetDecStr(char *buf, mclSize maxBufSize, const blsSecretKey *sec); +BLS_DLL_API mclSize blsSecretKeyGetHexStr(char *buf, mclSize maxBufSize, const blsSecretKey *sec); +BLS_DLL_API int blsPublicKeySetHexStr(blsPublicKey *pub, const char *buf, mclSize bufSize); +BLS_DLL_API mclSize blsPublicKeyGetHexStr(char *buf, mclSize maxBufSize, const blsPublicKey *pub); +BLS_DLL_API int blsSignatureSetHexStr(blsSignature *sig, const char *buf, mclSize bufSize); +BLS_DLL_API mclSize blsSignatureGetHexStr(char *buf, mclSize maxBufSize, const blsSignature *sig); /* Diffie Hellman key exchange diff --git a/src/bls_c.cpp b/src/bls_c.cpp index 0939802..7179cd5 100644 --- a/src/bls_c.cpp +++ b/src/bls_c.cpp @@ -84,7 +84,7 @@ bool isEqualTwoPairings(const G1& P1, const Fp6* Q1coeff, const G1& P2, const G2 return e.isOne(); } -size_t checkAndCopy(char *buf, size_t maxBufSize, const std::string& s) +mclSize checkAndCopy(char *buf, mclSize maxBufSize, const std::string& s) { if (s.size() > maxBufSize + 1) { return 0; @@ -94,12 +94,12 @@ size_t checkAndCopy(char *buf, size_t maxBufSize, const std::string& s) return s.size(); } -size_t blsGetOpUnitSize() // FpUint64Size +mclSize blsGetOpUnitSize() // FpUint64Size { return Fp::getUnitSize() * sizeof(mcl::fp::Unit) / sizeof(uint64_t); } -int blsGetCurveOrder(char *buf, size_t maxBufSize) +int blsGetCurveOrder(char *buf, mclSize maxBufSize) try { std::string s; @@ -109,7 +109,7 @@ int blsGetCurveOrder(char *buf, size_t maxBufSize) return 0; } -int blsGetFieldOrder(char *buf, size_t maxBufSize) +int blsGetFieldOrder(char *buf, mclSize maxBufSize) try { std::string s; @@ -128,18 +128,18 @@ void blsGetPublicKey(blsPublicKey *pub, const blsSecretKey *sec) { mclBnG2_mul(&pub->v, cast(&getQ()), &sec->v); } -void blsSign(blsSignature *sig, const blsSecretKey *sec, const void *m, size_t size) +void blsSign(blsSignature *sig, const blsSecretKey *sec, const void *m, mclSize size) { G1 Hm; BN::hashAndMapToG1(Hm, m, size); mclBnG1_mulCT(&sig->v, cast(&Hm), &sec->v); } -int blsSecretKeyShare(blsSecretKey *sec, const blsSecretKey* msk, size_t k, const blsId *id) +int blsSecretKeyShare(blsSecretKey *sec, const blsSecretKey* msk, mclSize k, const blsId *id) { return mclBn_FrEvaluatePolynomial(&sec->v, &msk->v, k, &id->v); } -int blsSecretKeyRecover(blsSecretKey *sec, const blsSecretKey *secVec, const blsId *idVec, size_t n) +int blsSecretKeyRecover(blsSecretKey *sec, const blsSecretKey *secVec, const blsId *idVec, mclSize n) { return mclBn_FrLagrangeInterpolation(&sec->v, &idVec->v, &secVec->v, n); } @@ -149,24 +149,24 @@ void blsGetPop(blsSignature *sig, const blsSecretKey *sec) blsPublicKey pub; blsGetPublicKey(&pub, sec); char buf[1024]; - size_t n = mclBnG2_serialize(buf, sizeof(buf), &pub.v); + mclSize n = mclBnG2_serialize(buf, sizeof(buf), &pub.v); assert(n); blsSign(sig, sec, buf, n); } -int blsPublicKeyShare(blsPublicKey *pub, const blsPublicKey *mpk, size_t k, const blsId *id) +int blsPublicKeyShare(blsPublicKey *pub, const blsPublicKey *mpk, mclSize k, const blsId *id) { return mclBn_G2EvaluatePolynomial(&pub->v, &mpk->v, k, &id->v); } -int blsPublicKeyRecover(blsPublicKey *pub, const blsPublicKey *pubVec, const blsId *idVec, size_t n) +int blsPublicKeyRecover(blsPublicKey *pub, const blsPublicKey *pubVec, const blsId *idVec, mclSize n) { return mclBn_G2LagrangeInterpolation(&pub->v, &idVec->v, &pubVec->v, n); } -int blsSignatureRecover(blsSignature *sig, const blsSignature *sigVec, const blsId *idVec, size_t n) +int blsSignatureRecover(blsSignature *sig, const blsSignature *sigVec, const blsId *idVec, mclSize n) { return mclBn_G1LagrangeInterpolation(&sig->v, &idVec->v, &sigVec->v, n); } -int blsVerify(const blsSignature *sig, const blsPublicKey *pub, const void *m, size_t size) +int blsVerify(const blsSignature *sig, const blsPublicKey *pub, const void *m, mclSize size) { G1 Hm; BN::hashAndMapToG1(Hm, m, size); @@ -180,7 +180,7 @@ int blsVerify(const blsSignature *sig, const blsPublicKey *pub, const void *m, s int blsVerifyPop(const blsSignature *sig, const blsPublicKey *pub) { char buf[1024]; - size_t n = mclBnG2_serialize(buf, sizeof(buf), &pub->v); + mclSize n = mclBnG2_serialize(buf, sizeof(buf), &pub->v); assert(n); return blsVerify(sig, pub, buf, n); } @@ -189,35 +189,35 @@ void blsIdSetInt(blsId *id, int x) { mclBnFr_setInt(&id->v, x); } -size_t blsIdSerialize(void *buf, size_t maxBufSize, const blsId *id) +mclSize blsIdSerialize(void *buf, mclSize maxBufSize, const blsId *id) { return mclBnFr_serialize(buf, maxBufSize, &id->v); } -size_t blsSecretKeySerialize(void *buf, size_t maxBufSize, const blsSecretKey *sec) +mclSize blsSecretKeySerialize(void *buf, mclSize maxBufSize, const blsSecretKey *sec) { return mclBnFr_serialize(buf, maxBufSize, &sec->v); } -size_t blsPublicKeySerialize(void *buf, size_t maxBufSize, const blsPublicKey *pub) +mclSize blsPublicKeySerialize(void *buf, mclSize maxBufSize, const blsPublicKey *pub) { return mclBnG2_serialize(buf, maxBufSize, &pub->v); } -size_t blsSignatureSerialize(void *buf, size_t maxBufSize, const blsSignature *sig) +mclSize blsSignatureSerialize(void *buf, mclSize maxBufSize, const blsSignature *sig) { return mclBnG1_serialize(buf, maxBufSize, &sig->v); } -int blsIdDeserialize(blsId *id, const void *buf, size_t bufSize) +mclRetType blsIdDeserialize(blsId *id, const void *buf, mclSize bufSize) { return mclBnFr_deserialize(&id->v, buf, bufSize); } -int blsSecretKeyDeserialize(blsSecretKey *sig, const void *buf, size_t bufSize) +mclRetType blsSecretKeyDeserialize(blsSecretKey *sig, const void *buf, mclSize bufSize) { return mclBnFr_deserialize(&sig->v, buf, bufSize); } -int blsPublicKeyDeserialize(blsPublicKey *pub, const void *buf, size_t bufSize) +mclRetType blsPublicKeyDeserialize(blsPublicKey *pub, const void *buf, mclSize bufSize) { return mclBnG2_deserialize(&pub->v, buf, bufSize); } -int blsSignatureDeserialize(blsSignature *sig, const void *buf, size_t bufSize) +mclRetType blsSignatureDeserialize(blsSignature *sig, const void *buf, mclSize bufSize) { return mclBnG1_deserialize(&sig->v, buf, bufSize); } @@ -249,55 +249,55 @@ void blsPublicKeyAdd(blsPublicKey *pub, const blsPublicKey *rhs) { mclBnG2_add(&pub->v, &pub->v, &rhs->v); } -int blsIdSetLittleEndian(blsId *id, const void *buf, size_t bufSize) +int blsIdSetLittleEndian(blsId *id, const void *buf, mclSize bufSize) { return mclBnFr_setLittleEndian(&id->v, buf, bufSize); } -int blsIdSetDecStr(blsId *id, const char *buf, size_t bufSize) +int blsIdSetDecStr(blsId *id, const char *buf, mclSize bufSize) { return mclBnFr_setStr(&id->v, buf, bufSize, 10); } -int blsIdSetHexStr(blsId *id, const char *buf, size_t bufSize) +int blsIdSetHexStr(blsId *id, const char *buf, mclSize bufSize) { return mclBnFr_setStr(&id->v, buf, bufSize, 16); } -size_t blsIdGetLittleEndian(void *buf, size_t maxBufSize, const blsId *id) +mclSize blsIdGetLittleEndian(void *buf, mclSize maxBufSize, const blsId *id) { return mclBnFr_serialize(buf, maxBufSize, &id->v); } -size_t blsIdGetDecStr(char *buf, size_t maxBufSize, const blsId *id) +mclSize blsIdGetDecStr(char *buf, mclSize maxBufSize, const blsId *id) { return mclBnFr_getStr(buf, maxBufSize, &id->v, 10); } -size_t blsIdGetHexStr(char *buf, size_t maxBufSize, const blsId *id) +mclSize blsIdGetHexStr(char *buf, mclSize maxBufSize, const blsId *id) { return mclBnFr_getStr(buf, maxBufSize, &id->v, 16); } -int blsSecretKeySetLittleEndian(blsSecretKey *sec, const void *buf, size_t bufSize) +int blsSecretKeySetLittleEndian(blsSecretKey *sec, const void *buf, mclSize bufSize) { return mclBnFr_setLittleEndian(&sec->v, buf, bufSize); } -int blsSecretKeySetDecStr(blsSecretKey *sec, const char *buf, size_t bufSize) +int blsSecretKeySetDecStr(blsSecretKey *sec, const char *buf, mclSize bufSize) { return mclBnFr_setStr(&sec->v, buf, bufSize, 10); } -int blsSecretKeySetHexStr(blsSecretKey *sec, const char *buf, size_t bufSize) +int blsSecretKeySetHexStr(blsSecretKey *sec, const char *buf, mclSize bufSize) { return mclBnFr_setStr(&sec->v, buf, bufSize, 16); } -size_t blsSecretKeyGetLittleEndian(void *buf, size_t maxBufSize, const blsSecretKey *sec) +mclSize blsSecretKeyGetLittleEndian(void *buf, mclSize maxBufSize, const blsSecretKey *sec) { return mclBnFr_serialize(buf, maxBufSize, &sec->v); } -size_t blsSecretKeyGetDecStr(char *buf, size_t maxBufSize, const blsSecretKey *sec) +mclSize blsSecretKeyGetDecStr(char *buf, mclSize maxBufSize, const blsSecretKey *sec) { return mclBnFr_getStr(buf, maxBufSize, &sec->v, 10); } -size_t blsSecretKeyGetHexStr(char *buf, size_t maxBufSize, const blsSecretKey *sec) +mclSize blsSecretKeyGetHexStr(char *buf, mclSize maxBufSize, const blsSecretKey *sec) { return mclBnFr_getStr(buf, maxBufSize, &sec->v, 16); } -int blsHashToSecretKey(blsSecretKey *sec, const void *buf, size_t bufSize) +int blsHashToSecretKey(blsSecretKey *sec, const void *buf, mclSize bufSize) { return mclBnFr_setHashOf(&sec->v, buf, bufSize); } @@ -305,19 +305,19 @@ int blsSecretKeySetByCSPRNG(blsSecretKey *sec) { return mclBnFr_setByCSPRNG(&sec->v); } -int blsPublicKeySetHexStr(blsPublicKey *pub, const char *buf, size_t bufSize) +int blsPublicKeySetHexStr(blsPublicKey *pub, const char *buf, mclSize bufSize) { return mclBnG2_setStr(&pub->v, buf, bufSize, 16); } -size_t blsPublicKeyGetHexStr(char *buf, size_t maxBufSize, const blsPublicKey *pub) +mclSize blsPublicKeyGetHexStr(char *buf, mclSize maxBufSize, const blsPublicKey *pub) { return mclBnG2_getStr(buf, maxBufSize, &pub->v, 16); } -int blsSignatureSetHexStr(blsSignature *sig, const char *buf, size_t bufSize) +int blsSignatureSetHexStr(blsSignature *sig, const char *buf, mclSize bufSize) { return mclBnG1_setStr(&sig->v, buf, bufSize, 16); } -size_t blsSignatureGetHexStr(char *buf, size_t maxBufSize, const blsSignature *sig) +mclSize blsSignatureGetHexStr(char *buf, mclSize maxBufSize, const blsSignature *sig) { return mclBnG1_getStr(buf, maxBufSize, &sig->v, 16); } diff --git a/test/bls_c384_test.cpp b/test/bls_c384_test.cpp index c37a8ba..a3b7686 100644 --- a/test/bls_c384_test.cpp +++ b/test/bls_c384_test.cpp @@ -40,7 +40,11 @@ void blsDataTest() n = blsSecretKeySerialize(buf, sizeof(buf), &sec1); CYBOZU_TEST_EQUAL(n, fpSize); ret = blsSecretKeyDeserialize(&sec2, buf, n); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsSecretKeyIsEqual(&sec1, &sec2)); blsPublicKey pub1, pub2; @@ -48,14 +52,22 @@ void blsDataTest() n = blsPublicKeySerialize(buf, sizeof(buf), &pub1); CYBOZU_TEST_EQUAL(n, fpSize * 2); ret = blsPublicKeyDeserialize(&pub2, buf, n); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsPublicKeyIsEqual(&pub1, &pub2)); blsSignature sig1, sig2; blsSign(&sig1, &sec1, msg, msgSize); n = blsSignatureSerialize(buf, sizeof(buf), &sig1); CYBOZU_TEST_EQUAL(n, fpSize); ret = blsSignatureDeserialize(&sig2, buf, n); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsSignatureIsEqual(&sig1, &sig2)); } @@ -132,16 +144,28 @@ void blsSerializeTest() CYBOZU_TEST_EQUAL(n, expectSize); ret = blsIdDeserialize(&id2, buf, n); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsIdIsEqual(&id1, &id2)); ret = blsIdDeserialize(&id2, buf, n - 1); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, 0); +#else CYBOZU_TEST_ASSERT(ret != 0); +#endif memset(&id2, 0, sizeof(id2)); buf[n] = dummyChar; ret = blsIdDeserialize(&id2, buf, n + 1); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsIdIsEqual(&id1, &id2)); n = blsIdSerialize(buf, expectSize, &id1); @@ -154,16 +178,28 @@ void blsSerializeTest() CYBOZU_TEST_EQUAL(n, expectSize); ret = blsSecretKeyDeserialize(&sec2, buf, n); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsSecretKeyIsEqual(&sec1, &sec2)); ret = blsSecretKeyDeserialize(&sec2, buf, n - 1); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, 0); +#else CYBOZU_TEST_ASSERT(ret != 0); +#endif memset(&sec2, 0, sizeof(sec2)); buf[n] = dummyChar; ret = blsSecretKeyDeserialize(&sec2, buf, n + 1); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsSecretKeyIsEqual(&sec1, &sec2)); n = blsSecretKeySerialize(buf, expectSize, &sec1); @@ -176,16 +212,28 @@ void blsSerializeTest() CYBOZU_TEST_EQUAL(n, expectSize); ret = blsPublicKeyDeserialize(&pub2, buf, n); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsPublicKeyIsEqual(&pub1, &pub2)); ret = blsPublicKeyDeserialize(&pub2, buf, n - 1); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, 0); +#else CYBOZU_TEST_ASSERT(ret != 0); +#endif memset(&pub2, 0, sizeof(pub2)); buf[n] = dummyChar; ret = blsPublicKeyDeserialize(&pub2, buf, n + 1); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsPublicKeyIsEqual(&pub1, &pub2)); n = blsPublicKeySerialize(buf, expectSize, &pub1); @@ -198,16 +246,28 @@ void blsSerializeTest() CYBOZU_TEST_EQUAL(n, expectSize); ret = blsSignatureDeserialize(&sig2, buf, n); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsSignatureIsEqual(&sig1, &sig2)); ret = blsSignatureDeserialize(&sig2, buf, n - 1); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, 0); +#else CYBOZU_TEST_ASSERT(ret != 0); +#endif memset(&sig2, 0, sizeof(sig2)); buf[n] = dummyChar; ret = blsSignatureDeserialize(&sig2, buf, n + 1); +#ifdef MCLBN_USE_NEW_DESERIALIZE_API + CYBOZU_TEST_EQUAL(ret, n); +#else CYBOZU_TEST_EQUAL(ret, 0); +#endif CYBOZU_TEST_ASSERT(blsSignatureIsEqual(&sig1, &sig2)); n = blsSignatureSerialize(buf, expectSize, &sig1); -- cgit v1.2.3