refactor: use X25519 instead of ScalarBaseMult (#533)

As suggested in https://pkg.go.dev/golang.org/x/crypto/curve25519#ScalarBaseMult,
use X25519 instead of ScalarBaseMult. When using Basepoint, it may employ
some precomputed values, enhancing performance.

Co-authored-by: Wade Simmons <wade@wades.im>
Co-authored-by: Wade Simmons <wadey@slack-corp.com>
This commit is contained in:
Manuel Romei
2021-10-12 18:03:43 +02:00
committed by GitHub
parent 34d002d695
commit 3a8f533b24
4 changed files with 32 additions and 16 deletions

View File

@@ -337,10 +337,11 @@ func (nc *NebulaCertificate) VerifyPrivateKey(key []byte) error {
return nil
}
var dst, key32 [32]byte
copy(key32[:], key)
curve25519.ScalarBaseMult(&dst, &key32)
if !bytes.Equal(dst[:], nc.Details.PublicKey) {
pub, err := curve25519.X25519(key, curve25519.Basepoint)
if err != nil {
return err
}
if !bytes.Equal(pub, nc.Details.PublicKey) {
return fmt.Errorf("public key in cert and private key supplied don't match")
}