noise

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SizePrefixLength = 2
	ChunkSize        = 0xFFFF
)

Streaming constants.

Variables

This section is empty.

Functions

func NewChunkedConn

func NewChunkedConn(c net.Conn, cipher Cipher) net.Conn

NewChunkedConn returns a noise chunked stream. Given stream is encrypted by chunks of 0xFFFF max size.

func NewChunkedStream

func NewChunkedStream(stream io.ReadWriter, cipher Cipher) io.ReadWriter

NewChunkedStream returns a noise chunked stream. Given stream is encrypted by chunks of 0xFFFF max size.

func ParseX25519key

func ParseX25519key(s string, key []byte)

ParseX25519key parse the given s into key.

Types

type ChunkedConn

type ChunkedConn struct {
	net.Conn
	// contains filtered or unexported fields
}

A ChunkedConn is able to encrypt/decrypt a net Conn by using chunked encryption.

func (*ChunkedConn) Read

func (c *ChunkedConn) Read(p []byte) (n int, err error)

func (*ChunkedConn) Write

func (c *ChunkedConn) Write(p []byte) (n int, err error)

type ChunkedStream

type ChunkedStream struct {
	// contains filtered or unexported fields
}

A ChunkedStream is able to encrypt/decrypt a stream by using chunked encryption.

func (*ChunkedStream) Read

func (c *ChunkedStream) Read(p []byte) (n int, err error)

func (*ChunkedStream) Write

func (c *ChunkedStream) Write(p []byte) (n int, err error)

type Cipher

type Cipher interface {
	Overhead() int
	EncryptRekey()
	Encrypt(out, ad, plaintext []byte) ([]byte, error)
	DecryptRekey()
	Decrypt(out, ad, ciphertext []byte) ([]byte, error)
}

Cipher provides symmetric encryption and decryption after a successful handshake.

func Handshake

func Handshake(stream io.ReadWriter, options HandshakeOptions, initiator bool) (Cipher, error)

Handshake performs the handshake for X25519Identity sender and recipient using given stream.

The cipher suite used is: Curve25519 ECDH and provided Cipher and Hash.

One of the Noise participants should be the initiator.

Documentation: https://noiseprotocol.org/noise.html https://latacora.micro.blog/factoring-the-noise/

type CipherFunction

type CipherFunction uint8

An CipherFunction is an AEAD symmetric cipher.

const (
	CipherChaCha20Poly1305 CipherFunction = 0x01
	CipherAES256GCM        CipherFunction = 0x02
)

Supported hash functions.

type HandshakeOptions

type HandshakeOptions struct {
	Pattern HandshakePattern

	Hash HashFunction

	Cipher CipherFunction

	Sender    *X25519Identity
	Recipient *X25519Recipient
	// contains filtered or unexported fields
}

An HandshakeOptions describes all the options needed for a Noise Protocol handshake.

func (*HandshakeOptions) Validate

func (o *HandshakeOptions) Validate() error

Validate checks if the options are valid.

type HandshakePattern

type HandshakePattern uint8

A HandshakePattern is an handshake pattern.

const (
	PatternIK HandshakePattern = 0x01
)

Supported patterns.

type HashFunction

type HashFunction uint8

An HashFunction is a cryptographic hash function.

const (
	HashBlake2b HashFunction = 0x01
	HashBlake2s HashFunction = 0x02
)

Supported hash functions.

type X25519Identity

type X25519Identity struct {
	// contains filtered or unexported fields
}

A X25519Identity is a X25519 assymmetric encryption key.

func GenerateX25519Identity

func GenerateX25519Identity() *X25519Identity

GenerateX25519Identity returns a new X25519Identity.

func NewX25519FromScalar

func NewX25519FromScalar(scalar []byte) *X25519Identity

NewX25519FromScalar returns a new X25519Identity based on the given 32 byte-length scalar.

func ParseX25519Identity

func ParseX25519Identity(private, public string) *X25519Identity

ParseX25519Identity returns a new X25519Recipient from a base58 private and public keys.

func (*X25519Identity) PrivateKey

func (k *X25519Identity) PrivateKey() X25519PrivateKey

PrivateKey returns the private key of the X25519 identity.

func (*X25519Identity) PrivateKeyString

func (k *X25519Identity) PrivateKeyString() string

PrivateKeyString returns the encoded private key of the X25519 identity.

func (*X25519Identity) PublicKey

func (k *X25519Identity) PublicKey() X25519PublicKey

PublicKey returns the public key of the X25519 identity.

func (*X25519Identity) PublicKeyString

func (k *X25519Identity) PublicKeyString() string

PublicKeyString returns the encoded public key of the X25519 identity.

type X25519PrivateKey

type X25519PrivateKey []byte

A X25519PrivateKey is the private part of a X25519 assymmetric encryption key.

type X25519PublicKey

type X25519PublicKey []byte

A X25519PublicKey is the public part of a X25519 assymmetric encryption key.

type X25519Recipient

type X25519Recipient = X25519PublicKey

X25519Recipient is the standard X25519 public key, based on a Curve25519 point.

func ParseX25519Recipient

func ParseX25519Recipient(s string) *X25519Recipient

ParseX25519Recipient returns a new X25519Recipient from a base58 public key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL