From 393aeac8cdc14a11efedd96e12f9daaa8a18c627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Ch=C3=A9ron?= Date: Sat, 2 Jun 2018 09:24:41 +0200 Subject: [PATCH] Test LE serialization --- .haskell-ci | 4 ++-- .travis.yml | 8 ++++---- cryptonite.cabal | 2 +- stack.yaml | 4 ++-- tests/Number.hs | 22 +++++++++++++++++----- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/.haskell-ci b/.haskell-ci index fc2947c..a7571c5 100644 --- a/.haskell-ci +++ b/.haskell-ci @@ -7,10 +7,10 @@ compiler: ghc-8.6 lts-13.3 # options # option: alias x=y z=v option: gaugedeps extradep=gauge-0.2.1 -option: basementmin extradep=basement-0.0.6 extradep=foundation-0.0.19 extradep=memory-0.14.14 +option: basementmin extradep=basement-0.0.8 extradep=memory-0.14.18 # builds -build: ghc-8.2 +build: ghc-8.2 basementmin build: ghc-8.0 basementmin gaugedeps build: ghc-8.0 basementmin gaugedeps os=osx build: ghc-8.4 diff --git a/.travis.yml b/.travis.yml index eb4f365..f32a94c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# ~*~ auto-generated by haskell-ci with config : 8f74deffc95fd794fa2996c167c6543bbfab1ae432f0a83e0898f0b5871a92eb ~*~ +# ~*~ auto-generated by haskell-ci with config : 68149dea5ea6ea0dcbeebc12e2f77fd3f4f0166e8666f9dccd49bae65e2df32c ~*~ # Use new container infrastructure to enable caching sudo: false @@ -49,15 +49,15 @@ script: # create the build stack.yaml case "$RESOLVER" in ghc-8.2) - echo "{ resolver: lts-11.22, packages: [ '.' ], extra-deps: [], flags: {} }" > stack.yaml + echo "{ resolver: lts-11.22, packages: [ '.' ], extra-deps: [ basement-0.0.8, memory-0.14.18 ], flags: {} }" > stack.yaml stack --no-terminal build --install-ghc --coverage --test --bench --no-run-benchmarks --haddock --no-haddock-deps ;; ghc-8.0) - echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ basement-0.0.6, foundation-0.0.19, memory-0.14.14, gauge-0.2.1 ], flags: {} }" > stack.yaml + echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ basement-0.0.8, memory-0.14.18, gauge-0.2.1 ], flags: {} }" > stack.yaml stack --no-terminal build --install-ghc --coverage --test --bench --no-run-benchmarks --haddock --no-haddock-deps ;; ghc-8.0) - echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ basement-0.0.6, foundation-0.0.19, memory-0.14.14, gauge-0.2.1 ], flags: {} }" > stack.yaml + echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ basement-0.0.8, memory-0.14.18, gauge-0.2.1 ], flags: {} }" > stack.yaml stack --no-terminal build --install-ghc --coverage --test --bench --no-run-benchmarks --haddock --no-haddock-deps ;; ghc-8.4) diff --git a/cryptonite.cabal b/cryptonite.cabal index 2dd7688..650094b 100644 --- a/cryptonite.cabal +++ b/cryptonite.cabal @@ -239,7 +239,7 @@ Library Build-depends: base Build-depends: bytestring - , memory >= 0.14.14 + , memory >= 0.14.18 , basement >= 0.0.6 , ghc-prim ghc-options: -Wall -fwarn-tabs -optc-O3 diff --git a/stack.yaml b/stack.yaml index bf246bb..9b882d2 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,3 +1,3 @@ -# ~*~ auto-generated by haskell-ci with config : 8f74deffc95fd794fa2996c167c6543bbfab1ae432f0a83e0898f0b5871a92eb ~*~ -{ resolver: lts-13.2, packages: [ '.' ], extra-deps: [], flags: {} } +# ~*~ auto-generated by haskell-ci with config : 68149dea5ea6ea0dcbeebc12e2f77fd3f4f0166e8666f9dccd49bae65e2df32c ~*~ +{ resolver: lts-13.3, packages: [ '.' ], extra-deps: [], flags: {} } diff --git a/tests/Number.hs b/tests/Number.hs index fd77fa7..0b8f654 100644 --- a/tests/Number.hs +++ b/tests/Number.hs @@ -4,9 +4,11 @@ module Number (tests) where import Imports import Data.ByteArray (Bytes) +import qualified Data.ByteArray as B import Crypto.Number.Basic import Crypto.Number.Generate -import Crypto.Number.Serialize +import qualified Crypto.Number.Serialize as BE +import qualified Crypto.Number.Serialize.LE as LE import Crypto.Number.Prime import Data.Bits @@ -50,14 +52,24 @@ tests = testGroup "number" bits = 6 + baseBits prime = withTestDRG testDRG $ generateSafePrime bits in bits == numBits prime - , testProperty "marshalling" $ \qaInt -> - getQAInteger qaInt == os2ip (i2osp (getQAInteger qaInt) :: Bytes) , testProperty "as-power-of-2-and-odd" $ \n -> let (e, a1) = asPowerOf2AndOdd n in n == (2^e)*a1 + , testProperty "marshalling-be" $ \qaInt -> + getQAInteger qaInt == BE.os2ip (BE.i2osp (getQAInteger qaInt) :: Bytes) + , testProperty "marshalling-le" $ \qaInt -> + getQAInteger qaInt == LE.os2ip (LE.i2osp (getQAInteger qaInt) :: Bytes) + , testProperty "be-rev-le" $ \qaInt -> + getQAInteger qaInt == LE.os2ip (B.reverse (BE.i2osp (getQAInteger qaInt) :: Bytes)) + , testProperty "be-rev-le-40" $ \qaInt -> + getQAInteger qaInt == LE.os2ip (B.reverse (BE.i2ospOf_ 40 (getQAInteger qaInt) :: Bytes)) + , testProperty "le-rev-be" $ \qaInt -> + getQAInteger qaInt == BE.os2ip (B.reverse (LE.i2osp (getQAInteger qaInt) :: Bytes)) + , testProperty "le-rev-be-40" $ \qaInt -> + getQAInteger qaInt == BE.os2ip (B.reverse (LE.i2ospOf_ 40 (getQAInteger qaInt) :: Bytes)) , testGroup "marshalling-kat-to-bytearray" $ map toSerializationKat $ zip [katZero..] serializationVectors , testGroup "marshalling-kat-to-integer" $ map toSerializationKatInteger $ zip [katZero..] serializationVectors ] where - toSerializationKat (i, (sz, n, ba)) = testCase (show i) (ba @=? i2ospOf_ sz n) - toSerializationKatInteger (i, (_, n, ba)) = testCase (show i) (n @=? os2ip ba) + toSerializationKat (i, (sz, n, ba)) = testCase (show i) (ba @=? BE.i2ospOf_ sz n) + toSerializationKatInteger (i, (_, n, ba)) = testCase (show i) (n @=? BE.os2ip ba)