summaryrefslogtreecommitdiff
path: root/Crypto.hs
diff options
context:
space:
mode:
authorGravatar guilhem <guilhem@fripost.org>2013-04-05 21:06:16 +0200
committerGravatar Joey Hess <joey@kitenet.net>2013-04-06 16:09:51 -0400
commita7f50205bb1ccd41d4a9ab4e11d984e643be755f (patch)
tree519c7148a87575896450b7dc43fc58e8b34dfe02 /Crypto.hs
parentf758f6d5cbef989bff75fcd140edb8e0b8899b84 (diff)
Generate ciphers with a better entropy.
Unless highRandomQuality=false (or --fast) is set, use Libgcypt's 'GCRY_VERY_STRONG_RANDOM' level by default for cipher generation, like it's done for OpenPGP key generation. On the assistant side, the random quality is left to the old (lower) level, in order not to scare the user with an enless page load due to the blocking PRNG waiting for IO actions.
Diffstat (limited to 'Crypto.hs')
-rw-r--r--Crypto.hs11
1 files changed, 6 insertions, 5 deletions
diff --git a/Crypto.hs b/Crypto.hs
index be326bf4c..21b1ae41b 100644
--- a/Crypto.hs
+++ b/Crypto.hs
@@ -67,15 +67,16 @@ cipherMac :: Cipher -> String
cipherMac (Cipher c) = take cipherBeginning c
{- Creates a new Cipher, encrypted to the specified key id. -}
-genEncryptedCipher :: String -> IO StorableCipher
-genEncryptedCipher keyid = do
+genEncryptedCipher :: String -> Bool -> IO StorableCipher
+genEncryptedCipher keyid highQuality = do
ks <- Gpg.findPubKeys keyid
- random <- Gpg.genRandom cipherSize
+ random <- Gpg.genRandom highQuality cipherSize
encryptCipher (Cipher random) ks
{- Creates a new, shared Cipher. -}
-genSharedCipher :: IO StorableCipher
-genSharedCipher = SharedCipher <$> Gpg.genRandom cipherSize
+genSharedCipher :: Bool -> IO StorableCipher
+genSharedCipher highQuality =
+ SharedCipher <$> Gpg.genRandom highQuality cipherSize
{- Updates an existing Cipher, re-encrypting it to add a keyid. -}
updateEncryptedCipher :: String -> StorableCipher -> IO StorableCipher