diff options
author | joe <joe@jerkface.net> | 2017-11-22 20:12:07 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-11-22 20:12:07 -0500 |
commit | de34b6ec46a7136c249c95d97de3a569cd60b835 (patch) | |
tree | 45f9fd49484ea7bb8fec20bfdafb62edfde2f239 /src/Crypto | |
parent | 27cb2cbe0338c19fd4f8a22b4453086288dae5c4 (diff) |
NoSpamId type to include nospam + checksum + public key.
Diffstat (limited to 'src/Crypto')
-rw-r--r-- | src/Crypto/Tox.hs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/Crypto/Tox.hs b/src/Crypto/Tox.hs index 9a365daa..a43e3379 100644 --- a/src/Crypto/Tox.hs +++ b/src/Crypto/Tox.hs | |||
@@ -55,6 +55,7 @@ module Crypto.Tox | |||
55 | , encryptSymmetric | 55 | , encryptSymmetric |
56 | , encodeSecret | 56 | , encodeSecret |
57 | , decodeSecret | 57 | , decodeSecret |
58 | , xorsum | ||
58 | ) where | 59 | ) where |
59 | 60 | ||
60 | import Control.Arrow | 61 | import Control.Arrow |
@@ -588,3 +589,13 @@ decodeSecret k64 = do | |||
588 | CryptoPassed x -> Just x | 589 | CryptoPassed x -> Just x |
589 | _ -> Nothing | 590 | _ -> Nothing |
590 | 591 | ||
592 | xorsum :: ByteArrayAccess ba => ba -> Word16 | ||
593 | xorsum bs = unsafeDupablePerformIO $ BA.withByteArray bs $ \ptr16 -> do | ||
594 | let (wcnt,r) = BA.length bs `divMod` 2 | ||
595 | loop cnt !ac = do | ||
596 | ac' <- xor ac <$> peekElemOff ptr16 cnt | ||
597 | case cnt of 0 -> return ac' | ||
598 | _ -> loop (cnt - 1) ac' | ||
599 | loop (wcnt - 1) $ case r of | ||
600 | 0 -> 0 | ||
601 | _ -> 256 * fromIntegral (BA.index bs (BA.length bs - 1)) | ||