Documentation
¶
Overview ¶
Package babble implements the Noise Protocol Framework.
https://noiseprotocol.org/
Supported patterns:
3 oneway patterns, 12 interactive patterns and 23 deffered patterns, with PSK mode supported.
Supported dh curves:
curve448, curve25519 and secp256k1
Supported ciphers:
ChaCha20-Poly1305 and AESGCM
Supported hash functions:
SHA256, SHA512, BLAKE2b and BLAKE2s
Index ¶
- Constants
- Variables
- type CipherState
- type DefaultRekeyerConfig
- type HandshakeState
- func (hs *HandshakeState) Finished() bool
- func (hs *HandshakeState) GetChainingKey() []byte
- func (hs *HandshakeState) GetDigest() []byte
- func (hs *HandshakeState) GetInfo() ([]byte, error)
- func (hs *HandshakeState) ReadMessage(message []byte) ([]byte, error)
- func (hs *HandshakeState) Reset()
- func (hs *HandshakeState) WriteMessage(payload []byte) ([]byte, error)
- type ProtocolConfig
Constants ¶
const CipherKeySize = 32
CipherKeySize defines the byte length of the key used for cipher.
const (
// NoisePrefix is the mandatory prefix defined by the noise protocol framework.
NoisePrefix = "Noise"
)
Variables ¶
var ( // ZEROS is a 32-byte array filled with zeros. ZEROS [CipherKeySize]byte // ZEROLEN is a zero-length byte sequence. ZEROLEN []byte )
var ( // ErrInvalidRekeyInterval is returned when interval is 0. ErrInvalidRekeyInterval = errors.New("rekey interval cannot be 0") // ErrMissingConfig is returned when no config file is provided. ErrMissingConfig = errors.New("missing config") // ErrProtocolInvalidName is returned when protocol name is wrong. ErrProtocolInvalidName = errors.New("invalid protocol name") )
Functions ¶
This section is empty.
Types ¶
type CipherState ¶
type CipherState struct { // Rekeyer is a customized rekey function. RekeyManger rekey.Rekeyer // contains filtered or unexported fields }
CipherState contains key and nonce variables, which it uses to encrypt and decrypt ciphertext. During the handshake phase each party has a single CipherState, but during the transport phase each party has two CipherState instances, one for sending, and one for receiving.
func (*CipherState) DecryptWithAd ¶
func (cs *CipherState) DecryptWithAd(ad, ciphertext []byte) ([]byte, error)
DecryptWithAd decrypts ciphertext with ad. If the key is non-empty it returns the decrypted plaintext, otherwise returns ciphertext.
If an authentication failure occurs in decryption then nonce is not incremented and an error is signaled to the caller.
func (*CipherState) EncryptWithAd ¶
func (cs *CipherState) EncryptWithAd(ad, plaintext []byte) ([]byte, error)
EncryptWithAd encrypts plaintext with ad. If the key is non-empty it returns the encrypted ciphertext, otherwise returns plaintext.
func (*CipherState) Nonce ¶
func (cs *CipherState) Nonce() uint64
Nonce returns the current nonce value.
func (*CipherState) Rekey ¶
func (cs *CipherState) Rekey() error
Rekey updates the underlying cipher with a new key. If a rekeyer is defined for the Cipherstate, it's used to generate the new key. Otherwise, it uses the Rekey from the underlying cipher to generate a new key.
There are actually two places to customize a Rekey function. First here, then there's an opportunity in the underlying cipher.Rekey(). Also note that Rekey only updates the cipher's key value, it doesn't reset the cipher's nonce value, so applications performing Rekey must still perform a new handshake if sending 2^64 or more transport messages.
func (*CipherState) Reset ¶
func (cs *CipherState) Reset()
Reset sets the cipher key to ZEROS, nonce to 0, and calls cipher.Reset.
func (*CipherState) SetNonce ¶
func (cs *CipherState) SetNonce(n uint64)
SetNonce sets the nonce. This function is used for handling out-of-order transport messages
type DefaultRekeyerConfig ¶
type DefaultRekeyerConfig struct { // Interval specifies the number of messages to be sent before a rekey is // performed. Interval uint64 // ResetNonce decides whether to reset the cipher nonce to zero when a rekey // is performed. ResetNonce bool }
DefaultRekeyerConfig is used for creating the default rekey manager.
type HandshakeState ¶
type HandshakeState struct { // SendCipherState is used for encrypting plaintext once the handshake is // finished. SendCipherState *CipherState // RecvCipherState is used for decrypting ciphertext once the handshake is // finished. RecvCipherState *CipherState // contains filtered or unexported fields }
HandshakeState object contains a symmetricState plus DH variables (s, e, rs, re) and a variable representing the handshake pattern. During the handshake phase each party has a single HandshakeState, which can be deleted once the handshake is finished.
func NewProtocol ¶
func NewProtocol(name, prologue string, initiator bool) (*HandshakeState, error)
NewProtocol creates a new handshake state with the specified name prologue, and initiator. It calls the NewProtocolWithConfig with a default config, in which,
a default rekeyer is used, which resets the cipher key with an interval of 10000 and resets the nonce to be zero.
if any local ephemeral/static or remote ephemeral/static keys are needed by the message pattern prior to the creation of the handshake state, it will create the corresponding keys automatically.
NewProtocl doesn't support PSK mode, or specifying remote public keys prior to the creation of the handshake state, if needed, please use NewProtocolWithConfig instead.
func NewProtocolWithConfig ¶
func NewProtocolWithConfig(config *ProtocolConfig) (*HandshakeState, error)
NewProtocolWithConfig creates a handshake state with parameters from a ProtocolConfig.
func (*HandshakeState) Finished ¶
func (hs *HandshakeState) Finished() bool
Finished returns a bool to indicate whether the handshake is done. The patternIndex is used to track the index of last processed pattern, when it reaches the end, it indicates the patterns have all been processed.
func (*HandshakeState) GetChainingKey ¶
func (hs *HandshakeState) GetChainingKey() []byte
GetChainingKey returns the chaining key in use.
func (*HandshakeState) GetDigest ¶
func (hs *HandshakeState) GetDigest() []byte
GetDigest returns the hash digest in use.
func (*HandshakeState) GetInfo ¶
func (hs *HandshakeState) GetInfo() ([]byte, error)
GetInfo gives a full picture of the handshake internal state.
func (*HandshakeState) ReadMessage ¶
func (hs *HandshakeState) ReadMessage(message []byte) ([]byte, error)
ReadMessage takes a byte sequence containing a Noise handshake message, and return the decrypted message plaintext.
func (*HandshakeState) Reset ¶
func (hs *HandshakeState) Reset()
Reset sets the handshake to initial state.
func (*HandshakeState) WriteMessage ¶
func (hs *HandshakeState) WriteMessage(payload []byte) ([]byte, error)
WriteMessage takes a payload byte sequence which may be zero-length, and returns the ciphertext.
type ProtocolConfig ¶
type ProtocolConfig struct { // Name is the protocol name defined by the noise specs, e.g., // Noise_XX_25519_AESGCM_SHA256 Name string // Initiator specifies whether it's the handshake initiator Initiator bool // Prologue is an optional information to be used when creating the // handskake state. Both parties must provide identical prologue data, // otherwisethe handshake will fail due to a decryption error. Prologue string // RekeyerConfig is a config used for set up the default rekeyer. If Rekeyer // is set, this variable is ignored. RekeyerConfig *DefaultRekeyerConfig // Rekeyer is a rekey manager, which controls when/how a rekey should be // performed, and whether the cipher nonce should be reset. Rekeyer rekey.Rekeyer // LocalStaticPriv is the s from the noise spec. Only provide it when it's // needed by the message pattern, otherwise leave it empty. LocalStaticPriv []byte // LocalEphemeralPriv is the e from the noise spec. Only provide it when // it's needed by the message pattern, otherwise leave it empty. LocalEphemeralPriv []byte // RemoteStaticPub is the rs from the noise spec. Only provide it when it's // needed by the message pattern, otherwise leave it empty. RemoteStaticPub []byte // RemoteEphemeralPub is the re from the noise spec. Only provide it when // it's needed by the message pattern, otherwise leave it empty. RemoteEphemeralPub []byte // Psks is used to store the pre-shared symmetric keys used if both parties // have a 32-byte shared secret keys. Psks [][]byte // contains filtered or unexported fields }
ProtocolConfig is used for constructing a new handshake state.
Directories
¶
Path | Synopsis |
---|---|
Package cipher implements the cipher functions specified in the noise protocol.
|
Package cipher implements the cipher functions specified in the noise protocol. |
Package dh implements the DH functions specified in the noise protocol.
|
Package dh implements the DH functions specified in the noise protocol. |
examples
|
|
babble
This is an implemention for demonstration only.
|
This is an implemention for demonstration only. |
handshake
This is an implemention for demonstration only.
|
This is an implemention for demonstration only. |
newcipher
This is an implemention for demonstration only.
|
This is an implemention for demonstration only. |
newdh
This is an implemention for demonstration only.
|
This is an implemention for demonstration only. |
newhash
This is an implemention for demonstration only.
|
This is an implemention for demonstration only. |
newpattern
This is an implemention for demonstration only.
|
This is an implemention for demonstration only. |
Package hash implements the hash functions specified in the noise protocol.
|
Package hash implements the hash functions specified in the noise protocol. |
Package pattern implements the noise handshake pattern.
|
Package pattern implements the noise handshake pattern. |
Package rekey defines the rekey functions to be used in the babbel package.
|
Package rekey defines the rekey functions to be used in the babbel package. |
Package vectors is created to help the vector test.
|
Package vectors is created to help the vector test. |