summaryrefslogtreecommitdiff
path: root/Data/OpenPGP/Util/DecryptSecretKey.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Data/OpenPGP/Util/DecryptSecretKey.hs')
-rw-r--r--Data/OpenPGP/Util/DecryptSecretKey.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/Data/OpenPGP/Util/DecryptSecretKey.hs b/Data/OpenPGP/Util/DecryptSecretKey.hs
index 1c519ae..1188f3e 100644
--- a/Data/OpenPGP/Util/DecryptSecretKey.hs
+++ b/Data/OpenPGP/Util/DecryptSecretKey.hs
@@ -4,6 +4,7 @@
4module Data.OpenPGP.Util.DecryptSecretKey where 4module Data.OpenPGP.Util.DecryptSecretKey where
5 5
6import qualified Data.OpenPGP as OpenPGP 6import qualified Data.OpenPGP as OpenPGP
7import Data.OpenPGP.Internal (decode_s2k_count)
7import qualified Data.ByteString as BS 8import qualified Data.ByteString as BS
8import qualified Data.ByteString.Lazy as LZ 9import qualified Data.ByteString.Lazy as LZ
9import Data.Word (Word16) 10import Data.Word (Word16)
@@ -19,6 +20,7 @@ import Data.Binary.Get (runGet)
19#endif 20#endif
20import Control.Exception as Exception (IOException(..),catch) 21import Control.Exception as Exception (IOException(..),catch)
21import Data.Binary.Put (runPut) 22import Data.Binary.Put (runPut)
23import qualified Data.Serialize as Cereal
22import Control.Applicative ( (<$>) ) 24import Control.Applicative ( (<$>) )
23 25
24import qualified Crypto.Cipher.AES as Vincent 26import qualified Crypto.Cipher.AES as Vincent
@@ -231,3 +233,15 @@ encryptSecretKey passphrase s2k salgo plain = do
231 233
232 234
233 -- k = string2key s2k passphrase -- OpenPGP.string2key hashBySymbol s2k passphrase 235 -- k = string2key s2k passphrase -- OpenPGP.string2key hashBySymbol s2k passphrase
236
237randomS2K :: OpenPGP.HashAlgorithm -> IO OpenPGP.S2K
238randomS2K hash = do
239 g <- makeGen Nothing
240#if defined(VERSION_cryptonite)
241 let (saltbs,g') = Vincent.randomBytesGenerate 9 g
242#else
243 let (saltbs,g') = Vincent.cprgGenerate 9 g
244#endif
245 let Right salt = Cereal.decode (BS.drop 1 saltbs)
246 return $ OpenPGP.IteratedSaltedS2K hash salt (decode_s2k_count $ BS.head saltbs)
247