Documentation ¶
Overview ¶
A simple to use implementation of ECDH with curve25519 for Go. The core mathematics of this algorithm are already present in golang.org/x/crypto/curve25519, this library just implements the algorithm in such a way that knowledge of the underlying mathematics is not necessary.
Index ¶
Constants ¶
const KeySize int = 32
KeySize is the length, in bytes, of both Private and Public keys.
Variables ¶
var KeySizeError error = errors.New("The data provided was not 32 bytes in length.")
KeySizeError is returned if the provided key is not the correct length. It can only be returned from PrivateFromBytes and PublicFromBytes.
Functions ¶
This section is empty.
Types ¶
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey represents the private portion of a curve25519 ECDH key pair.
func GenerateKey ¶
func GenerateKey() (*PrivateKey, error)
GenerateKey generates a new curve25519 private key. The public portion can be retrieved by calling Public().
func PrivateFromBytes ¶
func PrivateFromBytes(raw []byte, precompute bool) (*PrivateKey, error)
PrivateFromBytes creates a PrivateKey from the given input byte slice. If precompute is true, the public key is stored in PrivateKey immediately without having to be computed.
func (*PrivateKey) ComputeSecret ¶
func (prv *PrivateKey) ComputeSecret(pub *PublicKey) []byte
ComputeSecret computes the shared secret value for the calling private key when combined with the given public key.
func (*PrivateKey) Public ¶
func (prv *PrivateKey) Public() *PublicKey
Public returns the public key corresponding to prv.
func (*PrivateKey) ToBytes ¶
func (prv *PrivateKey) ToBytes() []byte
ToBytes marshals the given Private Key to a byte slice. It can be loaded back into a PrivateKey by using PrivateFromBytes.
type PublicKey ¶
PublicKey represents the public portion of a curve25519 ECHD key pair.
func PublicFromBytes ¶
PublicFromBytes creates a PublicKey from the given input byte slice.