Example #1
0
// TestCosiSignature test if the signature generation is correct,i.e. if we
// can verify the final signature.
func TestCosiSignature(t *testing.T) {
	msg := []byte("Hello World Cosi")
	nb := 2
	cosis := genCosis(nb)
	genFinalCosi(cosis, msg)
	root, children := cosis[0], cosis[1:]
	var publics []abstract.Point
	// add root public key
	rootPublic := testSuite.Point().Mul(nil, root.private)
	publics = append(publics, rootPublic)
	for _, ch := range children {
		// add children public key
		public := testSuite.Point().Mul(nil, ch.private)
		publics = append(publics, public)
	}
	sig := root.Signature()

	if err := VerifySignature(testSuite, publics, msg, sig); err != nil {
		t.Fatal("Error veriying:", err)
	}
	var Ed25519Publics []xEd25519.PublicKey
	for _, p := range publics {
		buff, err := p.MarshalBinary()
		assert.Nil(t, err)
		Ed25519Publics = append(Ed25519Publics, xEd25519.PublicKey(buff))
	}

	if !cosi.Verify(Ed25519Publics, nil, msg, sig) {
		t.Error("github.com/bforg/golang-x-crypto/ed25519/cosi fork can't verify")
	}
}
Example #2
0
func TestCosiSignatureWithMask(t *testing.T) {
	msg := []byte("Hello World Cosi")
	nb := 5
	fail := 2
	cosis, publics := genCosisFailing(nb, fail)
	genFinalCosi(cosis, msg)
	root := cosis[0]
	sig := root.Signature()

	if err := VerifySignature(testSuite, publics, msg, sig); err != nil {
		t.Fatal("Error veriying:", err)
	}

	var Ed25519Publics []xEd25519.PublicKey
	for _, p := range publics {
		buff, err := p.MarshalBinary()
		assert.Nil(t, err)
		Ed25519Publics = append(Ed25519Publics, xEd25519.PublicKey(buff))
	}

	if !cosi.Verify(Ed25519Publics, cosi.ThresholdPolicy(3), msg, sig) {
		t.Error("github.com/bforg/golang-x-crypto/ed25519/cosi fork can't verify")
	}
	if cosi.Verify(Ed25519Publics, cosi.ThresholdPolicy(4), msg, sig) {
		t.Error("github.com/bforg/golang-x-crypto/ed25519/cosi fork can't verify")
	}

}