package noise
Import Path
github.com/flynn/noise (on go.dev)
Dependency Relation
imports 16 packages, and imported by one package
Involved Source Files
cipher_suite.go
hkdf.go
patterns.go
Package noise implements the Noise Protocol Framework.
Noise is a low-level framework for building crypto protocols. Noise protocols
support mutual and optional authentication, identity hiding, forward secrecy,
zero round-trip encryption, and other advanced features. For more details,
visit https://noiseprotocol.org.
Package-Level Type Names (total 11)
A Cipher is a AEAD cipher that has been initialized with a key.
Decrypt authenticates the ciphertext and optional authenticated data and
then decrypts the provided ciphertext using the provided nonce and
appends it to out.
Encrypt encrypts the provided plaintext with a nonce and then appends the
ciphertext to out along with an authentication tag over the ciphertext
and optional authenticated data.
func CipherFunc.Cipher(k [32]byte) Cipher
func (*CipherState).Cipher() Cipher
func CipherSuite.Cipher(k [32]byte) Cipher
A CipherFunc implements an AEAD symmetric cipher.
Cipher initializes the algorithm with the provided key and returns a Cipher.
CipherName is the name of the cipher.
CipherSuite (interface)
func NewCipherSuite(dh DHFunc, c CipherFunc, h HashFunc) CipherSuite
var CipherAESGCM
var CipherChaChaPoly
A CipherState provides symmetric encryption and decryption after a successful
handshake.
Cipher returns the low-level symmetric encryption primitive. It should only
be used if nonces need to be managed manually, for example with a network
protocol that can deliver out-of-order messages. This is dangerous, users
must ensure that they are incrementing a nonce after every encrypt operation.
After calling this method, it is an error to call Encrypt/Decrypt on the
CipherState.
Decrypt checks the authenticity of the ciphertext and authenticated data and
then decrypts and appends the plaintext to out. This method automatically
increments the nonce after every call, messages must be provided in the same
order that they were encrypted with no missing messages. ErrMaxNonce is
returned after the maximum nonce of 2^64-2 is reached.
Encrypt encrypts the plaintext and then appends the ciphertext and an
authentication tag across the ciphertext and optional authenticated data to
out. This method automatically increments the nonce after every call, so
messages must be decrypted in the same order. ErrMaxNonce is returned after
the maximum nonce of 2^64-2 is reached.
Nonce returns the current value of n. This can be used to determine if a
new handshake should be performed due to approaching MaxNonce.
(*CipherState) Rekey()
SetNonce sets the current value of n.
UnsafeKey returns the current value of k. This exports the current key for the
CipherState. Intended to be used alongside UnsafeNewCipherState to resume a
CipherState at a later point.
func UnsafeNewCipherState(cs CipherSuite, k [32]byte, n uint64) *CipherState
func (*HandshakeState).ReadMessage(out, message []byte) ([]byte, *CipherState, *CipherState, error)
func (*HandshakeState).ReadMessage(out, message []byte) ([]byte, *CipherState, *CipherState, error)
func (*HandshakeState).WriteMessage(out, payload []byte) ([]byte, *CipherState, *CipherState, error)
func (*HandshakeState).WriteMessage(out, payload []byte) ([]byte, *CipherState, *CipherState, error)
A CipherSuite is a set of cryptographic primitives used in a Noise protocol.
It should be constructed with NewCipherSuite.
Cipher initializes the algorithm with the provided key and returns a Cipher.
CipherName is the name of the cipher.
DH performs a Diffie-Hellman calculation between the provided private and
public keys and returns the result.
DHLen is the number of bytes returned by DH.
DHName is the name of the DH function.
GenerateKeypair generates a new keypair using random as a source of
entropy.
Hash returns a hash state.
HashName is the name of the hash function.
( CipherSuite) Name() []byte
CipherSuite : CipherFunc
CipherSuite : DHFunc
CipherSuite : HashFunc
func NewCipherSuite(dh DHFunc, c CipherFunc, h HashFunc) CipherSuite
func UnsafeNewCipherState(cs CipherSuite, k [32]byte, n uint64) *CipherState
A Config provides the details necessary to process a Noise handshake. It is
never modified by this package, and can be reused.
CipherSuite is the set of cryptographic primitives that will be used.
EphemeralKeypair is this peer's ephemeral keypair that was provided as
a pre-message in the handshake.
Initiator must be true if the first message in the handshake will be sent
by this peer.
Pattern is the pattern for the handshake.
PeerEphemeral is the ephemeral public key of the remote peer that was
provided as a pre-message in the handshake.
PeerStatic is the static public key of the remote peer that was provided
as a pre-message in the handshake.
Prologue is an optional message that has already be communicated and must
be identical on both sides for the handshake to succeed.
Random is the source for cryptographically appropriate random bytes. If
zero, it is automatically configured.
StaticKeypair is this peer's static keypair, required if part of the
handshake.
func NewHandshakeState(c Config) (*HandshakeState, error)
A DHFunc implements Diffie-Hellman key agreement.
DH performs a Diffie-Hellman calculation between the provided private and
public keys and returns the result.
DHLen is the number of bytes returned by DH.
DHName is the name of the DH function.
GenerateKeypair generates a new keypair using random as a source of
entropy.
CipherSuite (interface)
func NewCipherSuite(dh DHFunc, c CipherFunc, h HashFunc) CipherSuite
var DH25519
A DHKey is a keypair used for Diffie-Hellman key agreement.
Private []byte
Public []byte
func CipherSuite.GenerateKeypair(random io.Reader) (DHKey, error)
func DHFunc.GenerateKeypair(random io.Reader) (DHKey, error)
func (*HandshakeState).LocalEphemeral() DHKey
A HandshakePattern is a list of messages and operations that are used to
perform a specific Noise handshake.
InitiatorPreMessages []MessagePattern
Messages [][]MessagePattern
Name string
ResponderPreMessages []MessagePattern
var HandshakeIK
var HandshakeIN
var HandshakeIX
var HandshakeK
var HandshakeKK
var HandshakeKN
var HandshakeKX
var HandshakeN
var HandshakeNK
var HandshakeNN
var HandshakeNX
var HandshakeX
var HandshakeXK
var HandshakeXN
var HandshakeXX
var HandshakeXXfallback
A HandshakeState tracks the state of a Noise handshake. It may be discarded
after the handshake is complete.
ChannelBinding provides a value that uniquely identifies the session and can
be used as a channel binding. It is an error to call this method before the
handshake is complete.
LocalEphemeral returns the local ephemeral key pair generated during
a handshake.
MessageIndex returns the current handshake message id
PeerEphemeral returns the ephemeral key provided by the remote peer during
a handshake. It is an error to call this method if a handshake message
containing a static key has not been read.
PeerStatic returns the static key provided by the remote peer during
a handshake. It is an error to call this method if a handshake message
containing a static key has not been read.
ReadMessage processes a received handshake message and appends the payload,
if any to out. If the handshake is completed by the call, two CipherStates
will be returned, one is used for encryption of messages to the remote peer,
the other is used for decryption of messages from the remote peer. It is an
error to call this method out of sync with the handshake pattern.
(*HandshakeState) SetPresharedKey(psk []byte) error
WriteMessage appends a handshake message to out. The message will include the
optional payload if provided. If the handshake is completed by the call, two
CipherStates will be returned, one is used for encryption of messages to the
remote peer, the other is used for decryption of messages from the remote
peer. It is an error to call this method out of sync with the handshake
pattern.
func NewHandshakeState(c Config) (*HandshakeState, error)
A HashFunc implements a cryptographic hash function.
Hash returns a hash state.
HashName is the name of the hash function.
CipherSuite (interface)
func NewCipherSuite(dh DHFunc, c CipherFunc, h HashFunc) CipherSuite
var HashBLAKE2b
var HashBLAKE2s
var HashSHA256
var HashSHA512
A MessagePattern is a single message or operation used in a Noise handshake.
const MessagePatternDHEE
const MessagePatternDHES
const MessagePatternDHSE
const MessagePatternDHSS
const MessagePatternE
const MessagePatternPSK
const MessagePatternS
Package-Level Functions (total 3)
NewCipherSuite returns a CipherSuite constructed from the specified
primitives.
NewHandshakeState starts a new handshake using the provided configuration.
UnsafeNewCipherState reconstructs a CipherState from exported components.
It is important that, when resuming from an exported state, care is taken
to synchronize the nonce state and not allow rollbacks.
Package-Level Variables (total 26)
CipherAESGCM is the AES256-GCM AEAD cipher.
CipherChaChaPoly is the ChaCha20-Poly1305 AEAD cipher construction.
DH25519 is the Curve25519 ECDH function.
var ErrMaxNonce error
ErrShortMessage is returned by ReadMessage if a message is not as long as it should be.
HashBLAKE2b is the BLAKE2b hash function.
HashBLAKE2s is the BLAKE2s hash function.
HashSHA256 is the SHA-256 hash function.
HashSHA512 is the SHA-512 hash function.
Package-Level Constants (total 9)
MaxMsgLen is the maximum number of bytes that can be sent in a single Noise
message.
MaxNonce is the maximum value of n that is allowed. ErrMaxNonce is returned
by Encrypt and Decrypt after this has been reached. 2^64-1 is reserved for rekeys.
const MessagePatternDHEE MessagePattern = 2 const MessagePatternDHES MessagePattern = 3 const MessagePatternDHSE MessagePattern = 4 const MessagePatternDHSS MessagePattern = 5 const MessagePatternE MessagePattern = 1 const MessagePatternPSK MessagePattern = 6 const MessagePatternS MessagePattern = 0![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |