saltine

Cryptography that's easy to digest (NaCl/libsodium bindings).

LTS Haskell 22.37:0.2.1.0
Stackage Nightly 2023-12-26:0.2.1.0
Latest on Hackage:0.2.1.0

See all snapshots saltine appears in

Saltine 0.2.1.0 Hackage version

A Haskell binding for @jedisct1’s portable binding for djb’s NaCl. This is an early release. Please try it out, but don’t just yet stake your life or job on it.

It is imperative you call sodiumInit before using any other function.

import           Crypto.Saltine
import           Crypto.Saltine.Core.SecretBox
import qualified Data.ByteString.Char8 as BSC8

main = do
  sodiumInit
  k <- newKey
  n <- newNonce
  let ciphertext = secretbox k n (BSC8.pack "foobar")
  print $ secretboxOpen k n ciphertext

-- Just "foobar"

In The Security Impact of a New Cryptographic Library Bernstein, Lange, and Schwabe argue that high-level cryptographic libraries eliminate whole spaces of cryptographic disasters which are nigh inevitable whenever programmers use low-level crypto primitives.

Crypto is complicated, so pre-rolled solutions are important prevention mechanisms.

NaCl is Bernstein, Lange, and Schwabe’s solution: a high-level, performant cryptography library with a no-fuss interface. Saltine is a Haskell binding to NaCl (via libsodium) which hopes to provide even more simplicity and safety to the usage of cryptography.

Note that it’s still possible to shoot yourself in the foot pretty easily using Saltine. Nonces must always be unique which must be managed by the library user. Crypto.Saltine.Core.Stream produces messages which can beundetectably tampered with in-flight. Keys are insecurely read from disk—they may be copied and then paged back to disk.

When uncertain, use Crypto.Saltine.Core.SecretBox and Crypto.Saltine.Core.Box. If you can think of ways to use Haskell’s type system to enforce security invariants, please suggest them.

To use it on Windows systems, download a prebuild libsodium-*-stable-mingw.tar.gz file and copy the files in libsodium-win64 into the equivalent places in C:\Program Files\Haskell Platform\*\mingw. Then just add saltine to your cabal file and watch it go.

Tested with libsodium-1.0.18.

Inspired by @thoughtpolice’s salt library. salt also binds to NaCl, but uses a Haskell managed version of djb’s code instead of libsodium.

Changes

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog

[Unreleased]

Added

Changed

[0.2.1.0] - 2023-02-17

Changed

  • Fix Show instances formatting, and add instances for Keypairs, thanks @NicolasT

[0.2.0.1] - 2022-04-30

Changed

  • Relax version bounds on text and bytestring, thanks @ysangkok

[0.2.0.0] - 2021-05-27

Added

  • All AEAD variants are now in saltine
  • Key comparisons now use sodium_memcmp to prevent timing attacks
  • Liberal use of Internal modules
  • Benchmarks added
  • Export Key/Nonce/… constructors from Internal module
  • New password hashing module
  • Show instances for most (all?) relevant data types
  • Signature types for detached functions

Changed

  • newtype accessor functions added, keypairs are separate data types now instead of tuples

[0.1.1.1] - 2021-01-15

Changed

  • Fix for running tests in cabal repl (thanks [@timds])
  • Allow newer profunctors

[0.1.1.0] - 2020-02-29

Added

  • bindings to generichash (Blake2), thanks @donatello

Changed

  • Don’t use fail in tests to fix compilation with GHC 8.8
  • Windows install instructions added, thanks @tmcl