aboutsummaryrefslogtreecommitdiffstats
path: root/ffi/cs/bls256_test.cs
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-05-16 07:57:20 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-05-16 07:57:20 +0800
commitd4dc458f2e4b11c942f9ebe9b7edd54e3b230641 (patch)
tree909ce5982fb165e9e862ba6787f4f82eb0e5477e /ffi/cs/bls256_test.cs
parent76b656ee3c85bfc9b30a26f1a565d5a4919bcc37 (diff)
downloaddexon-bls-d4dc458f2e4b11c942f9ebe9b7edd54e3b230641.tar
dexon-bls-d4dc458f2e4b11c942f9ebe9b7edd54e3b230641.tar.gz
dexon-bls-d4dc458f2e4b11c942f9ebe9b7edd54e3b230641.tar.bz2
dexon-bls-d4dc458f2e4b11c942f9ebe9b7edd54e3b230641.tar.lz
dexon-bls-d4dc458f2e4b11c942f9ebe9b7edd54e3b230641.tar.xz
dexon-bls-d4dc458f2e4b11c942f9ebe9b7edd54e3b230641.tar.zst
dexon-bls-d4dc458f2e4b11c942f9ebe9b7edd54e3b230641.zip
add sample of C# binding
Diffstat (limited to 'ffi/cs/bls256_test.cs')
-rw-r--r--ffi/cs/bls256_test.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/ffi/cs/bls256_test.cs b/ffi/cs/bls256_test.cs
index 5c358fe..aff7a44 100644
--- a/ffi/cs/bls256_test.cs
+++ b/ffi/cs/bls256_test.cs
@@ -39,12 +39,85 @@ namespace mcl {
Console.WriteLine("sec.Init={0}", sec);
}
}
+ static void TestPublicKey()
+ {
+ Console.WriteLine("TestPublicKey");
+ SecretKey sec = new SecretKey();
+ sec.Init();
+ PublicKey pub = sec.GetPublicKey();
+ String s = pub.ToString();
+ Console.WriteLine("pub={0}", s);
+ PublicKey pub2 = new PublicKey();
+ pub2.SetStr(s);
+ assert("pub.SetStr", pub.IsSame(pub2));
+ }
+ static void TestSign()
+ {
+ Console.WriteLine("TestSign");
+ SecretKey sec = new SecretKey();
+ sec.Init();
+ PublicKey pub = sec.GetPublicKey();
+ String m = "abc";
+ Sign s = sec.Sign(m);
+ assert("verify", s.Verify(pub, m));
+ assert("not verify", !s.Verify(pub, m + "a"));
+ }
+ static void TestSharing()
+ {
+ Console.WriteLine("TestSharing");
+ int k = 5;
+ SecretKey[] msk = new SecretKey[k];
+ PublicKey[] mpk = new PublicKey[k];
+ // make master secretkey
+ for (int i = 0; i < k; i++) {
+ msk[i].Init();
+ mpk[i] = msk[i].GetPublicKey();
+ }
+ int n = 30;
+ Id[] ids = new Id[n];
+ SecretKey[] secs = new SecretKey[n];
+ PublicKey[] pubs = new PublicKey[n];
+ for (int i = 0; i < n; i++) {
+ ids[i].SetInt(i * i + 123);
+ secs[i] = ShareSecretKey(msk, ids[i]);
+ pubs[i] = SharePublicKey(mpk, ids[i]);
+ assert("share publicKey", secs[i].GetPublicKey().IsSame(pubs[i]));
+ }
+ string m = "doremi";
+ for (int i = 0; i < n; i++) {
+ Sign sign = secs[i].Sign(m);
+ assert("sign.Verify", sign.Verify(pubs[i], m));
+ }
+ {
+ int[] idxTbl = { 0, 2, 5, 8, 10 };
+ assert("idxTbl.Length=k", idxTbl.Length == k);
+ Id[] subIds = new Id[k];
+ SecretKey[] subSecs = new SecretKey[k];
+ PublicKey[] subPubs = new PublicKey[k];
+ Sign[] subSigns = new Sign[k];
+ for (int i = 0; i < k; i++) {
+ int idx = idxTbl[i];
+ subIds[i] = ids[idx];
+ subSecs[i] = secs[idx];
+ subPubs[i] = pubs[idx];
+ subSigns[i] = secs[idx].Sign(m);
+ }
+ SecretKey sec = RecoverSecretKey(subSecs, subIds);
+ PublicKey pub = RecoverPublicKey(subPubs, subIds);
+ assert("check pub", pub.IsSame(sec.GetPublicKey()));
+ Sign sign = RecoverSign(subSigns, subIds);
+ assert("sign.verify", sign.Verify(pub, m));
+ }
+ }
static void Main(string[] args)
{
try {
Init();
TestId();
TestSecretKey();
+ TestPublicKey();
+ TestSign();
+ TestSharing();
if (err == 0) {
Console.WriteLine("all tests succeed");
} else {