summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Erebos/Network/Channel.hs18
-rw-r--r--src/Erebos/Network/Protocol.hs6
-rw-r--r--src/crypto/crypton/Crypto.hs6
-rw-r--r--src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs14
4 files changed, 22 insertions, 22 deletions
diff --git a/src/Erebos/Network/Channel.hs b/src/Erebos/Network/Channel.hs
index e8347ad..5b8d65e 100644
--- a/src/Erebos/Network/Channel.hs
+++ b/src/Erebos/Network/Channel.hs
@@ -17,7 +17,7 @@ import Control.Monad.Except
import Control.Monad.IO.Class
import Data.Binary
-import Data.ByteArray (Bytes, ScrubbedBytes, convert)
+import Data.ByteArray (ScrubbedBytes, convert)
import Data.ByteArray qualified as BA
import Data.ByteString (ByteString)
import Data.ByteString qualified as BS
@@ -32,8 +32,8 @@ import Erebos.Storable
data Channel = Channel
{ chPeers :: [Stored (Signed IdentityData)]
, chKey :: ScrubbedBytes
- , chNonceFixedOur :: Bytes
- , chNonceFixedPeer :: Bytes
+ , chNonceFixedOur :: ByteString
+ , chNonceFixedPeer :: ByteString
, chCounterNextOut :: MVar Word64
, chCounterNextIn :: MVar Word64
}
@@ -103,8 +103,8 @@ acceptChannelRequest self peer req = do
let chPeers = crPeers $ fromStored $ signedData $ fromStored req
chKey = BA.take keySize $ dhSecret xsecret $
fromStored $ crKey $ fromStored $ signedData $ fromStored req
- chNonceFixedOur = BA.pack [ 2, 0, 0, 0 ]
- chNonceFixedPeer = BA.pack [ 1, 0, 0, 0 ]
+ chNonceFixedOur = BS.pack [ 2, 0, 0, 0 ]
+ chNonceFixedPeer = BS.pack [ 1, 0, 0, 0 ]
chCounterNextOut <- newMVar 0
chCounterNextIn <- newMVar 0
@@ -129,8 +129,8 @@ acceptedChannel self peer acc = do
let chPeers = crPeers $ fromStored $ signedData $ fromStored req
chKey = BA.take keySize $ dhSecret xsecret $
fromStored $ caKey $ fromStored $ signedData $ fromStored acc
- chNonceFixedOur = BA.pack [ 1, 0, 0, 0 ]
- chNonceFixedPeer = BA.pack [ 2, 0, 0, 0 ]
+ chNonceFixedOur = BS.pack [ 1, 0, 0, 0 ]
+ chNonceFixedPeer = BS.pack [ 2, 0, 0, 0 ]
chCounterNextOut <- liftIO $ newMVar 0
chCounterNextIn <- liftIO $ newMVar 0
@@ -141,7 +141,7 @@ channelEncrypt :: (MonadIO m, MonadError e m, FromErebosError e) => Channel -> B
channelEncrypt Channel {..} plain = do
count <- liftIO $ modifyMVar chCounterNextOut $ \c -> return ( c + 1, c )
let cbytes = BL.toStrict $ encode count
- nonce = nonce8 chNonceFixedOur (convert cbytes)
+ nonce = nonce8 chNonceFixedOur cbytes
state <- case aeadInitialize chKey =<< nonce of
CryptoPassed state -> return state
CryptoFailed err -> throwOtherError $ "failed to init chacha-poly1305 cipher: " <> show err
@@ -159,7 +159,7 @@ channelDecrypt Channel {..} body = do
let countByte = body `BS.index` 0
body' = BS.drop 1 body
guessedCount = expectedCount - 128 + fromIntegral (countByte - fromIntegral expectedCount + 128 :: Word8)
- nonce = nonce8 chNonceFixedPeer $ convert $ BL.toStrict $ encode guessedCount
+ nonce = nonce8 chNonceFixedPeer $ BL.toStrict $ encode guessedCount
blen = BS.length body' - 16
ctext = BS.take blen body'
tag = BS.drop blen body'
diff --git a/src/Erebos/Network/Protocol.hs b/src/Erebos/Network/Protocol.hs
index 87272a2..92ec93a 100644
--- a/src/Erebos/Network/Protocol.hs
+++ b/src/Erebos/Network/Protocol.hs
@@ -49,7 +49,7 @@ import Data.Binary
import Data.Binary.Get
import Data.Binary.Put
import Data.Bits
-import Data.ByteArray (Bytes, ScrubbedBytes)
+import Data.ByteArray (ScrubbedBytes)
import Data.ByteArray qualified as BA
import Data.ByteString (ByteString)
import Data.ByteString qualified as B
@@ -145,7 +145,7 @@ instance Binary ParsedCookie where
putByteString cookieContent
get = do
- Just cookieNonce <- maybeCryptoError . C.nonce12 . BA.convert <$> getByteString 12
+ Just cookieNonce <- maybeCryptoError . C.nonce12 <$> getByteString 12
cookieValidity <- getWord32be
Just cookieMac <- maybeCryptoError . C.authTag <$> getByteString 16
cookieContent <- BL.toStrict <$> getRemainingLazyByteString
@@ -800,7 +800,7 @@ generateCookieHeaders Connection {..} ch = catMaybes <$> sequence [ echoHeader,
createCookie :: GlobalState addr -> addr -> IO Cookie
createCookie GlobalState {..} addr = do
- (nonceBytes :: Bytes) <- getRandomBytes 12
+ nonceBytes <- getRandomBytes 12
validUntil <- (fromNanoSecs (60 * 10^(9 :: Int)) +) <$> getTime Monotonic
let validSecondsFromStart = fromIntegral $ toNanoSecs (validUntil - gStartTime) `div` (10^(9 :: Int))
cookieValidity = validSecondsFromStart - gCookieStartTime
diff --git a/src/crypto/crypton/Crypto.hs b/src/crypto/crypton/Crypto.hs
index e84cec2..015bdb2 100644
--- a/src/crypto/crypton/Crypto.hs
+++ b/src/crypto/crypton/Crypto.hs
@@ -39,7 +39,7 @@ import Crypto.PubKey.Ed25519 qualified as Ed
import Crypto.Random
import Crypto.Random.Entropy
-import Data.ByteArray (Bytes, ByteArray)
+import Data.ByteArray (ByteArray)
import Data.ByteArray qualified as BA
import Data.ByteString (ByteString)
@@ -55,10 +55,10 @@ type AeadState = C.State
type Nonce = C.Nonce
-nonce8 :: Bytes -> Bytes -> CryptoFailable Nonce
+nonce8 :: ByteString -> ByteString -> CryptoFailable Nonce
nonce8 = C.nonce8
-nonce12 :: Bytes -> CryptoFailable Nonce
+nonce12 :: ByteString -> CryptoFailable Nonce
nonce12 = C.nonce12
aeadInitialize :: ScrubbedBytes -> Nonce -> CryptoFailable AeadState
diff --git a/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs b/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs
index c849c0b..7f0ef20 100644
--- a/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs
+++ b/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs
@@ -27,16 +27,16 @@ data AeadState = AeadState
newtype Nonce = Nonce ByteString
deriving (Eq, ByteArrayAccess)
-nonce8 :: Bytes -> Bytes -> CryptoFailable Nonce
+nonce8 :: ByteString -> ByteString -> CryptoFailable Nonce
nonce8 c iv
- | BA.length c /= 4 = CryptoFailed CryptoError
- | BA.length iv /= 8 = CryptoFailed CryptoError
- | otherwise = CryptoPassed $ Nonce $ B.concat $ [ BA.convert c, BA.convert iv ]
+ | B.length c /= 4 = CryptoFailed CryptoError
+ | B.length iv /= 8 = CryptoFailed CryptoError
+ | otherwise = CryptoPassed $ Nonce $ B.concat [ c, iv ]
-nonce12 :: Bytes -> CryptoFailable Nonce
+nonce12 :: ByteString -> CryptoFailable Nonce
nonce12 iv
- | BA.length iv /= 12 = CryptoFailed CryptoError
- | otherwise = CryptoPassed $ Nonce $ BA.convert iv
+ | B.length iv /= 12 = CryptoFailed CryptoError
+ | otherwise = CryptoPassed $ Nonce iv
aeadInitialize :: ScrubbedBytes -> Nonce -> CryptoFailable AeadState
aeadInitialize key nonce