tls 0.3 → 0.3.1
raw patch · 2 files changed
+21/−22 lines, 2 filesdep −randomdep ~cereal
Dependencies removed: random
Dependency ranges changed: cereal
Files
- Network/TLS/SRandom.hs +17/−17
- tls.cabal +4/−5
Network/TLS/SRandom.hs view
@@ -7,14 +7,12 @@ ) where import Data.Word-import Control.Arrow (first) import Crypto.Random-import System.Random import System.Crypto.Random (getEntropy) import Data.ByteString (ByteString) import qualified Data.ByteString as B import qualified Codec.Crypto.AES as AES-import Data.Bits (xor, shiftL)+import Data.Bits (xor) import Data.Serialize {-@@ -40,28 +38,32 @@ add1 :: Word128 -> Word128 add1 (Word128 a b) = if b == 0xffffffffffffffff then Word128 (a+1) 0 else Word128 a (b+1) -toBigInt :: Word128 -> Integer-toBigInt (Word128 a b) = ((fromIntegral a) `shiftL` 64) + fromIntegral b+makeParams :: ByteString -> (ByteString, ByteString, ByteString)+makeParams b = (key, cnt, iv)+ where+ key = B.take 32 left2+ (cnt, left2) = B.splitAt 16 left1+ (iv, left1) = B.splitAt 16 b make :: B.ByteString -> Either GenError SRandomGen make b | B.length b < 64 = Left NotEnoughEntropy | otherwise = Right $ RNG iv (get128 cnt) key where- key = B.take 32 left2- (cnt, left2) = B.splitAt 16 left1- (iv, left1) = B.splitAt 16 b+ (key, cnt, iv) = makeParams b chunkSize :: Int chunkSize = 16 +bxor :: ByteString -> ByteString -> ByteString+bxor a b = B.pack $ B.zipWith xor a b+ nextChunk :: SRandomGen -> (ByteString, SRandomGen) nextChunk (RNG iv counter key) = (chunk, newrng) where newrng = RNG chunk (add1 counter) key chunk = AES.crypt' AES.CBC key iv AES.Encrypt bytes bytes = iv `bxor` (put128 counter)- bxor a b = B.pack $ B.zipWith xor a b makeSRandomGen :: IO (Either GenError SRandomGen) makeSRandomGen = getEntropy 64 >>= return . make@@ -82,11 +84,9 @@ newGen = make genSeedLength = 64 genBytes len rng = Right $ getRandomBytes rng len- reseed b rng = Right rng--instance RandomGen SRandomGen where- split _ = error "split not supported on SRandomGen"- next rng = (fromIntegral $ toBigInt w, rng')- where- (w, rng') = first get128 $ nextChunk rng-+ reseed b rng@(RNG _ cnt1 _)+ | B.length b < 64 = Left NotEnoughEntropy+ | otherwise = Right $ RNG (r16 `bxor` iv2) (get128 (put128 cnt1 `bxor` cnt2)) key2+ where+ (r16, _) = nextChunk rng+ (key2, cnt2, iv2) = makeParams b
tls.cabal view
@@ -1,5 +1,5 @@ Name: tls-Version: 0.3+Version: 0.3.1 Description: native TLS protocol implementation, focusing on purity and more type-checking. .@@ -34,14 +34,13 @@ mtl, cryptohash >= 0.6, binary >= 0.5,- cereal,+ cereal >= 0.3, bytestring, vector,- random, AES, crypto-api >= 0.2, cryptocipher >= 0.2,- certificate >= 0.3+ certificate >= 0.3.2 Exposed-modules: Network.TLS.Client Network.TLS.Server Network.TLS.Struct@@ -71,7 +70,7 @@ Main-is: Tests.hs if flag(test) Buildable: True- Build-Depends: base >= 3 && < 7, HUnit, QuickCheck >= 2, bytestring, random+ Build-Depends: base >= 3 && < 7, HUnit, QuickCheck >= 2, bytestring else Buildable: False