diff options
Diffstat (limited to 'ffi')
-rw-r--r-- | ffi/cs/bls_test.cs | 17 | ||||
-rw-r--r-- | ffi/cs/readme-ja.md | 54 | ||||
-rw-r--r-- | ffi/cs/readme.md | 53 |
3 files changed, 116 insertions, 8 deletions
diff --git a/ffi/cs/bls_test.cs b/ffi/cs/bls_test.cs index af4f761..2eb451b 100644 --- a/ffi/cs/bls_test.cs +++ b/ffi/cs/bls_test.cs @@ -63,7 +63,7 @@ namespace mcl } static void TestSign() { Console.WriteLine("TestSign"); - SecretKey sec = new SecretKey(); + SecretKey sec; sec.SetByCSPRNG(); PublicKey pub = sec.GetPublicKey(); string m = "abc"; @@ -138,14 +138,17 @@ namespace mcl popVec[i] = secVec[i].GetPop(); sigVec[i] = secVec[i].Sign(m); } - for (int i = 1; i < n; i++) { - secVec[0].Add(secVec[i]); + SecretKey secAgg; + PublicKey pubAgg; + Signature sigAgg; + for (int i = 0; i < n; i++) { + secAgg.Add(secVec[i]); assert("verify pop", pubVec[i].VerifyPop(popVec[i])); - pubVec[0].Add(pubVec[i]); - sigVec[0].Add(sigVec[i]); + pubAgg.Add(pubVec[i]); + sigAgg.Add(sigVec[i]); } - assert("aggregate sec", secVec[0].Sign(m).IsEqual(sigVec[0])); - assert("aggregate", pubVec[0].Verify(sigVec[0], m)); + assert("aggregate sec", secAgg.Sign(m).IsEqual(sigAgg)); + assert("aggregate", pubAgg.Verify(sigAgg, m)); } static void Main(string[] args) { try { diff --git a/ffi/cs/readme-ja.md b/ffi/cs/readme-ja.md index 784db53..f0fa114 100644 --- a/ffi/cs/readme-ja.md +++ b/ffi/cs/readme-ja.md @@ -18,7 +18,7 @@ git clone https://github.com/herumi/bls cd bls
mklib dll
```
-としてbls/binにDLLを作成する。
+`bls/bin/*.dll`が作成される。
# サンプルのビルド方法
@@ -124,6 +124,58 @@ bls/ffi/cs/bls.slnを開いて実行する。 * `string GetHexStr();`
* 16進数表記を取得する。
+## 使い方
+
+### 最小サンプル
+
+```
+using static BLS;
+
+Init(BN254); // ライブラリ初期化
+SecretKey sec;
+sec.SetByCSPRNG(); // 秘密鍵の初期化
+PublicKey pub = sec.GetPublicKey(); // 公開鍵の取得
+string m = "abc";
+Signature sig = sec.Sign(m); // 署名の作成
+if (pub.Verify(sig, m))) {
+ // 署名の確認
+}
+```
+
+### 集約署名
+```
+Init(BN254); // ライブラリ初期化
+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(); // 所有(PoP)の証明
+ sigVec[i] = secVec[i].Sign(m); // 署名
+}
+
+SecretKey secAgg;
+PublicKey pubAgg;
+Signature sigAgg;
+for (int i = 0; i < n; i++) {
+ // PoPの確認
+ if (pubVec[i].VerifyPop(popVec[i]))) {
+ // エラー
+ return;
+ }
+ pubAgg.Add(pubVec[i]); // 公開鍵の集約
+ sigAgg.Add(sigVec[i]); // 署名の集約
+}
+if (pubAgg.Verify(sigAgg, m)) {
+ // 署名の確認
+}
+```
+
# ライセンス
modified new BSD License
diff --git a/ffi/cs/readme.md b/ffi/cs/readme.md index 456dc0c..db604c9 100644 --- a/ffi/cs/readme.md +++ b/ffi/cs/readme.md @@ -17,6 +17,7 @@ git clone https://github.com/herumi/bls cd bls mklib dll ``` +bls/bin/*.dll are created # How to build a sample @@ -122,6 +123,58 @@ Identifier class * `string GetHexStr();` * get a hexadecimal string +## How to use + +### A minimum sample + +``` +using static BLS; + +Init(BN254); // init library +SecretKey sec; +sec.SetByCSPRNG(); // init secret key +PublicKey pub = sec.GetPublicKey(); // get public key +string m = "abc"; +Signature sig = sec.Sign(m); // create signature +if (pub.Verify(sig, m))) { + // signature is verified +} +``` + +### Aggregate signature +``` +Init(BN254); // init library +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(); // init secret key + pubVec[i] = secVec[i].GetPublicKey(); // get public key + popVec[i] = secVec[i].GetPop(); // get a proof of Possesion (PoP) + sigVec[i] = secVec[i].Sign(m); // create signature +} + +SecretKey secAgg; +PublicKey pubAgg; +Signature sigAgg; +for (int i = 0; i < n; i++) { + // verify PoP + if (pubVec[i].VerifyPop(popVec[i]))) { + // error + return; + } + pubAgg.Add(pubVec[i]); // aggregate public key + sigAgg.Add(sigVec[i]); // aggregate signature +} +if (pubAgg.Verify(sigAgg, m)) { + // aggregated signature is verified +} +``` + # License modified new BSD License |