• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ed25519.Verify函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/agl/ed25519.Verify函数的典型用法代码示例。如果您正苦于以下问题:Golang Verify函数的具体用法?Golang Verify怎么用?Golang Verify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Verify函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: AddFullUpdateTx

func (ch *Channel) AddFullUpdateTx(ev *wire.Envelope, utx *wire.UpdateTx) error {
	if !(ch.Phase == OPEN || ch.Phase == PENDING_CLOSED) {
		return errors.New("channel not OPEN or PENDING_CLOSED")
	}
	if len(ev.Signatures) != 2 {
		return errors.New("wrong number of signatures")
	}
	if !ed25519.Verify(sliceTo32Byte(ch.Account.Pubkey), ev.Payload, sliceTo64Byte(ev.Signatures[ch.Me])) {
		return errors.New("my account signature not valid")
	}
	if !ed25519.Verify(sliceTo32Byte(ch.Counterparty.Pubkey), ev.Payload, sliceTo64Byte(ev.Signatures[swap[ch.Me]])) {
		return errors.New("counterparty signature not valid")
	}
	if utx.ChannelId != ch.OpeningTx.ChannelId {
		return errors.New("channel id incorrect")
	}
	if ch.LastFullUpdateTx != nil {
		if utx.SequenceNumber > ch.LastFullUpdateTx.SequenceNumber {
			return errors.New("sequence number too low")
		}
	}

	ch.LastFullUpdateTx = utx
	ch.LastFullUpdateTxEnvelope = ev

	return nil
}
开发者ID:jtremback,项目名称:universal-state-channels,代码行数:27,代码来源:peer.go


示例2: AddChannel

func (jd *Judge) AddChannel(ev *wire.Envelope, otx *wire.OpeningTx, acct0 *Account, acct1 *Account) (*Channel, error) {
	if len(ev.Signatures) != 2 {
		return nil, errors.New("wrong number of signatures")
	}
	if len(otx.Pubkeys) != 2 {
		return nil, errors.New("wrong number of public keys")
	}
	if bytes.Compare(acct0.Judge.Pubkey, acct1.Judge.Pubkey) != 0 {
		return nil, errors.New("accounts do not have matching judges")
	}
	if !ed25519.Verify(sliceTo32Byte(otx.Pubkeys[0]), ev.Payload, sliceTo64Byte(ev.Signatures[0])) {
		return nil, errors.New("signature 0 not valid")
	}
	if !ed25519.Verify(sliceTo32Byte(otx.Pubkeys[1]), ev.Payload, sliceTo64Byte(ev.Signatures[1])) {
		return nil, errors.New("signature 1 not valid")
	}

	ch := &Channel{
		ChannelId:         otx.ChannelId,
		OpeningTx:         otx,
		OpeningTxEnvelope: ev,
		Accounts:          []*Account{acct0, acct1},
		Judge:             jd,
		Phase:             PENDING_OPEN,
	}

	return ch, nil
}
开发者ID:jtremback,项目名称:universal-state-channels,代码行数:28,代码来源:judge.go


示例3: Open

func (ch *Channel) Open(ev *wire.Envelope, otx *wire.OpeningTx) error {
	if ch.Phase != PENDING_OPEN {
		return errors.New("channel not PENDING_OPEN")
	}
	if len(ev.Signatures) != 3 {
		return errors.New("wrong number of signatures")
	}
	if !ed25519.Verify(sliceTo32Byte(ch.Account.Pubkey), ev.Payload, sliceTo64Byte(ev.Signatures[ch.Me])) {
		return errors.New("my account signature not valid")
	}
	if !ed25519.Verify(sliceTo32Byte(ch.Counterparty.Pubkey), ev.Payload, sliceTo64Byte(ev.Signatures[swap[ch.Me]])) {
		return errors.New("counterparty signature not valid")
	}
	if !ed25519.Verify(sliceTo32Byte(ch.Judge.Pubkey), ev.Payload, sliceTo64Byte(ev.Signatures[2])) {
		return errors.New("judge signature not valid")
	}

	if bytes.Compare(ev.Payload, ch.OpeningTxEnvelope.Payload) != 0 {
		return errors.New("opening tx not valid")
	}

	ch.Phase = OPEN
	ch.OpeningTx = otx
	ch.OpeningTxEnvelope = ev

	return nil
}
开发者ID:jtremback,项目名称:universal-state-channels,代码行数:27,代码来源:peer.go


示例4: checkAuth

func checkAuth(w http.ResponseWriter, login, token, sig string) {
	tokenRaw, err := base64.StdEncoding.DecodeString(token)
	if err != nil {
		log.Println(err)
		http.Error(w, "Error with your request", http.StatusBadRequest)
		return
	}

	sigRaw, err := base64.StdEncoding.DecodeString(sig)
	if err != nil {
		log.Println(err)
		http.Error(w, "Error with your request", http.StatusBadRequest)
		return
	}

	var sigForVerif [ed25519.SignatureSize]byte
	copy(sigForVerif[:], sigRaw[:])

	user, ok := users[login]
	if !ok {
		http.Error(w, "Bad auth", http.StatusUnauthorized)
		return
	}

	userPubKeyRaw, err := base64.StdEncoding.DecodeString(user.PubKey)
	if err != nil || len(userPubKeyRaw) != ed25519.PublicKeySize {
		http.Error(w, "Internal error", http.StatusInternalServerError)
		return
	}
	var userPubKey [ed25519.PublicKeySize]byte
	copy(userPubKey[:], userPubKeyRaw)

	ok = ed25519.Verify(&userPubKey, tokenRaw, &sigForVerif)
	if ok {
		if len(tokenRaw) != 32+ed25519.SignatureSize {
			http.Error(w, "Bad token", http.StatusUnauthorized)
			return
		}
		ourToken := tokenRaw[:len(tokenRaw)-ed25519.SignatureSize]
		ourSig := tokenRaw[len(tokenRaw)-ed25519.SignatureSize:]
		var ourSigForVerif [ed25519.SignatureSize]byte
		copy(ourSigForVerif[:], ourSig)

		ok = ed25519.Verify(signingPubKey, ourToken, &ourSigForVerif)
		if !ok {
			http.Error(w, "Bad token", http.StatusUnauthorized)
			return
		}
		log.Printf("%s just logged in\n", login)
	} else {
		log.Printf("%s didn't log in", login)
		http.Error(w, "Bad auth", http.StatusUnauthorized)
	}
}
开发者ID:rakoo,项目名称:challengeauth,代码行数:54,代码来源:main.go


示例5: AddFollowOnTx

func (ch *Channel) AddFollowOnTx(ev *wire.Envelope) error {
	if ch.Phase != OPEN {
		return errors.New("channel not OPEN")
	}
	if len(ev.Signatures) != 1 {
		return errors.New("wrong number of signatures")
	}
	if !ed25519.Verify(sliceTo32Byte(ch.Accounts[0].Pubkey), ev.Payload, sliceTo64Byte(ev.Signatures[0])) ||
		!ed25519.Verify(sliceTo32Byte(ch.Accounts[1].Pubkey), ev.Payload, sliceTo64Byte(ev.Signatures[0])) {
		return errors.New("signature not valid")
	}

	ch.FollowOnTxs = append(ch.FollowOnTxs, ev)
	return nil
}
开发者ID:jtremback,项目名称:universal-state-channels,代码行数:15,代码来源:judge.go


示例6: Verify

// Verify checks whether the message has a valid signature.
func Verify(publicKey [32]byte, message []byte, signature *[64]byte) bool {

	publicKey[31] &= 0x7F

	/* Convert the Curve25519 public key into an Ed25519 public key.  In
	particular, convert Curve25519's "montgomery" x-coordinate into an
	Ed25519 "edwards" y-coordinate:

	ed_y = (mont_x - 1) / (mont_x + 1)

	NOTE: mont_x=-1 is converted to ed_y=0 since fe_invert is mod-exp

	Then move the sign bit into the pubkey from the signature.
	*/

	var edY, one, montX, montXMinusOne, montXPlusOne edwards25519.FieldElement
	edwards25519.FeFromBytes(&montX, &publicKey)
	edwards25519.FeOne(&one)
	edwards25519.FeSub(&montXMinusOne, &montX, &one)
	edwards25519.FeAdd(&montXPlusOne, &montX, &one)
	edwards25519.FeInvert(&montXPlusOne, &montXPlusOne)
	edwards25519.FeMul(&edY, &montXMinusOne, &montXPlusOne)

	var A_ed [32]byte
	edwards25519.FeToBytes(&A_ed, &edY)

	A_ed[31] |= signature[63] & 0x80
	signature[63] &= 0x7F

	return ed25519.Verify(&A_ed, message, signature)
}
开发者ID:mutantmonkey,项目名称:textsecure,代码行数:32,代码来源:curve25519sign.go


示例7: Verify

// Verify checks that an ed25519 signature is valid
func (v Ed25519Verifier) Verify(key data.PublicKey, sig []byte, msg []byte) error {
	if key.Algorithm() != data.ED25519Key {
		return ErrInvalidKeyType{}
	}
	var sigBytes [ed25519.SignatureSize]byte
	if len(sig) != ed25519.SignatureSize {
		logrus.Debugf("signature length is incorrect, must be %d, was %d.", ed25519.SignatureSize, len(sig))
		return ErrInvalid
	}
	copy(sigBytes[:], sig)

	var keyBytes [ed25519.PublicKeySize]byte
	pub := key.Public()
	if len(pub) != ed25519.PublicKeySize {
		logrus.Errorf("public key is incorrect size, must be %d, was %d.", ed25519.PublicKeySize, len(pub))
		return ErrInvalidKeyLength{msg: fmt.Sprintf("ed25519 public key must be %d bytes.", ed25519.PublicKeySize)}
	}
	n := copy(keyBytes[:], key.Public())
	if n < ed25519.PublicKeySize {
		logrus.Errorf("failed to copy the key, must have %d bytes, copied %d bytes.", ed25519.PublicKeySize, n)
		return ErrInvalid
	}

	if !ed25519.Verify(&keyBytes, msg, &sigBytes) {
		logrus.Debugf("failed ed25519 verification")
		return ErrInvalid
	}
	return nil
}
开发者ID:jfrazelle,项目名称:notary,代码行数:30,代码来源:verifiers.go


示例8: SetKeys

func (u *User) SetKeys(pubkey *[ed25519.PublicKeySize]byte, privkey *[ed25519.PrivateKeySize]byte) (err error) {
	sign := ed25519.Sign(privkey, signtestmsg)
	if ed25519.Verify(pubkey, signtestmsg, sign) {
		return nil
	}
	return ErrInvalidKey
}
开发者ID:jackyyf,项目名称:isreversi,代码行数:7,代码来源:user.go


示例9: NewED25519Verifier

// NewED25519Verifierr returns a Verifier that uses the ED25519 algorithm to verify updates.
func NewED25519Verifier(targetVersion string) update.Verifier {

	return verifyFn(func(checksum, signature []byte, hash crypto.Hash, publicKey crypto.PublicKey) error {
		key, ok := publicKey.(*[32]byte)
		if !ok {
			return errors.New("not a valid public key length")
		}

		if len(signature) != 64 {
			return fmt.Errorf("invalid signature length")
		}
		var sigRes = new([64]byte)
		for i, v := range signature {
			sigRes[i] = v
		}
		var b []byte
		b = append(b, []byte(targetVersion)...)
		b = append(b, byte(0))
		b = append(b, checksum...)
		if !ed25519.Verify(key, checksum, sigRes) {
			return errors.New("failed to verify signature")
		}

		return nil
	})
}
开发者ID:thomasf,项目名称:alkasir,代码行数:27,代码来源:ed25519Verifier.go


示例10: VerifySessionKey

// VerifySessionKey authenticates a session key.
func (id *Identity) VerifySessionKey(sk *[SessionKeySize]byte) (*[64]byte, bool) {
	peerID := new([ed25519.PublicKeySize]byte)
	keyData := new([64]byte)
	signature := new([ed25519.SignatureSize]byte)
	copy(peerID[:], sk[:])
	copy(keyData[:], sk[ed25519.PublicKeySize:])
	copy(signature[:], sk[blobDataSize:])

	var found bool
	for i := range id.peers {
		if subtle.ConstantTimeCompare(id.peers[i][:], peerID[:]) == 1 {
			found = true
		}
	}

	if !found {
		if id.PeerLookup != nil {
			if !id.PeerLookup(peerID) {
				return nil, false
			}
		} else {
			return nil, false
		}
	}

	if !ed25519.Verify(peerID, sk[:blobDataSize], signature) {
		return nil, false
	}

	return keyData, true
}
开发者ID:jmptrader,项目名称:gocrypto,代码行数:32,代码来源:session.go


示例11: GetKey

func GetKey(conn *transport.Conn, inBuf []byte, pk *[32]byte, dename string, pkSig *[32]byte) (*[32]byte, error) {
	getKey := &proto.ClientToServer{
		GetSignedKey: (*proto.Byte32)(pk),
	}
	if err := WriteProtobuf(conn, getKey); err != nil {
		return nil, err
	}

	response, err := ReceiveProtobuf(conn, inBuf)
	if err != nil {
		return nil, err
	}

	var userKey [32]byte
	copy(userKey[:], response.SignedKey[:32])

	var sig [64]byte
	copy(sig[:], response.SignedKey[32:(32+64)])

	if !ed25519.Verify(pkSig, userKey[:], &sig) {
		return nil, errors.New("Improperly signed key returned")
	}

	return &userKey, nil
}
开发者ID:andres-erbsen,项目名称:chatterbox,代码行数:25,代码来源:client_util.go


示例12: Verify

// Verify verifies a public key using SignaturePublicKey.
func (pk PublicKey) Verify(SignaturePublicKey *[ed25519.PublicKeySize]byte) bool {
	tcalc := pk.CalcKeyID()
	if tcalc != pk.KeyID {
		return false
	}
	return ed25519.Verify(SignaturePublicKey, tcalc[:], &pk.Signature)
}
开发者ID:JonathanLogan,项目名称:mute,代码行数:8,代码来源:keys.go


示例13: VerifyOpeningTx

// VerifyOpeningTx checks the signatures of an OpeningTx, unmarshals it and returns it.
func VerifyOpeningTx(ev *wire.Envelope) (*wire.OpeningTx, error) {
	otx := wire.OpeningTx{}
	err := proto.Unmarshal(ev.Payload, &otx)
	if err != nil {
		return nil, err
	}

	// Check signatures
	if !ed25519.Verify(sliceTo32Byte(otx.Pubkey1), ev.Payload, sliceTo64Byte(ev.Signature1)) {
		return nil, errors.New("signature 1 invalid")
	}
	if !ed25519.Verify(sliceTo32Byte(otx.Pubkey2), ev.Payload, sliceTo64Byte(ev.Signature2)) {
		return nil, errors.New("signature 2 invalid")
	}

	return &otx, nil
}
开发者ID:jtremback,项目名称:upc-go,代码行数:18,代码来源:logic.go


示例14: VerifyUpdateTx

// VerifyUpdateTx checks the signatures of an UpdateTx, unmarshals it and returns it.
func (ch *Channel) VerifyUpdateTx(ev *wire.Envelope) (*wire.UpdateTx, error) {
	// Check signatures
	if !ed25519.Verify(sliceTo32Byte(ch.OpeningTx.Pubkey1), ev.Payload, sliceTo64Byte(ev.Signature1)) {
		return nil, errors.New("signature 1 invalid")
	}
	if !ed25519.Verify(sliceTo32Byte(ch.OpeningTx.Pubkey2), ev.Payload, sliceTo64Byte(ev.Signature2)) {
		return nil, errors.New("signature 2 invalid")
	}

	utx := wire.UpdateTx{}
	err := proto.Unmarshal(ev.Payload, &utx)
	if err != nil {
		return nil, err
	}

	return &utx, nil
}
开发者ID:jtremback,项目名称:upc-go,代码行数:18,代码来源:logic.go


示例15: AddClosingTx

func (ch *Channel) AddClosingTx(ev *wire.Envelope) error {
	if ch.Phase != OPEN {
		return errors.New("channel not OPEN")
	}
	if len(ev.Signatures) != 1 {
		return errors.New("wrong number of signatures")
	}
	if !ed25519.Verify(sliceTo32Byte(ch.Accounts[0].Pubkey), ev.Payload, sliceTo64Byte(ev.Signatures[0])) &&
		!ed25519.Verify(sliceTo32Byte(ch.Accounts[1].Pubkey), ev.Payload, sliceTo64Byte(ev.Signatures[0])) {
		return errors.New("signature not valid")
	}

	ch.ClosingTxEnvelope = ev
	ch.CloseTime = time.Now()

	return nil
}
开发者ID:jtremback,项目名称:universal-state-channels,代码行数:17,代码来源:judge.go


示例16: Verify

func (key ed25519PublicKey) Verify(data []byte, sig *ssh.Signature) error {
	signature := [ed25519.SignatureSize]byte{}
	copy(signature[:], sig.Blob)
	if !ed25519.Verify(&key.publicKey, data, &signature) {
		return ErrorVerificationFailed
	}

	return nil
}
开发者ID:kmeaw,项目名称:wrongssh,代码行数:9,代码来源:ed.go


示例17: Verify

// Verify runs the NaCl verification routine on the given msg / sig
// input.
func (k SigningPublicKey) Verify(msg []byte, sig []byte) error {
	var tmp [ed25519.SignatureSize]byte
	copy(tmp[:], sig)
	ok := ed25519.Verify((*[ed25519.PublicKeySize]byte)(&k), msg, &tmp)
	if !ok {
		return saltpack.ErrBadSignature
	}
	return nil
}
开发者ID:Varjelus,项目名称:keybase-client,代码行数:11,代码来源:key.go


示例18: AddFulfillment

// AddFulfillment verifies a fulfillment's signature and adds it to the Channel's
// Fulfillments array.
func (ch *Channel) AddFulfillment(ev *wire.Envelope, eval func()) error {
	if ch.State != schema.Channel_PendingClosed {
		return errors.New("channel must be pending closed")
	}

	if !ed25519.Verify(sliceTo32Byte(ch.OpeningTx.Pubkey1), ev.Payload, sliceTo64Byte(ev.Signature1)) ||
		!ed25519.Verify(sliceTo32Byte(ch.OpeningTx.Pubkey2), ev.Payload, sliceTo64Byte(ev.Signature1)) {
		return errors.New("signature invalid")
	}

	ful := wire.Fulfillment{}
	err := proto.Unmarshal(ev.Payload, &ful)
	if err != nil {
		return err
	}

	ch.Fulfillments = append(ch.Fulfillments, &ful)
	return nil
}
开发者ID:jtremback,项目名称:upc-go,代码行数:21,代码来源:logic.go


示例19: Verify

// Verify attempts to verify a signature on a message with a key.
func Verify(vk, message []byte, signature []byte) bool {
	key, err := ToByteArray32(vk)
	if err != nil {
		return false
	}
	sig, err := ToByteArray64(signature)
	if err != nil {
		return false
	}
	return ed25519.Verify(key, message, sig)
}
开发者ID:pylls,项目名称:balloon,代码行数:12,代码来源:sign.go


示例20: Verify

func (ek *Ed25519PublicKey) Verify(message []byte, signature *ssh.Signature) error {
	if signature.Format != ek.Type() {
		return fmt.Errorf("edssh: signature type %s for key type %s", signature.Format, ek.Type())
	}
	sig := new([ed25519.SignatureSize]byte)
	copy(sig[:], signature.Blob)
	if ok := ed25519.Verify(ek.bytes, message, sig); !ok {
		return errors.New("edssh: invalid signature for given message")
	}
	return nil
}
开发者ID:fudanchii,项目名称:edssh,代码行数:11,代码来源:keys.go



注:本文中的github.com/agl/ed25519.Verify函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang edwards25519.ExtendedGroupElement类代码示例发布时间:2022-05-24
下一篇:
Golang ed25519.Sign函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap