cacophony 0.10.0 → 0.10.1
raw patch · 14 files changed
+137/−51 lines, 14 filesdep ~basedep ~base16-bytestringPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base, base16-bytestring
API changes (from Hackage documentation)
- Crypto.Noise.Exception: instance GHC.Exception.Exception Crypto.Noise.Exception.NoiseException
+ Crypto.Noise.Cipher: -- | Represents a nonce.
+ Crypto.Noise.DH: -- | Represents a secret key.
+ Crypto.Noise.Exception: instance GHC.Exception.Type.Exception Crypto.Noise.Exception.NoiseException
+ Crypto.Noise.Hash: -- | Represents a hash digest.
+ Crypto.Noise.Internal.Handshake.Pattern: instance GHC.Base.Semigroup Crypto.Noise.Internal.Handshake.Pattern.HasPSK
- Crypto.Noise: NoiseResultMessage :: ScrubbedBytes -> (NoiseState c d h) -> NoiseResult c d h
+ Crypto.Noise: NoiseResultMessage :: ScrubbedBytes -> NoiseState c d h -> NoiseResult c d h
- Crypto.Noise: NoiseResultNeedPSK :: (NoiseState c d h) -> NoiseResult c d h
+ Crypto.Noise: NoiseResultNeedPSK :: NoiseState c d h -> NoiseResult c d h
- Crypto.Noise: class Cipher c where cipherRekey k = cipherBytesToSym . cipherTextToBytes $ cipherEncrypt k cipherMaxNonce mempty (replicate 32 0)
+ Crypto.Noise: class Cipher c
- Crypto.Noise: data ScrubbedBytes :: *
+ Crypto.Noise: data ScrubbedBytes
- Crypto.Noise.Cipher: class Cipher c where data Ciphertext c :: * data SymmetricKey c :: * data Nonce c :: * cipherRekey k = cipherBytesToSym . cipherTextToBytes $ cipherEncrypt k cipherMaxNonce mempty (replicate 32 0) where {
+ Crypto.Noise.Cipher: class Cipher c where {
- Crypto.Noise.DH: class DH d where data PublicKey d :: * data SecretKey d :: * where {
+ Crypto.Noise.DH: class DH d where {
- Crypto.Noise.Hash: class Hash h where data ChainingKey h :: * data Digest h :: * where {
+ Crypto.Noise.Hash: class Hash h where {
- Crypto.Noise.Internal.CipherState: csk :: forall c_awAN. Lens' (CipherState c_awAN) (Maybe (SymmetricKey c_awAN))
+ Crypto.Noise.Internal.CipherState: csk :: forall c_akCx. Lens' (CipherState c_akCx) (Maybe (SymmetricKey c_akCx))
- Crypto.Noise.Internal.CipherState: csn :: forall c_awAN. Lens' (CipherState c_awAN) (Nonce c_awAN)
+ Crypto.Noise.Internal.CipherState: csn :: forall c_akCx. Lens' (CipherState c_akCx) (Nonce c_akCx)
- Crypto.Noise.Internal.Handshake.Pattern: Initiator :: (MessagePattern ()) -> next -> Message next
+ Crypto.Noise.Internal.Handshake.Pattern: Initiator :: MessagePattern () -> next -> Message next
- Crypto.Noise.Internal.Handshake.Pattern: PreInitiator :: (MessagePattern ()) -> next -> Message next
+ Crypto.Noise.Internal.Handshake.Pattern: PreInitiator :: MessagePattern () -> next -> Message next
- Crypto.Noise.Internal.Handshake.Pattern: PreResponder :: (MessagePattern ()) -> next -> Message next
+ Crypto.Noise.Internal.Handshake.Pattern: PreResponder :: MessagePattern () -> next -> Message next
- Crypto.Noise.Internal.Handshake.Pattern: Responder :: (MessagePattern ()) -> next -> Message next
+ Crypto.Noise.Internal.Handshake.Pattern: Responder :: MessagePattern () -> next -> Message next
- Crypto.Noise.Internal.Handshake.State: hoLocalEphemeral :: forall d_aD2Q. Lens' (HandshakeOpts d_aD2Q) (Maybe (KeyPair d_aD2Q))
+ Crypto.Noise.Internal.Handshake.State: hoLocalEphemeral :: forall d_auf6. Lens' (HandshakeOpts d_auf6) (Maybe (KeyPair d_auf6))
- Crypto.Noise.Internal.Handshake.State: hoLocalStatic :: forall d_aD2Q. Lens' (HandshakeOpts d_aD2Q) (Maybe (KeyPair d_aD2Q))
+ Crypto.Noise.Internal.Handshake.State: hoLocalStatic :: forall d_auf6. Lens' (HandshakeOpts d_auf6) (Maybe (KeyPair d_auf6))
- Crypto.Noise.Internal.Handshake.State: hoPrologue :: forall d_aD2Q. Lens' (HandshakeOpts d_aD2Q) Plaintext
+ Crypto.Noise.Internal.Handshake.State: hoPrologue :: forall d_auf6. Lens' (HandshakeOpts d_auf6) Plaintext
- Crypto.Noise.Internal.Handshake.State: hoRemoteEphemeral :: forall d_aD2Q. Lens' (HandshakeOpts d_aD2Q) (Maybe (PublicKey d_aD2Q))
+ Crypto.Noise.Internal.Handshake.State: hoRemoteEphemeral :: forall d_auf6. Lens' (HandshakeOpts d_auf6) (Maybe (PublicKey d_auf6))
- Crypto.Noise.Internal.Handshake.State: hoRemoteStatic :: forall d_aD2Q. Lens' (HandshakeOpts d_aD2Q) (Maybe (PublicKey d_aD2Q))
+ Crypto.Noise.Internal.Handshake.State: hoRemoteStatic :: forall d_auf6. Lens' (HandshakeOpts d_auf6) (Maybe (PublicKey d_auf6))
- Crypto.Noise.Internal.Handshake.State: hoRole :: forall d_aD2Q. Lens' (HandshakeOpts d_aD2Q) HandshakeRole
+ Crypto.Noise.Internal.Handshake.State: hoRole :: forall d_auf6. Lens' (HandshakeOpts d_auf6) HandshakeRole
- Crypto.Noise.Internal.Handshake.State: hsMsgBuffer :: forall c_aD5o d_aD5p h_aD5q. Lens' (HandshakeState c_aD5o d_aD5p h_aD5q) ScrubbedBytes
+ Crypto.Noise.Internal.Handshake.State: hsMsgBuffer :: forall c_aui2 d_aui3 h_aui4. Lens' (HandshakeState c_aui2 d_aui3 h_aui4) ScrubbedBytes
- Crypto.Noise.Internal.Handshake.State: hsOpts :: forall c_aD5o d_aD5p h_aD5q d_aD8m. Lens (HandshakeState c_aD5o d_aD5p h_aD5q) (HandshakeState c_aD5o d_aD8m h_aD5q) (HandshakeOpts d_aD5p) (HandshakeOpts d_aD8m)
+ Crypto.Noise.Internal.Handshake.State: hsOpts :: forall c_aui2 d_aui3 h_aui4 d_aumJ. Lens (HandshakeState c_aui2 d_aui3 h_aui4) (HandshakeState c_aui2 d_aumJ h_aui4) (HandshakeOpts d_aui3) (HandshakeOpts d_aumJ)
- Crypto.Noise.Internal.Handshake.State: hsPSKMode :: forall c_aD5o d_aD5p h_aD5q. Lens' (HandshakeState c_aD5o d_aD5p h_aD5q) Bool
+ Crypto.Noise.Internal.Handshake.State: hsPSKMode :: forall c_aui2 d_aui3 h_aui4. Lens' (HandshakeState c_aui2 d_aui3 h_aui4) Bool
- Crypto.Noise.Internal.Handshake.State: hsSymmetricState :: forall c_aD5o d_aD5p h_aD5q c_aD8n h_aD8o. Lens (HandshakeState c_aD5o d_aD5p h_aD5q) (HandshakeState c_aD8n d_aD5p h_aD8o) (SymmetricState c_aD5o h_aD5q) (SymmetricState c_aD8n h_aD8o)
+ Crypto.Noise.Internal.Handshake.State: hsSymmetricState :: forall c_aui2 d_aui3 h_aui4 c_aumK h_aumL. Lens (HandshakeState c_aui2 d_aui3 h_aui4) (HandshakeState c_aumK d_aui3 h_aumL) (SymmetricState c_aui2 h_aui4) (SymmetricState c_aumK h_aumL)
- Crypto.Noise.Internal.NoiseState: nsHandshakePattern :: forall c_aIH6 d_aIH7 h_aIH8. Lens' (NoiseState c_aIH6 d_aIH7 h_aIH8) HandshakePattern
+ Crypto.Noise.Internal.NoiseState: nsHandshakePattern :: forall c_azQL d_azQM h_azQN. Lens' (NoiseState c_azQL d_azQM h_azQN) HandshakePattern
- Crypto.Noise.Internal.NoiseState: nsHandshakeState :: forall c_aIH6 d_aIH7 h_aIH8. Lens' (NoiseState c_aIH6 d_aIH7 h_aIH8) (HandshakeState c_aIH6 d_aIH7 h_aIH8)
+ Crypto.Noise.Internal.NoiseState: nsHandshakeState :: forall c_azQL d_azQM h_azQN. Lens' (NoiseState c_azQL d_azQM h_azQN) (HandshakeState c_azQL d_azQM h_azQN)
- Crypto.Noise.Internal.NoiseState: nsHandshakeSuspension :: forall c_aIH6 d_aIH7 h_aIH8. Lens' (NoiseState c_aIH6 d_aIH7 h_aIH8) (Maybe (ScrubbedBytes -> Handshake c_aIH6 d_aIH7 h_aIH8 ()))
+ Crypto.Noise.Internal.NoiseState: nsHandshakeSuspension :: forall c_azQL d_azQM h_azQN. Lens' (NoiseState c_azQL d_azQM h_azQN) (Maybe (ScrubbedBytes -> Handshake c_azQL d_azQM h_azQN ()))
- Crypto.Noise.Internal.NoiseState: nsReceivingCipherState :: forall c_aIH6 d_aIH7 h_aIH8. Lens' (NoiseState c_aIH6 d_aIH7 h_aIH8) (Maybe (CipherState c_aIH6))
+ Crypto.Noise.Internal.NoiseState: nsReceivingCipherState :: forall c_azQL d_azQM h_azQN. Lens' (NoiseState c_azQL d_azQM h_azQN) (Maybe (CipherState c_azQL))
- Crypto.Noise.Internal.NoiseState: nsSendingCipherState :: forall c_aIH6 d_aIH7 h_aIH8. Lens' (NoiseState c_aIH6 d_aIH7 h_aIH8) (Maybe (CipherState c_aIH6))
+ Crypto.Noise.Internal.NoiseState: nsSendingCipherState :: forall c_azQL d_azQM h_azQN. Lens' (NoiseState c_azQL d_azQM h_azQN) (Maybe (CipherState c_azQL))
- Crypto.Noise.Internal.SymmetricState: ssCipher :: forall c_axsB h_axsC c_axtm. Lens (SymmetricState c_axsB h_axsC) (SymmetricState c_axtm h_axsC) (CipherState c_axsB) (CipherState c_axtm)
+ Crypto.Noise.Internal.SymmetricState: ssCipher :: forall c_asxk h_asxl c_asy5. Lens (SymmetricState c_asxk h_asxl) (SymmetricState c_asy5 h_asxl) (CipherState c_asxk) (CipherState c_asy5)
- Crypto.Noise.Internal.SymmetricState: ssck :: forall c_axsB h_axsC. Lens' (SymmetricState c_axsB h_axsC) (ChainingKey h_axsC)
+ Crypto.Noise.Internal.SymmetricState: ssck :: forall c_asxk h_asxl. Lens' (SymmetricState c_asxk h_asxl) (ChainingKey h_asxl)
- Crypto.Noise.Internal.SymmetricState: ssh :: forall c_axsB h_axsC. Lens' (SymmetricState c_axsB h_axsC) (Either ScrubbedBytes (Digest h_axsC))
+ Crypto.Noise.Internal.SymmetricState: ssh :: forall c_asxk h_asxl. Lens' (SymmetricState c_asxk h_asxl) (Either ScrubbedBytes (Digest h_asxl))
Files
- .travis.yml +11/−5
- README.md +56/−0
- cacophony.cabal +16/−9
- changelog.md +12/−0
- package.yaml +5/−7
- src/Crypto/Noise.hs +2/−2
- src/Crypto/Noise/DH/Curve448.hs +1/−1
- src/Crypto/Noise/Internal/Handshake/Interpreter.hs +1/−1
- src/Crypto/Noise/Internal/Handshake/Pattern.hs +6/−2
- src/Crypto/Noise/Internal/Handshake/State.hs +1/−1
- src/Crypto/Noise/Internal/NoiseState.hs +5/−5
- stack.yaml +1/−1
- tests/vectors/Types.hs +19/−16
- tools/noise-repl/Socket.hs +1/−1
.travis.yml view
@@ -12,15 +12,21 @@ matrix: include:- - env: ARGS="--resolver lts-8"- compiler: ": #stack 8.0.2"+ - env: ARGS="--resolver lts-9.21"+ compiler: "stack-8.0.2" + - env: ARGS="--resolver lts-11.22"+ compiler: "stack-8.2.2"++ - env: ARGS=""+ compiler: "stack-8.4.3"+ - env: ARGS="--resolver nightly"- compiler: ": #stack nightly"+ compiler: "stack-nightly" allow_failures: - env: ARGS="--resolver nightly"- compiler: ": #stack nightly"+ compiler: "stack-nightly" before_install: - unset CC@@ -33,4 +39,4 @@ script: - stack $ARGS --no-terminal test --flag "cacophony:build-tools" --bench --no-run-benchmarks --haddock --no-haddock-deps- - stack sdist+ - stack $ARGS sdist
README.md view
@@ -107,6 +107,62 @@ * `rekeySending` and `rekeyReceiving` -- Rekeys the given NoiseState according to section 11.3 of the protocol. +## Supported Features++All combinations of the following handshake parameters are officially supported and covered by the unit tests:++* Patterns+ * NN+ * KN+ * NK+ * KK+ * NX+ * KX+ * XN+ * IN+ * XK+ * IK+ * XX+ * IX+ * N+ * K+ * X+ * NNpsk0+ * NNpsk2+ * NKpsk0+ * NKpsk2+ * NXpsk2+ * XNpsk3+ * XKpsk3+ * XXpsk3+ * KNpsk0+ * KNpsk2+ * KKpsk0+ * KKpsk2+ * KXpsk2+ * INpsk1+ * INpsk2+ * IKpsk1+ * IKpsk2+ * IXpsk2+ * Npsk0+ * Kpsk0+ * Xpsk1++* Ciphers+ * AESGCM+ * ChaChaPoly1305++* Curves+ * Curve25519+ * Curve448++* Hashes+ * BLAKE2b+ * BLAKE2s+ * SHA256+ * SHA512+ ## Vectors Test vectors can be generated and verified using the `vectors` program. It accepts no arguments. When run,
cacophony.cabal view
@@ -1,9 +1,11 @@--- This file has been generated from package.yaml by hpack version 0.17.0.+-- This file has been generated from package.yaml by hpack version 0.28.2. -- -- see: https://github.com/sol/hpack+--+-- hash: 272fee6928a83c4ebb4abfab6ac7c6cb68e59c5c6b0cd1d52cfbc96d04e43875 name: cacophony-version: 0.10.0+version: 0.10.1 synopsis: A library implementing the Noise protocol. description: This library implements the <https://noiseprotocol.org Noise> protocol. category: Cryptography@@ -14,7 +16,6 @@ license-file: LICENSE build-type: Simple cabal-version: >= 1.10- extra-source-files: .travis.yml changelog.md@@ -42,9 +43,9 @@ default-extensions: OverloadedStrings ghc-options: -Wall build-depends:- base >= 4.9 && < 4.10+ base >=4.9 && <5 , bytestring- , cryptonite+ , cryptonite >=0.22 , exceptions , free , lens@@ -86,10 +87,11 @@ tools/noise-repl default-extensions: OverloadedStrings ghc-options: -Wall -O2 -rtsopts -threaded -with-rtsopts=-N+ build-depends:+ base >=4.9 && <5 if flag(build-tools) build-depends: attoparsec- , base , base16-bytestring , base64-bytestring , bytestring@@ -105,16 +107,19 @@ Pipe Socket Types+ Paths_cacophony default-language: Haskell2010 test-suite hlint type: exitcode-stdio-1.0 main-is: hlint.hs+ other-modules:+ Paths_cacophony hs-source-dirs: tests/hlint ghc-options: -Wall -O2 -rtsopts -threaded -with-rtsopts=-N build-depends:- base >= 4.9 && < 4.10+ base >=4.9 && <5 , hlint default-language: Haskell2010 @@ -128,7 +133,7 @@ build-depends: aeson , attoparsec- , base >= 4.9 && < 4.10+ , base >=4.9 && <5 , base16-bytestring , bytestring , cacophony@@ -140,6 +145,7 @@ Types VectorFile Verify+ Paths_cacophony default-language: Haskell2010 benchmark bench@@ -151,7 +157,7 @@ ghc-options: -Wall -O2 -rtsopts -threaded -with-rtsopts=-N build-depends: async- , base >= 4.9 && < 4.10+ , base >=4.9 && <5 , base16-bytestring , bytestring , cacophony@@ -160,4 +166,5 @@ other-modules: Keys Types+ Paths_cacophony default-language: Haskell2010
changelog.md view
@@ -1,3 +1,15 @@+# 0.10.1++* Set default GHC version to 8.4++* Support GHC > 8.0.2++* Parse pattern names more efficiently in unit tests++* Use preferred Curve448 module from cryptonite++* Add list of supported handshake parameters to README+ # 0.10.0 * Completely refactored API
package.yaml view
@@ -1,6 +1,6 @@ name: cacophony synopsis: A library implementing the Noise protocol.-version: 0.10.0+version: 0.10.1 license: PublicDomain license-file: LICENSE maintainer: John Galt <jgalt@centromere.net>@@ -27,12 +27,14 @@ default: False manual: True +dependencies:+ - base >= 4.9 && < 5+ library: source-dirs: src dependencies:- - base >= 4.9 && < 4.10 - bytestring- - cryptonite+ - cryptonite >= 0.22 - exceptions - free - lens@@ -74,7 +76,6 @@ main: hlint.hs source-dirs: tests/hlint dependencies:- - base >= 4.9 && < 4.10 - hlint ghc-options:@@ -89,7 +90,6 @@ dependencies: - aeson - attoparsec- - base >= 4.9 && < 4.10 - base16-bytestring - bytestring - cacophony@@ -111,7 +111,6 @@ source-dirs: benchmarks dependencies: - async- - base >= 4.9 && < 4.10 - base16-bytestring - bytestring - cacophony@@ -136,7 +135,6 @@ then: dependencies: - attoparsec- - base - base16-bytestring - base64-bytestring - bytestring
src/Crypto/Noise.hs view
@@ -92,7 +92,7 @@ (ns ^. nsSendingCipherState) where ctToMsg = arr cipherTextToBytes- updateState = arr $ \cs -> ns & nsSendingCipherState .~ Just cs+ updateState = arr $ \cs -> ns & nsSendingCipherState ?~ cs encryptMsg cs = (ctToMsg *** updateState) <$> encryptWithAd mempty msg cs -- | Reads a handshake or transport message and returns the embedded payload. If@@ -115,7 +115,7 @@ (ns ^. nsReceivingCipherState) where ct' = cipherBytesToText ct- updateState = arr $ \cs -> ns & nsReceivingCipherState .~ Just cs+ updateState = arr $ \cs -> ns & nsReceivingCipherState ?~ cs decryptMsg cs = second updateState <$> decryptWithAd mempty ct' cs -- | Given an operation ('writeMessage' or 'readMessage'), a list of PSKs, and
src/Crypto/Noise/DH/Curve448.hs view
@@ -12,7 +12,7 @@ import Crypto.Error (throwCryptoError, maybeCryptoError) import Crypto.Random.Entropy (getEntropy)-import qualified Crypto.PubKey.Ed448 as C+import qualified Crypto.PubKey.Curve448 as C import Crypto.Noise.DH import Data.ByteArray (ScrubbedBytes, convert)
src/Crypto/Noise/Internal/Handshake/Interpreter.hs view
@@ -20,7 +20,7 @@ import Crypto.Noise.DH import Crypto.Noise.Exception import Crypto.Noise.Hash-import Crypto.Noise.Internal.Handshake.Pattern hiding (e, s, ee, es, se, ss)+import Crypto.Noise.Internal.Handshake.Pattern hiding (ss) import Crypto.Noise.Internal.Handshake.State import Crypto.Noise.Internal.CipherState import Crypto.Noise.Internal.SymmetricState
src/Crypto/Noise/Internal/Handshake/Pattern.hs view
@@ -10,6 +10,7 @@ import Control.Applicative.Free import Control.Lens import Data.ByteString (ByteString)+import Data.Semigroup (Semigroup(..)) data Token next = E next@@ -94,6 +95,9 @@ scanP (Psk _) = HasPSK True scanP _ = mempty +instance Semigroup HasPSK where+ (HasPSK a) <> (HasPSK b) = HasPSK $ a || b+ instance Monoid HasPSK where- mempty = HasPSK False- (HasPSK a) `mappend` (HasPSK b) = HasPSK $ a || b+ mempty = HasPSK False+ mappend = (<>)
src/Crypto/Noise/Internal/Handshake/State.hs view
@@ -23,7 +23,7 @@ import Crypto.Noise.Cipher import Crypto.Noise.DH import Crypto.Noise.Hash-import Crypto.Noise.Internal.Handshake.Pattern hiding (e, s, ee, es, se, ss)+import Crypto.Noise.Internal.Handshake.Pattern hiding (ss) import Crypto.Noise.Internal.SymmetricState -- | Represents the side of the conversation upon which a party resides.
src/Crypto/Noise/Internal/NoiseState.hs view
@@ -76,7 +76,7 @@ -- The handshake pattern has not finished running. Save the suspension -- and the mutated HandshakeState and return what was yielded. Left (Request req resp) -> do- let ns' = ns & nsHandshakeSuspension .~ Just (Handshake . resp)+ let ns' = ns & nsHandshakeSuspension ?~ (Handshake . resp) & nsHandshakeState .~ hs return (req, ns') -- The handshake pattern has finished running. Create the CipherStates.@@ -84,10 +84,10 @@ let (cs1, cs2) = split (hs ^. hsSymmetricState) ns' = if hs ^. hsOpts . hoRole == InitiatorRole- then ns & nsSendingCipherState .~ Just cs1- & nsReceivingCipherState .~ Just cs2- else ns & nsSendingCipherState .~ Just cs2- & nsReceivingCipherState .~ Just cs1+ then ns & nsSendingCipherState ?~ cs1+ & nsReceivingCipherState ?~ cs2+ else ns & nsSendingCipherState ?~ cs2+ & nsReceivingCipherState ?~ cs1 ns'' = ns' & nsHandshakeState .~ hs
stack.yaml view
@@ -1,4 +1,4 @@-resolver: lts-8.19+resolver: lts-12.16 packages: - '.' extra-deps: []
tests/vectors/Types.hs view
@@ -1,15 +1,15 @@ {-# LANGUAGE RecordWildCards, RankNTypes, GADTs, KindSignatures #-} module Types where -import Control.Monad (mzero) import Data.Aeson-import Data.Aeson.Types (typeMismatch)+import Data.Aeson.Types (typeMismatch) import Data.Attoparsec.ByteString.Char8-import Data.Maybe (fromMaybe)-import Data.Monoid ((<>))-import Data.Text (pack)-import Data.Text.Encoding (encodeUtf8)-import Data.Tuple (swap)+import Data.ByteString.Char8 (ByteString, unpack)+import Data.Maybe (fromMaybe)+import Data.Monoid ((<>))+import Data.Text (pack)+import Data.Text.Encoding (encodeUtf8)+import Data.Tuple (swap) import Crypto.Noise import Crypto.Noise.Cipher.ChaChaPoly1305@@ -91,7 +91,7 @@ data SomeHashType where WrapHashType :: forall h. Hash h => HashType h -> SomeHashType -patternMap :: [(String, PatternName)]+patternMap :: [(ByteString, PatternName)] patternMap = [ ("NN", PatternNN) , ("KN", PatternKN)@@ -131,19 +131,19 @@ , ("Xpsk1" , PatternXpsk1) ] -dhMap :: [(String, SomeDHType)]+dhMap :: [(ByteString, SomeDHType)] dhMap = [ ("25519", WrapDHType Curve25519) , ("448" , WrapDHType Curve448) ] -cipherMap :: [(String, SomeCipherType)]+cipherMap :: [(ByteString, SomeCipherType)] cipherMap = [ ("AESGCM" , WrapCipherType AESGCM) , ("ChaChaPoly", WrapCipherType ChaChaPoly1305) ] -hashMap :: [(String, SomeHashType)]+hashMap :: [(ByteString, SomeHashType)] hashMap = [ ("BLAKE2b", WrapHashType BLAKE2b) , ("BLAKE2s", WrapHashType BLAKE2s)@@ -155,15 +155,18 @@ parseHandshakeName = do _ <- string "Noise_" - let untilUnderscore = anyChar `manyTill'` (char '_')- untilEOI = anyChar `manyTill'` endOfInput+ let untilUnderscore = do+ val <- takeWhile1 (/= '_')+ skipWhile (== '_')+ return val + untilEOI = takeByteString+ pattern <- (flip lookup patternMap) <$> untilUnderscore dh <- (flip lookup dhMap) <$> untilUnderscore cipher <- (flip lookup cipherMap) <$> untilUnderscore hash <- (flip lookup hashMap) <$> untilEOI - let mHandshakeName = do p <- pattern d <- dh@@ -215,7 +218,7 @@ instance FromJSON HandshakeName where parseJSON (String s) =- either (const mzero) pure $ parseOnly parseHandshakeName (encodeUtf8 s)+ either fail pure $ parseOnly parseHandshakeName (encodeUtf8 s) parseJSON bad = typeMismatch "HandshakeName" bad instance ToJSON HandshakeName where@@ -232,7 +235,7 @@ <> show hsHash instance Show PatternName where- show = fromMaybe "unknown" . flip lookup (map swap patternMap)+ show = unpack . fromMaybe "unknown" . flip lookup (map swap patternMap) instance Show SomeCipherType where show (WrapCipherType ChaChaPoly1305) = "ChaChaPoly"
tools/noise-repl/Socket.hs view
@@ -2,7 +2,7 @@ import Data.ByteString.Char8 import Data.Monoid ((<>))-import Network.Socket hiding (send, sendTo, recv, recvFrom)+import Network.Socket hiding (recvFrom) import Network.Socket.ByteString import Prelude hiding (putStrLn) import System.Exit (exitFailure)