Merge pull request #1555 from filecoin-project/feat/hashverify

Use HashVerify
This commit is contained in:
Jakub Sztandera 2020-06-15 17:47:42 +02:00 committed by GitHub
commit c98972ab23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 16 deletions

View File

@ -8,7 +8,6 @@ import (
"os"
"sort"
"strings"
"sync"
"time"
"github.com/Gurpartap/async"
@ -949,23 +948,14 @@ func (syncer *Syncer) verifyBlsAggregate(ctx context.Context, sig *crypto.Signat
trace.Int64Attribute("msgCount", int64(len(msgs))),
)
var wg sync.WaitGroup
digests := make([]bls.Digest, len(msgs))
for i := 0; i < 10; i++ {
wg.Add(1)
go func(w int) {
defer wg.Done()
for j := 0; (j*10)+w < len(msgs); j++ {
digests[j*10+w] = bls.Hash(bls.Message(msgs[j*10+w].Bytes()))
}
}(i)
bmsgs := make([]bls.Message, len(msgs))
for i, m := range msgs {
bmsgs[i] = m.Bytes()
}
wg.Wait()
var bsig bls.Signature
copy(bsig[:], sig.Data)
if !bls.Verify(&bsig, digests, pubks) {
if !bls.HashVerify(&bsig, bmsgs, pubks) {
return xerrors.New("bls aggregate signature failed to verify")
}

View File

@ -33,16 +33,16 @@ func (blsSigner) Sign(p []byte, msg []byte) ([]byte, error) {
}
func (blsSigner) Verify(sig []byte, a address.Address, msg []byte) error {
digests := []ffi.Digest{ffi.Hash(ffi.Message(msg))}
var pubk ffi.PublicKey
copy(pubk[:], a.Payload())
pubkeys := []ffi.PublicKey{pubk}
digests := []ffi.Message{msg}
var s ffi.Signature
copy(s[:], sig)
if !ffi.Verify(&s, digests, pubkeys) {
if !ffi.HashVerify(&s, digests, pubkeys) {
return fmt.Errorf("bls signature failed to verify")
}