本文整理汇总了Golang中github.com/agl/ed25519.Verify函数的典型用法代码示例。如果您正苦于以下问题:Golang Verify函数的具体用法?Golang Verify怎么用?Golang Verify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Verify函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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
}
示例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)
}
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
})
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}