Example #1
0
func TestNewED25519Signature(t *testing.T) {
	testData := primitives.Sha([]byte("sig first half  one")).Bytes()
	priv := testHelper.NewPrivKey(0)

	sig := NewED25519Signature(priv, testData)

	pub := testHelper.PrivateKeyToEDPub(priv)
	pub2 := [32]byte{}
	copy(pub2[:], pub)

	s := sig.Signature
	valid := ed25519.VerifyCanonical(&pub2, testData, &s)
	if valid == false {
		t.Errorf("Signature is invalid - %v", valid)
	}

	priv2 := [64]byte{}
	copy(priv2[:], append(priv, pub...)[:])

	sig2 := ed25519.Sign(&priv2, testData)

	valid = ed25519.VerifyCanonical(&pub2, testData, sig2)
	if valid == false {
		t.Errorf("Test signature is invalid - %v", valid)
	}
}
func TestCheckSig(t *testing.T) {
	priv := testHelper.NewPrivKey(1)
	msg := []byte("Hello!")
	pub := testHelper.PrivateKeyToEDPub(priv)

	pre := []byte{0x01}
	pre = append(pre, pub...)
	id := primitives.Shad(pre)

	sig := primitives.Sign(priv, msg)

	if CheckSig(id, pub, msg, sig) == false {
		t.Error("Valid signature not valid")
	}

	sig[0] += 1

	if CheckSig(id, pub, msg, sig) == true {
		t.Error("Invalid signature valid")
	}
}