From a218b4ea3bd319f38f049194abb999ed49b88b55 Mon Sep 17 00:00:00 2001 From: Colin Atkinson Date: Wed, 11 Jan 2017 02:19:58 -0500 Subject: [PATCH] Update tests for new generate(Safe)Prime Update generatePrime test to test smaller bit sizes Add test for generateSafePrime Remove -fobject-code --- cryptonite.cabal | 2 +- tests/Number.hs | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cryptonite.cabal b/cryptonite.cabal index e82f1e5..1ea74f7 100644 --- a/cryptonite.cabal +++ b/cryptonite.cabal @@ -205,7 +205,7 @@ Library , bytestring , memory >= 0.8 , ghc-prim - ghc-options: -Wall -fwarn-tabs -optc-O3 -fno-warn-unused-imports -fobject-code + ghc-options: -Wall -fwarn-tabs -optc-O3 -fno-warn-unused-imports default-language: Haskell2010 cc-options: -std=gnu99 if flag(old_toolchain_inliner) diff --git a/tests/Number.hs b/tests/Number.hs index 24ae96f..8016e70 100644 --- a/tests/Number.hs +++ b/tests/Number.hs @@ -42,17 +42,19 @@ tests = testGroup "number" in 0 <= r && r < range , testProperty "generate-prime" $ \testDRG (Int0_2901 baseBits') -> let baseBits = baseBits' `mod` 800 - bits = 48 + baseBits -- no point generating lower than 48 bits .. + bits = 5 + baseBits -- generating lower than 5 bits causes an error .. prime = withTestDRG testDRG $ generatePrime bits - -- with small base bits numbers, the probability that we "cross" this bit size ness - -- to the next is quite high, as the number generated has two highest bit set. - -- - in bits == numBits prime || (if baseBits < 64 then (bits + 1) == numBits prime else False) + in bits == numBits prime + , testProperty "generate-safe-prime" $ \testDRG (Int0_2901 baseBits') -> + let baseBits = baseBits' `mod` 200 + bits = 6 + baseBits + prime = withTestDRG testDRG $ generateSafePrime bits + in bits == numBits prime , testProperty "marshalling" $ \qaInt -> getQAInteger qaInt == os2ip (i2osp (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)