-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashpoint.go
44 lines (36 loc) · 811 Bytes
/
hashpoint.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
package bls
import (
"math/big"
"github.com/SickleZhang/bls/bn256"
"golang.org/x/crypto/sha3"
)
type HashPoint struct {
val bn256.G1
}
func (hpt *HashPoint) Sum(msg []byte) *HashPoint {
h := sha3.Sum256(msg)
k := new(big.Int).SetBytes(h[:])
hpt.val.ScalarBaseMult(k)
return hpt
}
func (hpt *HashPoint) Aggregate(hpts ...*HashPoint) *HashPoint {
hpt.val.Zero()
for _, hptI := range hpts {
hpt.val.Add(&hpt.val, &hptI.val)
}
return hpt
}
func (hpt *HashPoint) SumAggregate(msgs ...[]byte) *HashPoint {
hps := make([]*HashPoint, len(msgs))
for i, msg := range msgs {
hps[i] = new(HashPoint).Sum(msg)
}
hpt.Aggregate(hps...)
return hpt
}
func (hp *HashPoint) Marshal() []byte {
return hp.val.Marshal()
}
func (hp *HashPoint) Unmarshal(in []byte) error {
return hp.val.Unmarshal(in)
}