aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2019-04-01 11:55:42 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2019-04-01 11:55:42 +0800
commit20cfb8c0f35f5e74fcdb3522baf80b2edf734660 (patch)
treebf4540fcd7d7de2bba669ba157dfb2e47f0df802
parent38044ada41d699d43d72d6ddd54ed2f9de2ab583 (diff)
downloaddexon-bls-20cfb8c0f35f5e74fcdb3522baf80b2edf734660.tar
dexon-bls-20cfb8c0f35f5e74fcdb3522baf80b2edf734660.tar.gz
dexon-bls-20cfb8c0f35f5e74fcdb3522baf80b2edf734660.tar.bz2
dexon-bls-20cfb8c0f35f5e74fcdb3522baf80b2edf734660.tar.lz
dexon-bls-20cfb8c0f35f5e74fcdb3522baf80b2edf734660.tar.xz
dexon-bls-20cfb8c0f35f5e74fcdb3522baf80b2edf734660.tar.zst
dexon-bls-20cfb8c0f35f5e74fcdb3522baf80b2edf734660.zip
[cs] update doc and add Add() methods
-rw-r--r--ffi/cs/bls.cs42
-rw-r--r--ffi/cs/bls_test.cs30
-rw-r--r--ffi/cs/readme-ja.md98
-rw-r--r--ffi/cs/readme.md107
4 files changed, 254 insertions, 23 deletions
diff --git a/ffi/cs/bls.cs b/ffi/cs/bls.cs
index 0afb9ca..6bcaf07 100644
--- a/ffi/cs/bls.cs
+++ b/ffi/cs/bls.cs
@@ -213,27 +213,32 @@ namespace mcl
}
}
public PublicKey GetPublicKey() {
- PublicKey pub = new PublicKey();
+ PublicKey pub;
blsGetPublicKey(ref pub, this);
return pub;
}
- public Signature Signature(string m) {
- Signature Signature = new Signature();
- blsSign(ref Signature, this, m, (ulong)m.Length);
- return Signature;
+ public Signature Sign(string m) {
+ Signature sig;
+ blsSign(ref sig, this, m, (ulong)m.Length);
+ return sig;
+ }
+ public Signature GetPop() {
+ Signature sig;
+ blsGetPop(ref sig, this);
+ return sig;
}
}
// secretKey = sum_{i=0}^{msk.Length - 1} msk[i] * id^i
public static SecretKey ShareSecretKey(in SecretKey[] msk, in Id id) {
- SecretKey sec = new SecretKey();
+ SecretKey sec;
if (blsSecretKeyShare(ref sec, msk[0], (ulong)msk.Length, id) != 0) {
throw new ArgumentException("GetSecretKeyForId:" + id.ToString());
}
return sec;
}
- public static SecretKey RecoverSecretKey(in SecretKey[] secs, in Id[] ids) {
- SecretKey sec = new SecretKey();
- if (blsSecretKeyRecover(ref sec, secs[0], ids[0], (ulong)secs.Length) != 0) {
+ public static SecretKey RecoverSecretKey(in SecretKey[] secVec, in Id[] idVec) {
+ SecretKey sec;
+ if (blsSecretKeyRecover(ref sec, secVec[0], idVec[0], (ulong)secVec.Length) != 0) {
throw new ArgumentException("Recover");
}
return sec;
@@ -278,18 +283,21 @@ namespace mcl
public bool Verify(in Signature sig, string m) {
return blsVerify(sig, this, m, (ulong)m.Length) == 1;
}
+ public bool VerifyPop(in Signature pop) {
+ return blsVerifyPop(pop, this) == 1;
+ }
}
// publicKey = sum_{i=0}^{mpk.Length - 1} mpk[i] * id^i
public static PublicKey SharePublicKey(in PublicKey[] mpk, in Id id) {
- PublicKey pub = new PublicKey();
+ PublicKey pub;
if (blsPublicKeyShare(ref pub, mpk[0], (ulong)mpk.Length, id) != 0) {
throw new ArgumentException("GetPublicKeyForId:" + id.ToString());
}
return pub;
}
- public static PublicKey RecoverPublicKey(in PublicKey[] pubs, in Id[] ids) {
- PublicKey pub = new PublicKey();
- if (blsPublicKeyRecover(ref pub, pubs[0], ids[0], (ulong)pubs.Length) != 0) {
+ public static PublicKey RecoverPublicKey(in PublicKey[] pubVec, in Id[] idVec) {
+ PublicKey pub;
+ if (blsPublicKeyRecover(ref pub, pubVec[0], idVec[0], (ulong)pubVec.Length) != 0) {
throw new ArgumentException("Recover");
}
return pub;
@@ -332,12 +340,12 @@ namespace mcl
blsSignatureAdd(ref this, rhs);
}
}
- public static Signature RecoverSign(in Signature[] signs, in Id[] ids) {
- Signature Signature = new Signature();
- if (blsSignatureRecover(ref Signature, signs[0], ids[0], (ulong)signs.Length) != 0) {
+ public static Signature RecoverSign(in Signature[] sigVec, in Id[] idVec) {
+ Signature sig;
+ if (blsSignatureRecover(ref sig, sigVec[0], idVec[0], (ulong)sigVec.Length) != 0) {
throw new ArgumentException("Recover");
}
- return Signature;
+ return sig;
}
}
}
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 {
diff --git a/ffi/cs/readme-ja.md b/ffi/cs/readme-ja.md
index 73c4a3e..784db53 100644
--- a/ffi/cs/readme-ja.md
+++ b/ffi/cs/readme-ja.md
@@ -26,6 +26,104 @@ bls/ffi/cs/bls.slnを開いて実行する。
* 注意 bls256.slnは古いため使わないでください。
+# クラスとAPI
+
+## API
+
+* `Init(int curveType = BN254);`
+ * ライブラリを曲線curveTypeで初期化する。
+ * curveType = BN254 or BLS12_381
+* `SecretKey ShareSecretKey(in SecretKey[] msk, in Id id);`
+ * マスター秘密鍵の列mskに対するidの秘密鍵を生成(共有)する。
+* `SecretKey RecoverSecretKey(in SecretKey[] secVec, in Id[] idVec);`
+ * 秘密鍵secVecとID idVecのペアから秘密鍵を復元する。
+* `PublicKey SharePublicKey(in PublicKey[] mpk, in Id id);`
+ * マスター公開鍵の列mpkに対するidの公開鍵を生成(共有)する。
+* `PublicKey RecoverPublicKey(in PublicKey[] pubVec, in Id[] idVec);`
+ * 公開鍵pubVecとID idVecのペアから公開鍵を復元する。
+* `Signature RecoverSign(in Signature[] sigVec, in Id[] idVec);`
+ * 署名sigVecとID idVecのペアから署名を復元する。
+
+## Id
+
+識別子クラス
+
+* `byte[] Serialize();`
+ * Idをシリアライズする。
+* `void Deserialize(byte[] buf);`
+ * バイト列bufからIdをデシリアライズする。
+* `bool IsEqual(in Id rhs);`
+ * 同値判定。
+* `void SetDecStr(string s);`
+ * 10進数文字列を設定する。
+* `void SetHexStr(string s);`
+ * 16進数文字列を設定する。
+* `void SetInt(int x);`
+ * 整数xを設定する。
+* `string GetDecStr();`
+ * 10進数表記を取得する。
+* `string GetHexStr();`
+ * 16進数表記を取得する。
+
+## SecretKey
+
+* `byte[] Serialize();`
+ * Idをシリアライズする。
+* `void Deserialize(byte[] buf);`
+ * バイト列bufからSecretKeyをデシリアライズする。
+* `bool IsEqual(in SecretKey rhs);`
+ * 同値判定。
+* `void SetHexStr(string s);`
+ * 16進数文字列を設定する。
+* `string GetHexStr();`
+ * 16進数表記を取得する。
+* `void Add(in SecretKey rhs);`
+ * 秘密鍵rhsを加算する。
+* `void SetByCSPRNG();`
+ * 暗号学的乱数で設定する。
+* `void SetHashOf(string s);`
+ * 文字列sのハッシュ値を設定する。
+* `PublicKey GetPublicKey();`
+ * 対応する公開鍵を取得する。
+* `Signature Sign(string m);`
+ * 文字列mの署名を生成する。
+* `Signature GetPop();`
+ * 自身の秘密鍵による署名(Proof Of Posession)を生成する。
+
+## PublicKey
+
+* `byte[] Serialize();`
+ * PublicKeyをシリアライズする。
+* `void Deserialize(byte[] buf);`
+ * バイト列bufからPublicKeyをデシリアライズする。
+* `bool IsEqual(in PublicKey rhs);`
+ * 同値判定。
+* `void Add(in PublicKey rhs);`
+ * 公開鍵rhsを加算する。
+* `void SetHexStr(string s);`
+ * 16進数文字列を設定する。
+* `string GetHexStr();`
+ * 16進数表記を取得する。
+* `bool Verify(in Signature sig, string m);`
+ * 文字列mに対する署名sigの正当性を確認する。
+* `bool VerifyPop(in Signature pop);`
+ * PoPの正当性を確認する。
+
+## Signature
+
+* `byte[] Serialize();`
+ * Signatureをシリアライズする。
+* `void Deserialize(byte[] buf);`
+ * バイト列bufからSignatureをデシリアライズする。
+* `bool IsEqual(in Signature rhs);`
+ * 同値判定。
+* `void Add(in Signature rhs);`
+ * 署名rhsを加算する。
+* `void SetHexStr(string s);`
+ * 16進数文字列を設定する。
+* `string GetHexStr();`
+ * 16進数表記を取得する。
+
# ライセンス
modified new BSD License
diff --git a/ffi/cs/readme.md b/ffi/cs/readme.md
index 70e87c1..456dc0c 100644
--- a/ffi/cs/readme.md
+++ b/ffi/cs/readme.md
@@ -1,4 +1,4 @@
-# BLS threshold signature for C#
+# C# binding of BLS threshold signature library
# Installation Requirements
@@ -18,8 +18,109 @@ cd bls
mklib dll
```
-# Remark
-bls256 is obsolete. Please use bls.sln.
+# How to build a sample
+
+Open bls/ffi/cs/bls.sln and exec it.
+
+* Remark. bls256 is obsolete. Please use bls.sln.
+
+# class and API
+
+## API
+
+* `Init(int curveType = BN254);`
+ * initialize this library with a curve `curveType`.
+ * curveType = BN254 or BLS12_381
+* `SecretKey ShareSecretKey(in SecretKey[] msk, in Id id);`
+ * generate the shared secret key from a sequence of master secret keys msk and Id.
+* `SecretKey RecoverSecretKey(in SecretKey[] secVec, in Id[] idVec);`
+ * recover the secret key from a sequence of secret keys secVec and idVec.
+* `PublicKey SharePublicKey(in PublicKey[] mpk, in Id id);`
+ * generate the shared public key from a sequence of master public keys mpk and Id.
+* `PublicKey RecoverPublicKey(in PublicKey[] pubVec, in Id[] idVec);`
+ * recover the public key from a sequence of public keys pubVec and idVec.
+* `Signature RecoverSign(in Signature[] sigVec, in Id[] idVec);`
+ * recover the signature from a sequence of signatures siVec and idVec.
+
+## Id
+
+Identifier class
+
+* `byte[] Serialize();`
+ * serialize Id
+* `void Deserialize(byte[] buf);`
+ * deserialize from byte[] buf
+* `bool IsEqual(in Id rhs);`
+ * equality
+* `void SetDecStr(string s);`
+ * set by a decimal string s
+* `void SetHexStr(string s);`
+ * set by a hexadecimal string s
+* `void SetInt(int x);`
+ * set an integer x
+* `string GetDecStr();`
+ * get a decimal string
+* `string GetHexStr();`
+ * get a hexadecimal string
+
+## SecretKey
+
+* `byte[] Serialize();`
+ * serialize SecretKey
+* `void Deserialize(byte[] buf);`
+ * deserialize from byte[] buf
+* `bool IsEqual(in SecretKey rhs);`
+ * equality
+* `string GetDecStr();`
+ * get a decimal string
+* `string GetHexStr();`
+ * get a hexadecimal string
+* `void Add(in SecretKey rhs);`
+ * add a secret key rhs
+* `void SetByCSPRNG();`
+ * set a secret key by cryptographically secure pseudo random number generator
+* `void SetHashOf(string s);`
+ * set a secret key by a hash of string s
+* `PublicKey GetPublicKey();`
+ * get the corresponding public key to a secret key
+* `Signature Sign(string m);`
+ * sign a string m
+* `Signature GetPop();`
+ * get a PoP (Proof Of Posession) for a secret key
+
+## PublicKey
+
+* `byte[] Serialize();`
+ * serialize PublicKey
+* `void Deserialize(byte[] buf);`
+ * deserialize from byte[] buf
+* `bool IsEqual(in PublicKey rhs);`
+ * equality
+* `void Add(in PublicKey rhs);`
+ * add a public key rhs
+* `string GetDecStr();`
+ * get a decimal string
+* `string GetHexStr();`
+ * get a hexadecimal string
+* `bool Verify(in Signature sig, string m);`
+ * verify the validness of the sig with m
+* `bool VerifyPop(in Signature pop);`
+ * verify the validness of PoP
+
+## Signature
+
+* `byte[] Serialize();`
+ * serialize Signature
+* `void Deserialize(byte[] buf);`
+ * deserialize from byte[] buf
+* `bool IsEqual(in Signature rhs);`
+ * equality
+* `void Add(in Signature rhs);`
+ * add a signature key rhs
+* `string GetDecStr();`
+ * get a decimal string
+* `string GetHexStr();`
+ * get a hexadecimal string
# License