diff options
author | joe <joe@jerkface.net> | 2016-09-02 01:01:34 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-07-01 09:19:55 -0400 |
commit | 595e1bec3dda5f04d58a4c94d1f3c6da0e256061 (patch) | |
tree | bb40bee5f1746b01686baaf228fb9fa445d11fc6 /Data | |
parent | 05e5830aab6b71735f347d8963bd1fb037e59732 (diff) |
randomS2K utility.
Diffstat (limited to 'Data')
-rw-r--r-- | Data/OpenPGP/Util.hs | 1 | ||||
-rw-r--r-- | Data/OpenPGP/Util/DecryptSecretKey.hs | 14 |
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 | ||
11 | import Data.OpenPGP.Util.Fingerprint | 12 | import 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 @@ | |||
4 | module Data.OpenPGP.Util.DecryptSecretKey where | 4 | module Data.OpenPGP.Util.DecryptSecretKey where |
5 | 5 | ||
6 | import qualified Data.OpenPGP as OpenPGP | 6 | import qualified Data.OpenPGP as OpenPGP |
7 | import Data.OpenPGP.Internal (decode_s2k_count) | ||
7 | import qualified Data.ByteString as BS | 8 | import qualified Data.ByteString as BS |
8 | import qualified Data.ByteString.Lazy as LZ | 9 | import qualified Data.ByteString.Lazy as LZ |
9 | import Data.Word (Word16) | 10 | import Data.Word (Word16) |
@@ -19,6 +20,7 @@ import Data.Binary.Get (runGet) | |||
19 | #endif | 20 | #endif |
20 | import Control.Exception as Exception (IOException(..),catch) | 21 | import Control.Exception as Exception (IOException(..),catch) |
21 | import Data.Binary.Put (runPut) | 22 | import Data.Binary.Put (runPut) |
23 | import qualified Data.Serialize as Cereal | ||
22 | import Control.Applicative ( (<$>) ) | 24 | import Control.Applicative ( (<$>) ) |
23 | 25 | ||
24 | import qualified Crypto.Cipher.AES as Vincent | 26 | import 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 | |||
237 | randomS2K :: OpenPGP.HashAlgorithm -> IO OpenPGP.S2K | ||
238 | randomS2K 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 | |||