コード例 #1
0
ファイル: signature_test.go プロジェクト: jjdevbiz/factomd
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)
	}
}
コード例 #2
0
func TestSignatureBlock(t *testing.T) {
	priv := testHelper.NewPrivKey(0)
	testData, err := hex.DecodeString("00112233445566778899")
	if err != nil {
		t.Error(err)
	}

	sig := NewSingleSignatureBlock(priv, testData)

	rcd := testHelper.NewFactoidRCDAddress(0)
	pub := rcd.(*RCD_1).GetPublicKey()
	pub2 := [32]byte{}
	copy(pub2[:], pub)

	s := sig.Signatures[0].(*FactoidSignature).Signature
	valid := ed25519.VerifyCanonical(&pub2, testData, &s)
	if valid == false {
		t.Error("Invalid signature")
	}
}
コード例 #3
0
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")
	}
}