simplexmq-6.5.0.16: SimpleXMQ message broker
Safe HaskellNone
LanguageHaskell2010

Simplex.Messaging.Crypto.Ratchet

Synopsis

Documentation

data Ratchet (a :: Algorithm) Source #

Constructors

Ratchet 

Fields

Instances

Instances details
AlgorithmI a => FromJSON (Ratchet a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

parseJSON :: Value -> Parser (Ratchet a)

parseJSONList :: Value -> Parser [Ratchet a]

omittedField :: Maybe (Ratchet a)

AlgorithmI a => ToJSON (Ratchet a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toJSON :: Ratchet a -> Value

toEncoding :: Ratchet a -> Encoding

toJSONList :: [Ratchet a] -> Value

toEncodingList :: [Ratchet a] -> Encoding

omitField :: Ratchet a -> Bool

Show (Ratchet a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> Ratchet a -> ShowS

show :: Ratchet a -> String

showList :: [Ratchet a] -> ShowS

(AlgorithmI a, Typeable a) => FromField (Ratchet a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

fromField :: FieldParser (Ratchet a) #

AlgorithmI a => ToField (Ratchet a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toField :: Ratchet a -> SQLData #

data MsgEncryptKey (a :: k) Source #

Constructors

MsgEncryptKey 

Fields

Instances

Instances details
Show (MsgEncryptKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> MsgEncryptKey a -> ShowS

show :: MsgEncryptKey a -> String

showList :: [MsgEncryptKey a] -> ShowS

Encoding (MsgEncryptKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

smpEncode :: MsgEncryptKey a -> ByteString Source #

smpDecode :: ByteString -> Either String (MsgEncryptKey a) Source #

smpP :: Parser (MsgEncryptKey a) Source #

(AlgorithmI a, Typeable a) => FromField (MsgEncryptKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

fromField :: FieldParser (MsgEncryptKey a) #

AlgorithmI a => ToField (MsgEncryptKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toField :: MsgEncryptKey a -> SQLData #

data SkippedMsgDiff Source #

Constructors

SMDNoChange 
SMDRemove HeaderKey Word32 
SMDAdd SkippedMsgKeys 

type SkippedMsgKeys = Map HeaderKey SkippedHdrMsgKeys Source #

data InitialKeys Source #

Constructors

IKUsePQ 
IKLinkPQ PQSupport 

Instances

Instances details
Show InitialKeys Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> InitialKeys -> ShowS

show :: InitialKeys -> String

showList :: [InitialKeys] -> ShowS

Eq InitialKeys Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

(==) :: InitialKeys -> InitialKeys -> Bool

(/=) :: InitialKeys -> InitialKeys -> Bool

StrEncoding InitialKeys Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

strEncode :: InitialKeys -> ByteString Source #

strDecode :: ByteString -> Either String InitialKeys Source #

strP :: Parser InitialKeys Source #

newtype PQEncryption Source #

Constructors

PQEncryption 

Fields

Instances

Instances details
FromJSON PQEncryption Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

parseJSON :: Value -> Parser PQEncryption

parseJSONList :: Value -> Parser [PQEncryption]

omittedField :: Maybe PQEncryption

ToJSON PQEncryption Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toJSON :: PQEncryption -> Value

toEncoding :: PQEncryption -> Encoding

toJSONList :: [PQEncryption] -> Value

toEncodingList :: [PQEncryption] -> Encoding

omitField :: PQEncryption -> Bool

Show PQEncryption Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> PQEncryption -> ShowS

show :: PQEncryption -> String

showList :: [PQEncryption] -> ShowS

Eq PQEncryption Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

(==) :: PQEncryption -> PQEncryption -> Bool

(/=) :: PQEncryption -> PQEncryption -> Bool

StrEncoding PQEncryption Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

strEncode :: PQEncryption -> ByteString Source #

strDecode :: ByteString -> Either String PQEncryption Source #

strP :: Parser PQEncryption Source #

FromField PQEncryption Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

fromField :: FieldParser PQEncryption #

ToField PQEncryption Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toField :: PQEncryption -> SQLData #

newtype PQSupport Source #

Constructors

PQSupport 

Fields

Instances

Instances details
FromJSON PQSupport Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

parseJSON :: Value -> Parser PQSupport

parseJSONList :: Value -> Parser [PQSupport]

omittedField :: Maybe PQSupport

ToJSON PQSupport Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toJSON :: PQSupport -> Value

toEncoding :: PQSupport -> Encoding

toJSONList :: [PQSupport] -> Value

toEncodingList :: [PQSupport] -> Encoding

omitField :: PQSupport -> Bool

Show PQSupport Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> PQSupport -> ShowS

show :: PQSupport -> String

showList :: [PQSupport] -> ShowS

Eq PQSupport Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

(==) :: PQSupport -> PQSupport -> Bool

(/=) :: PQSupport -> PQSupport -> Bool

StrEncoding PQSupport Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

strEncode :: PQSupport -> ByteString Source #

strDecode :: ByteString -> Either String PQSupport Source #

strP :: Parser PQSupport Source #

FromField PQSupport Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

fromField :: FieldParser PQSupport #

ToField PQSupport Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toField :: PQSupport -> SQLData #

data AUseKEM Source #

Constructors

RatchetKEMStateI s => AUseKEM (SRatchetKEMState s) (UseKEM s) 

data RatchetKEMState Source #

Constructors

RKSProposed 
RKSAccepted 

Instances

Instances details
TestEquality SRatchetKEMState Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

testEquality :: forall (a :: RatchetKEMState) (b :: RatchetKEMState). SRatchetKEMState a -> SRatchetKEMState b -> Maybe (a :~: b)

data SRatchetKEMState (s :: RatchetKEMState) where Source #

Instances

Instances details
TestEquality SRatchetKEMState Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

testEquality :: forall (a :: RatchetKEMState) (b :: RatchetKEMState). SRatchetKEMState a -> SRatchetKEMState b -> Maybe (a :~: b)

Show (SRatchetKEMState s) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> SRatchetKEMState s -> ShowS

show :: SRatchetKEMState s -> String

showList :: [SRatchetKEMState s] -> ShowS

type RcvPrivRKEMParams = PrivRKEMParams 'RKSProposed Source #

data APrivRKEMParams Source #

Constructors

RatchetKEMStateI s => APRKP (SRatchetKEMState s) (PrivRKEMParams s) 

Instances

Instances details
Encoding APrivRKEMParams Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

smpEncode :: APrivRKEMParams -> ByteString Source #

smpDecode :: ByteString -> Either String APrivRKEMParams Source #

smpP :: Parser APrivRKEMParams Source #

data AE2ERatchetParams (a :: Algorithm) Source #

Constructors

RatchetKEMStateI s => AE2ERatchetParams (SRatchetKEMState s) (E2ERatchetParams s a) 

Instances

Instances details
Show (AE2ERatchetParams a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> AE2ERatchetParams a -> ShowS

show :: AE2ERatchetParams a -> String

showList :: [AE2ERatchetParams a] -> ShowS

AlgorithmI a => Encoding (AE2ERatchetParams a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

smpEncode :: AE2ERatchetParams a -> ByteString Source #

smpDecode :: ByteString -> Either String (AE2ERatchetParams a) Source #

smpP :: Parser (AE2ERatchetParams a) Source #

data E2ERatchetParamsUri (s :: RatchetKEMState) (a :: Algorithm) Source #

Instances

Instances details
Show (E2ERatchetParamsUri s a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> E2ERatchetParamsUri s a -> ShowS

show :: E2ERatchetParamsUri s a -> String

showList :: [E2ERatchetParamsUri s a] -> ShowS

Eq (E2ERatchetParamsUri s a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

(RatchetKEMStateI s, AlgorithmI a) => Encoding (E2ERatchetParamsUri s a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

smpEncode :: E2ERatchetParamsUri s a -> ByteString Source #

smpDecode :: ByteString -> Either String (E2ERatchetParamsUri s a) Source #

smpP :: Parser (E2ERatchetParamsUri s a) Source #

(RatchetKEMStateI s, AlgorithmI a) => StrEncoding (E2ERatchetParamsUri s a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

strEncode :: E2ERatchetParamsUri s a -> ByteString Source #

strDecode :: ByteString -> Either String (E2ERatchetParamsUri s a) Source #

strP :: Parser (E2ERatchetParamsUri s a) Source #

data E2ERatchetParams (s :: RatchetKEMState) (a :: Algorithm) Source #

Constructors

E2ERatchetParams VersionE2E (PublicKey a) (PublicKey a) (Maybe (RKEMParams s)) 

Instances

Instances details
Show (E2ERatchetParams s a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> E2ERatchetParams s a -> ShowS

show :: E2ERatchetParams s a -> String

showList :: [E2ERatchetParams s a] -> ShowS

(RatchetKEMStateI s, AlgorithmI a) => Encoding (E2ERatchetParams s a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

smpEncode :: E2ERatchetParams s a -> ByteString Source #

smpDecode :: ByteString -> Either String (E2ERatchetParams s a) Source #

smpP :: Parser (E2ERatchetParams s a) Source #

type VersionE2E = Version E2EVersion Source #

pattern VersionE2E :: Word16 -> VersionE2E Source #

data RatchetVersions Source #

Instances

Instances details
FromJSON RatchetVersions Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

parseJSON :: Value -> Parser RatchetVersions

parseJSONList :: Value -> Parser [RatchetVersions]

omittedField :: Maybe RatchetVersions

ToJSON RatchetVersions Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Show RatchetVersions Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> RatchetVersions -> ShowS

show :: RatchetVersions -> String

showList :: [RatchetVersions] -> ShowS

Eq RatchetVersions Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

generateRcvE2EParams :: forall (a :: Algorithm). (AlgorithmI a, DhAlgorithm a) => TVar ChaChaDRG -> VersionE2E -> PQSupport -> IO (PrivateKey a, PrivateKey a, Maybe (PrivRKEMParams 'RKSProposed), E2ERatchetParams 'RKSProposed a) Source #

generateSndE2EParams :: forall (a :: Algorithm). (AlgorithmI a, DhAlgorithm a) => TVar ChaChaDRG -> VersionE2E -> Maybe AUseKEM -> IO (PrivateKey a, PrivateKey a, Maybe APrivRKEMParams, AE2ERatchetParams a) Source #

pqX3dhRcv :: forall (s :: RatchetKEMState) (a :: Algorithm). (RatchetKEMStateI s, DhAlgorithm a) => PrivateKey a -> PrivateKey a -> Maybe (PrivRKEMParams 'RKSProposed) -> E2ERatchetParams s a -> ExceptT CryptoError IO (RatchetInitParams, Maybe KEMKeyPair) Source #

initSndRatchet :: forall (a :: Algorithm). (AlgorithmI a, DhAlgorithm a) => RatchetVersions -> PublicKey a -> PrivateKey a -> (RatchetInitParams, Maybe KEMKeyPair) -> Ratchet a Source #

Sending ratchet initialization

Please note that sPKey is not stored, and its public part together with random salt is sent to the recipient. RatchetInitAlicePQ2HE(state, SK, bob_dh_public_key, shared_hka, shared_nhkb, bob_pq_kem_encapsulation_key) // below added for post-quantum KEM state.PQRs = GENERATE_PQKEM() state.PQRr = bob_pq_kem_encapsulation_key state.PQRss = random // shared secret for KEM state.PQRct = PQKEM-ENC(state.PQRr, state.PQRss) // encapsulated additional shared secret // above added for KEM

initRcvRatchet :: forall (a :: Algorithm). (AlgorithmI a, DhAlgorithm a) => RatchetVersions -> PrivateKey a -> (RatchetInitParams, Maybe KEMKeyPair) -> PQSupport -> Ratchet a Source #

Receiving ratchet initialization, equivalent to RatchetInitBobPQ2HE in double ratchet spec

def RatchetInitBobPQ2HE(state, SK, bob_dh_key_pair, shared_hka, shared_nhkb, bob_pq_kem_key_pair)

Please note that the public part of rcDHRs was sent to the sender as part of the connection request and random salt was received from the sender.

rcCheckCanPad :: Int -> ByteString -> ExceptT CryptoError IO () Source #

rcEncryptHeader :: forall (a :: Algorithm). AlgorithmI a => Ratchet a -> Maybe PQEncryption -> VersionE2E -> ExceptT CryptoError IO (MsgEncryptKey a, Ratchet a) Source #

rcEncryptMsg :: forall (a :: Algorithm). AlgorithmI a => MsgEncryptKey a -> Int -> ByteString -> ExceptT CryptoError IO ByteString Source #

rcDecrypt :: forall (a :: Algorithm). (AlgorithmI a, DhAlgorithm a) => TVar ChaChaDRG -> Ratchet a -> SkippedMsgKeys -> ByteString -> ExceptT CryptoError IO (DecryptResult a) Source #

data MsgHeader (a :: Algorithm) Source #

Constructors

MsgHeader 

Fields

Instances

Instances details
Show (MsgHeader a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> MsgHeader a -> ShowS

show :: MsgHeader a -> String

showList :: [MsgHeader a] -> ShowS

data RatchetInitParams Source #

Constructors

RatchetInitParams 

Fields

Instances

Instances details
Show RatchetInitParams Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> RatchetInitParams -> ShowS

show :: RatchetInitParams -> String

showList :: [RatchetInitParams] -> ShowS

data RKEMParams (s :: RatchetKEMState) where Source #

Instances

Instances details
Show (RKEMParams s) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> RKEMParams s -> ShowS

show :: RKEMParams s -> String

showList :: [RKEMParams s] -> ShowS

Eq (RKEMParams s) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

(==) :: RKEMParams s -> RKEMParams s -> Bool

(/=) :: RKEMParams s -> RKEMParams s -> Bool

RatchetKEMStateI s => Encoding (RKEMParams s) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

smpEncode :: RKEMParams s -> ByteString Source #

smpDecode :: ByteString -> Either String (RKEMParams s) Source #

smpP :: Parser (RKEMParams s) Source #

data ARKEMParams Source #

Constructors

RatchetKEMStateI s => ARKP (SRatchetKEMState s) (RKEMParams s) 

Instances

Instances details
Show ARKEMParams Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> ARKEMParams -> ShowS

show :: ARKEMParams -> String

showList :: [ARKEMParams] -> ShowS

Encoding ARKEMParams Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

smpEncode :: ARKEMParams -> ByteString Source #

smpDecode :: ByteString -> Either String ARKEMParams Source #

smpP :: Parser ARKEMParams Source #

FromField ARKEMParams Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

fromField :: FieldParser ARKEMParams #

ToField ARKEMParams Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toField :: ARKEMParams -> SQLData #

data SndRatchet (a :: Algorithm) Source #

Constructors

SndRatchet 

Fields

Instances

Instances details
AlgorithmI a => FromJSON (SndRatchet a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

parseJSON :: Value -> Parser (SndRatchet a)

parseJSONList :: Value -> Parser [SndRatchet a]

omittedField :: Maybe (SndRatchet a)

AlgorithmI a => ToJSON (SndRatchet a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toJSON :: SndRatchet a -> Value

toEncoding :: SndRatchet a -> Encoding

toJSONList :: [SndRatchet a] -> Value

toEncodingList :: [SndRatchet a] -> Encoding

omitField :: SndRatchet a -> Bool

Show (SndRatchet a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> SndRatchet a -> ShowS

show :: SndRatchet a -> String

showList :: [SndRatchet a] -> ShowS

data RcvRatchet Source #

Constructors

RcvRatchet 

Fields

Instances

Instances details
FromJSON RcvRatchet Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

parseJSON :: Value -> Parser RcvRatchet

parseJSONList :: Value -> Parser [RcvRatchet]

omittedField :: Maybe RcvRatchet

ToJSON RcvRatchet Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toJSON :: RcvRatchet -> Value

toEncoding :: RcvRatchet -> Encoding

toJSONList :: [RcvRatchet] -> Value

toEncodingList :: [RcvRatchet] -> Encoding

omitField :: RcvRatchet -> Bool

Show RcvRatchet Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> RcvRatchet -> ShowS

show :: RcvRatchet -> String

showList :: [RcvRatchet] -> ShowS

data RatchetKEM Source #

Constructors

RatchetKEM 

Instances

Instances details
FromJSON RatchetKEM Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

parseJSON :: Value -> Parser RatchetKEM

parseJSONList :: Value -> Parser [RatchetKEM]

omittedField :: Maybe RatchetKEM

ToJSON RatchetKEM Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toJSON :: RatchetKEM -> Value

toEncoding :: RatchetKEM -> Encoding

toJSONList :: [RatchetKEM] -> Value

toEncodingList :: [RatchetKEM] -> Encoding

omitField :: RatchetKEM -> Bool

Show RatchetKEM Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> RatchetKEM -> ShowS

show :: RatchetKEM -> String

showList :: [RatchetKEM] -> ShowS

data RatchetKEMAccepted Source #

Instances

Instances details
FromJSON RatchetKEMAccepted Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

parseJSON :: Value -> Parser RatchetKEMAccepted

parseJSONList :: Value -> Parser [RatchetKEMAccepted]

omittedField :: Maybe RatchetKEMAccepted

ToJSON RatchetKEMAccepted Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Show RatchetKEMAccepted Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> RatchetKEMAccepted -> ShowS

show :: RatchetKEMAccepted -> String

showList :: [RatchetKEMAccepted] -> ShowS

newtype RatchetKey Source #

Input key material for double ratchet HKDF functions

Constructors

RatchetKey ByteString 

Instances

Instances details
FromJSON RatchetKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

parseJSON :: Value -> Parser RatchetKey

parseJSONList :: Value -> Parser [RatchetKey]

omittedField :: Maybe RatchetKey

ToJSON RatchetKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

toJSON :: RatchetKey -> Value

toEncoding :: RatchetKey -> Encoding

toJSONList :: [RatchetKey] -> Value

toEncodingList :: [RatchetKey] -> Encoding

omitField :: RatchetKey -> Bool

Show RatchetKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto.Ratchet

Methods

showsPrec :: Int -> RatchetKey -> ShowS

show :: RatchetKey -> String

showList :: [RatchetKey] -> ShowS

applySMDiff :: SkippedMsgKeys -> SkippedMsgDiff -> SkippedMsgKeys Source #

this function is only used in tests to apply changes in skipped messages, in the agent the diff is persisted, and the whole state is loaded for the next message.

encodeMsgHeader :: forall (a :: Algorithm). AlgorithmI a => VersionE2E -> MsgHeader a -> ByteString Source #

msgHeaderP :: forall (a :: Algorithm). AlgorithmI a => VersionE2E -> Parser (MsgHeader a) Source #