cacophony-0.4.0: A library implementing the Noise protocol.

MaintainerJohn Galt <jgalt@centromere.net>
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Crypto.Noise.Handshake

Contents

Description

For more information regarding HandshakePatterns, please see the Crypto.Noise.HandshakePatterns module.

Synopsis

Types

data HandshakeState c d h Source

Contains the state of a handshake.

type MessagePattern c d h a = MessagePatternT c d h Identity a Source

Represents a series of operations that can be performed on a Noise message.

type MessagePatternIO c d h a = MessagePatternT c d h IO a Source

Represents a series of operations that will result in a Noise message. This must be done in IO to facilitate the generation of ephemeral keys.

data HandshakePattern c d h Source

Represents a series of message patterns, the first for writing and the second for reading.

data CipherState c Source

Represents a symmetric key and associated nonce.

Functions

getRemoteStaticKey :: Curve d => HandshakeState c d h -> PublicKey d Source

Returns the remote party's public static key. This is useful when the static key has been transmitted to you and you want to save it for future use.

handshakeState Source

Arguments

:: (Cipher c, Curve d, Hash h) 
=> HandshakePattern c d h

The handshake pattern to use

-> Plaintext

Prologue

-> Maybe Plaintext

Pre-shared key

-> Maybe (KeyPair d)

Local static key

-> Maybe (KeyPair d)

Local ephemeral key

-> Maybe (PublicKey d)

Remote public static key

-> Maybe (PublicKey d)

Remote public ephemeral key

-> HandshakeState c d h 

Constructs a HandshakeState. The keys you need to provide are dependent on the type of handshake you are using. If you fail to provide a key that your handshake type depends on, or you provide a static key which is supposed to be set during the exchange, you will receive a HandshakeStateFailure exception.

writeMessage Source

Arguments

:: (Cipher c, Curve d, Hash h) 
=> HandshakeState c d h

The handshake state

-> Plaintext

Optional message to transmit

-> IO (ByteString, HandshakeState c d h) 

Creates a handshake message. The plaintext can be left empty if no plaintext is to be transmitted. All subsequent handshake processing must use the returned state.

readMessage Source

Arguments

:: (Cipher c, Curve d, Hash h) 
=> HandshakeState c d h

The handshake state

-> ByteString

The handshake message received

-> (Plaintext, HandshakeState c d h) 

Reads a handshake message. All subsequent handshake processing must use the returned state.

writeMessageFinal Source

Arguments

:: (Cipher c, Curve d, Hash h) 
=> HandshakeState c d h

The handshake state

-> Plaintext

Optional message to transmit

-> IO (ByteString, CipherState c, CipherState c) 

The final call of a handshake negotiation. Used to generate a pair of CipherStates, one for each transmission direction.

readMessageFinal Source

Arguments

:: (Cipher c, Curve d, Hash h) 
=> HandshakeState c d h

The handshake state

-> ByteString

The handshake message received

-> (Plaintext, CipherState c, CipherState c) 

The final call of a handshake negotiation. Used to generate a pair of CipherStates, one for each transmission direction.

encryptPayload Source

Arguments

:: Cipher c 
=> Plaintext

The data to encrypt

-> CipherState c

The CipherState to use for encryption

-> (ByteString, CipherState c) 

Encrypts a payload. The returned CipherState must be used for all subsequent calls.

decryptPayload Source

Arguments

:: Cipher c 
=> ByteString

The data to decrypt

-> CipherState c

The CipherState to use for decryption

-> (Plaintext, CipherState c) 

Decrypts a payload. The returned CipherState must be used for all subsequent calls.