This commit is contained in:
jdl
2024-12-13 21:30:06 +01:00
parent d9233af4c9
commit 6fcd8637a3
16 changed files with 191 additions and 364 deletions

View File

@@ -2,7 +2,6 @@ package peer
import (
"golang.org/x/crypto/nacl/box"
"golang.org/x/crypto/nacl/sign"
)
func encryptPacket(sharedKey, nonce, packet, out []byte) []byte {
@@ -16,15 +15,6 @@ func decryptPacket(sharedKey, packet, out []byte) (decrypted []byte, ok bool) {
return decrypted, ok
}
// Signed packet should be encrypted with the encryptPacket function first.
func signPacket(privKey, packet, out []byte) []byte {
return sign.Sign(out[:0], packet, (*[64]byte)(privKey))
}
func openPacket(pubKey, packet, out []byte) (encPacket []byte, ok bool) {
return sign.Open(out[:0], packet, (*[32]byte)(pubKey))
}
func computeSharedKey(peerPubKey, privKey []byte) []byte {
shared := [32]byte{}
box.Precompute(&shared, (*[32]byte)(peerPubKey), (*[32]byte)(privKey))