-
Notifications
You must be signed in to change notification settings - Fork 1
/
private_key.go
49 lines (43 loc) · 918 Bytes
/
private_key.go
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
package tpke
import (
bls "github.com/kilic/bls12-381"
)
type PrivateKey struct {
fr *bls.Fr
}
func NewPrivateKey(secretShares []*bls.Fr) *PrivateKey {
fr := bls.NewFr().Set(secretShares[0])
// Add up fi
for i := 1; i < len(secretShares); i++ {
fr.Add(fr, secretShares[i])
}
return &PrivateKey{
fr: fr,
}
}
func (sk *PrivateKey) GetPublicKey() *PublicKey {
g1 := bls.NewG1()
pg1 := g1.New()
return &PublicKey{
pg1: g1.MulScalar(pg1, &bls.G1One, sk.fr),
}
}
func (sk *PrivateKey) DecryptShare(ct *CipherText) *DecryptionShare {
// S=R1*sk
g1 := bls.NewG1()
pg1 := g1.New().Set(ct.bigR)
g1.MulScalar(pg1, pg1, sk.fr)
return &DecryptionShare{
pg1: pg1,
}
}
func (sk *PrivateKey) SignShare(msg []byte) *SignatureShare {
// S=H(msg)*sk
g2 := bls.NewG2()
g2Hash, _ := g2.HashToCurve(msg, Domain)
sig := g2.New()
g2.MulScalar(sig, g2Hash, sk.fr)
return &SignatureShare{
pg2: sig,
}
}