packages feed

cipher-rc4 0.1.2 → 0.1.3

raw patch · 4 files changed

+38/−64 lines, 4 filesdep +byteabledep +crypto-cipher-benchmarksdep +crypto-cipher-testsPVP ok

version bump matches the API change (PVP)

Dependencies added: byteable, crypto-cipher-benchmarks, crypto-cipher-tests, crypto-cipher-types

API changes (from Hackage documentation)

+ Crypto.Cipher.RC4: data RC4
+ Crypto.Cipher.RC4: instance Byteable RC4
+ Crypto.Cipher.RC4: instance Cipher RC4
+ Crypto.Cipher.RC4: instance StreamCipher RC4

Files

Benchmarks/Benchmarks.hs view
@@ -1,34 +1,4 @@ module Main where--import Criterion.Main-+import Crypto.Cipher.Benchmarks import Crypto.Cipher.RC4-import qualified Data.ByteString as B-import Control.DeepSeq--instance NFData Ctx where-    rnf (Ctx c) = c `seq` ()--main = defaultMain-    [ bgroup "init"-        [ bench "1"    $ whnf initCtx b1-        , bench "8"    $ whnf initCtx b8-        , bench "32"   $ whnf initCtx b32-        , bench "64"   $ whnf initCtx b64-        , bench "256"  $ whnf initCtx b256-        ]-    , bgroup "encrypt"-        [ bench "8"    $ nf (combine ctx) b8-        , bench "32"   $ nf (combine ctx) b32-        , bench "64"   $ nf (combine ctx) b64-        , bench "256"  $ nf (combine ctx) b256-        , bench "1024" $ nf (combine ctx) b1024-        ]-    ]-    where b1    = B.replicate 1 0xf7-          b8    = B.replicate 8 0xf7-          b32   = B.replicate 32 0xf7-          b64   = B.replicate 64 0x7f-          b256  = B.replicate 256 0x7f-          b1024 = B.replicate 1024 0x7f-          ctx   = initCtx $ B.pack [1..10]+main = defaultMainAll [Stream $ GStreamCipher (undefined :: RC4)]
Crypto/Cipher/RC4.hs view
@@ -14,7 +14,11 @@ -- Reorganized and simplified to have an opaque context. -- module Crypto.Cipher.RC4-    ( Ctx(..)+    (+      RC4+    -- * deprecated types+    , Ctx(..)+    -- * deprecated functions, use crypto-cipher-types StreamCipher function     , initCtx     , generate     , combine@@ -23,6 +27,7 @@     ) where  import Data.Word+import Data.Byteable import Foreign.Ptr import Foreign.ForeignPtr import System.IO.Unsafe@@ -30,6 +35,7 @@ import qualified Data.ByteString as B import qualified Data.ByteString.Internal as B import Control.Applicative ((<$>))+import Crypto.Cipher.Types  ---------------------------------------------------------------------- unsafeDoIO :: IO a -> a@@ -38,6 +44,20 @@ #else unsafeDoIO = unsafePerformIO #endif++-- | RC4 Stream cipher+newtype RC4 = RC4 Ctx++instance Byteable RC4 where+    toBytes (RC4 (Ctx b)) = b++instance Cipher RC4 where+    cipherInit key  = RC4 (initCtx $ toBytes key)+    cipherName _    = "RC4"+    cipherKeySize _ = KeySizeRange 1 1024++instance StreamCipher RC4 where+    streamCombine (RC4 ctx) b = (\(ctx2, r) -> (r, RC4 ctx2)) $ combine ctx b  -- | The encryption context for RC4 newtype Ctx = Ctx B.ByteString
Tests/Tests.hs view
@@ -14,11 +14,14 @@  import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC-import qualified Crypto.Cipher.RC4 as RC4+import Crypto.Cipher.RC4 (RC4) +import Crypto.Cipher.Types+import Crypto.Cipher.Tests+ -- taken from wikipedia pages-kats :: [ (B.ByteString, B.ByteString, B.ByteString) ]-kats =+kats :: [KAT_Stream]+kats = map (\(k,p,c) -> KAT_Stream k p c)     [   ("Key"         ,"Plaintext"         ,B.pack [0xBB,0xF3,0x16,0xE8,0xD9,0x40,0xAF,0x0A,0xD3]@@ -33,31 +36,6 @@         )     ] -runKat (key,plainText,cipherText) =-       snd (RC4.combine ctx plainText)  == cipherText-    && snd (RC4.combine ctx cipherText) == plainText-    where ctx = RC4.initCtx $ key--katToTestProperty (kat, i) = testProperty ("KAT " ++ show i) (runKat kat)--data RC4Unit = RC4Unit B.ByteString B.ByteString-    deriving (Show)--instance Arbitrary RC4Unit where-    arbitrary = RC4Unit <$> generateKey <*> generatePlaintext--generateKey = choose (1, 284) >>= \sz -> (B.pack <$> replicateM sz arbitrary)-generatePlaintext = choose (0,324) >>= \sz -> (B.pack <$> replicateM sz arbitrary)--runOp f1 f2 (RC4Unit key plainText) =-    let ctx = RC4.initCtx key-     in (snd $ f2 ctx $ snd $ f1 ctx plainText) == plainText--tests =-    [ testGroup "KAT-RC4" $ map katToTestProperty $ zip kats [0..]-    , testGroup "id"-        [ testProperty "combine.combine" (runOp RC4.combine RC4.combine)-        ]+main = defaultMain+    [ testStreamCipher kats (undefined :: RC4)     ]--main = defaultMain tests
cipher-rc4.cabal view
@@ -1,5 +1,5 @@ Name:                cipher-rc4-Version:             0.1.2+Version:             0.1.3 Description:         Fast RC4 cipher implementation License:             BSD3 License-file:        LICENSE@@ -17,6 +17,8 @@ Library   Build-Depends:     base >= 4 && < 5                    , bytestring+                   , byteable+                   , crypto-cipher-types >= 0.0.5   Exposed-modules:   Crypto.Cipher.RC4   ghc-options:       -Wall   C-sources:         cbits/rc4.c@@ -31,6 +33,8 @@                    , QuickCheck >= 2                    , test-framework >= 0.3.3                    , test-framework-quickcheck2 >= 0.2.9+                   , crypto-cipher-types >= 0.0.5+                   , crypto-cipher-tests >= 0.0.7  Benchmark bench-cipher-rc4   hs-source-dirs:    Benchmarks@@ -39,6 +43,8 @@   Build-depends:     base >= 4 && < 5                    , bytestring                    , cipher-rc4+                   , crypto-cipher-types >= 0.0.5+                   , crypto-cipher-benchmarks >= 0.0.3                    , deepseq                    , criterion                    , mtl