About

Metadata

  • Last updated , by AndreasAbel
  • License BSD-3-Clause
  • Categories Cryptography
  • Maintained by: Thomas DuBuisson <thomas.dubuisson@gmail.com>

  • Lottery factor: 0

Links

Installation

This package uses the Custom cabal build type

Tested Compilers

  1. 9.12.1
  2. 9.10.1
  3. 9.8.4
  4. 9.6.6
  5. 9.4.8
  6. 9.2.8
  7. 9.0.2
  8. 8.10.7
  9. 8.8.4
  10. 8.6.5
  11. 8.4.4
  12. 8.2.2

Package Flags

Use the -f option with cabal commands to enable flags

    donotgetentropy (off by default)

    Avoid use of the getentropy() *nix function. By default getentropy will be used if detected during compilation (this plays poorly with cross compilation).

Readme

Introduction

This package allows Haskell users to easily acquire entropy for use in critical security applications by calling out to either windows crypto api, unix/linux's getrandom and /dev/urandom. Hardware RNGs (currently RDRAND, patches welcome) are supported via the hardwareRNG function.

Quick Start

To simply get random bytes use getEntropy:

#!/usr/bin/env cabal
{- cabal:
    build-depends: base, entropy, bytestring
-}
import qualified Data.ByteString as BS
import           System.Entropy

main :: IO ()
main = print . BS.unpack =<< getEntropy 16
-- Example output: [241,191,215,193,225,27,121,244,16,155,252,41,131,38,6,100]

Faster Randoms from Hardware

Most x86 systems include a hardware random number generator. These can be faster but require more trust in the platform:

import qualified Data.ByteString as B
import           System.Entropy

eitherRNG :: Int -> IO B.ByteString
eitherRNG sz = maybe (getEntropy sz) pure =<< getHardwareEntropy sz

main :: IO ()
main = print . B.unpack =<< eitherRNG 32

This package supports Windows, {li,u}nix, QNX, and has preliminary support for HaLVM.

Typically tested on Linux and OSX - testers are as welcome as patches.

Build Status