memory 0.2 → 0.3
raw patch · 4 files changed
+320/−1 lines, 4 files
Files
- memory.cabal +7/−1
- tests/Imports.hs +12/−0
- tests/SipHash.hs +276/−0
- tests/Utils.hs +25/−0
memory.cabal view
@@ -1,12 +1,15 @@ Name: memory-Version: 0.2+Version: 0.3 Synopsis: memory and related abtraction stuff Description: Chunk of memory, polymorphic byte array management and manipulation . * A polymorphic byte array abstraction and function similar to strict ByteString.+ . * Different type of byte array abstraction.+ . * Raw memory IO operations (memory set, memory copy, ..)+ . * Aliasing with endianness support. License: BSD3 License-file: LICENSE@@ -86,6 +89,9 @@ type: exitcode-stdio-1.0 hs-source-dirs: tests Main-is: Tests.hs+ Other-modules: Imports+ SipHash+ Utils Build-Depends: base >= 3 && < 5 , tasty , tasty-quickcheck
+ tests/Imports.hs view
@@ -0,0 +1,12 @@+module Imports+ ( module X+ ) where++import Control.Applicative as X+import Control.Monad as X+import Data.Foldable as X (foldl')+import Data.Monoid as X++import Test.Tasty as X+import Test.Tasty.HUnit as X+import Test.Tasty.QuickCheck as X hiding (vector)
+ tests/SipHash.hs view
@@ -0,0 +1,276 @@+{-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE OverloadedStrings #-}+module SipHash (tests) where++import Imports+import Utils+import qualified Data.ByteArray as B+import Data.ByteArray.Hash (SipKey(..), SipHash(..), sipHash)++katKey = SipKey 0x0706050403020100 0x0f0e0d0c0b0a0908++vectors =+ [ ( katKey+ , ""+ , SipHash 0x726fdb47dd0e0e31+ )+ , ( katKey+ , "\x00"+ , SipHash 0x74f839c593dc67fd+ )+ , ( katKey+ , "\x00\x01"+ , SipHash 0x0d6c8009d9a94f5a+ )+ , ( katKey+ , "\x00\x01\x02"+ , SipHash 0x85676696d7fb7e2d+ )+ , ( katKey+ , "\x00\x01\x02\x03"+ , SipHash 0xcf2794e0277187b7+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04"+ , SipHash 0x18765564cd99a68d+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05"+ , SipHash 0xcbc9466e58fee3ce+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06"+ , SipHash 0xab0200f58b01d137+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07"+ , SipHash 0x93f5f5799a932462+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08"+ , SipHash 0x9e0082df0ba9e4b0+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09"+ , SipHash 0x7a5dbbc594ddb9f3+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"+ , SipHash 0xf4b32f46226bada7+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"+ , SipHash 0x751e8fbc860ee5fb+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c"+ , SipHash 0x14ea5627c0843d90+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d"+ , SipHash 0xf723ca908e7af2ee+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"+ , SipHash 0xa129ca6149be45e5+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"+ , SipHash 0x3f2acc7f57c29bdb+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"+ , SipHash 0x699ae9f52cbe4794+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11"+ , SipHash 0x4bc1b3f0968dd39c+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12"+ , SipHash 0xbb6dc91da77961bd+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13"+ , SipHash 0xbed65cf21aa2ee98+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"+ , SipHash 0xd0f2cbb02e3b67c7+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15"+ , SipHash 0x93536795e3a33e88+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16"+ , SipHash 0xa80c038ccd5ccec8+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17"+ , SipHash 0xb8ad50c6f649af94+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18"+ , SipHash 0xbce192de8a85b8ea+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19"+ , SipHash 0x17d835b85bbb15f3+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a"+ , SipHash 0x2f2e6163076bcfad+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b"+ , SipHash 0xde4daaaca71dc9a5+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c"+ , SipHash 0xa6a2506687956571+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d"+ , SipHash 0xad87a3535c49ef28+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e"+ , SipHash 0x32d892fad841c342+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"+ , SipHash 0x7127512f72f27cce+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"+ , SipHash 0xa7f32346f95978e3+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21"+ , SipHash 0x12e0b01abb051238+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22"+ , SipHash 0x15e034d40fa197ae+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23"+ , SipHash 0x314dffbe0815a3b4+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24"+ , SipHash 0x027990f029623981+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25"+ , SipHash 0xcadcd4e59ef40c4d+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26"+ , SipHash 0x9abfd8766a33735c+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27"+ , SipHash 0x0e3ea96b5304a7d0+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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"+ , SipHash 0xad0c42d6fc585992+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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"+ , SipHash 0x187306c89bc215a9+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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"+ , SipHash 0xd4a60abcf3792b95+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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"+ , SipHash 0xf935451de4f21df2+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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"+ , SipHash 0xa9538f0419755787+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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"+ , SipHash 0xdb9acddff56ca510+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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"+ , SipHash 0xd06c98cd5c0975eb+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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"+ , SipHash 0xe612a3cb9ecba951+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30"+ , SipHash 0xc766e62cfcadaf96+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31"+ , SipHash 0xee64435a9752fe72+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32"+ , SipHash 0xa192d576b245165a+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33"+ , SipHash 0x0a8787bf8ecb74b2+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34"+ , SipHash 0x81b3e73d20b49b6f+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34\x35"+ , SipHash 0x7fa8220ba3b2ecea+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34\x35\x36"+ , SipHash 0x245731c13ca42499+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34\x35\x36\x37"+ , SipHash 0xb78dbfaf3a8d83bd+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34\x35\x36\x37\x38"+ , SipHash 0xea1ad565322a1a0b+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39"+ , SipHash 0x60e61c23a3795013+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a"+ , SipHash 0x6606d7e446282b93+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b"+ , SipHash 0x6ca4ecb15c5f91e1+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c"+ , SipHash 0x9f626da15c9625f3+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d"+ , SipHash 0xe51b38608ef25f57+ )+ , ( katKey+ , "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\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\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e"+ , SipHash 0x958a324ceb064572+ )+ ]++katTests witnessID v = map makeTest $ numberedList v+ where makeTest (i, (key,msg,tag)) = testCase ("kat " ++ show i) $ tag @=? sipHash key (witnessID $ B.pack $ unS msg)++tests witnessID =+ [ testGroup "KAT" $ katTests witnessID vectors+ ]
+ tests/Utils.hs view
@@ -0,0 +1,25 @@+module Utils where++import Data.Word+import Data.ByteArray (Bytes, ScrubbedBytes)++unS :: String -> [Word8]+unS = map (fromIntegral . fromEnum)++ascii :: [Word8] -> String+ascii = map (toEnum . fromIntegral)++-- | similar to proxy+data Witness a = Witness++withWitness :: Witness a -> a -> a+withWitness _ a = a++withBytesWitness :: Bytes -> Bytes+withBytesWitness = withWitness (Witness :: Witness Bytes)++withScrubbedBytesWitness :: ScrubbedBytes -> ScrubbedBytes+withScrubbedBytesWitness = id++numberedList :: [a] -> [(Int, a)]+numberedList = zip [1..]