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, 6 insertions, 8 deletions
diff --git a/Data/OpenPGP/Util/DecryptSecretKey.hs b/Data/OpenPGP/Util/DecryptSecretKey.hs
index 01728d3..1c519ae 100644
--- a/Data/OpenPGP/Util/DecryptSecretKey.hs
+++ b/Data/OpenPGP/Util/DecryptSecretKey.hs
@@ -47,13 +47,13 @@ data Enciphered =
47 EncipheredWithIV !LZ.ByteString -- initial vector is appended to front of ByteString 47 EncipheredWithIV !LZ.ByteString -- initial vector is appended to front of ByteString
48 | EncipheredZeroIV !LZ.ByteString -- initial vector is zero, ByteString contains only the block 48 | EncipheredZeroIV !LZ.ByteString -- initial vector is zero, ByteString contains only the block
49 49
50withIV :: (Vincent.BlockCipher k) => (Vincent.IV k -> LZ.ByteString -> LZ.ByteString) -> Enciphered -> LZ.ByteString 50withIV :: forall k. (Vincent.BlockCipher k) => (Vincent.IV k -> LZ.ByteString -> LZ.ByteString) -> Enciphered -> LZ.ByteString
51withIV f (EncipheredWithIV s) = f iv bs 51withIV f (EncipheredWithIV s) = f iv bs
52 where 52 where
53 Just iv = Vincent.makeIV (toStrictBS ivbs) 53 Just iv = Vincent.makeIV (toStrictBS ivbs)
54 (ivbs,bs) = LZ.splitAt (fromIntegral ivlen) s 54 (ivbs,bs) = LZ.splitAt (fromIntegral ivlen) s
55#if defined(VERSION_cryptonite) 55#if defined(VERSION_cryptonite)
56 ivlen = Bytes.length iv 56 ivlen = Bytes.length (Vincent.nullIV :: Vincent.IV k)
57#else 57#else
58 ivlen = Vincent.byteableLength z 58 ivlen = Vincent.byteableLength z
59 _ = Vincent.constEqBytes z iv 59 _ = Vincent.constEqBytes z iv
@@ -126,8 +126,7 @@ withS2K codec OpenPGP.AES128 s2k s = withIV $ codec (string2key s2k s :: Vince
126withS2K codec OpenPGP.AES192 s2k s = withIV $ codec (string2key s2k s :: Vincent.AES192) 126withS2K codec OpenPGP.AES192 s2k s = withIV $ codec (string2key s2k s :: Vincent.AES192)
127withS2K codec OpenPGP.AES256 s2k s = withIV $ codec (string2key s2k s :: Vincent.AES256) 127withS2K codec OpenPGP.AES256 s2k s = withIV $ codec (string2key s2k s :: Vincent.AES256)
128withS2K codec OpenPGP.Blowfish s2k s = withIV $ codec (string2key s2k s :: Vincent.Blowfish128) 128withS2K codec OpenPGP.Blowfish s2k s = withIV $ codec (string2key s2k s :: Vincent.Blowfish128)
129-- TODO: cast5 support 129withS2K codec OpenPGP.CAST5 s2k s = withIV $ codec (string2key s2k s :: ThomasToVincent CAST5_128)
130-- withS2K codec OpenPGP.CAST5 s2k s = withIV $ codec (string2key s2k s :: ThomasToVincent CAST5_128)
131withS2K codec algo _ _ = error $ "Unsupported symmetric algorithm : " ++ show algo ++ " in Data.OpenPGP.CryptoAPI.withS2K" 130withS2K codec algo _ _ = error $ "Unsupported symmetric algorithm : " ++ show algo ++ " in Data.OpenPGP.CryptoAPI.withS2K"
132 131
133withS2K' :: OpenPGP.SymmetricAlgorithm -> OpenPGP.S2K -> LZ.ByteString 132withS2K' :: OpenPGP.SymmetricAlgorithm -> OpenPGP.S2K -> LZ.ByteString
@@ -136,21 +135,20 @@ withS2K' OpenPGP.AES128 s2k s f = f (string2key s2k s :: Vincent.AES128)
136withS2K' OpenPGP.AES192 s2k s f = f (string2key s2k s :: Vincent.AES192) 135withS2K' OpenPGP.AES192 s2k s f = f (string2key s2k s :: Vincent.AES192)
137withS2K' OpenPGP.AES256 s2k s f = f (string2key s2k s :: Vincent.AES256) 136withS2K' OpenPGP.AES256 s2k s f = f (string2key s2k s :: Vincent.AES256)
138withS2K' OpenPGP.Blowfish s2k s f = f (string2key s2k s :: Vincent.Blowfish128) 137withS2K' OpenPGP.Blowfish s2k s f = f (string2key s2k s :: Vincent.Blowfish128)
139-- TODO: cast5 support 138withS2K' OpenPGP.CAST5 s2k s f = f (string2key s2k s :: ThomasToVincent CAST5_128)
140-- withS2K' OpenPGP.CAST5 s2k s f = f (string2key s2k s :: ThomasToVincent CAST5_128)
141 139
142-- decryption codec for withS2K 140-- decryption codec for withS2K
143simpleUnCFB :: (Vincent.BlockCipher k) => k -> Vincent.IV k -> LZ.ByteString -> LZ.ByteString 141simpleUnCFB :: (Vincent.BlockCipher k) => k -> Vincent.IV k -> LZ.ByteString -> LZ.ByteString
144simpleUnCFB k iv = padThenUnpad k (toLazyBS . Vincent.cfbDecrypt k iv . toStrictBS) 142simpleUnCFB k iv = padThenUnpad k (toLazyBS . Vincent.cfbDecrypt k iv . toStrictBS)
145 143
146simpleCFB :: (Vincent.BlockCipher k, RG g) => g -> k -> LZ.ByteString -> (LZ.ByteString, g) 144simpleCFB :: forall k g. (Vincent.BlockCipher k, RG g) => g -> k -> LZ.ByteString -> (LZ.ByteString, g)
147simpleCFB g k bs = ( padThenUnpad k (LZ.fromChunks . (ivbs:) . (:[]) . Vincent.cfbEncrypt k iv . toStrictBS) bs 145simpleCFB g k bs = ( padThenUnpad k (LZ.fromChunks . (ivbs:) . (:[]) . Vincent.cfbEncrypt k iv . toStrictBS) bs
148 , g' ) 146 , g' )
149 where 147 where
150 Just iv = Vincent.makeIV ivbs 148 Just iv = Vincent.makeIV ivbs
151#if defined(VERSION_cryptonite) 149#if defined(VERSION_cryptonite)
152 (ivbs,g') = Vincent.randomBytesGenerate ivlen g 150 (ivbs,g') = Vincent.randomBytesGenerate ivlen g
153 ivlen = Bytes.length iv 151 ivlen = Bytes.length (Vincent.nullIV :: Vincent.IV k)
154#else 152#else
155 z = Vincent.nullIV 153 z = Vincent.nullIV
156 (ivbs,g') = Vincent.cprgGenerate ivlen g 154 (ivbs,g') = Vincent.cprgGenerate ivlen g