packages feed

crypton-2.0.0: tests/BlockCipher/AES/CTR.hs

{-# LANGUAGE OverloadedStrings #-}

-- | Counter mode, which had no known-answer test at any key size: the
-- suite checked it only by encrypting and decrypting again, which a
-- wrong-but-consistent implementation passes.  From OpenSSL 3.5.
--
-- The lengths are one block, nine blocks, and eight and a bit, so that
-- both the group of eight the hardware paths take at a time and the
-- block-at-a-time tail after it are covered.
module BlockCipher.AES.CTR where

import qualified Data.ByteString as B
import Data.ByteString.Char8 ()

-- (key, iv, input, out)
type KATCTR = (B.ByteString, B.ByteString, B.ByteString, B.ByteString)

vectors_aes128_enc :: [KATCTR]
vectors_aes128_enc =
    [
        ( "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
        , "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
        , "\x03\x0a\x11\x18\x1f\x26\x2d\x34\x3b\x42\x49\x50\x57\x5e\x65\x6c"
        , "\xca\x1b\xb2\x0a\xf3\x52\xb1\x9b\xf0\xb0\xdc\xde\xb3\x0b\x77\x47"
        )
    ,
        ( "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
        , "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
        , "\x03\x0a\x11\x18\x1f\x26\x2d\x34\x3b\x42\x49\x50\x57\x5e\x65\x6c\x73\x7a\x81\x88\x8f\x96\x9d\xa4\xab\xb2\xb9\xc0\xc7\xce\xd5\xdc\xe3\xea\xf1\xf8\xff\x06\x0d\x14\x1b\x22\x29\x30\x37\x3e\x45\x4c\x53\x5a\x61\x68\x6f\x76\x7d\x84\x8b\x92\x99\xa0\xa7\xae\xb5\xbc\xc3\xca\xd1\xd8\xdf\xe6\xed\xf4\xfb\x02\x09\x10\x17\x1e\x25\x2c\x33\x3a\x41\x48\x4f\x56\x5d\x64\x6b\x72\x79\x80\x87\x8e\x95\x9c\xa3\xaa\xb1\xb8\xbf\xc6\xcd\xd4\xdb\xe2\xe9\xf0\xf7\xfe\x05\x0c\x13\x1a\x21\x28\x2f\x36\x3d\x44\x4b\x52\x59\x60\x67\x6e\x75\x7c\x83\x8a\x91\x98\x9f\xa6\xad\xb4\xbb\xc2\xc9\xd0\xd7\xde\xe5\xec"
        , "\xca\x1b\xb2\x0a\xf3\x52\xb1\x9b\xf0\xb0\xdc\xde\xb3\x0b\x77\x47\x38\x57\x21\x94\xc8\xf7\x8d\xc3\x7b\x19\x83\xa3\x08\x94\x57\xdd\xf9\x33\x8f\xd5\x03\x3e\xef\x0d\x05\x74\x18\xae\xe5\x2a\x25\xc4\xa3\x44\xed\x31\xa7\x06\x32\x44\x63\x7d\xe5\xc4\xd6\x8c\x42\xe5\x23\xb5\x7d\x54\x08\x30\x16\x6c\x7c\x3b\x54\x24\x67\x23\x18\x2c\xdb\x08\xc4\x38\x65\xca\xb7\x0a\x48\xe1\xa9\x19\x4d\x9e\x97\xd8\x53\x50\x20\xfa\xe1\x27\xc4\x07\x3a\x6b\xb4\x94\x49\xdd\x07\x87\xfb\x0b\x15\x88\xd2\x98\x98\xc6\xeb\x5a\x7d\xbf\x38\x1d\x78\x56\x44\x6e\xd3\x54\xfd\x48\x20\x4c\xc2\xd5\x14\xf5\xa2\xe0\xf7\xa3"
        )
    ,
        ( "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
        , "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
        , "\x03\x0a\x11\x18\x1f\x26\x2d\x34\x3b\x42\x49\x50\x57\x5e\x65\x6c\x73\x7a\x81\x88\x8f\x96\x9d\xa4\xab\xb2\xb9\xc0\xc7\xce\xd5\xdc\xe3\xea\xf1\xf8\xff\x06\x0d\x14\x1b\x22\x29\x30\x37\x3e\x45\x4c\x53\x5a\x61\x68\x6f\x76\x7d\x84\x8b\x92\x99\xa0\xa7\xae\xb5\xbc\xc3\xca\xd1\xd8\xdf\xe6\xed\xf4\xfb\x02\x09\x10\x17\x1e\x25\x2c\x33\x3a\x41\x48\x4f\x56\x5d\x64\x6b\x72\x79\x80\x87\x8e\x95\x9c\xa3\xaa\xb1\xb8\xbf\xc6\xcd\xd4\xdb\xe2\xe9\xf0\xf7\xfe\x05\x0c\x13\x1a\x21\x28\x2f\x36\x3d\x44\x4b\x52\x59\x60\x67\x6e\x75\x7c\x83\x8a"
        , "\xca\x1b\xb2\x0a\xf3\x52\xb1\x9b\xf0\xb0\xdc\xde\xb3\x0b\x77\x47\x38\x57\x21\x94\xc8\xf7\x8d\xc3\x7b\x19\x83\xa3\x08\x94\x57\xdd\xf9\x33\x8f\xd5\x03\x3e\xef\x0d\x05\x74\x18\xae\xe5\x2a\x25\xc4\xa3\x44\xed\x31\xa7\x06\x32\x44\x63\x7d\xe5\xc4\xd6\x8c\x42\xe5\x23\xb5\x7d\x54\x08\x30\x16\x6c\x7c\x3b\x54\x24\x67\x23\x18\x2c\xdb\x08\xc4\x38\x65\xca\xb7\x0a\x48\xe1\xa9\x19\x4d\x9e\x97\xd8\x53\x50\x20\xfa\xe1\x27\xc4\x07\x3a\x6b\xb4\x94\x49\xdd\x07\x87\xfb\x0b\x15\x88\xd2\x98\x98\xc6\xeb\x5a\x7d\xbf\x38\x1d\x78\x56\x44\x6e"
        )
    ]

vectors_aes192_enc :: [KATCTR]
vectors_aes192_enc =
    [
        ( "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27"
        , "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
        , "\x03\x0a\x11\x18\x1f\x26\x2d\x34\x3b\x42\x49\x50\x57\x5e\x65\x6c"
        , "\xe6\xd7\xe3\x96\xd1\x4c\xd0\x2a\x6a\x22\xe5\x71\x61\xcd\x1d\xc0"
        )
    ,
        ( "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27"
        , "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
        , "\x03\x0a\x11\x18\x1f\x26\x2d\x34\x3b\x42\x49\x50\x57\x5e\x65\x6c\x73\x7a\x81\x88\x8f\x96\x9d\xa4\xab\xb2\xb9\xc0\xc7\xce\xd5\xdc\xe3\xea\xf1\xf8\xff\x06\x0d\x14\x1b\x22\x29\x30\x37\x3e\x45\x4c\x53\x5a\x61\x68\x6f\x76\x7d\x84\x8b\x92\x99\xa0\xa7\xae\xb5\xbc\xc3\xca\xd1\xd8\xdf\xe6\xed\xf4\xfb\x02\x09\x10\x17\x1e\x25\x2c\x33\x3a\x41\x48\x4f\x56\x5d\x64\x6b\x72\x79\x80\x87\x8e\x95\x9c\xa3\xaa\xb1\xb8\xbf\xc6\xcd\xd4\xdb\xe2\xe9\xf0\xf7\xfe\x05\x0c\x13\x1a\x21\x28\x2f\x36\x3d\x44\x4b\x52\x59\x60\x67\x6e\x75\x7c\x83\x8a\x91\x98\x9f\xa6\xad\xb4\xbb\xc2\xc9\xd0\xd7\xde\xe5\xec"
        , "\xe6\xd7\xe3\x96\xd1\x4c\xd0\x2a\x6a\x22\xe5\x71\x61\xcd\x1d\xc0\x85\xfc\x17\x66\x30\x7c\x51\x03\xbb\x13\x61\x16\x60\x11\xff\xaa\x5a\xbd\x39\xf2\xcf\x3c\x87\x73\x39\x02\x6b\xaa\x8c\x71\xce\xb6\x3a\x30\x81\xad\x8b\xbf\xc7\x1d\x0c\xd8\x2b\x65\xa8\xe9\x08\x7c\x46\xec\xaf\x61\xe3\xa8\x66\x11\x32\x8b\x17\x37\xb1\xec\x3e\xd6\x12\x28\xb0\xcc\x7d\x38\xc3\x0e\xee\xf0\xc8\xbf\x82\x47\xb9\x8c\x2a\x59\x89\xa3\x3d\x9a\x47\x09\xb6\xdf\xc5\xb4\x1d\x06\x9d\xe5\x8e\x7b\x82\x0f\xf6\x13\xad\xf4\x9c\xc3\x27\x94\x56\xe5\x70\x17\xd9\x24\x99\x77\xb7\xcd\x06\x17\x91\x9b\xf5\x7d\x29\x95\xa3\xe2"
        )
    ,
        ( "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27"
        , "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
        , "\x03\x0a\x11\x18\x1f\x26\x2d\x34\x3b\x42\x49\x50\x57\x5e\x65\x6c\x73\x7a\x81\x88\x8f\x96\x9d\xa4\xab\xb2\xb9\xc0\xc7\xce\xd5\xdc\xe3\xea\xf1\xf8\xff\x06\x0d\x14\x1b\x22\x29\x30\x37\x3e\x45\x4c\x53\x5a\x61\x68\x6f\x76\x7d\x84\x8b\x92\x99\xa0\xa7\xae\xb5\xbc\xc3\xca\xd1\xd8\xdf\xe6\xed\xf4\xfb\x02\x09\x10\x17\x1e\x25\x2c\x33\x3a\x41\x48\x4f\x56\x5d\x64\x6b\x72\x79\x80\x87\x8e\x95\x9c\xa3\xaa\xb1\xb8\xbf\xc6\xcd\xd4\xdb\xe2\xe9\xf0\xf7\xfe\x05\x0c\x13\x1a\x21\x28\x2f\x36\x3d\x44\x4b\x52\x59\x60\x67\x6e\x75\x7c\x83\x8a"
        , "\xe6\xd7\xe3\x96\xd1\x4c\xd0\x2a\x6a\x22\xe5\x71\x61\xcd\x1d\xc0\x85\xfc\x17\x66\x30\x7c\x51\x03\xbb\x13\x61\x16\x60\x11\xff\xaa\x5a\xbd\x39\xf2\xcf\x3c\x87\x73\x39\x02\x6b\xaa\x8c\x71\xce\xb6\x3a\x30\x81\xad\x8b\xbf\xc7\x1d\x0c\xd8\x2b\x65\xa8\xe9\x08\x7c\x46\xec\xaf\x61\xe3\xa8\x66\x11\x32\x8b\x17\x37\xb1\xec\x3e\xd6\x12\x28\xb0\xcc\x7d\x38\xc3\x0e\xee\xf0\xc8\xbf\x82\x47\xb9\x8c\x2a\x59\x89\xa3\x3d\x9a\x47\x09\xb6\xdf\xc5\xb4\x1d\x06\x9d\xe5\x8e\x7b\x82\x0f\xf6\x13\xad\xf4\x9c\xc3\x27\x94\x56\xe5\x70\x17\xd9\x24"
        )
    ]

vectors_aes256_enc :: [KATCTR]
vectors_aes256_enc =
    [
        ( "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f"
        , "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
        , "\x03\x0a\x11\x18\x1f\x26\x2d\x34\x3b\x42\x49\x50\x57\x5e\x65\x6c"
        , "\xcd\x79\x9a\x1e\xf2\xd4\x81\x6b\x8a\xaa\x64\xb5\x73\x0c\x49\x80"
        )
    ,
        ( "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f"
        , "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
        , "\x03\x0a\x11\x18\x1f\x26\x2d\x34\x3b\x42\x49\x50\x57\x5e\x65\x6c\x73\x7a\x81\x88\x8f\x96\x9d\xa4\xab\xb2\xb9\xc0\xc7\xce\xd5\xdc\xe3\xea\xf1\xf8\xff\x06\x0d\x14\x1b\x22\x29\x30\x37\x3e\x45\x4c\x53\x5a\x61\x68\x6f\x76\x7d\x84\x8b\x92\x99\xa0\xa7\xae\xb5\xbc\xc3\xca\xd1\xd8\xdf\xe6\xed\xf4\xfb\x02\x09\x10\x17\x1e\x25\x2c\x33\x3a\x41\x48\x4f\x56\x5d\x64\x6b\x72\x79\x80\x87\x8e\x95\x9c\xa3\xaa\xb1\xb8\xbf\xc6\xcd\xd4\xdb\xe2\xe9\xf0\xf7\xfe\x05\x0c\x13\x1a\x21\x28\x2f\x36\x3d\x44\x4b\x52\x59\x60\x67\x6e\x75\x7c\x83\x8a\x91\x98\x9f\xa6\xad\xb4\xbb\xc2\xc9\xd0\xd7\xde\xe5\xec"
        , "\xcd\x79\x9a\x1e\xf2\xd4\x81\x6b\x8a\xaa\x64\xb5\x73\x0c\x49\x80\x26\xa2\x41\x4b\x82\xcf\xf3\xbb\xb5\x04\x99\x2d\xc4\xe8\xfc\xed\xe2\xc9\x2d\x86\xa7\x78\xb5\x1c\xe4\x75\x81\xe2\x89\x99\xae\x3c\xcf\x56\xfe\x04\x71\xc4\x9b\x1f\x09\xeb\xff\x94\xaa\x19\x74\x8a\x4b\xfd\x59\x18\x0c\xbe\xe0\x4e\x9b\x92\xf8\x6b\x10\xb0\xe8\x67\x76\xd6\x76\x80\x38\x09\xe5\xc7\x9b\x8a\x7d\x4e\x48\x43\xa2\x9b\x87\x26\xbb\x4d\x30\xf7\x23\xcb\x62\x53\xc2\x70\x58\x5c\xf0\xa9\xbd\x2d\x48\xf7\x05\x33\xaf\x3c\x2a\xa6\xf6\xc0\x23\x7f\xb7\x0b\x8d\x8a\xe3\xd1\x9d\x31\xbe\x99\x3d\x83\xf3\x24\xa6\x10\x4b\x71"
        )
    ,
        ( "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f"
        , "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
        , "\x03\x0a\x11\x18\x1f\x26\x2d\x34\x3b\x42\x49\x50\x57\x5e\x65\x6c\x73\x7a\x81\x88\x8f\x96\x9d\xa4\xab\xb2\xb9\xc0\xc7\xce\xd5\xdc\xe3\xea\xf1\xf8\xff\x06\x0d\x14\x1b\x22\x29\x30\x37\x3e\x45\x4c\x53\x5a\x61\x68\x6f\x76\x7d\x84\x8b\x92\x99\xa0\xa7\xae\xb5\xbc\xc3\xca\xd1\xd8\xdf\xe6\xed\xf4\xfb\x02\x09\x10\x17\x1e\x25\x2c\x33\x3a\x41\x48\x4f\x56\x5d\x64\x6b\x72\x79\x80\x87\x8e\x95\x9c\xa3\xaa\xb1\xb8\xbf\xc6\xcd\xd4\xdb\xe2\xe9\xf0\xf7\xfe\x05\x0c\x13\x1a\x21\x28\x2f\x36\x3d\x44\x4b\x52\x59\x60\x67\x6e\x75\x7c\x83\x8a"
        , "\xcd\x79\x9a\x1e\xf2\xd4\x81\x6b\x8a\xaa\x64\xb5\x73\x0c\x49\x80\x26\xa2\x41\x4b\x82\xcf\xf3\xbb\xb5\x04\x99\x2d\xc4\xe8\xfc\xed\xe2\xc9\x2d\x86\xa7\x78\xb5\x1c\xe4\x75\x81\xe2\x89\x99\xae\x3c\xcf\x56\xfe\x04\x71\xc4\x9b\x1f\x09\xeb\xff\x94\xaa\x19\x74\x8a\x4b\xfd\x59\x18\x0c\xbe\xe0\x4e\x9b\x92\xf8\x6b\x10\xb0\xe8\x67\x76\xd6\x76\x80\x38\x09\xe5\xc7\x9b\x8a\x7d\x4e\x48\x43\xa2\x9b\x87\x26\xbb\x4d\x30\xf7\x23\xcb\x62\x53\xc2\x70\x58\x5c\xf0\xa9\xbd\x2d\x48\xf7\x05\x33\xaf\x3c\x2a\xa6\xf6\xc0\x23\x7f\xb7\x0b\x8d\x8a"
        )
    ]