diff options
Diffstat (limited to 'Data/OpenPGP/Util/DecryptSecretKey.hs')
-rw-r--r-- | Data/OpenPGP/Util/DecryptSecretKey.hs | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/Data/OpenPGP/Util/DecryptSecretKey.hs b/Data/OpenPGP/Util/DecryptSecretKey.hs index 1188f3e..a637b29 100644 --- a/Data/OpenPGP/Util/DecryptSecretKey.hs +++ b/Data/OpenPGP/Util/DecryptSecretKey.hs | |||
@@ -90,7 +90,7 @@ decryptSecretKey pass k@(OpenPGP.SecretKeyPacket { | |||
90 | | OpenPGP.s2k_useage k == 254 = (20, sha1 . toStrictBS) | 90 | | OpenPGP.s2k_useage k == 254 = (20, sha1 . toStrictBS) |
91 | | otherwise = (2, toStrictBS . encode . checksum . toStrictBS) | 91 | | otherwise = (2, toStrictBS . encode . checksum . toStrictBS) |
92 | -- Words16s are written as 2 bytes in big-endian (network) order | 92 | -- Words16s are written as 2 bytes in big-endian (network) order |
93 | decd = withS2K simpleUnCFB salgo s2k (toLazyBS pass) (EncipheredWithIV encd) | 93 | decd = withS2K simpleUnCFB salgo (Just s2k) (toLazyBS pass) (EncipheredWithIV encd) |
94 | 94 | ||
95 | #if defined(VERSION_cryptonite) | 95 | #if defined(VERSION_cryptonite) |
96 | sha1 x = Bytes.convert (hash x :: Digest SHA1) | 96 | sha1 x = Bytes.convert (hash x :: Digest SHA1) |
@@ -122,7 +122,7 @@ maybeGet g bs = unsafePerformIO $ | |||
122 | 122 | ||
123 | withS2K :: (forall k. (Vincent.BlockCipher k) => k -> Vincent.IV k -> LZ.ByteString -> LZ.ByteString) | 123 | withS2K :: (forall k. (Vincent.BlockCipher k) => k -> Vincent.IV k -> LZ.ByteString -> LZ.ByteString) |
124 | -> OpenPGP.SymmetricAlgorithm | 124 | -> OpenPGP.SymmetricAlgorithm |
125 | -> OpenPGP.S2K | 125 | -> Maybe OpenPGP.S2K |
126 | -> LZ.ByteString -> Enciphered -> LZ.ByteString | 126 | -> LZ.ByteString -> Enciphered -> LZ.ByteString |
127 | withS2K codec OpenPGP.AES128 s2k s = withIV $ codec (string2key s2k s :: Vincent.AES128) | 127 | withS2K codec OpenPGP.AES128 s2k s = withIV $ codec (string2key s2k s :: Vincent.AES128) |
128 | withS2K codec OpenPGP.AES192 s2k s = withIV $ codec (string2key s2k s :: Vincent.AES192) | 128 | withS2K codec OpenPGP.AES192 s2k s = withIV $ codec (string2key s2k s :: Vincent.AES192) |
@@ -131,7 +131,7 @@ withS2K codec OpenPGP.Blowfish s2k s = withIV $ codec (string2key s2k s :: Vince | |||
131 | withS2K codec OpenPGP.CAST5 s2k s = withIV $ codec (string2key s2k s :: ThomasToVincent CAST5_128) | 131 | withS2K codec OpenPGP.CAST5 s2k s = withIV $ codec (string2key s2k s :: ThomasToVincent CAST5_128) |
132 | withS2K codec algo _ _ = error $ "Unsupported symmetric algorithm : " ++ show algo ++ " in Data.OpenPGP.CryptoAPI.withS2K" | 132 | withS2K codec algo _ _ = error $ "Unsupported symmetric algorithm : " ++ show algo ++ " in Data.OpenPGP.CryptoAPI.withS2K" |
133 | 133 | ||
134 | withS2K' :: OpenPGP.SymmetricAlgorithm -> OpenPGP.S2K -> LZ.ByteString | 134 | withS2K' :: OpenPGP.SymmetricAlgorithm -> Maybe OpenPGP.S2K -> LZ.ByteString |
135 | -> (forall b. Vincent.BlockCipher b => b -> x) -> x | 135 | -> (forall b. Vincent.BlockCipher b => b -> x) -> x |
136 | withS2K' OpenPGP.AES128 s2k s f = f (string2key s2k s :: Vincent.AES128) | 136 | withS2K' OpenPGP.AES128 s2k s f = f (string2key s2k s :: Vincent.AES128) |
137 | withS2K' OpenPGP.AES192 s2k s f = f (string2key s2k s :: Vincent.AES192) | 137 | withS2K' OpenPGP.AES192 s2k s f = f (string2key s2k s :: Vincent.AES192) |
@@ -169,27 +169,16 @@ padThenUnpad k f s = dropPadEnd (f padded) | |||
169 | padAmount = blksize - (LZ.length s `mod` blksize) | 169 | padAmount = blksize - (LZ.length s `mod` blksize) |
170 | blksize = fromIntegral $ Vincent.blockSize k | 170 | blksize = fromIntegral $ Vincent.blockSize k |
171 | 171 | ||
172 | {- | 172 | string2key :: (Vincent.BlockCipher k) => Maybe OpenPGP.S2K -> LZ.ByteString -> k |
173 | Data/OpenPGP/Util/DecryptSecretKey.hs:172:20: | 173 | string2key ms2k s = cipher |
174 | Couldn't match expected type ‘k’ | ||
175 | with actual type ‘cryptonite-0.15:Crypto.Error.Types.CryptoFailable | ||
176 | cipher0’ | ||
177 | ‘k’ is a rigid type variable bound by | ||
178 | the type signature for | ||
179 | string2key :: Vincent.BlockCipher k => | ||
180 | OpenPGP.S2K -> LZ.ByteString -> k | ||
181 | at Data/OpenPGP/Util/DecryptSecretKey.hs:171:15 | ||
182 | -} | ||
183 | string2key :: (Vincent.BlockCipher k) => OpenPGP.S2K -> LZ.ByteString -> k | ||
184 | string2key s2k s = cipher | ||
185 | where | 174 | where |
186 | #if defined(VERSION_cryptonite) | 175 | #if defined(VERSION_cryptonite) |
187 | CryptoPassed cipher = Vincent.cipherInit k | 176 | CryptoPassed cipher = Vincent.cipherInit k |
188 | k = toStrictBS $ LZ.take ksize $ OpenPGP.string2key hashBySymbol s2k s | 177 | k = toStrictBS $ LZ.take ksize $ maybe s (\s2k -> OpenPGP.string2key hashBySymbol s2k s) ms2k |
189 | #else | 178 | #else |
190 | cipher = Vincent.cipherInit k | 179 | cipher = Vincent.cipherInit k |
191 | Right k = Vincent.makeKey $ toStrictBS $ | 180 | Right k = Vincent.makeKey $ toStrictBS $ |
192 | LZ.take ksize $ OpenPGP.string2key hashBySymbol s2k s | 181 | LZ.take ksize $ maybe s (\s2k -> OpenPGP.string2key hashBySymbol s2k s) ms2k |
193 | #endif | 182 | #endif |
194 | ksize = case Vincent.cipherKeySize cipher of | 183 | ksize = case Vincent.cipherKeySize cipher of |
195 | Vincent.KeySizeFixed n -> fromIntegral n | 184 | Vincent.KeySizeFixed n -> fromIntegral n |
@@ -217,7 +206,7 @@ encryptSecretKey passphrase s2k salgo plain = do | |||
217 | maybeToList $ lookup f (OpenPGP.key plain) | 206 | maybeToList $ lookup f (OpenPGP.key plain) |
218 | chk = LZ.fromChunks [ chkF material ] | 207 | chk = LZ.fromChunks [ chkF material ] |
219 | decd = LZ.append material chk | 208 | decd = LZ.append material chk |
220 | encd g = fst $ withS2K' salgo s2k (toLazyBS passphrase) (simpleCFB g) decd | 209 | encd g = fst $ withS2K' salgo (Just s2k) (toLazyBS passphrase) (simpleCFB g) decd |
221 | 210 | ||
222 | -- If the string-to-key usage octet is zero or 255, then a two-octet | 211 | -- If the string-to-key usage octet is zero or 255, then a two-octet |
223 | -- checksum of the plaintext of the algorithm-specific portion (sum | 212 | -- checksum of the plaintext of the algorithm-specific portion (sum |