aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/bls/ffi/cs/readme.md
blob: 2b7191871fc9dc3fb1ca60d1d8948aac5d8691e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# C# binding of BLS threshold signature library

# Installation Requirements

* Visual Studio 2017 or later
* C# 7.2 or later
* .NET Framework 4.5.2 or later

# How to build

```
md work
cd work
git clone https://github.com/herumi/cybozulib_ext
git clone https://github.com/herumi/mcl
git clone https://github.com/herumi/bls
cd bls
mklib dll
```
bls/bin/*.dll are created

# 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

## 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
http://opensource.org/licenses/BSD-3-Clause

# Author

(C)2019 MITSUNARI Shigeo(herumi@nifty.com) All rights reserved.