From 39d8a08aad1d2dd48b807ab867aa17475e4278c4 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 26 Aug 2016 03:10:40 -0400 Subject: Completed cryptonite support. --- Data/OpenPGP/Util/DecryptSecretKey.hs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'Data') 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 = EncipheredWithIV !LZ.ByteString -- initial vector is appended to front of ByteString | EncipheredZeroIV !LZ.ByteString -- initial vector is zero, ByteString contains only the block -withIV :: (Vincent.BlockCipher k) => (Vincent.IV k -> LZ.ByteString -> LZ.ByteString) -> Enciphered -> LZ.ByteString +withIV :: forall k. (Vincent.BlockCipher k) => (Vincent.IV k -> LZ.ByteString -> LZ.ByteString) -> Enciphered -> LZ.ByteString withIV f (EncipheredWithIV s) = f iv bs where Just iv = Vincent.makeIV (toStrictBS ivbs) (ivbs,bs) = LZ.splitAt (fromIntegral ivlen) s #if defined(VERSION_cryptonite) - ivlen = Bytes.length iv + ivlen = Bytes.length (Vincent.nullIV :: Vincent.IV k) #else ivlen = Vincent.byteableLength z _ = Vincent.constEqBytes z iv @@ -126,8 +126,7 @@ withS2K codec OpenPGP.AES128 s2k s = withIV $ codec (string2key s2k s :: Vince withS2K codec OpenPGP.AES192 s2k s = withIV $ codec (string2key s2k s :: Vincent.AES192) withS2K codec OpenPGP.AES256 s2k s = withIV $ codec (string2key s2k s :: Vincent.AES256) withS2K codec OpenPGP.Blowfish s2k s = withIV $ codec (string2key s2k s :: Vincent.Blowfish128) --- TODO: cast5 support --- withS2K codec OpenPGP.CAST5 s2k s = withIV $ codec (string2key s2k s :: ThomasToVincent CAST5_128) +withS2K codec OpenPGP.CAST5 s2k s = withIV $ codec (string2key s2k s :: ThomasToVincent CAST5_128) withS2K codec algo _ _ = error $ "Unsupported symmetric algorithm : " ++ show algo ++ " in Data.OpenPGP.CryptoAPI.withS2K" withS2K' :: OpenPGP.SymmetricAlgorithm -> OpenPGP.S2K -> LZ.ByteString @@ -136,21 +135,20 @@ withS2K' OpenPGP.AES128 s2k s f = f (string2key s2k s :: Vincent.AES128) withS2K' OpenPGP.AES192 s2k s f = f (string2key s2k s :: Vincent.AES192) withS2K' OpenPGP.AES256 s2k s f = f (string2key s2k s :: Vincent.AES256) withS2K' OpenPGP.Blowfish s2k s f = f (string2key s2k s :: Vincent.Blowfish128) --- TODO: cast5 support --- withS2K' OpenPGP.CAST5 s2k s f = f (string2key s2k s :: ThomasToVincent CAST5_128) +withS2K' OpenPGP.CAST5 s2k s f = f (string2key s2k s :: ThomasToVincent CAST5_128) -- decryption codec for withS2K simpleUnCFB :: (Vincent.BlockCipher k) => k -> Vincent.IV k -> LZ.ByteString -> LZ.ByteString simpleUnCFB k iv = padThenUnpad k (toLazyBS . Vincent.cfbDecrypt k iv . toStrictBS) -simpleCFB :: (Vincent.BlockCipher k, RG g) => g -> k -> LZ.ByteString -> (LZ.ByteString, g) +simpleCFB :: forall k g. (Vincent.BlockCipher k, RG g) => g -> k -> LZ.ByteString -> (LZ.ByteString, g) simpleCFB g k bs = ( padThenUnpad k (LZ.fromChunks . (ivbs:) . (:[]) . Vincent.cfbEncrypt k iv . toStrictBS) bs , g' ) where Just iv = Vincent.makeIV ivbs #if defined(VERSION_cryptonite) (ivbs,g') = Vincent.randomBytesGenerate ivlen g - ivlen = Bytes.length iv + ivlen = Bytes.length (Vincent.nullIV :: Vincent.IV k) #else z = Vincent.nullIV (ivbs,g') = Vincent.cprgGenerate ivlen g -- cgit v1.2.3