mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 06:35:07 +03:00
Fix #413 by always generating public keys from private ones instead of trusting public keys supplied by config
This commit is contained in:
parent
a5152f1d44
commit
145a43e5f0
2 changed files with 37 additions and 9 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
|
||||
"golang.org/x/crypto/curve25519"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
"golang.org/x/crypto/nacl/box"
|
||||
|
||||
|
@ -124,6 +125,15 @@ func Verify(pub *SigPubKey, msg []byte, sig *SigBytes) bool {
|
|||
return ed25519.Verify(pub[:], msg, sig[:])
|
||||
}
|
||||
|
||||
func (p SigPrivKey) Public() SigPubKey {
|
||||
priv := make(ed25519.PrivateKey, ed25519.PrivateKeySize)
|
||||
copy(priv[:], p[:])
|
||||
pub := priv.Public().(ed25519.PublicKey)
|
||||
var sigPub SigPubKey
|
||||
copy(sigPub[:], pub[:])
|
||||
return sigPub
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// NaCl-like crypto "box" (curve25519+xsalsa20+poly1305)
|
||||
|
@ -204,6 +214,14 @@ func (n *BoxNonce) Increment() {
|
|||
}
|
||||
}
|
||||
|
||||
func (p BoxPrivKey) Public() BoxPubKey {
|
||||
var boxPub [BoxPubKeyLen]byte
|
||||
var boxPriv [BoxPrivKeyLen]byte
|
||||
copy(boxPriv[:BoxPrivKeyLen], p[:BoxPrivKeyLen])
|
||||
curve25519.ScalarBaseMult(&boxPub, &boxPriv)
|
||||
return boxPub
|
||||
}
|
||||
|
||||
// Used to subtract one nonce from another, staying in the range +- 64.
|
||||
// This is used by the nonce progression machinery to advance the bitmask of recently received packets (indexed by nonce), or to check the appropriate bit of the bitmask.
|
||||
// It's basically part of the machinery that prevents replays and duplicate packets.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue