The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/test/crypto/bls/main.go

57 lines
1.6 KiB

package main
import (
6 years ago
"crypto/ecdsa"
"crypto/rand"
"encoding/hex"
6 years ago
"log"
"time"
6 years ago
"github.com/ethereum/go-ethereum/crypto"
"github.com/harmony-one/bls/ffi/go/bls"
)
func init() {
bls.Init(bls.BLS12_381)
}
func main() {
6 years ago
m := "message to sign"
var aggSig *bls.Sign
var aggPub *bls.PublicKey
6 years ago
startTime := time.Now()
for i := 0; i < 1000; i++ {
var sec bls.SecretKey
sec.SetByCSPRNG()
6 years ago
if i == 0 {
testECKey, _ := ecdsa.GenerateKey(crypto.S256(), rand.Reader)
log.Printf("Secret Key: 0x%s", sec.GetHexString())
log.Printf("Secret Key: 0x%s", hex.EncodeToString(sec.GetLittleEndian()))
log.Printf("Secret Key Length: %d", len(sec.GetLittleEndian()))
log.Printf("Secret Key: 0x%s", hex.EncodeToString(testECKey.D.Bytes()))
log.Printf("Secret Key Length: %d", len(testECKey.D.Bytes()))
}
6 years ago
if i == 0 {
aggSig = sec.Sign(m)
aggPub = sec.GetPublicKey()
} else {
aggSig.Add(sec.Sign(m))
aggPub.Add(sec.GetPublicKey())
}
}
endTime := time.Now()
log.Printf("Time required to sign 1000 messages and aggregate 1000 pub keys and signatures: %f seconds", endTime.Sub(startTime).Seconds())
6 years ago
log.Printf("Aggregate Signature: 0x%s, length: %d", aggSig.GetHexString(), len(aggSig.Serialize()))
log.Printf("Aggregate Public Key: 0x%s, length: %d", aggPub.GetHexString(), len(aggPub.Serialize()))
6 years ago
startTime = time.Now()
if !aggSig.Verify(aggPub, m) {
log.Fatal("Aggregate Signature Does Not Verify")
}
log.Printf("Aggregate Signature Verifies Correctly!")
endTime = time.Now()
log.Printf("Time required to verify aggregate sig: %f seconds", endTime.Sub(startTime).Seconds())
}