crypto-pubkey 0.1.4 → 0.2.0
raw patch · 7 files changed
+41/−26 lines, 7 filesdep +byteabledep +crypto-randomdep −cprng-aesdep −crypto-random-apidep ~crypto-numbersdep ~cryptohashPVP ok
version bump matches the API change (PVP)
Dependencies added: byteable, crypto-random
Dependencies removed: cprng-aes, crypto-random-api
Dependency ranges changed: crypto-numbers, cryptohash
API changes (from Hackage documentation)
Files
- Benchs/Bench.hs +2/−2
- Crypto/PubKey/HashDescr.hs +9/−8
- Crypto/PubKey/RSA/OAEP.hs +1/−1
- Crypto/PubKey/RSA/PKCS15.hs +1/−1
- Crypto/PubKey/RSA/PSS.hs +3/−2
- Tests/RNG.hs +17/−5
- crypto-pubkey.cabal +8/−7
Benchs/Bench.hs view
@@ -10,15 +10,15 @@ import Crypto.PubKey.RSA.OAEP as OAEP import Crypto.PubKey.RSA.PSS as PSS import Crypto.PubKey.HashDescr+import Crypto.Random -import Crypto.Random.AESCtr import qualified Data.ByteString as B right (Right r) = r right (Left _) = error "left received" main = do- rng <- makeSystem+ rng <- cprgCreate `fmap` createEntropyPool :: IO SystemRNG let !bs = B.replicate 32 0 !encryptedMsgPKCS = (right . fst . PKCS15.encrypt rng rsaPublickey) bs !encryptedMsgOAEP = (right . fst . OAEP.encrypt rng oaepParams rsaPublickey) bs
Crypto/PubKey/HashDescr.hs view
@@ -25,6 +25,7 @@ ) where import Data.ByteString (ByteString)+import Data.Byteable (toBytes) import qualified Data.ByteString as B import Crypto.Hash @@ -40,50 +41,50 @@ -- | Describe the MD2 hashing algorithm hashDescrMD2 :: HashDescr hashDescrMD2 =- HashDescr { hashFunction = digestToByteString . (hash :: ByteString -> Digest MD2)+ HashDescr { hashFunction = toBytes . (hash :: ByteString -> Digest MD2) , digestToASN1 = toHashWithInfo "\x30\x20\x30\x0c\x06\x08\x2a\x86\x48\x86\xf7\x0d\x02\x02\x05\x00\x04\x10" } -- | Describe the MD5 hashing algorithm hashDescrMD5 :: HashDescr hashDescrMD5 =- HashDescr { hashFunction = digestToByteString . (hash :: ByteString -> Digest MD5)+ HashDescr { hashFunction = toBytes . (hash :: ByteString -> Digest MD5) , digestToASN1 = toHashWithInfo "\x30\x20\x30\x0c\x06\x08\x2a\x86\x48\x86\xf7\x0d\x02\x05\x05\x00\x04\x10" } -- | Describe the SHA1 hashing algorithm hashDescrSHA1 :: HashDescr hashDescrSHA1 =- HashDescr { hashFunction = digestToByteString . (hash :: ByteString -> Digest SHA1)+ HashDescr { hashFunction = toBytes . (hash :: ByteString -> Digest SHA1) , digestToASN1 = toHashWithInfo "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14" } -- | Describe the SHA224 hashing algorithm hashDescrSHA224 :: HashDescr hashDescrSHA224 =- HashDescr { hashFunction = digestToByteString . (hash :: ByteString -> Digest SHA224)+ HashDescr { hashFunction = toBytes . (hash :: ByteString -> Digest SHA224) , digestToASN1 = toHashWithInfo "\x30\x2d\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x04\x05\x00\x04\x1c" } -- | Describe the SHA256 hashing algorithm hashDescrSHA256 :: HashDescr hashDescrSHA256 =- HashDescr { hashFunction = digestToByteString . (hash :: ByteString -> Digest SHA256)+ HashDescr { hashFunction = toBytes . (hash :: ByteString -> Digest SHA256) , digestToASN1 = toHashWithInfo "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20" } -- | Describe the SHA384 hashing algorithm hashDescrSHA384 :: HashDescr hashDescrSHA384 =- HashDescr { hashFunction = digestToByteString . (hash :: ByteString -> Digest SHA384)+ HashDescr { hashFunction = toBytes . (hash :: ByteString -> Digest SHA384) , digestToASN1 = toHashWithInfo "\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02\x05\x00\x04\x30" } -- | Describe the SHA512 hashing algorithm hashDescrSHA512 :: HashDescr hashDescrSHA512 =- HashDescr { hashFunction = digestToByteString . (hash :: ByteString -> Digest SHA512)+ HashDescr { hashFunction = toBytes . (hash :: ByteString -> Digest SHA512) , digestToASN1 = toHashWithInfo "\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03\x05\x00\x04\x40" } -- | Describe the RIPEMD160 hashing algorithm hashDescrRIPEMD160 :: HashDescr hashDescrRIPEMD160 =- HashDescr { hashFunction = digestToByteString . (hash :: ByteString -> Digest RIPEMD160)+ HashDescr { hashFunction = toBytes . (hash :: ByteString -> Digest RIPEMD160) , digestToASN1 = toHashWithInfo "\x30\x21\x30\x09\x06\x05\x2b\x24\x03\x02\x01\x05\x00\x04\x14" }
Crypto/PubKey/RSA/OAEP.hs view
@@ -86,7 +86,7 @@ encrypt g oaep pk msg = (encryptWithSeed seed oaep pk msg, g') where hashF = oaepHash oaep hashLen = B.length (hashF B.empty)- (seed, g') = genRandomBytes hashLen g+ (seed, g') = cprgGenerate hashLen g -- | un-pad a OAEP encoded message. --
Crypto/PubKey/RSA/PKCS15.hs view
@@ -43,7 +43,7 @@ where {- get random non-null bytes -} getNonNullRandom :: CPRG g => g -> Int -> (ByteString, g) getNonNullRandom g n =- let (bs0,g') = genRandomBytes n g+ let (bs0,g') = cprgGenerate n g bytes = B.pack $ filter (/= 0) $ B.unpack $ bs0 left = (n - B.length bytes) in if left == 0
Crypto/PubKey/RSA/PSS.hs view
@@ -19,6 +19,7 @@ import Crypto.Random.API import Crypto.Types.PubKey.RSA import Data.ByteString (ByteString)+import Data.Byteable import qualified Data.ByteString as B import Crypto.PubKey.RSA.Prim import Crypto.PubKey.RSA.Types@@ -47,7 +48,7 @@ -- | Default Params using SHA1 algorithm. defaultPSSParamsSHA1 :: PSSParams-defaultPSSParamsSHA1 = defaultPSSParams (digestToByteString . (hash :: ByteString -> Digest SHA1))+defaultPSSParamsSHA1 = defaultPSSParams (toBytes . (hash :: ByteString -> Digest SHA1)) -- | Sign using the PSS parameters and the salt explicitely passed as parameters. --@@ -85,7 +86,7 @@ -> ByteString -- ^ Message to sign -> (Either Error ByteString, g) sign rng blinder params pk m = (signWithSalt salt blinder params pk m, rng')- where (salt,rng') = genRandomBytes (pssSaltLength params) rng+ where (salt,rng') = cprgGenerate (pssSaltLength params) rng -- | Sign using the PSS Parameters and an automatically generated blinder. signSafer :: CPRG g
Tests/RNG.hs view
@@ -2,8 +2,9 @@ import Data.Word import Data.List (foldl')+import Data.Byteable import qualified Data.ByteString as B-import Crypto.Random.API+import Crypto.Random import Control.Arrow (first) {- this is a just test rng. this is absolutely not a serious RNG. DO NOT use elsewhere -}@@ -24,10 +25,21 @@ in (b:l, g'') instance CPRG Rng where- cprgGenBytes len g = first B.pack $ getBytes len g- cprgSupplyEntropy e g = reseed e g- cprgNeedReseed _ = NeverReseed+ cprgCreate pool = let ent = grabEntropy 4 pool in generate (B.unpack $ toBytes ent)+ cprgSetReseedThreshold _ g = g+ cprgGenerate len g = first B.pack $ getBytes len g+ cprgGenerateWithEntropy = cprgGenerate+ cprgFork g = let (bs, g') = getBytes 4 g+ in case bs of+ [a,b,c,d] -> let g2 = Rng (fromIntegral a * 256 + fromIntegral b, fromIntegral c * 256 + fromIntegral d)+ in (g2, g')+ _ -> error "getBytes assertion" ++generate :: [Word8] -> Rng+generate [a,b,c,d] = Rng (fromIntegral a * 256 + fromIntegral b, fromIntegral c * 256 + fromIntegral d)+generate _ = error "generate assertion: need 4 bytes"+ reseed :: B.ByteString -> Rng -> Rng reseed bs (Rng (a,b)) = Rng (fromIntegral a', b') where a' = foldl' (\v i -> ((fromIntegral v) + (fromIntegral i) * 36969) `mod` 65536) a l@@ -35,4 +47,4 @@ l = B.unpack bs rng :: Rng-rng = Rng (1,2) +rng = Rng (2,2)
crypto-pubkey.cabal view
@@ -1,5 +1,5 @@ Name: crypto-pubkey-Version: 0.1.4+Version: 0.2.0 Description: Public Key cryptography .@@ -27,10 +27,11 @@ Library Build-Depends: base >= 4 && < 5 , bytestring- , crypto-random-api >= 0.2 && < 0.3+ , byteable+ , crypto-random >= 0.0 && < 0.1 , crypto-pubkey-types >= 0.4 && < 0.5- , cryptohash >= 0.8- , crypto-numbers+ , cryptohash >= 0.9.1+ , crypto-numbers >= 0.2 Exposed-modules: Crypto.PubKey.RSA Crypto.PubKey.RSA.PKCS15 Crypto.PubKey.RSA.OAEP@@ -51,10 +52,11 @@ Main-Is: Tests.hs Build-depends: base >= 4 && < 5 , bytestring+ , byteable , cryptohash , crypto-pubkey , crypto-numbers- , crypto-random-api+ , crypto-random , QuickCheck >= 2 , HUnit , test-framework >= 0.3.3@@ -67,9 +69,8 @@ type: exitcode-stdio-1.0 Build-depends: base >= 4 && < 5 , bytestring- , cprng-aes >= 0.3.0 , cryptohash- , crypto-random-api+ , crypto-random , crypto-pubkey , criterion , mtl