[RSA] properly indent modules imports
This commit is contained in:
parent
94d0da9676
commit
dc34ce8289
@ -21,16 +21,16 @@ module Crypto.PubKey.RSA.OAEP
|
|||||||
, decryptSafer
|
, decryptSafer
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Crypto.Hash
|
import Crypto.Hash
|
||||||
import Crypto.Random.Types
|
import Crypto.Random.Types
|
||||||
import Crypto.PubKey.RSA.Types
|
import Crypto.PubKey.RSA.Types
|
||||||
import Crypto.PubKey.MaskGenFunction
|
import Crypto.PubKey.MaskGenFunction
|
||||||
import Crypto.PubKey.RSA.Prim
|
import Crypto.PubKey.RSA.Prim
|
||||||
import Crypto.PubKey.RSA (generateBlinder)
|
import Crypto.PubKey.RSA (generateBlinder)
|
||||||
import Crypto.PubKey.Internal (and')
|
import Crypto.PubKey.Internal (and')
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
import Data.Bits (xor)
|
import Data.Bits (xor)
|
||||||
|
|
||||||
import qualified Crypto.Internal.ByteArray as B (convert)
|
import qualified Crypto.Internal.ByteArray as B (convert)
|
||||||
|
|
||||||
|
|||||||
@ -22,28 +22,32 @@ module Crypto.PubKey.RSA.PKCS15
|
|||||||
, verify
|
, verify
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Crypto.Random.Types
|
import Crypto.Random.Types
|
||||||
import Crypto.PubKey.Internal (and')
|
import Crypto.PubKey.Internal (and')
|
||||||
import Crypto.PubKey.RSA.Types
|
import Crypto.PubKey.RSA.Types
|
||||||
import Data.ByteString (ByteString)
|
import Crypto.PubKey.RSA.Prim
|
||||||
import qualified Data.ByteString as B
|
import Crypto.PubKey.RSA (generateBlinder)
|
||||||
import Crypto.PubKey.RSA.Prim
|
import Crypto.PubKey.HashDescr
|
||||||
import Crypto.PubKey.RSA (generateBlinder)
|
|
||||||
import Crypto.PubKey.HashDescr
|
import Data.ByteString (ByteString)
|
||||||
|
|
||||||
|
import Crypto.Internal.ByteArray (ByteArray, Bytes)
|
||||||
|
import qualified Crypto.Internal.ByteArray as B
|
||||||
|
|
||||||
-- | This produce a standard PKCS1.5 padding for encryption
|
-- | This produce a standard PKCS1.5 padding for encryption
|
||||||
pad :: MonadRandom m => Int -> ByteString -> m (Either Error ByteString)
|
pad :: (MonadRandom m, ByteArray message) => Int -> message -> m (Either Error message)
|
||||||
pad len m
|
pad len m
|
||||||
| B.length m > len - 11 = return (Left MessageTooLong)
|
| B.length m > len - 11 = return (Left MessageTooLong)
|
||||||
| otherwise = do
|
| otherwise = do
|
||||||
padding <- getNonNullRandom (len - B.length m - 3)
|
padding <- getNonNullRandom (len - B.length m - 3)
|
||||||
return $ Right $ B.concat [ B.singleton 0, B.singleton 2, padding, B.singleton 0, m ]
|
return $ Right $ B.concat [ B.pack [0,2], padding, B.pack [0], m ]
|
||||||
|
|
||||||
where {- get random non-null bytes -}
|
where
|
||||||
getNonNullRandom :: MonadRandom m => Int -> m ByteString
|
-- get random non-null bytes
|
||||||
|
getNonNullRandom :: (ByteArray bytearray, MonadRandom m) => Int -> m bytearray
|
||||||
getNonNullRandom n = do
|
getNonNullRandom n = do
|
||||||
bs0 <- getRandomBytes n
|
bs0 <- getRandomBytes n
|
||||||
let bytes = B.pack $ filter (/= 0) $ B.unpack $ bs0
|
let bytes = B.pack $ filter (/= 0) $ B.unpack (bs0 :: Bytes)
|
||||||
left = n - B.length bytes
|
left = n - B.length bytes
|
||||||
if left == 0
|
if left == 0
|
||||||
then return bytes
|
then return bytes
|
||||||
@ -51,25 +55,25 @@ pad len m
|
|||||||
return (bytes `B.append` bend)
|
return (bytes `B.append` bend)
|
||||||
|
|
||||||
-- | Produce a standard PKCS1.5 padding for signature
|
-- | Produce a standard PKCS1.5 padding for signature
|
||||||
padSignature :: Int -> ByteString -> Either Error ByteString
|
padSignature :: ByteArray signature => Int -> signature -> Either Error signature
|
||||||
padSignature klen signature
|
padSignature klen signature
|
||||||
| klen < siglen+1 = Left SignatureTooLong
|
| klen < siglen+1 = Left SignatureTooLong
|
||||||
| otherwise = Right $ B.concat [B.singleton 0,B.singleton 1,padding,B.singleton 0,signature]
|
| otherwise = Right (B.pack padding `B.append` signature)
|
||||||
where
|
where
|
||||||
siglen = B.length signature
|
siglen = B.length signature
|
||||||
padding = B.replicate (klen - siglen - 3) 0xff
|
padding = 0 : 1 : (replicate (klen - siglen - 3) 0xff ++ [0])
|
||||||
|
|
||||||
-- | Try to remove a standard PKCS1.5 encryption padding.
|
-- | Try to remove a standard PKCS1.5 encryption padding.
|
||||||
unpad :: ByteString -> Either Error ByteString
|
unpad :: ByteArray bytearray => bytearray -> Either Error bytearray
|
||||||
unpad packed
|
unpad packed
|
||||||
| paddingSuccess = Right m
|
| paddingSuccess = Right m
|
||||||
| otherwise = Left MessageNotRecognized
|
| otherwise = Left MessageNotRecognized
|
||||||
where
|
where
|
||||||
(zt, ps0m) = B.splitAt 2 packed
|
(zt, ps0m) = B.splitAt 2 packed
|
||||||
(ps, zm) = B.span (/= 0) ps0m
|
(ps, zm) = B.span (/= 0) ps0m
|
||||||
(z, m) = B.splitAt 1 zm
|
(z, m) = B.splitAt 1 zm
|
||||||
paddingSuccess = and' [ zt == "\x00\x02"
|
paddingSuccess = and' [ zt `B.constEq` (B.pack [0,2] :: Bytes)
|
||||||
, z == "\x00"
|
, z == B.zero 1
|
||||||
, B.length ps >= 8
|
, B.length ps >= 8
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -16,17 +16,18 @@ module Crypto.PubKey.RSA.PSS
|
|||||||
, verify
|
, verify
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Crypto.Random.Types
|
import Crypto.Random.Types
|
||||||
import Crypto.PubKey.RSA.Types
|
import Crypto.PubKey.RSA.Types
|
||||||
import Data.ByteString (ByteString)
|
import Crypto.PubKey.RSA.Prim
|
||||||
import qualified Data.ByteString as B
|
import Crypto.PubKey.RSA (generateBlinder)
|
||||||
import Crypto.PubKey.RSA.Prim
|
import Crypto.PubKey.MaskGenFunction
|
||||||
import Crypto.PubKey.RSA (generateBlinder)
|
import Crypto.Hash
|
||||||
import Crypto.PubKey.MaskGenFunction
|
import Data.Bits (xor, shiftR, (.&.))
|
||||||
import Crypto.Hash
|
import Data.Word
|
||||||
import Data.Bits (xor, shiftR, (.&.))
|
|
||||||
import Data.Word
|
|
||||||
import qualified Crypto.Internal.ByteArray as B (convert)
|
import qualified Crypto.Internal.ByteArray as B (convert)
|
||||||
|
import Data.ByteString (ByteString)
|
||||||
|
import qualified Data.ByteString as B
|
||||||
|
|
||||||
-- | Parameters for PSS signature/verification.
|
-- | Parameters for PSS signature/verification.
|
||||||
data PSSParams hash = PSSParams
|
data PSSParams hash = PSSParams
|
||||||
|
|||||||
@ -13,10 +13,10 @@ module Crypto.PubKey.RSA.Prim
|
|||||||
, ep
|
, ep
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import Crypto.PubKey.RSA.Types
|
import Crypto.PubKey.RSA.Types
|
||||||
import Crypto.Number.ModArithmetic (expFast, expSafe)
|
import Crypto.Number.ModArithmetic (expFast, expSafe)
|
||||||
import Crypto.Number.Serialize (os2ip, i2ospOf_)
|
import Crypto.Number.Serialize (os2ip, i2ospOf_)
|
||||||
|
|
||||||
{- dpSlow computes the decrypted message not using any precomputed cache value.
|
{- dpSlow computes the decrypted message not using any precomputed cache value.
|
||||||
only n and d need to valid. -}
|
only n and d need to valid. -}
|
||||||
|
|||||||
@ -19,7 +19,7 @@ module Crypto.PubKey.RSA.Types
|
|||||||
, private_e
|
, private_e
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Data
|
import Data.Data
|
||||||
|
|
||||||
-- | Blinder which is used to obfuscate the timing
|
-- | Blinder which is used to obfuscate the timing
|
||||||
-- of the decryption primitive (used by decryption and signing).
|
-- of the decryption primitive (used by decryption and signing).
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user