cacophony

A library implementing the Noise protocol.

https://github.com/centromere/cacophony

Version on this page:0.5.0
LTS Haskell 22.14:0.10.1
Stackage Nightly 2024-03-29:0.10.1
Latest on Hackage:0.10.1

See all snapshots cacophony appears in

LicenseRef-PublicDomain licensed by John Galt
Maintained by [email protected]
This version can be pinned in stack with:cacophony-0.5.0@sha256:3e99fce03d24d0d1feb696dec7e5a1360f512a0e6d7334f5d1e97efee0594d0a,3430

Module documentation for 0.5.0

Used by 1 package in nightly-2016-04-03(full list with versions):

cacophony

Build Status Haskell

This library implements the Noise protocol.

Basic usage

  1. Define functions which will be called when protocol messages are to be read and written to the remote peer. The payloadIn and payloadOut functions are called when payloads are received and needed.

    writeMsg   :: ByteString -> IO ()
    readMsg    :: IO ByteString
    payloadIn  :: Plaintext -> IO ()
    payloadOut :: IO Plaintext
    -- If you don't need to use payloads, do the following:
    let hc = HandshakeCallbacks (writeMsg socket)
                                 (readMsg socket)
                                 (\_ -> return ())
                                 (return "")
    
  2. Create the handshake state: Select a handshake pattern to use. Patterns are defined in the Crypto.Noise.HandshakePatterns module. Ensure that you provide the keys which are required by the handshake pattern you choose. For example, the Noise_IK pattern requires that the initiator provides a local static key and a remote static key. Remote keys are communicated out-of-band.

    let hs = handshakeState $ HandshakeStateParams
       noiseIK
       ""
       -- ^ Prologue
       (Just "foo")
       -- ^ Pre-shared key
       (Just initStatic)
       -- ^ Local static key
       Nothing
       -- ^ Local ephemeral key
       (Just (snd respStatic))
       -- ^ Remote static key
       Nothing
       -- ^ Remote ephemeral key
       True
       -- ^ True if we are initiator
    
  3. Run the handshake:

    (encryptionCipherState, decryptionCipherState) <- runHandshake hs hc
    
  4. Send and receive transport messages:

    let (cipherText, encryptionCipherState') = encryptPayload "hello world" encryptionCipherState
    let (Plaintext pt, decryptionCipherState') = decryptPayload msg decryptionCipherState
    

    Ensure that you never re-use a cipher state with encryptPayload and decryptPayload.

Changes

0.5.0

  • Added Curve448 support

  • Major refactoring and API changes A DSL was created to represent handshake patterns.

  • Added GHC 7.10.3 to unit tests

0.4.0

  • Improved documentation

  • Added basic benchmarks

  • Added better exception handling

  • Improved handshakeState API

  • Added psk2 functionality

  • Unit test cleanup

  • Renamed symmetricHandshake to symmetricState

  • Added BLAKE2, SHA512, AESGCM support

0.3.0

  • Brought API up to date with current version of spec (17)

0.2.0

  • Added support for one-way handshakes

  • Fixed Noise_IX

  • Added helper functions for ScrubbedBytes / ByteString conversion

0.1.0.0

  • First version.