commit f08beb6716db27889e0bcb140d208978765e4eac
parent 334ac0c530e5aca019ca25f483a1bb4593b61326
Author: Jared Tobin <jared@jtobin.io>
Date: Thu, 6 Mar 2025 16:41:46 +0400
lib: handle last chunk
Diffstat:
2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/lib/Crypto/Cipher/ChaCha.hs b/lib/Crypto/Cipher/ChaCha.hs
@@ -260,7 +260,7 @@ chacha20_encrypt
chacha20_encrypt key counter nonce = loop mempty counter where
loop acc j bs = case BS.splitAt 64 bs of
(chunk@(BI.PS _ _ l), etc)
- | l == 0 && BS.length etc == 0 -> pure $
+ | l /= 0 && BS.length etc == 0 -> pure $
BS.toStrict (BSB.toLazyByteString acc)
| otherwise -> do
stream <- chacha20_block key j nonce
diff --git a/test/Main.hs b/test/Main.hs
@@ -14,7 +14,6 @@ import Data.Word (Word32)
import Test.Tasty
import qualified Test.Tasty.HUnit as H
-
main :: IO ()
main = defaultMain $ testGroup "ppad-chacha" [
quarter
@@ -126,7 +125,3 @@ chacha20_encrypt = H.testCase "chacha20 encrypt" $ do
o <- ChaCha.chacha20_encrypt block_key 1 crypt_non crypt_plain
H.assertEqual mempty crypt_cip o
-
-
-
-