[aes] fast track length == 0 with ECB encryption/decryption

This commit is contained in:
Vincent Hanquez 2015-06-02 14:22:26 +01:00
parent c7068873c5
commit be75de64e1

View File

@ -351,8 +351,10 @@ doECB :: ByteArray ba
=> (Ptr b -> Ptr AES -> CString -> CUInt -> IO ()) => (Ptr b -> Ptr AES -> CString -> CUInt -> IO ())
-> AES -> ba -> ba -> AES -> ba -> ba
doECB f ctx input doECB f ctx input
| len == 0 = B.empty
| r /= 0 = error $ "Encryption error: input length must be a multiple of block size (16). Its length is: " ++ (show len) | r /= 0 = error $ "Encryption error: input length must be a multiple of block size (16). Its length is: " ++ (show len)
| otherwise = B.allocAndFreeze len $ \o -> | otherwise =
B.allocAndFreeze len $ \o ->
keyToPtr ctx $ \k -> keyToPtr ctx $ \k ->
withByteArray input $ \i -> withByteArray input $ \i ->
f (castPtr o) k i (fromIntegral nbBlocks) f (castPtr o) k i (fromIntegral nbBlocks)