diff --git a/Crypto/Random/Entropy/Unix.hs b/Crypto/Random/Entropy/Unix.hs index b480d7d..e08fe78 100644 --- a/Crypto/Random/Entropy/Unix.hs +++ b/Crypto/Random/Entropy/Unix.hs @@ -31,7 +31,7 @@ newtype DevURandom = DevURandom DeviceName instance EntropySource DevRandom where entropyOpen = fmap DevRandom `fmap` testOpen "/dev/random" entropyGather (DevRandom name) ptr n = - withDev name $ \h -> gatherDevEntropy h ptr n + withDev name $ \h -> gatherDevEntropyNonBlock h ptr n entropyClose (DevRandom _) = return () instance EntropySource DevURandom where @@ -67,3 +67,8 @@ gatherDevEntropy :: H -> Ptr Word8 -> Int -> IO Int gatherDevEntropy h ptr sz = (fromIntegral `fmap` hGetBufSome h ptr (fromIntegral sz)) `E.catch` \(_ :: IOException) -> return 0 + +gatherDevEntropyNonBlock :: H -> Ptr Word8 -> Int -> IO Int +gatherDevEntropyNonBlock h ptr sz = + (fromIntegral `fmap` hGetBufNonBlocking h ptr (fromIntegral sz)) + `E.catch` \(_ :: IOException) -> return 0