remove old deserialize api

dev new_deserialize_api
MITSUNARI Shigeo 7 years ago
parent 8c7256c6be
commit 57f11a5854
  1. 2
      Makefile
  2. 8
      go/bls/mcl.go
  3. 12
      include/bls/bls.h
  4. 8
      src/bls_c.cpp
  5. 60
      test/bls_c384_test.cpp

@ -91,7 +91,7 @@ EMCC_OPT+=-s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s NO_EXIT_RUNTIME=1
JS_DEP=src/bls_c.cpp ../mcl/src/fp.cpp Makefile
../bls-wasm/bls_c.js: $(JS_DEP)
emcc -o $@ src/bls_c.cpp ../mcl/src/fp.cpp $(EMCC_OPT) -s "MODULARIZE=1" -DMCLBN_USE_NEW_DESERIALIZE_API
emcc -o $@ src/bls_c.cpp ../mcl/src/fp.cpp $(EMCC_OPT) -s "MODULARIZE=1"
clean:
$(RM) $(BLS_LIB) $(OBJ_DIR)/*.d $(OBJ_DIR)/*.o $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_SRC) $(ASM_OBJ) $(LIB_OBJ) $(LLVM_SRC) $(BLS384_SLIB)

@ -91,7 +91,7 @@ func (x *Fr) SetString(s string, base int) error {
func (x *Fr) Deserialize(buf []byte) error {
// #nosec
err := C.mclBnFr_deserialize(x.getPointer(), unsafe.Pointer(&buf[0]), C.size_t(len(buf)))
if err != 0 {
if err == 0 {
return fmt.Errorf("err mclBnFr_deserialize %x", buf)
}
return nil
@ -220,7 +220,7 @@ func (x *G1) SetString(s string, base int) error {
func (x *G1) Deserialize(buf []byte) error {
// #nosec
err := C.mclBnG1_deserialize(x.getPointer(), unsafe.Pointer(&buf[0]), C.size_t(len(buf)))
if err != 0 {
if err == 0 {
return fmt.Errorf("err mclBnG1_deserialize %x", buf)
}
return nil
@ -330,7 +330,7 @@ func (x *G2) SetString(s string, base int) error {
func (x *G2) Deserialize(buf []byte) error {
// #nosec
err := C.mclBnG2_deserialize(x.getPointer(), unsafe.Pointer(&buf[0]), C.size_t(len(buf)))
if err != 0 {
if err == 0 {
return fmt.Errorf("err mclBnG2_deserialize %x", buf)
}
return nil
@ -441,7 +441,7 @@ func (x *GT) SetString(s string, base int) error {
func (x *GT) Deserialize(buf []byte) error {
// #nosec
err := C.mclBnGT_deserialize(x.getPointer(), unsafe.Pointer(&buf[0]), C.size_t(len(buf)))
if err != 0 {
if err == 0 {
return fmt.Errorf("err mclBnGT_deserialize %x", buf)
}
return nil

@ -88,15 +88,11 @@ BLS_DLL_API mclSize blsSecretKeySerialize(void *buf, mclSize maxBufSize, const b
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
#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);
BLS_DLL_API mclSize blsIdDeserialize(blsId *id, const void *buf, mclSize bufSize);
BLS_DLL_API mclSize blsSecretKeyDeserialize(blsSecretKey *sec, const void *buf, mclSize bufSize);
BLS_DLL_API mclSize blsPublicKeyDeserialize(blsPublicKey *pub, const void *buf, mclSize bufSize);
BLS_DLL_API mclSize 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);

@ -205,19 +205,19 @@ mclSize blsSignatureSerialize(void *buf, mclSize maxBufSize, const blsSignature
{
return mclBnG1_serialize(buf, maxBufSize, &sig->v);
}
mclRetType blsIdDeserialize(blsId *id, const void *buf, mclSize bufSize)
mclSize blsIdDeserialize(blsId *id, const void *buf, mclSize bufSize)
{
return mclBnFr_deserialize(&id->v, buf, bufSize);
}
mclRetType blsSecretKeyDeserialize(blsSecretKey *sig, const void *buf, mclSize bufSize)
mclSize blsSecretKeyDeserialize(blsSecretKey *sig, const void *buf, mclSize bufSize)
{
return mclBnFr_deserialize(&sig->v, buf, bufSize);
}
mclRetType blsPublicKeyDeserialize(blsPublicKey *pub, const void *buf, mclSize bufSize)
mclSize blsPublicKeyDeserialize(blsPublicKey *pub, const void *buf, mclSize bufSize)
{
return mclBnG2_deserialize(&pub->v, buf, bufSize);
}
mclRetType blsSignatureDeserialize(blsSignature *sig, const void *buf, mclSize bufSize)
mclSize blsSignatureDeserialize(blsSignature *sig, const void *buf, mclSize bufSize)
{
return mclBnG1_deserialize(&sig->v, buf, bufSize);
}

@ -40,11 +40,7 @@ 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;
@ -52,22 +48,14 @@ 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));
}
@ -144,28 +132,16 @@ 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);
@ -178,28 +154,16 @@ 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);
@ -212,28 +176,16 @@ 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);
@ -246,28 +198,16 @@ 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);

Loading…
Cancel
Save