packages feed

RSA 2.3.1 → 2.4.1

raw patch · 3 files changed

+22/−26 lines, 3 filesdep +cipher-aes128dep −DRBGdep ~basedep ~binarydep ~bytestringPVP ok

version bump matches the API change (PVP)

Dependencies added: cipher-aes128

Dependencies removed: DRBG

Dependency ranges changed: base, binary, bytestring, crypto-api, crypto-pubkey-types

API changes (from Hackage documentation)

Files

RSA.cabal view
@@ -1,6 +1,6 @@ name:       RSA category:   Cryptography, Codec-version:    2.3.1+version:    2.4.1 license:    BSD3 license-file: LICENSE author:     Adam Wick <awick@galois.com>@@ -25,6 +25,8 @@                    crypto-api          >= 0.10    && < 0.14,                    crypto-pubkey-types >= 0.2     && < 0.6,                    SHA                 >= 1.6.4.1 && < 2.0+  if impl(ghc < 8.0)+    build-depends: cipher-aes128       < 0.7.0.4   exposed-modules: Codec.Crypto.RSA,                    Codec.Crypto.RSA.Exceptions,                    Codec.Crypto.RSA.Pure@@ -41,7 +43,6 @@                   bytestring                 >  0.8     && < 0.12,                   crypto-api                 >= 0.10    && < 0.14,                   crypto-pubkey-types        >= 0.4     && < 0.6,-                  DRBG                       >= 0.5.2   && < 0.7,                   QuickCheck                 >= 2.5     && < 3,                   tagged                     >= 0.2     && < 0.9,                   test-framework             >= 0.8.0.3 && < 0.10,
Test.hs view
@@ -1,14 +1,12 @@ import Codec.Crypto.RSA.Pure import Control.Monad import Data.Binary-import qualified Data.ByteString as BSS import Data.ByteString.Lazy(ByteString) import qualified Data.ByteString.Lazy as BS import Data.Digest.Pure.SHA import System.IO import Test.QuickCheck import Crypto.Random-import Crypto.Random.DRBG  import Test.Framework (defaultMain, testGroup) import Test.Framework.Providers.QuickCheck2 (testProperty)@@ -25,7 +23,7 @@ main = do   putStr   "Generating testing keys ... "   hFlush   stdout-  g :: GenAutoReseed HashDRBG HashDRBG <- newGenIO+  g :: SystemRandom <- newGenIO   let (keys, g') = buildRandomKeyPairs g (cycle keySizes) numRandomKeyPairs   unless (all ((> 5) . public_n . fst) keys) $ fail "Something odd."   putStrLn "done!"@@ -37,7 +35,7 @@     , testGroup "Testing basic helper functions" [         testProperty "ByteString chunking works"    prop_chunkifyWorks       , testProperty "Modular exponentiation works" prop_modExpWorks-      , testProperty "Modular inversion works"      prop_modInvWorks+      , testProperty "Modular inversion works"      (prop_modInvWorks g')       ]     , testGroup "Testing RSA core functions" [         testProperty "Can roundtrip from Integer to BS and back" prop_i2o2iIdent@@ -91,19 +89,6 @@   arbitrary = elements [hashSHA1, hashSHA224,                        hashSHA256, hashSHA384, hashSHA512] -newtype LargePrime = LP Integer-  deriving (Show)--instance Arbitrary LargePrime where-  arbitrary =-    do seed <- BSS.pack `fmap` replicateM 4096 arbitrary-       case newGen seed of-        Left _ -> fail "DRBG initialization error."-        Right (g :: HashDRBG) ->-          case largeRandomPrime g 64 of-            Left _ -> fail "Large prime generation failure."-            Right (i, _) -> return (LP i)- data KeyPairIdx = KPI Int  deriving (Show) @@ -149,12 +134,22 @@   e' = getPositive e   m' = getPositive m -prop_modInvWorks :: LargePrime -> LargePrime -> Bool-prop_modInvWorks (LP p) (LP q) = (e * d) `mod` phi == 1- where -  e   = 65537-  phi = (p - 1) * (q - 1)-  d   = modular_inverse e phi+prop_modInvWorks :: CryptoRandomGen g => g -> Word16 -> Bool+prop_modInvWorks g0 x =+  let (p, g1) = primeGen (x `mod` 512) g0+      (q, _)  = primeGen (x `mod` 512) g1+      e       = 65537+      phi     = (p - 1) * (q - 1)+      d       = modular_inverse e phi+  in (e * d) `mod` phi == 1+ where+  primeGen pre g =+    case randomBS g (fromIntegral pre) of+      Left e -> error ("Error prefetching bytestring:" ++ show e)+      Right (_, g') ->+        case largeRandomPrime g' 64 of+          Left  _   -> error "Large prime generation failure."+          Right res -> res  prop_i2o2iIdent :: Positive Integer -> Bool prop_i2o2iIdent px =
src/Codec/Crypto/RSA/Pure.hs view
@@ -112,7 +112,7 @@               return (PrivateKey pub d 0 0 0 0 0)  failOnError :: (Monad m, Show a) => Either a b -> m b-failOnError (Left e)  = fail (show e)+failOnError (Left e)  = error (show e) failOnError (Right b) = return b  -- ----------------------------------------------------------------------------