File: KAT_RC4.hs

package info (click to toggle)
haskell-crypton 1.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,548 kB
  • sloc: haskell: 26,764; ansic: 22,294; makefile: 6
file content (42 lines) | stat: -rw-r--r-- 927 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

module KAT_RC4 where

import Test.Tasty
import Test.Tasty.HUnit

import qualified Crypto.Cipher.RC4 as RC4
import Data.ByteString (ByteString)
import Data.ByteString.Char8 ()

-- taken from wikipedia pages
vectors :: [(ByteString, ByteString, ByteString)]
vectors =
    [
        ( "Key"
        , "Plaintext"
        , "\xBB\xF3\x16\xE8\xD9\x40\xAF\x0A\xD3"
        )
    ,
        ( "Wiki"
        , "pedia"
        , "\x10\x21\xBF\x04\x20"
        )
    ,
        ( "Secret"
        , "Attack at dawn"
        , "\x45\xA0\x1F\x64\x5F\xC3\x5B\x38\x35\x52\x54\x4B\x9B\xF5"
        )
    ]

tests =
    testGroup "RC4" $
        zipWith toKatTest is vectors
  where
    toKatTest i (key, plainText, cipherText) =
        testCase
            (show i)
            (cipherText @=? snd (RC4.combine (RC4.initialize key) plainText))
    is :: [Int]
    is = [1 ..]