aboutsummaryrefslogtreecommitdiffstats
path: root/test/bls_c384_test.cpp
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2018-09-13 04:23:28 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2018-09-13 04:23:28 +0800
commitbe54124ccf649ace15ef0f90dbf04f01fab8ac3c (patch)
tree2c483ec9d8e0c2d1b4ba00ffcf456d5dbb9d79b6 /test/bls_c384_test.cpp
parent33bee1b86a6b28ec543c96faecfbbc194552c0d6 (diff)
downloaddexon-bls-be54124ccf649ace15ef0f90dbf04f01fab8ac3c.tar
dexon-bls-be54124ccf649ace15ef0f90dbf04f01fab8ac3c.tar.gz
dexon-bls-be54124ccf649ace15ef0f90dbf04f01fab8ac3c.tar.bz2
dexon-bls-be54124ccf649ace15ef0f90dbf04f01fab8ac3c.tar.lz
dexon-bls-be54124ccf649ace15ef0f90dbf04f01fab8ac3c.tar.xz
dexon-bls-be54124ccf649ace15ef0f90dbf04f01fab8ac3c.tar.zst
dexon-bls-be54124ccf649ace15ef0f90dbf04f01fab8ac3c.zip
add bls*Sub functions
Diffstat (limited to 'test/bls_c384_test.cpp')
-rw-r--r--test/bls_c384_test.cpp39
1 files changed, 39 insertions, 0 deletions
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();
}
}