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)
	}
}
Example #2
0
func (auth *Authority) VerifySignature(msg []byte, sig *[constants.SIGNATURE_LENGTH]byte) (bool, error) {
	//return true, nil // Testing
	var pub [32]byte
	tmp, err := auth.SigningKey.MarshalBinary()
	if err != nil {
		return false, err
	} else {
		copy(pub[:], tmp)
		valid := ed.VerifyCanonical(&pub, msg, sig)
		if !valid {
			for _, histKey := range auth.KeyHistory {
				histTemp, err := histKey.SigningKey.MarshalBinary()
				if err != nil {
					continue
				}
				copy(pub[:], histTemp)
				if ed.VerifyCanonical(&pub, msg, sig) {
					return true, nil
				}
			}
		} else {
			return true, nil
		}
	}
	return false, nil
}
Example #3
0
func (this *State) ExchangeRateAuthorityIsValid(e interfaces.IEBEntry) bool {

	// convert the conf quthority address into a
	authorityAddress := base58.Decode(this.ExchangeRateAuthorityAddress)
	ecPubPrefix := []byte{0x59, 0x2a}

	if !bytes.Equal(authorityAddress[:2], ecPubPrefix) {
		fmt.Errorf("Invalid Entry Credit Private Address")
		return false
	}

	pub := new([32]byte)
	copy(pub[:], authorityAddress[2:34])

	// in case verify can't handle empty public key
	if this.ExchangeRateAuthorityAddress == "" {
		return false
	}
	sig := new([64]byte)
	externalIds := e.ExternalIDs()

	// check for number of ext ids
	if len(externalIds) < 1 {
		return false
	}

	copy(sig[:], externalIds[0]) // First ext id needs to be the signature of the content

	if !ed.VerifyCanonical(pub, e.GetContent(), sig) {
		return false
	}

	return true
}
Example #4
0
func (c *CommitEntry) IsValid() bool {

	//double check the credits in the commit
	if c.Credits < 1 || c.Version != 0 {
		return false
	}
	return ed.VerifyCanonical((*[32]byte)(c.ECPubKey), c.CommitMsg(), (*[64]byte)(c.Sig))
}
Example #5
0
func (c *CommitChain) IsValid() bool {

	//double check the credits in the commit
	if c.Credits < 1 || c.Version != 0 {
		return false
	}

	return ed.VerifyCanonical(c.ECPubKey, c.CommitMsg(), c.Sig)
}
Example #6
0
func (id *Identity) VerifySignature(msg []byte, sig *[constants.SIGNATURE_LENGTH]byte) (bool, error) {
	//return true, nil // Testing
	var pub [32]byte
	tmp, err := id.SigningKey.MarshalBinary()
	if err != nil {
		return false, err
	} else {
		copy(pub[:], tmp)
		valid := ed.VerifyCanonical(&pub, msg, sig)
		if !valid {

		} else {
			return true, nil
		}
	}
	return false, nil
}
Example #7
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
	}
}
Example #8
0
func (w RCD_1) CheckSig(trans interfaces.ITransaction, sigblk interfaces.ISignatureBlock) bool {
	if sigblk == nil {
		return false
	}
	data, err := trans.MarshalBinarySig()
	if err != nil {
		return false
	}
	signature := sigblk.GetSignature(0)
	if signature == nil {
		return false
	}
	cryptosig := signature.GetSignature()
	if cryptosig == nil {
		return false
	}

	return ed25519.VerifyCanonical(&w.PublicKey, data, cryptosig)
}
Example #9
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")
	}
}
Example #10
0
func VerifySignature(data, publicKey, signature []byte) error {
	pub := [32]byte{}
	sig := [64]byte{}

	if len(publicKey) == 32 {
		copy(pub[:], publicKey[:])
	} else {
		return fmt.Errorf("Invalid public key length")
	}

	if len(signature) == 64 {
		copy(sig[:], signature[:])
	} else {
		return fmt.Errorf("Invalid signature length")
	}

	valid := ed25519.VerifyCanonical(&pub, data, &sig)
	if valid == false {
		return fmt.Errorf("Invalid signature")
	}
	return nil
}
Example #11
0
// Verify returns true iff sig is a valid signature of message by publicKey.
func Verify(publicKey *[ed25519.PublicKeySize]byte, message []byte, sig *[ed25519.SignatureSize]byte) bool {
	return ed25519.VerifyCanonical(publicKey, message, sig)
}
Example #12
0
func (k *PublicKey) Verify(msg []byte, sig *[ed25519.SignatureSize]byte) bool {
	return ed25519.VerifyCanonical((*[32]byte)(k), msg, sig)
}
Example #13
0
// Verify returns true iff sig is a valid signature of msg by PublicKey.
func (sig *Signature) Verify(msg []byte) bool {
	return ed25519.VerifyCanonical((*[32]byte)(sig.Pub), msg, (*[ed25519.SignatureSize]byte)(sig.Sig))
}
Example #14
0
// Verify returns true iff sig is a valid signature of msg by PublicKey.
func (sig Signature) Verify(msg []byte) bool {
	return ed25519.VerifyCanonical(sig.Pub.Key, msg, sig.Sig)
}
Example #15
0
func (k PublicKey) Verify(msg []byte, sig *[ed25519.SignatureSize]byte) bool {
	return ed25519.VerifyCanonical(k.Key, msg, sig)
}
Example #16
0
func (c *CommitEntry) IsValid() bool {
	return ed.VerifyCanonical(c.ECPubKey, c.CommitMsg(), c.Sig)
}