diff --git a/test/ecdsa_c_test.cpp b/test/ecdsa_c_test.cpp index d3b360f..e0af381 100644 --- a/test/ecdsa_c_test.cpp +++ b/test/ecdsa_c_test.cpp @@ -2,6 +2,18 @@ #include #include +template +void serializeTest(const T& x, const Serializer& serialize, const Deserializer& deserialize) +{ + char buf[128]; + size_t n = serialize(buf, sizeof(buf), &x); + CYBOZU_TEST_ASSERT(n > 0); + T y; + size_t m = deserialize(&y, buf, n); + CYBOZU_TEST_EQUAL(m, n); + CYBOZU_TEST_ASSERT(memcmp(&x, &y, n) == 0); +} + CYBOZU_TEST_AUTO(ecdsa) { int ret; @@ -16,9 +28,12 @@ CYBOZU_TEST_AUTO(ecdsa) ret = ecdsaSecretKeySetByCSPRNG(&sec); CYBOZU_TEST_EQUAL(ret, 0); + serializeTest(sec, ecdsaSecretKeySerialize, ecdsaSecretKeyDeserialize); ecdsaGetPublicKey(&pub, &sec); + serializeTest(pub, ecdsaPublicKeySerialize, ecdsaPublicKeyDeserialize); ecdsaSign(&sig, &sec, msg, msgSize); + serializeTest(sig, ecdsaSignatureSerialize, ecdsaSignatureDeserialize); CYBOZU_TEST_ASSERT(ecdsaVerify(&sig, &pub, msg, msgSize)); ppub = ecdsaPrecomputedPublicKeyCreate();