mirror of
https://git.zx2c4.com/wireguard-go
synced 2025-10-17 06:00:41 +08:00
Beginning work noise handshake
This commit is contained in:
53
src/noise_types.go
Normal file
53
src/noise_types.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
)
|
||||
|
||||
const (
|
||||
NoisePublicKeySize = 32
|
||||
NoisePrivateKeySize = 32
|
||||
NoiseSymmetricKeySize = 32
|
||||
)
|
||||
|
||||
type (
|
||||
NoisePublicKey [NoisePublicKeySize]byte
|
||||
NoisePrivateKey [NoisePrivateKeySize]byte
|
||||
)
|
||||
|
||||
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) 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 *NoiseSymmetricKey) FromHex(src string) error {
|
||||
return loadExactHex(key[:], src)
|
||||
}
|
||||
|
||||
func (key NoiseSymmetricKey) ToHex() string {
|
||||
return hex.EncodeToString(key[:])
|
||||
}
|
Reference in New Issue
Block a user