diff options
author | joe <joe@jerkface.net> | 2017-11-17 19:16:05 -0500 |
---|---|---|
committer | James Crayne <jim.crayne@gmail.com> | 2017-11-19 23:40:17 +0000 |
commit | 5c34b3bffc286b6cc5010a30c1016355c86359a5 (patch) | |
tree | 70da5ce59228e807796f580291205263ddcfdf25 /src/Crypto/Tox.hs | |
parent | d12baaa1c0866a410b87386cf8ea577f1dcbaf44 (diff) |
More pure variant of lookupSharedSecret: lookupNonceFunction.
Diffstat (limited to 'src/Crypto/Tox.hs')
-rw-r--r-- | src/Crypto/Tox.hs | 10 |
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 | ||
299 | lookupSharedSecret :: TransportCrypto -> SecretKey -> PublicKey -> Nonce24 -> IO State | 299 | lookupSharedSecret :: TransportCrypto -> SecretKey -> PublicKey -> Nonce24 -> IO State |
300 | lookupSharedSecret TransportCrypto{secretsCache} sk recipient nonce = do | 300 | lookupSharedSecret crypto sk recipient nonce |
301 | = ($ nonce) <$> lookupNonceFunction crypto sk recipient | ||
302 | |||
303 | lookupNonceFunction :: TransportCrypto -> SecretKey -> PublicKey -> IO (Nonce24 -> State) | ||
304 | lookupNonceFunction 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 | ||
320 | hsalsa20 :: (ByteArrayAccess t, ByteArrayAccess t1) => t1 -> t -> BA.ScrubbedBytes | 324 | hsalsa20 :: (ByteArrayAccess t, ByteArrayAccess t1) => t1 -> t -> BA.ScrubbedBytes |