예제 #1
0
// Sig is signed message, msg is raw message
func CheckSig(idKey interfaces.IHash, pub []byte, msg []byte, sig []byte) bool {
	var pubFix [32]byte
	var sigFix [64]byte

	copy(pubFix[:], pub[:32])
	copy(sigFix[:], sig[:64])

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

	if id.IsSameAs(idKey) {
		return ed.VerifyCanonical(&pubFix, msg, &sigFix)
	} else {
		return false
	}
}
예제 #2
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")
	}
}
예제 #3
0
파일: rcd1.go 프로젝트: jjdevbiz/factomd
func (w RCD_1) GetAddress() (interfaces.IAddress, error) {
	data := []byte{1}
	data = append(data, w.PublicKey[:]...)
	return CreateAddress(primitives.Shad(data)), nil
}