nonce 1.0.2 → 1.0.3
raw patch · 2 files changed
+8/−10 lines, 2 filesdep +cryptonitedep −cprng-aesdep −crypto-randomdep ~basenew-uploader
Dependencies added: cryptonite
Dependencies removed: cprng-aes, crypto-random
Dependency ranges changed: base
Files
- nonce.cabal +3/−4
- src/Crypto/Nonce.hs +5/−6
nonce.cabal view
@@ -1,5 +1,5 @@ name: nonce-version: 1.0.2+version: 1.0.3 synopsis: Generate cryptographic nonces. homepage: https://github.com/prowdsponsor/nonce license: BSD3@@ -28,11 +28,10 @@ exposed-modules: Crypto.Nonce build-depends:- base >= 4.5 && < 4.9+ base >= 4.5 && < 4.11 , base64-bytestring == 1.0.* , bytestring >= 0.9- , crypto-random == 0.0.*- , cprng-aes >= 0.5 && < 0.7+ , cryptonite >= 0.4 , text >= 0.9 , transformers >= 0.2 hs-source-dirs: src/
src/Crypto/Nonce.hs view
@@ -32,11 +32,10 @@ import Control.Monad (liftM) import Control.Monad.IO.Class (MonadIO, liftIO)+import Crypto.Random import Data.Tuple (swap) import Data.Typeable (Typeable) -import qualified Crypto.Random as R-import qualified Crypto.Random.AESCtr as AESCtr import qualified Data.ByteString as B import qualified Data.ByteString.Base64.URL as B64URL import qualified Data.IORef as I@@ -46,7 +45,7 @@ -- | An encapsulated nonce generator. data Generator =- G (I.IORef AESCtr.AESRNG)+ G (I.IORef SystemDRG) deriving (Typeable) instance Show Generator where@@ -55,12 +54,12 @@ -- | Create a new nonce generator using the system entropy. new :: MonadIO m => m Generator-new = liftM G . liftIO $ AESCtr.makeSystem >>= I.newIORef+new = liftM G . liftIO $ getSystemDRG >>= I.newIORef --- | (Internal) Generate the given number of bytes from the AES CPRNG.+-- | (Internal) Generate the given number of bytes from the DRG. genBytes :: MonadIO m => Int -> Generator -> m B.ByteString-genBytes n (G v) = liftIO $ I.atomicModifyIORef v $ swap . R.cprgGenerate n+genBytes n (G v) = liftIO $ I.atomicModifyIORef v $ swap . randomBytesGenerate n -- | Generate a 128 bit nonce as a 'B.ByteString' of 16 bytes.