NaCl-0.0.3.0: Easy-and-safe-to-use high-level Haskell bindings to NaCl
Safe HaskellNone
LanguageHaskell2010

Crypto.Box.Internal

Description

Internals of crypto_box.

Synopsis

Documentation

type SecretKey = SizedByteArray CRYPTO_BOX_SECRETKEYBYTES ScrubbedBytes Source #

Secret key that can be used for Box.

toSecretKey :: ScrubbedBytes -> Maybe SecretKey Source #

Convert bytes to a secret key.

type PublicKey = SizedByteArray CRYPTO_BOX_PUBLICKEYBYTES ByteString Source #

Public key that can be used for Box.

keypair :: IO (PublicKey, SecretKey) Source #

Generate a new SecretKey together with its PublicKey.

Note: this function is not thread-safe (since the underlying C function is not thread-safe both in Sodium and in NaCl)! Either make sure there are no concurrent calls or see Crypto.Init in crypto-sodium to learn how to make this function thread-safe.

type Nonce a = SizedByteArray CRYPTO_BOX_NONCEBYTES a Source #

Nonce that can be used for Box.

This type is parametrised by the actual data type that contains bytes. This can be, for example, a ByteString.

toNonce :: ByteArrayAccess ba => ba -> Maybe (Nonce ba) Source #

Make a Nonce from an arbitrary byte array.

This function returns Just if and only if the byte array has the right length to be used as a nonce with a Box.

create Source #

Arguments

:: (ByteArrayAccess nonce, ByteArrayAccess pt, ByteArray ct) 
=> PublicKey

Receiver’s public key

-> SecretKey

Sender’s secret key

-> Nonce nonce

Nonce

-> pt

Plaintext message

-> IO ct 

Encrypt a message.

open Source #

Arguments

:: (ByteArrayAccess nonce, ByteArray pt, ByteArrayAccess ct) 
=> SecretKey

Receiver’s secret key

-> PublicKey

Sender’s public key

-> Nonce nonce

Nonce

-> ct

Cyphertext

-> IO (Maybe pt) 

Decrypt a message.