crypton-box-1.1.0: NaCl crypto/secret box implementations based on crypton primitives.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Crypto.Box

Description

This module provides the creation and opening of a crypto_box.

Synopsis

Documentation

create Source #

Arguments

:: (ByteArray content, ByteArray nonce) 
=> content

Message to encrypt

-> nonce

192-bit nonce

-> PublicKey

Receiver's public key

-> SecretKey

Sender's private key

-> content

Ciphertext

Build a crypto_box packet encrypting the specified content with a 192-bit nonce, receiver public key and sender private key.

This function performs no validation for the key pair, and will use an all-zero shared secret if the Diffie hellman secret value is at infinity. Use beforeNM to get only the precomputed secret if you want to verify the key pair before use.

beforeNM Source #

Arguments

:: PublicKey

Receiver public key

-> SecretKey

Sender private key

-> CryptoFailable State

XSalsa State that contains the precomputed first-level key to use with createAfterNM or openAfterNM

Precompute the shared key for building a crypto_box packet. This function first computes the shared secret using the receiver public key and sender private key. Then, a first-level key is computed using HSalsa20 with the shared secret and a nonce of zero. This is as described in section 7 (page 15) of https://cr.yp.to/highspeed/naclcrypto-20090310.pdf.

The function returns a XSalsa State that contains the first-level key.

May fail if the Diffie hellman secret value is at infinity. See ecdh for more information.

createAfterNM Source #

Arguments

:: (ByteArray content, ByteArray nonce) 
=> content

Message to encrypt

-> nonce

192-bit nonce

-> State

XSalsa State that contains the precomputed first-level key

-> content

Ciphertext

Build a crypto_box packet that encrypts the specified content with a 192-bit nonce and a state containing the precomputed first-level key. Use beforeNM to create such a state.

open Source #

Arguments

:: (ByteArray content, ByteArray nonce) 
=> content

Ciphertext to decrypt

-> nonce

192-bit nonce

-> PublicKey

Sender's public key

-> SecretKey

Receiver's private key

-> Maybe content

Plaintext

Try to open a crypto_box packet and recover the content using the 192-bit nonce, sender public key and receiver private key.

This function performs no validation for the key pair, and will use an all-zero shared secret if the Diffie hellman secret value is at infinity. Use beforeNM to get only the precomputed secret if you want to verify the key pair before use.

openAfterNM Source #

Arguments

:: (ByteArray content, ByteArray nonce) 
=> content

Ciphertext

-> nonce

192-bit nonce

-> State

XSalsa State that contains the precomputed first-level key

-> Maybe content 

Try to open a crypto_box packet and recover the content using the 192-bit nonce and a state containing the precomputed first-level key. Use beforeNM to create such a state.