device: use wgcfg key types

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
David Crawshaw
2020-02-23 17:18:00 -05:00
committed by David Crawshaw
parent 40c3530006
commit 83ca9b47b6
10 changed files with 68 additions and 190 deletions

View File

@@ -7,12 +7,10 @@ package device
import (
"crypto/hmac"
"crypto/rand"
"crypto/subtle"
"hash"
"golang.org/x/crypto/blake2s"
"golang.org/x/crypto/curve25519"
)
/* KDF related functions.
@@ -75,28 +73,3 @@ func setZero(arr []byte) {
arr[i] = 0
}
}
func (sk *NoisePrivateKey) clamp() {
sk[0] &= 248
sk[31] = (sk[31] & 127) | 64
}
func newPrivateKey() (sk NoisePrivateKey, err error) {
_, err = rand.Read(sk[:])
sk.clamp()
return
}
func (sk *NoisePrivateKey) publicKey() (pk NoisePublicKey) {
apk := (*[NoisePublicKeySize]byte)(&pk)
ask := (*[NoisePrivateKeySize]byte)(sk)
curve25519.ScalarBaseMult(apk, ask)
return
}
func (sk *NoisePrivateKey) sharedSecret(pk NoisePublicKey) (ss [NoisePublicKeySize]byte) {
apk := (*[NoisePublicKeySize]byte)(&pk)
ask := (*[NoisePrivateKeySize]byte)(sk)
curve25519.ScalarMult(&ss, ask, apk)
return ss
}