summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2016-09-02 01:01:34 -0400
committerJoe Crayne <joe@jerkface.net>2019-07-01 09:19:55 -0400
commit595e1bec3dda5f04d58a4c94d1f3c6da0e256061 (patch)
treebb40bee5f1746b01686baaf228fb9fa445d11fc6
parent05e5830aab6b71735f347d8963bd1fb037e59732 (diff)
randomS2K utility.
-rw-r--r--Data/OpenPGP/Util.hs1
-rw-r--r--Data/OpenPGP/Util/DecryptSecretKey.hs14
2 files changed, 15 insertions, 0 deletions
diff --git a/Data/OpenPGP/Util.hs b/Data/OpenPGP/Util.hs
index 19d98ec..6b1ebb1 100644
--- a/Data/OpenPGP/Util.hs
+++ b/Data/OpenPGP/Util.hs
@@ -6,6 +6,7 @@ module Data.OpenPGP.Util
6 , pgpSign 6 , pgpSign
7 , GenerateKeyParams(..) 7 , GenerateKeyParams(..)
8 , generateKey 8 , generateKey
9 , randomS2K
9 ) where 10 ) where
10 11
11import Data.OpenPGP.Util.Fingerprint 12import Data.OpenPGP.Util.Fingerprint
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