From be54124ccf649ace15ef0f90dbf04f01fab8ac3c Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Thu, 13 Sep 2018 05:23:28 +0900 Subject: add bls*Sub functions --- test/bls_c384_test.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test/bls_c384_test.cpp') diff --git a/test/bls_c384_test.cpp b/test/bls_c384_test.cpp index 984c9c3..ede3596 100644 --- a/test/bls_c384_test.cpp +++ b/test/bls_c384_test.cpp @@ -250,6 +250,44 @@ void blsVerifyOrderTest() blsSignatureVerifyOrder(1); } +void blsAddSubTest() +{ + blsSecretKey sec[3]; + blsPublicKey pub[3]; + blsSignature sig[3]; + const char *msg = "this is a pen"; + const size_t msgSize = strlen(msg); + + const char *secHexStr[8] = { "12", "34" }; + for (int i = 0; i < 2; i++) { + blsSecretKeySetHexStr(&sec[i], secHexStr[i], strlen(secHexStr[i])); + blsGetPublicKey(&pub[i], &sec[i]); + blsSign(&sig[i], &sec[i], msg, msgSize); + } + sec[2] = sec[0]; + blsSecretKeyAdd(&sec[2], &sec[1]); + char buf[1024]; + size_t n = blsSecretKeyGetHexStr(buf, sizeof(buf), &sec[2]); + CYBOZU_TEST_EQUAL(n, 2); + CYBOZU_TEST_EQUAL(buf, "46"); // "12" + "34" + + pub[2] = pub[0]; + blsPublicKeyAdd(&pub[2], &pub[1]); + sig[2] = sig[0]; + blsSignatureAdd(&sig[2], &sig[1]); // sig[2] = sig[0] + sig[1] + blsSignature sig2; + blsSign(&sig2, &sec[2], msg, msgSize); // sig2 = signature by sec[2] + CYBOZU_TEST_ASSERT(blsSignatureIsEqual(&sig2, &sig[2])); + CYBOZU_TEST_ASSERT(blsVerify(&sig[2], &pub[2], msg, msgSize)); // verify by pub[2] + + blsSecretKeySub(&sec[2], &sec[1]); + CYBOZU_TEST_ASSERT(blsSecretKeyIsEqual(&sec[2], &sec[0])); + blsPublicKeySub(&pub[2], &pub[1]); + CYBOZU_TEST_ASSERT(blsPublicKeyIsEqual(&pub[2], &pub[0])); + blsSignatureSub(&sig[2], &sig[1]); + CYBOZU_TEST_ASSERT(blsSignatureIsEqual(&sig[2], &sig[0])); +} + CYBOZU_TEST_AUTO(all) { const int tbl[] = { @@ -277,5 +315,6 @@ CYBOZU_TEST_AUTO(all) blsOrderTest(curveOrderTbl[i], fieldOrderTbl[i]); blsSerializeTest(); if (tbl[i] == MCL_BLS12_381) blsVerifyOrderTest(); + blsAddSubTest(); } } -- cgit v1.2.3