pull/297/head
Rongjian Lan 6 years ago
parent 9a95aa6a71
commit 37e3c696e3
  1. 60
      test/crypto/bls/main.go

@ -1,39 +1,39 @@
package main package main
import ( import (
"github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/bls/ffi/go/bls"
"log" "log"
"time" "time"
) )
func main() { func main() {
m := "message to sign" m := "message to sign"
var aggSig *bls.Sign var aggSig *bls.Sign
var aggPub *bls.PublicKey var aggPub *bls.PublicKey
startTime := time.Now() startTime := time.Now()
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
bls.Init(bls.BLS12_381) bls.Init(bls.BLS12_381)
var sec bls.SecretKey var sec bls.SecretKey
sec.SetByCSPRNG() sec.SetByCSPRNG()
if i == 0 { if i == 0 {
aggSig = sec.Sign(m) aggSig = sec.Sign(m)
aggPub = sec.GetPublicKey() aggPub = sec.GetPublicKey()
} else { } else {
aggSig.Add(sec.Sign(m)) aggSig.Add(sec.Sign(m))
aggPub.Add(sec.GetPublicKey()) aggPub.Add(sec.GetPublicKey())
} }
} }
endTime := time.Now() endTime := time.Now()
log.Printf("Time required to sign 1000 messages and aggregate 1000 pub keys and signatures: %f seconds", endTime.Sub(startTime).Seconds()) log.Printf("Time required to sign 1000 messages and aggregate 1000 pub keys and signatures: %f seconds", endTime.Sub(startTime).Seconds())
log.Printf("Aggregate Signature: 0x%x", aggSig.GetHexString()) log.Printf("Aggregate Signature: 0x%x", aggSig.GetHexString())
log.Printf("Aggregate Public Key: 0x%x", aggPub.GetHexString()) log.Printf("Aggregate Public Key: 0x%x", aggPub.GetHexString())
startTime = time.Now() startTime = time.Now()
if !aggSig.Verify(aggPub, m) { if !aggSig.Verify(aggPub, m) {
log.Fatal("Aggregate Signature Does Not Verify") log.Fatal("Aggregate Signature Does Not Verify")
} }
log.Printf("Aggregate Signature Verifies Correctly!") log.Printf("Aggregate Signature Verifies Correctly!")
endTime = time.Now() endTime = time.Now()
log.Printf("Time required to verify aggregate sig: %f seconds", endTime.Sub(startTime).Seconds()) log.Printf("Time required to verify aggregate sig: %f seconds", endTime.Sub(startTime).Seconds())
} }

Loading…
Cancel
Save