add test of ecdsa::serializer

dev
MITSUNARI Shigeo 7 years ago
parent a7cf9247a2
commit d8b4694845
  1. 15
      test/ecdsa_c_test.cpp

@ -2,6 +2,18 @@
#include <cybozu/test.hpp>
#include <string.h>
template<class T, class Serializer, class Deserializer>
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();

Loading…
Cancel
Save