~ubuntu-branches/ubuntu/raring/haskell-clientsession/raring

« back to all changes in this revision

Viewing changes to src/Web/ClientSession.hs

  • Committer: Package Import Robot
  • Author(s): Clint Adams
  • Date: 2012-05-15 15:40:22 UTC
  • mfrom: (2.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120515154022-dq1wpq5cbm42as8y
Tags: 0.7.5-3
Tweak to test with newer hspec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
 
55
55
-- from base
56
56
import Control.Monad (guard, when)
57
 
import Data.Bits ((.|.), xor)
58
 
import Data.List (foldl')
59
57
import qualified Data.IORef as I
60
58
import System.IO.Unsafe (unsafePerformIO)
61
59
import Control.Concurrent (forkIO)
74
72
import Data.Tagged (Tagged, untag)
75
73
 
76
74
-- from crypto-api
77
 
import Crypto.Classes (buildKey)
 
75
import Crypto.Classes (buildKey, constTimeEq)
78
76
import Crypto.Random (genSeedLength, reseed)
79
77
import Crypto.Types (ByteLength)
80
78
import qualified Crypto.Modes as Modes
208
206
    guard (S.length dataBS >= 48) -- 16 bytes of IV + 32 bytes of Skein-MAC-512-256
209
207
    let (auth, toBeAuthed) = S.splitAt 32 dataBS
210
208
        auth' = macKey key toBeAuthed
211
 
    guard (encode auth' `compareHash` auth)
 
209
    guard (encode auth' `constTimeEq` auth)
212
210
    let (iv_e, encrypted) = S.splitAt 16 toBeAuthed
213
211
    iv <- either (const Nothing) Just $ decode iv_e
214
212
    let (x, _) = Modes.unCtr' Modes.incIV (aesKey key) iv encrypted
215
213
    return x
216
214
 
217
 
compareHash :: S.ByteString -> S.ByteString -> Bool
218
 
compareHash s1 s2 =
219
 
    S.length s1 == S.length s2 &&
220
 
    foldl' (.|.) 0 (S.zipWith xor s1 s2) == 0
221
 
 
222
215
-- Significantly more efficient random IV generation. Initial
223
216
-- benchmarks placed it at 6.06 us versus 1.69 ms for Modes.getIVIO,
224
217
-- since it does not require /dev/urandom I/O for every call.