aboutsummaryrefslogtreecommitdiffstats
path: root/src/noise_types.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2018-02-04 16:08:26 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2018-02-04 16:08:26 +0100
commita0f54cbe5ac2cd8b8296c2c57c30029dd349cff0 (patch)
tree64574090d79ff3899c5c18e5268e450028e4656b /src/noise_types.go
parentFixed tests (diff)
downloadwireguard-go-a0f54cbe5ac2cd8b8296c2c57c30029dd349cff0.tar.xz
wireguard-go-a0f54cbe5ac2cd8b8296c2c57c30029dd349cff0.zip
Align with go library layout
Diffstat (limited to 'src/noise_types.go')
-rw-r--r--src/noise_types.go74
1 files changed, 0 insertions, 74 deletions
diff --git a/src/noise_types.go b/src/noise_types.go
deleted file mode 100644
index 1a944df..0000000
--- a/src/noise_types.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package main
-
-import (
- "crypto/subtle"
- "encoding/hex"
- "errors"
- "golang.org/x/crypto/chacha20poly1305"
-)
-
-const (
- NoisePublicKeySize = 32
- NoisePrivateKeySize = 32
-)
-
-type (
- NoisePublicKey [NoisePublicKeySize]byte
- NoisePrivateKey [NoisePrivateKeySize]byte
- NoiseSymmetricKey [chacha20poly1305.KeySize]byte
- NoiseNonce uint64 // padded to 12-bytes
-)
-
-func loadExactHex(dst []byte, src string) error {
- slice, err := hex.DecodeString(src)
- if err != nil {
- return err
- }
- if len(slice) != len(dst) {
- return errors.New("Hex string does not fit the slice")
- }
- copy(dst, slice)
- return nil
-}
-
-func (key NoisePrivateKey) IsZero() bool {
- 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 {
- return loadExactHex(key[:], src)
-}
-
-func (key NoisePrivateKey) ToHex() string {
- return hex.EncodeToString(key[:])
-}
-
-func (key *NoisePublicKey) FromHex(src string) error {
- return loadExactHex(key[:], src)
-}
-
-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)
-}
-
-func (key NoiseSymmetricKey) ToHex() string {
- return hex.EncodeToString(key[:])
-}