Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haskell/entropy
Easy entropy source for Haskell users.
https://github.com/haskell/entropy
Last synced: about 1 month ago
JSON representation
Easy entropy source for Haskell users.
- Host: GitHub
- URL: https://github.com/haskell/entropy
- Owner: haskell
- License: other
- Created: 2013-05-12T19:21:56.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2023-03-24T20:32:35.000Z (over 1 year ago)
- Last Synced: 2024-04-16T00:49:06.888Z (7 months ago)
- Language: Haskell
- Size: 98.6 KB
- Stars: 23
- Watchers: 5
- Forks: 46
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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.Entropymain :: 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.EntropyeitherRNG :: Int -> IO B.ByteString
eitherRNG sz = maybe (getEntropy sz) pure =<< getHardwareEntropy szmain :: 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](https://travis-ci.org/TomMD/entropy.svg?branch=master)](https://travis-ci.org/TomMD/entropy)