summaryrefslogtreecommitdiff
path: root/src/Crypto/Tox.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-11-17 19:16:05 -0500
committerJames Crayne <jim.crayne@gmail.com>2017-11-19 23:40:17 +0000
commit5c34b3bffc286b6cc5010a30c1016355c86359a5 (patch)
tree70da5ce59228e807796f580291205263ddcfdf25 /src/Crypto/Tox.hs
parentd12baaa1c0866a410b87386cf8ea577f1dcbaf44 (diff)
More pure variant of lookupSharedSecret: lookupNonceFunction.
Diffstat (limited to 'src/Crypto/Tox.hs')
-rw-r--r--src/Crypto/Tox.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Crypto/Tox.hs b/src/Crypto/Tox.hs
index 665a38dd..18cdb5d2 100644
--- a/src/Crypto/Tox.hs
+++ b/src/Crypto/Tox.hs
@@ -297,7 +297,11 @@ unsafeCompare32Bytes' !n !pa !pb = do
297 297
298 298
299lookupSharedSecret :: TransportCrypto -> SecretKey -> PublicKey -> Nonce24 -> IO State 299lookupSharedSecret :: TransportCrypto -> SecretKey -> PublicKey -> Nonce24 -> IO State
300lookupSharedSecret TransportCrypto{secretsCache} sk recipient nonce = do 300lookupSharedSecret crypto sk recipient nonce
301 = ($ nonce) <$> lookupNonceFunction crypto sk recipient
302
303lookupNonceFunction :: TransportCrypto -> SecretKey -> PublicKey -> IO (Nonce24 -> State)
304lookupNonceFunction TransportCrypto{secretsCache} sk recipient = do
301 now <- getPOSIXTime 305 now <- getPOSIXTime
302 atomically $ do 306 atomically $ do
303 mm <- readTVar $ sharedSecret secretsCache 307 mm <- readTVar $ sharedSecret secretsCache
@@ -306,7 +310,7 @@ lookupSharedSecret TransportCrypto{secretsCache} sk recipient nonce = do
306 let miss = computeSharedSecret sk recipient 310 let miss = computeSharedSecret sk recipient
307 writeTVar (sharedSecret secretsCache) 311 writeTVar (sharedSecret secretsCache)
308 (MM.insertTake' 160 recipient (MM.singleton' sk miss (Down now)) (Down now) mm) 312 (MM.insertTake' 160 recipient (MM.singleton' sk miss (Down now)) (Down now) mm)
309 return $ miss nonce 313 return miss
310 Just (stamp,smm) -> do 314 Just (stamp,smm) -> do
311 let (r,v) = case MM.lookup' sk smm of 315 let (r,v) = case MM.lookup' sk smm of
312 Nothing | let miss = computeSharedSecret sk recipient 316 Nothing | let miss = computeSharedSecret sk recipient
@@ -314,7 +318,7 @@ lookupSharedSecret TransportCrypto{secretsCache} sk recipient nonce = do
314 Just (stamp2,hit) -> (hit , MM.insert' sk hit (Down now) smm) 318 Just (stamp2,hit) -> (hit , MM.insert' sk hit (Down now) smm)
315 writeTVar (sharedSecret secretsCache) 319 writeTVar (sharedSecret secretsCache)
316 (MM.insertTake' 160 recipient v (Down now) mm) 320 (MM.insertTake' 160 recipient v (Down now) mm)
317 return $ r nonce 321 return r
318 322
319 323
320hsalsa20 :: (ByteArrayAccess t, ByteArrayAccess t1) => t1 -> t -> BA.ScrubbedBytes 324hsalsa20 :: (ByteArrayAccess t, ByteArrayAccess t1) => t1 -> t -> BA.ScrubbedBytes