Documentation ¶
Overview ¶
Package dh implments the Noise Protocol Framework Diffie-Hellman function abstract interface and standard DH functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMalformedPrivateKey is the error returned when a serialized // private key is malformed. ErrMalformedPrivateKey = errors.New("nyquist/dh: malformed private key") // ErrMalformedPublicKey is the error returned when a serialized public // key is malformed. ErrMalformedPublicKey = errors.New("nyquist/dh: malformed public key") // ErrMismatchedPublicKey is the error returned when a public key for an // unexpected algorithm is provided to a DH calculation. ErrMismatchedPublicKey = errors.New("nyquist/dh: mismatched public key") )
Functions ¶
Types ¶
type DH ¶
type DH interface { fmt.Stringer // GenerateKeypair generates a new Diffie-Hellman keypair using the // provided entropy source. GenerateKeypair(rng io.Reader) (Keypair, error) // ParsePrivateKey parses a binary encoded private key. ParsePrivateKey(data []byte) (Keypair, error) // ParsePublicKey parses a binary encoded public key. ParsePublicKey(data []byte) (PublicKey, error) // Size returns the size of public keys and DH outputs in bytes (`DHLEN`). Size() int }
DH is a Diffie-Hellman key exchange algorithm.
var X25519 DH = &dh25519{}
X25519 is the 25519 DH function.
var X448 DH = &dh448{}
X448 is the X448 DH function.
type Keypair ¶
type Keypair interface { encoding.BinaryMarshaler encoding.BinaryUnmarshaler // DropPrivate discards the private key. DropPrivate() // Public returns the public key of the keypair. Public() PublicKey // DH performs a Diffie-Hellman calculation between the private key // in the keypair and the provided public key. DH(publicKey PublicKey) ([]byte, error) }
Keypair is a Diffie-Hellman keypair.
type Keypair25519 ¶
type Keypair25519 struct {
// contains filtered or unexported fields
}
Keypair25519 is a X25519 keypair.
func (*Keypair25519) DH ¶
func (kp *Keypair25519) DH(publicKey PublicKey) ([]byte, error)
DH performs a Diffie-Hellman calculation between the private key in the keypair and the provided public key.
func (*Keypair25519) DropPrivate ¶
func (kp *Keypair25519) DropPrivate()
DropPrivate discards the private key.
func (*Keypair25519) MarshalBinary ¶
func (kp *Keypair25519) MarshalBinary() ([]byte, error)
MarshalBinary marshals the keypair's private key to binary form.
func (*Keypair25519) Public ¶
func (kp *Keypair25519) Public() PublicKey
Public returns the public key of the keypair.
func (*Keypair25519) UnmarshalBinary ¶
func (kp *Keypair25519) UnmarshalBinary(data []byte) error
UnmarshalBinary unmarshals the keypair's private key from binary form, and re-derives the corresponding public key.
type Keypair448 ¶
type Keypair448 struct {
// contains filtered or unexported fields
}
Keypair448 is a X448 keypair.
func (*Keypair448) DH ¶
func (kp *Keypair448) DH(publicKey PublicKey) ([]byte, error)
DH performs a Diffie-Hellman calculation between the private key in the keypair and the provided public key.
func (*Keypair448) DropPrivate ¶
func (kp *Keypair448) DropPrivate()
DropPrivate discards the private key.
func (*Keypair448) MarshalBinary ¶
func (kp *Keypair448) MarshalBinary() ([]byte, error)
MarshalBinary marshals the keypair's private key to binary form.
func (*Keypair448) Public ¶
func (kp *Keypair448) Public() PublicKey
Public returns the public key of the keypair.
func (*Keypair448) UnmarshalBinary ¶
func (kp *Keypair448) UnmarshalBinary(data []byte) error
UnmarshalBinary unmarshals the keypair's private key from binary form, and re-derives the corresponding public key.
type PublicKey ¶
type PublicKey interface { encoding.BinaryMarshaler encoding.BinaryUnmarshaler // Bytes returns the binary serialized public key. // // Warning: Altering the returned slice is unsupported and will lead // to unexpected behavior. Bytes() []byte }
PublicKey is a Diffie-Hellman public key.
type PublicKey25519 ¶
type PublicKey25519 struct {
// contains filtered or unexported fields
}
PublicKey25519 is a X25519 public key.
func (*PublicKey25519) Bytes ¶
func (pk *PublicKey25519) Bytes() []byte
Bytes returns the binary serialized public key.
Warning: Altering the returned slice is unsupported and will lead to unexpected behavior.
func (*PublicKey25519) MarshalBinary ¶
func (pk *PublicKey25519) MarshalBinary() ([]byte, error)
MarshalBinary marshals the public key to binary form.
func (*PublicKey25519) UnmarshalBinary ¶
func (pk *PublicKey25519) UnmarshalBinary(data []byte) error
UnmarshalBinary unmarshals the public key from binary form.
type PublicKey448 ¶
type PublicKey448 struct {
// contains filtered or unexported fields
}
PublicKey448 is a X448 public key.
func (*PublicKey448) Bytes ¶
func (pk *PublicKey448) Bytes() []byte
Bytes returns the binary serialized public key.
Warning: Altering the returned slice is unsupported and will lead to unexpected behavior.
func (*PublicKey448) MarshalBinary ¶
func (pk *PublicKey448) MarshalBinary() ([]byte, error)
MarshalBinary marshals the public key to binary form.
func (*PublicKey448) UnmarshalBinary ¶
func (pk *PublicKey448) UnmarshalBinary(data []byte) error
UnmarshalBinary unmarshals the public key from binary form.