aboutsummaryrefslogtreecommitdiffstats
path: root/src/noise_types.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-04 16:15:53 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-04 16:15:53 +0200
commit8c34c4cbb3780c433148966a004f5a51aace0f64 (patch)
treea590de76c326f6dfe3c92d2e27b78ce2ab792289 /src/noise_types.go
parentMerge branch 'master' of git.zx2c4.com:wireguard-go (diff)
downloadwireguard-go-8c34c4cbb3780c433148966a004f5a51aace0f64.tar.xz
wireguard-go-8c34c4cbb3780c433148966a004f5a51aace0f64.zip
First set of code review patches
Diffstat (limited to '')
-rw-r--r--src/noise_types.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/noise_types.go b/src/noise_types.go
index 5ebc130..1a944df 100644
--- a/src/noise_types.go
+++ b/src/noise_types.go
@@ -1,6 +1,7 @@
package main
import (
+ "crypto/subtle"
"encoding/hex"
"errors"
"golang.org/x/crypto/chacha20poly1305"
@@ -31,12 +32,12 @@ func loadExactHex(dst []byte, src string) error {
}
func (key NoisePrivateKey) IsZero() bool {
- for _, b := range key[:] {
- if b != 0 {
- return false
- }
- }
- return true
+ var zero NoisePrivateKey
+ return key.Equals(zero)
+}
+
+func (key NoisePrivateKey) Equals(tar NoisePrivateKey) bool {
+ return subtle.ConstantTimeCompare(key[:], tar[:]) == 1
}
func (key *NoisePrivateKey) FromHex(src string) error {
@@ -55,6 +56,15 @@ func (key NoisePublicKey) ToHex() string {
return hex.EncodeToString(key[:])
}
+func (key NoisePublicKey) IsZero() bool {
+ var zero NoisePublicKey
+ return key.Equals(zero)
+}
+
+func (key NoisePublicKey) Equals(tar NoisePublicKey) bool {
+ return subtle.ConstantTimeCompare(key[:], tar[:]) == 1
+}
+
func (key *NoiseSymmetricKey) FromHex(src string) error {
return loadExactHex(key[:], src)
}