Skip to content

Commit

Permalink
Merge branch 'pattern-synonyms'
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Dec 4, 2023
2 parents 8e9c495 + a5b0643 commit 750d895
Show file tree
Hide file tree
Showing 23 changed files with 1,014 additions and 992 deletions.
4 changes: 2 additions & 2 deletions core/Network/TLS/Context/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ data Information = Information
, infoExtendedMasterSec :: Bool
, infoClientRandom :: Maybe ClientRandom
, infoServerRandom :: Maybe ServerRandom
, infoNegotiatedGroup :: Maybe Group
, infoSupportedGroup :: Maybe Group
, infoTLS13HandshakeMode :: Maybe HandshakeMode13
, infoIsEarlyDataAccepted :: Bool
}
Expand Down Expand Up @@ -204,7 +204,7 @@ contextGetInformation ctx = do
, Just (hstClientRandom st)
, hstServerRandom st
, if ver == Just TLS13 then Just (hstTLS13HandshakeMode st) else Nothing
, hstNegotiatedGroup st
, hstSupportedGroup st
)
Nothing -> (Nothing, False, Nothing, Nothing, Nothing, Nothing)
(cipher, comp) <-
Expand Down
2 changes: 1 addition & 1 deletion core/Network/TLS/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ recvData13 ctx = do
(_, usedCipher, _, _) <- getTxState ctx
let choice = makeCipherChoice TLS13 usedCipher
psk = derivePSK choice resumptionMasterSecret nonce
maxSize = case extensionLookup extensionID_EarlyData exts
maxSize = case extensionLookup EID_EarlyData exts
>>= extensionDecode MsgTNewSessionTicket of
Just (EarlyDataIndication (Just ms)) -> fromIntegral $ safeNonNegative32 ms
_ -> 0
Expand Down
2 changes: 2 additions & 0 deletions core/Network/TLS/Crypto/IES.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ groupGenerateKeyPair FFDHE3072 = gen ffdhe3072 exp3072 GroupPri_FFDHE3072 GroupP
groupGenerateKeyPair FFDHE4096 = gen ffdhe4096 exp4096 GroupPri_FFDHE4096 GroupPub_FFDHE4096
groupGenerateKeyPair FFDHE6144 = gen ffdhe6144 exp6144 GroupPri_FFDHE6144 GroupPub_FFDHE6144
groupGenerateKeyPair FFDHE8192 = gen ffdhe8192 exp8192 GroupPri_FFDHE8192 GroupPub_FFDHE8192
groupGenerateKeyPair _ = error "groupGenerateKeyPair"

dhGroupGenerateKeyPair
:: MonadRandom r => Group -> r (Params, PrivateNumber, PublicNumber)
Expand Down Expand Up @@ -244,6 +245,7 @@ decodeGroupPublic FFDHE3072 bs = Right . GroupPub_FFDHE3072 . PublicNumber $ os2
decodeGroupPublic FFDHE4096 bs = Right . GroupPub_FFDHE4096 . PublicNumber $ os2ip bs
decodeGroupPublic FFDHE6144 bs = Right . GroupPub_FFDHE6144 . PublicNumber $ os2ip bs
decodeGroupPublic FFDHE8192 bs = Right . GroupPub_FFDHE8192 . PublicNumber $ os2ip bs
decodeGroupPublic _ _ = error "decodeGroupPublic"

-- Check that group element in not in the 2-element subgroup { 1, p - 1 }.
-- See RFC 7919 section 3 and NIST SP 56A rev 2 section 5.6.2.3.1.
Expand Down
74 changes: 60 additions & 14 deletions core/Network/TLS/Crypto/Types.hs
Original file line number Diff line number Diff line change
@@ -1,23 +1,69 @@
{-# LANGUAGE PatternSynonyms #-}

-- |
-- Module : Network.TLS.Crypto.Types
-- License : BSD-style
-- Maintainer : Kazu Yamamoto <[email protected]>
-- Stability : experimental
-- Portability : unknown
module Network.TLS.Crypto.Types where

data Group
= P256
| P384
| P521
| X25519
| X448
| FFDHE2048
| FFDHE3072
| FFDHE4096
| FFDHE6144
| FFDHE8192
deriving (Eq, Show)
module Network.TLS.Crypto.Types (
Group (
Group,
P256,
P384,
P521,
X25519,
X448,
FFDHE2048,
FFDHE3072,
FFDHE4096,
FFDHE6144,
FFDHE8192
),
availableFFGroups,
availableECGroups,
KeyExchangeSignatureAlg (..),
) where

import Data.Word

newtype Group = Group Word16 deriving (Eq)

{- FOURMOLU_DISABLE -}
pattern P256 :: Group
pattern P256 = Group 23
pattern P384 :: Group
pattern P384 = Group 24
pattern P521 :: Group
pattern P521 = Group 25
pattern X25519 :: Group
pattern X25519 = Group 29
pattern X448 :: Group
pattern X448 = Group 30
pattern FFDHE2048 :: Group
pattern FFDHE2048 = Group 256
pattern FFDHE3072 :: Group
pattern FFDHE3072 = Group 257
pattern FFDHE4096 :: Group
pattern FFDHE4096 = Group 258
pattern FFDHE6144 :: Group
pattern FFDHE6144 = Group 259
pattern FFDHE8192 :: Group
pattern FFDHE8192 = Group 260

instance Show Group where
show P256 = "P256"
show P384 = "P384"
show P521 = "P521"
show X25519 = "X25519"
show X448 = "X448"
show FFDHE2048 = "FFDHE2048"
show FFDHE3072 = "FFDHE3072"
show FFDHE4096 = "FFDHE4096"
show FFDHE6144 = "FFDHE6144"
show FFDHE8192 = "FFDHE8192"
show (Group x) = "Group " ++ show x
{- FOURMOLU_ENABLE -}

availableFFGroups :: [Group]
availableFFGroups = [FFDHE2048, FFDHE3072, FFDHE4096, FFDHE6144, FFDHE8192]
Expand Down
Loading

0 comments on commit 750d895

Please sign in to comment.