From 20cfb8c0f35f5e74fcdb3522baf80b2edf734660 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Mon, 1 Apr 2019 12:55:42 +0900 Subject: [cs] update doc and add Add() methods --- ffi/cs/bls_test.cs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'ffi/cs/bls_test.cs') diff --git a/ffi/cs/bls_test.cs b/ffi/cs/bls_test.cs index e021e19..af4f761 100644 --- a/ffi/cs/bls_test.cs +++ b/ffi/cs/bls_test.cs @@ -67,7 +67,7 @@ namespace mcl sec.SetByCSPRNG(); PublicKey pub = sec.GetPublicKey(); string m = "abc"; - Signature sig = sec.Signature(m); + Signature sig = sec.Sign(m); Console.WriteLine("sig={0}", sig.GetHexStr()); assert("verify", pub.Verify(sig, m)); assert("not verify", !pub.Verify(sig, m + "a")); @@ -100,7 +100,7 @@ namespace mcl } string m = "doremi"; for (int i = 0; i < n; i++) { - Signature Signature = secs[i].Signature(m); + Signature Signature = secs[i].Sign(m); assert("Signature.Verify", pubs[i].Verify(Signature, m)); } { @@ -115,7 +115,7 @@ namespace mcl subIds[i] = ids[idx]; subSecs[i] = secs[idx]; subPubs[i] = pubs[idx]; - subSigns[i] = secs[idx].Signature(m); + subSigns[i] = secs[idx].Sign(m); } SecretKey sec = RecoverSecretKey(subSecs, subIds); PublicKey pub = RecoverPublicKey(subPubs, subIds); @@ -124,6 +124,29 @@ namespace mcl assert("Signature.verify", pub.Verify(Signature, m)); } } + static void TestAggregate() { + Console.WriteLine("TestAggregate"); + const int n = 10; + const string m = "abc"; + SecretKey[] secVec = new SecretKey[n]; + PublicKey[] pubVec = new PublicKey[n]; + Signature[] popVec = new Signature[n]; + Signature[] sigVec = new Signature[n]; + for (int i = 0; i < n; i++) { + secVec[i].SetByCSPRNG(); + pubVec[i] = secVec[i].GetPublicKey(); + popVec[i] = secVec[i].GetPop(); + sigVec[i] = secVec[i].Sign(m); + } + for (int i = 1; i < n; i++) { + secVec[0].Add(secVec[i]); + assert("verify pop", pubVec[i].VerifyPop(popVec[i])); + pubVec[0].Add(pubVec[i]); + sigVec[0].Add(sigVec[i]); + } + assert("aggregate sec", secVec[0].Sign(m).IsEqual(sigVec[0])); + assert("aggregate", pubVec[0].Verify(sigVec[0], m)); + } static void Main(string[] args) { try { int[] curveTypeTbl = { BN254, BLS12_381 }; @@ -135,6 +158,7 @@ namespace mcl TestPublicKey(); TestSign(); TestSharing(); + TestAggregate(); if (err == 0) { Console.WriteLine("all tests succeed"); } else { -- cgit v1.2.3