Closed zsp042 closed 5 years ago
package main
import (
"crypto/rand"
"fmt"
"github.com/phoreproject/bls"
)
func main() {
alicePrivateKey, err := bls.RandFR(rand.Reader)
if err != nil {
panic(err)
}
alicePublicKey := bls.G1AffineOne.MulFR(alicePrivateKey.ToRepr())
bobPrivateKey, err := bls.RandFR(rand.Reader)
if err != nil {
panic(err)
}
bobPublicKey := bls.G1AffineOne.MulFR(bobPrivateKey.ToRepr())
s1 := bobPublicKey.MulFR(alicePrivateKey.ToRepr()).ToAffine()
s2 := alicePublicKey.MulFR(bobPrivateKey.ToRepr()).ToAffine()
if !s1.Equals(s2) {
panic("shared secret should be the same")
}
fmt.Printf("shared secret: %s\n", s1)
}
I think that should work, but you should compare it with other implementations and probably not use it in production.
thanks
I am an application programmer, not very familiar with encryption algorithms. I want to negotiate the key based on ECDH, but I don't know how to implement it based on BLS.
Is there a easy understand example code how to implement ECDH on bls g1 ?
just like this https://github.com/andreacorbellini/ecc/blob/master/scripts/ecdhe.py