simplexmq-6.5.0.16: SimpleXMQ message broker
Copyright(c) simplex.chat
LicenseAGPL-3
Maintainerchat@simplex.chat
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Simplex.Messaging.Crypto

Description

This module provides cryptography implementation for SMP protocols based on cryptonite package.

Synopsis

Cryptographic keys

data Algorithm Source #

Cryptographic algorithms.

Constructors

Ed25519 
Ed448 
X25519 
X448 

Instances

Instances details
TestEquality SAlgorithm Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

testEquality :: forall (a :: k) (b :: k). SAlgorithm a -> SAlgorithm b -> Maybe (a :~: b)

(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 SAlgorithm :: Algorithm -> Type where Source #

Singleton types for Algorithm.

Instances

Instances details
TestEquality SAlgorithm Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

testEquality :: forall (a :: k) (b :: k). SAlgorithm a -> SAlgorithm b -> Maybe (a :~: b)

Show (SAlgorithm a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> SAlgorithm a -> ShowS

show :: SAlgorithm a -> String

showList :: [SAlgorithm a] -> ShowS

SignatureAlgorithm a => SignatureAlgorithmX509 (SAlgorithm a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureAlgorithmX509 :: SAlgorithm a -> SignatureALG Source #

data Alg Source #

Constructors

forall a.AlgorithmI a => Alg (SAlgorithm a) 

data AuthAlg Source #

Constructors

forall a.(AlgorithmI a, AuthAlgorithm a) => AuthAlg (SAlgorithm a) 

data DhAlg Source #

Constructors

forall a.(AlgorithmI a, DhAlgorithm a) => DhAlg (SAlgorithm a) 

type family DhAlgorithm (a :: Algorithm) :: Constraint where ... Source #

Equations

DhAlgorithm X25519 = () 
DhAlgorithm X448 = () 
DhAlgorithm a = (Int ~ Bool, TypeError ((Text "Algorithm " :<>: ShowType a) :<>: Text " cannot be used for DH exchange")) 

data PrivateKey (a :: Algorithm) where Source #

GADT for private keys.

Constructors

PrivateKeyEd25519 :: SecretKey -> PrivateKey Ed25519 
PrivateKeyEd448 :: SecretKey -> PrivateKey Ed448 
PrivateKeyX25519 :: SecretKey -> PrivateKey X25519 
PrivateKeyX448 :: SecretKey -> PrivateKey X448 

Instances

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

Defined in Simplex.Messaging.Crypto

Methods

parseJSON :: Value -> Parser (PrivateKey a)

parseJSONList :: Value -> Parser [PrivateKey a]

omittedField :: Maybe (PrivateKey a)

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

Defined in Simplex.Messaging.Crypto

Methods

toJSON :: PrivateKey a -> Value

toEncoding :: PrivateKey a -> Encoding

toJSONList :: [PrivateKey a] -> Value

toEncodingList :: [PrivateKey a] -> Encoding

omitField :: PrivateKey a -> Bool

AlgorithmI a => IsString (PrivateKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromString :: String -> PrivateKey a

Show (PrivateKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> PrivateKey a -> ShowS

show :: PrivateKey a -> String

showList :: [PrivateKey a] -> ShowS

Eq (PrivateKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: PrivateKey a -> PrivateKey a -> Bool

(/=) :: PrivateKey a -> PrivateKey a -> Bool

AlgorithmI a => CryptoPrivateKey (PrivateKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Associated Types

type PublicKeyType (PrivateKey a) Source #

Methods

toPrivKey :: (forall (a0 :: Algorithm). AlgorithmI a0 => PrivateKey a0 -> b) -> PrivateKey a -> b Source #

privKey :: APrivateKey -> Either String (PrivateKey a) Source #

toPublic :: PrivateKey a -> PublicKeyType (PrivateKey a) Source #

SignatureAlgorithm a => SignatureSize (PrivateKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureSize :: PrivateKey a -> Int Source #

StrEncoding (PrivateKey 'X25519) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: PrivateKey 'X25519 -> ByteString Source #

strDecode :: ByteString -> Either String (PrivateKey 'X25519) Source #

strP :: Parser (PrivateKey 'X25519) Source #

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

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser (PrivateKey a) #

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

Defined in Simplex.Messaging.Crypto

Methods

toField :: PrivateKey a -> SQLData #

type PublicKeyType (PrivateKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

data PublicKey (a :: Algorithm) where Source #

GADT for public keys.

Constructors

PublicKeyEd25519 :: PublicKey -> PublicKey Ed25519 
PublicKeyEd448 :: PublicKey -> PublicKey Ed448 
PublicKeyX25519 :: PublicKey -> PublicKey X25519 
PublicKeyX448 :: PublicKey -> PublicKey X448 

Instances

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

Defined in Simplex.Messaging.Crypto

Methods

parseJSON :: Value -> Parser (PublicKey a)

parseJSONList :: Value -> Parser [PublicKey a]

omittedField :: Maybe (PublicKey a)

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

Defined in Simplex.Messaging.Crypto

Methods

toJSON :: PublicKey a -> Value

toEncoding :: PublicKey a -> Encoding

toJSONList :: [PublicKey a] -> Value

toEncodingList :: [PublicKey a] -> Encoding

omitField :: PublicKey a -> Bool

AlgorithmI a => IsString (PublicKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromString :: String -> PublicKey a

Show (PublicKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> PublicKey a -> ShowS

show :: PublicKey a -> String

showList :: [PublicKey a] -> ShowS

Eq (PublicKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: PublicKey a -> PublicKey a -> Bool

(/=) :: PublicKey a -> PublicKey a -> Bool

AlgorithmI a => CryptoPublicKey (PublicKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toPubKey :: (forall (a0 :: Algorithm). AlgorithmI a0 => PublicKey a0 -> b) -> PublicKey a -> b Source #

pubKey :: APublicKey -> Either String (PublicKey a) Source #

SignatureAlgorithm a => SignatureSize (PublicKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureSize :: PublicKey a -> Int Source #

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

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: PublicKey a -> ByteString Source #

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

smpP :: Parser (PublicKey a) Source #

AlgorithmI a => StrEncoding (PublicKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: PublicKey a -> ByteString Source #

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

strP :: Parser (PublicKey a) Source #

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

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser (PublicKey a) #

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

Defined in Simplex.Messaging.Crypto

Methods

toField :: PublicKey a -> SQLData #

data APrivateKey Source #

Constructors

forall a.AlgorithmI a => APrivateKey (SAlgorithm a) (PrivateKey a) 

Instances

Instances details
Show APrivateKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> APrivateKey -> ShowS

show :: APrivateKey -> String

showList :: [APrivateKey] -> ShowS

CryptoPrivateKey APrivateKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Associated Types

type PublicKeyType APrivateKey Source #

type PublicKeyType APrivateKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

data APublicKey Source #

Constructors

forall a.AlgorithmI a => APublicKey (SAlgorithm a) (PublicKey a) 

Instances

Instances details
Show APublicKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> APublicKey -> ShowS

show :: APublicKey -> String

showList :: [APublicKey] -> ShowS

CryptoPublicKey APublicKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toPubKey :: (forall (a :: Algorithm). AlgorithmI a => PublicKey a -> b) -> APublicKey -> b Source #

pubKey :: APublicKey -> Either String APublicKey Source #

Encoding APublicKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: APublicKey -> ByteString Source #

smpDecode :: ByteString -> Either String APublicKey Source #

smpP :: Parser APublicKey Source #

data APrivateSignKey Source #

Constructors

forall a.(AlgorithmI a, SignatureAlgorithm a) => APrivateSignKey (SAlgorithm a) (PrivateKey a) 

Instances

Instances details
Show APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> APrivateSignKey -> ShowS

show :: APrivateSignKey -> String

showList :: [APrivateSignKey] -> ShowS

CryptoPrivateKey APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Associated Types

type PublicKeyType APrivateSignKey Source #

SignatureAlgorithmX509 APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

SignatureSize APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Encoding APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: APrivateSignKey -> ByteString Source #

smpDecode :: ByteString -> Either String APrivateSignKey Source #

smpP :: Parser APrivateSignKey Source #

StrEncoding APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: APrivateSignKey -> ByteString Source #

strDecode :: ByteString -> Either String APrivateSignKey Source #

strP :: Parser APrivateSignKey Source #

FromField APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser APrivateSignKey #

ToField APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: APrivateSignKey -> SQLData #

type PublicKeyType APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

data APublicVerifyKey Source #

Constructors

forall a.(AlgorithmI a, SignatureAlgorithm a) => APublicVerifyKey (SAlgorithm a) (PublicKey a) 

Instances

Instances details
Show APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> APublicVerifyKey -> ShowS

show :: APublicVerifyKey -> String

showList :: [APublicVerifyKey] -> ShowS

CryptoPublicKey APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toPubKey :: (forall (a :: Algorithm). AlgorithmI a => PublicKey a -> b) -> APublicVerifyKey -> b Source #

pubKey :: APublicKey -> Either String APublicVerifyKey Source #

SignatureAlgorithmX509 APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

SignatureSize APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Encoding APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: APublicVerifyKey -> ByteString Source #

smpDecode :: ByteString -> Either String APublicVerifyKey Source #

smpP :: Parser APublicVerifyKey Source #

StrEncoding APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: APublicVerifyKey -> ByteString Source #

strDecode :: ByteString -> Either String APublicVerifyKey Source #

strP :: Parser APublicVerifyKey Source #

FromField APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser APublicVerifyKey #

ToField APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: APublicVerifyKey -> SQLData #

data APrivateDhKey Source #

Constructors

forall a.(AlgorithmI a, DhAlgorithm a) => APrivateDhKey (SAlgorithm a) (PrivateKey a) 

Instances

Instances details
Show APrivateDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> APrivateDhKey -> ShowS

show :: APrivateDhKey -> String

showList :: [APrivateDhKey] -> ShowS

CryptoPrivateKey APrivateDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Associated Types

type PublicKeyType APrivateDhKey Source #

FromField APrivateDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser APrivateDhKey #

ToField APrivateDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: APrivateDhKey -> SQLData #

type PublicKeyType APrivateDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

data APublicDhKey Source #

Constructors

forall a.(AlgorithmI a, DhAlgorithm a) => APublicDhKey (SAlgorithm a) (PublicKey a) 

Instances

Instances details
Show APublicDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> APublicDhKey -> ShowS

show :: APublicDhKey -> String

showList :: [APublicDhKey] -> ShowS

CryptoPublicKey APublicDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toPubKey :: (forall (a :: Algorithm). AlgorithmI a => PublicKey a -> b) -> APublicDhKey -> b Source #

pubKey :: APublicKey -> Either String APublicDhKey Source #

Encoding APublicDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: APublicDhKey -> ByteString Source #

smpDecode :: ByteString -> Either String APublicDhKey Source #

smpP :: Parser APublicDhKey Source #

StrEncoding APublicDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: APublicDhKey -> ByteString Source #

strDecode :: ByteString -> Either String APublicDhKey Source #

strP :: Parser APublicDhKey Source #

FromField APublicDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser APublicDhKey #

ToField APublicDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: APublicDhKey -> SQLData #

data APrivateAuthKey Source #

Constructors

forall a.(AlgorithmI a, AuthAlgorithm a) => APrivateAuthKey (SAlgorithm a) (PrivateKey a) 

Instances

Instances details
Show APrivateAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> APrivateAuthKey -> ShowS

show :: APrivateAuthKey -> String

showList :: [APrivateAuthKey] -> ShowS

Eq APrivateAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

CryptoPrivateKey APrivateAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Associated Types

type PublicKeyType APrivateAuthKey Source #

Encoding APrivateAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: APrivateAuthKey -> ByteString Source #

smpDecode :: ByteString -> Either String APrivateAuthKey Source #

smpP :: Parser APrivateAuthKey Source #

StrEncoding APrivateAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: APrivateAuthKey -> ByteString Source #

strDecode :: ByteString -> Either String APrivateAuthKey Source #

strP :: Parser APrivateAuthKey Source #

FromField APrivateAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser APrivateAuthKey #

ToField APrivateAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: APrivateAuthKey -> SQLData #

type PublicKeyType APrivateAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

data APublicAuthKey Source #

Constructors

forall a.(AlgorithmI a, AuthAlgorithm a) => APublicAuthKey (SAlgorithm a) (PublicKey a) 

Instances

Instances details
Show APublicAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> APublicAuthKey -> ShowS

show :: APublicAuthKey -> String

showList :: [APublicAuthKey] -> ShowS

Eq APublicAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

CryptoPublicKey APublicAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toPubKey :: (forall (a :: Algorithm). AlgorithmI a => PublicKey a -> b) -> APublicAuthKey -> b Source #

pubKey :: APublicKey -> Either String APublicAuthKey Source #

Encoding APublicAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: APublicAuthKey -> ByteString Source #

smpDecode :: ByteString -> Either String APublicAuthKey Source #

smpP :: Parser APublicAuthKey Source #

StrEncoding APublicAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: APublicAuthKey -> ByteString Source #

strDecode :: ByteString -> Either String APublicAuthKey Source #

strP :: Parser APublicAuthKey Source #

FromField APublicAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser APublicAuthKey #

ToField APublicAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: APublicAuthKey -> SQLData #

class CryptoPublicKey k where Source #

Class for public key types

Methods

toPubKey :: (forall a. AlgorithmI a => PublicKey a -> b) -> k -> b Source #

pubKey :: APublicKey -> Either String k Source #

Instances

Instances details
CryptoPublicKey APublicAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toPubKey :: (forall (a :: Algorithm). AlgorithmI a => PublicKey a -> b) -> APublicAuthKey -> b Source #

pubKey :: APublicKey -> Either String APublicAuthKey Source #

CryptoPublicKey APublicDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toPubKey :: (forall (a :: Algorithm). AlgorithmI a => PublicKey a -> b) -> APublicDhKey -> b Source #

pubKey :: APublicKey -> Either String APublicDhKey Source #

CryptoPublicKey APublicKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toPubKey :: (forall (a :: Algorithm). AlgorithmI a => PublicKey a -> b) -> APublicKey -> b Source #

pubKey :: APublicKey -> Either String APublicKey Source #

CryptoPublicKey APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toPubKey :: (forall (a :: Algorithm). AlgorithmI a => PublicKey a -> b) -> APublicVerifyKey -> b Source #

pubKey :: APublicKey -> Either String APublicVerifyKey Source #

AlgorithmI a => CryptoPublicKey (PublicKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toPubKey :: (forall (a0 :: Algorithm). AlgorithmI a0 => PublicKey a0 -> b) -> PublicKey a -> b Source #

pubKey :: APublicKey -> Either String (PublicKey a) Source #

class CryptoPrivateKey pk where Source #

Associated Types

type PublicKeyType pk Source #

Methods

toPrivKey :: (forall a. AlgorithmI a => PrivateKey a -> b) -> pk -> b Source #

privKey :: APrivateKey -> Either String pk Source #

toPublic :: pk -> PublicKeyType pk Source #

Instances

Instances details
CryptoPrivateKey APrivateAuthKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Associated Types

type PublicKeyType APrivateAuthKey Source #

CryptoPrivateKey APrivateDhKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Associated Types

type PublicKeyType APrivateDhKey Source #

CryptoPrivateKey APrivateKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Associated Types

type PublicKeyType APrivateKey Source #

CryptoPrivateKey APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Associated Types

type PublicKeyType APrivateSignKey Source #

AlgorithmI a => CryptoPrivateKey (PrivateKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Associated Types

type PublicKeyType (PrivateKey a) Source #

Methods

toPrivKey :: (forall (a0 :: Algorithm). AlgorithmI a0 => PrivateKey a0 -> b) -> PrivateKey a -> b Source #

privKey :: APrivateKey -> Either String (PrivateKey a) Source #

toPublic :: PrivateKey a -> PublicKeyType (PrivateKey a) Source #

type KeyPair a = KeyPairType (PrivateKey a) Source #

data DhSecret (a :: Algorithm) where Source #

Constructors

DhSecretX25519 :: DhSecret -> DhSecret X25519 
DhSecretX448 :: DhSecret -> DhSecret X448 

Instances

Instances details
AlgorithmI a => IsString (DhSecret a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromString :: String -> DhSecret a

Show (DhSecret a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> DhSecret a -> ShowS

show :: DhSecret a -> String

showList :: [DhSecret a] -> ShowS

Eq (DhSecret a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: DhSecret a -> DhSecret a -> Bool

(/=) :: DhSecret a -> DhSecret a -> Bool

AlgorithmI a => StrEncoding (DhSecret a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: DhSecret a -> ByteString Source #

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

strP :: Parser (DhSecret a) Source #

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

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser (DhSecret a) #

ToField (DhSecret a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: DhSecret a -> SQLData #

data ADhSecret Source #

Constructors

forall a.(AlgorithmI a, DhAlgorithm a) => ADhSecret (SAlgorithm a) (DhSecret a) 

Instances

Instances details
StrEncoding ADhSecret Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: ADhSecret -> ByteString Source #

strDecode :: ByteString -> Either String ADhSecret Source #

strP :: Parser ADhSecret Source #

newtype KeyHash Source #

Certificate fingerpint newtype.

Previously was used for server's public key hash in ad-hoc transport scheme, kept as is for compatibility.

Constructors

KeyHash 

Fields

Instances

Instances details
FromJSON KeyHash Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

parseJSON :: Value -> Parser KeyHash

parseJSONList :: Value -> Parser [KeyHash]

omittedField :: Maybe KeyHash

ToJSON KeyHash Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toJSON :: KeyHash -> Value

toEncoding :: KeyHash -> Encoding

toJSONList :: [KeyHash] -> Value

toEncodingList :: [KeyHash] -> Encoding

omitField :: KeyHash -> Bool

IsString KeyHash Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromString :: String -> KeyHash

Show KeyHash Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> KeyHash -> ShowS

show :: KeyHash -> String

showList :: [KeyHash] -> ShowS

Eq KeyHash Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: KeyHash -> KeyHash -> Bool

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

Ord KeyHash Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

compare :: KeyHash -> KeyHash -> Ordering

(<) :: KeyHash -> KeyHash -> Bool

(<=) :: KeyHash -> KeyHash -> Bool

(>) :: KeyHash -> KeyHash -> Bool

(>=) :: KeyHash -> KeyHash -> Bool

max :: KeyHash -> KeyHash -> KeyHash

min :: KeyHash -> KeyHash -> KeyHash

Encoding KeyHash Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: KeyHash -> ByteString Source #

smpDecode :: ByteString -> Either String KeyHash Source #

smpP :: Parser KeyHash Source #

StrEncoding KeyHash Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: KeyHash -> ByteString Source #

strDecode :: ByteString -> Either String KeyHash Source #

strP :: Parser KeyHash Source #

FromField KeyHash Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser KeyHash #

ToField KeyHash Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: KeyHash -> SQLData #

newRandom :: IO (TVar ChaChaDRG) Source #

newRandomDRG :: TVar ChaChaDRG -> STM (TVar ChaChaDRG) Source #

generateAKeyPair :: AlgorithmI a => SAlgorithm a -> TVar ChaChaDRG -> STM AKeyPair Source #

generateKeyPair :: forall a. AlgorithmI a => TVar ChaChaDRG -> STM (KeyPair a) Source #

generateDhKeyPair :: (AlgorithmI a, DhAlgorithm a) => SAlgorithm a -> TVar ChaChaDRG -> STM ADhKeyPair Source #

x509ToPublic :: (PubKey, [ASN1]) -> Either String APublicKey Source #

x509ToPublic' :: CryptoPublicKey k => PubKey -> Either String k Source #

x509ToPrivate :: (PrivKey, [ASN1]) -> Either String APrivateKey Source #

x509ToPrivate' :: CryptoPrivateKey k => PrivKey -> Either String k Source #

signatureKeyPair :: APrivateSignKey -> ASignatureKeyPair Source #

Expand signature private key to a key pair.

encodeASNObj :: ASN1Object a => a -> ByteString Source #

key encoding/decoding

encodePubKey :: CryptoPublicKey k => k -> ByteString Source #

decodePubKey :: CryptoPublicKey k => ByteString -> Either String k Source #

encodePrivKey :: CryptoPrivateKey pk => pk -> ByteString Source #

decodePrivKey :: CryptoPrivateKey k => ByteString -> Either String k Source #

pubKeyBytes :: PublicKey a -> ByteString Source #

sign/verify

data Signature (a :: Algorithm) where Source #

Constructors

SignatureEd25519 :: Signature -> Signature Ed25519 
SignatureEd448 :: Signature -> Signature Ed448 

Instances

Instances details
CryptoSignature (Signature s) => FromJSON (Signature s) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

parseJSON :: Value -> Parser (Signature s)

parseJSONList :: Value -> Parser [Signature s]

omittedField :: Maybe (Signature s)

CryptoSignature (Signature s) => ToJSON (Signature s) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toJSON :: Signature s -> Value

toEncoding :: Signature s -> Encoding

toJSONList :: [Signature s] -> Value

toEncodingList :: [Signature s] -> Encoding

omitField :: Signature s -> Bool

Show (Signature a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> Signature a -> ShowS

show :: Signature a -> String

showList :: [Signature a] -> ShowS

Eq (Signature a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: Signature a -> Signature a -> Bool

(/=) :: Signature a -> Signature a -> Bool

AlgorithmI a => CryptoSignature (Signature a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureBytes :: Signature a -> ByteString Source #

decodeSignature :: ByteString -> Either String (Signature a) Source #

SignatureSize (Signature a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureSize :: Signature a -> Int Source #

CryptoSignature (Signature s) => Encoding (Signature s) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: Signature s -> ByteString Source #

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

smpP :: Parser (Signature s) Source #

CryptoSignature (Signature s) => StrEncoding (Signature s) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: Signature s -> ByteString Source #

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

strP :: Parser (Signature s) Source #

data ASignature Source #

Constructors

forall a.(AlgorithmI a, SignatureAlgorithm a) => ASignature (SAlgorithm a) (Signature a) 

Instances

Instances details
IsString ASignature Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromString :: String -> ASignature

Show ASignature Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> ASignature -> ShowS

show :: ASignature -> String

showList :: [ASignature] -> ShowS

CryptoSignature ASignature Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureBytes :: ASignature -> ByteString Source #

decodeSignature :: ByteString -> Either String ASignature Source #

SignatureSize ASignature Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureSize :: ASignature -> Int Source #

CryptoSignature (Maybe ASignature) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureBytes :: Maybe ASignature -> ByteString Source #

decodeSignature :: ByteString -> Either String (Maybe ASignature) Source #

class CryptoSignature s where Source #

Methods

signatureBytes :: s -> ByteString Source #

decodeSignature :: ByteString -> Either String s Source #

Instances

Instances details
CryptoSignature ASignature Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureBytes :: ASignature -> ByteString Source #

decodeSignature :: ByteString -> Either String ASignature Source #

AlgorithmI a => CryptoSignature (Signature a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureBytes :: Signature a -> ByteString Source #

decodeSignature :: ByteString -> Either String (Signature a) Source #

CryptoSignature (Maybe ASignature) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureBytes :: Maybe ASignature -> ByteString Source #

decodeSignature :: ByteString -> Either String (Maybe ASignature) Source #

class SignatureSize s where Source #

Methods

signatureSize :: s -> Int Source #

Instances

Instances details
SignatureSize APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

SignatureSize APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

SignatureSize ASignature Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureSize :: ASignature -> Int Source #

SignatureAlgorithm a => SignatureSize (PrivateKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureSize :: PrivateKey a -> Int Source #

SignatureAlgorithm a => SignatureSize (PublicKey a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureSize :: PublicKey a -> Int Source #

SignatureSize (Signature a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureSize :: Signature a -> Int Source #

type family SignatureAlgorithm (a :: Algorithm) :: Constraint where ... Source #

Equations

SignatureAlgorithm Ed25519 = () 
SignatureAlgorithm Ed448 = () 
SignatureAlgorithm a = (Int ~ Bool, TypeError ((Text "Algorithm " :<>: ShowType a) :<>: Text " cannot be used to sign/verify")) 

type family AuthAlgorithm (a :: Algorithm) :: Constraint where ... Source #

Equations

AuthAlgorithm Ed25519 = () 
AuthAlgorithm Ed448 = () 
AuthAlgorithm X25519 = () 
AuthAlgorithm a = (Int ~ Bool, TypeError ((Text "Algorithm " :<>: ShowType a) :<>: Text " cannot be used for authorization")) 

class AlgorithmI (a :: Algorithm) where Source #

Instances

Instances details
AlgorithmI 'Ed25519 Source # 
Instance details

Defined in Simplex.Messaging.Crypto

AlgorithmI 'Ed448 Source # 
Instance details

Defined in Simplex.Messaging.Crypto

AlgorithmI 'X25519 Source # 
Instance details

Defined in Simplex.Messaging.Crypto

AlgorithmI 'X448 Source # 
Instance details

Defined in Simplex.Messaging.Crypto

sign :: APrivateSignKey -> ByteString -> ASignature Source #

sign' :: SignatureAlgorithm a => PrivateKey a -> ByteString -> Signature a Source #

Message signing.

Used by SMP clients to sign SMP commands and by SMP agents to sign messages.

verify :: APublicVerifyKey -> ASignature -> ByteString -> Bool Source #

verify' :: SignatureAlgorithm a => PublicKey a -> Signature a -> ByteString -> Bool Source #

Signature verification.

Used by SMP servers to authorize SMP commands and by SMP agents to verify messages.

validSignatureSize :: Int -> Bool Source #

checkAlgorithm :: forall t a a'. (AlgorithmI a, AlgorithmI a') => t a' -> Either String (t a) Source #

crypto_box authenticator, as discussed in https://groups.google.com/g/sci.crypt/c/73yb5a9pz2Y/m/LNgRO7IYXOwJ

newtype CbAuthenticator Source #

Constructors

CbAuthenticator ByteString 

Instances

Instances details
Show CbAuthenticator Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> CbAuthenticator -> ShowS

show :: CbAuthenticator -> String

showList :: [CbAuthenticator] -> ShowS

Eq CbAuthenticator Source # 
Instance details

Defined in Simplex.Messaging.Crypto

DH derivation

dhBytes' :: DhSecret a -> ByteString Source #

AES256 AEAD-GCM scheme

newtype Key Source #

AES key newtype.

Constructors

Key 

Fields

Instances

Instances details
FromJSON Key Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

parseJSON :: Value -> Parser Key

parseJSONList :: Value -> Parser [Key]

omittedField :: Maybe Key

ToJSON Key Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toJSON :: Key -> Value

toEncoding :: Key -> Encoding

toJSONList :: [Key] -> Value

toEncodingList :: [Key] -> Encoding

omitField :: Key -> Bool

Show Key Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> Key -> ShowS

show :: Key -> String

showList :: [Key] -> ShowS

Eq Key Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: Key -> Key -> Bool

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

Ord Key Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

compare :: Key -> Key -> Ordering

(<) :: Key -> Key -> Bool

(<=) :: Key -> Key -> Bool

(>) :: Key -> Key -> Bool

(>=) :: Key -> Key -> Bool

max :: Key -> Key -> Key

min :: Key -> Key -> Key

FromField Key Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser Key #

ToField Key Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: Key -> SQLData #

newtype IV Source #

IV bytes newtype.

Constructors

IV 

Fields

  • unIV :: ByteString
     

Instances

Instances details
FromJSON IV Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

parseJSON :: Value -> Parser IV

parseJSONList :: Value -> Parser [IV]

omittedField :: Maybe IV

ToJSON IV Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toJSON :: IV -> Value

toEncoding :: IV -> Encoding

toJSONList :: [IV] -> Value

toEncodingList :: [IV] -> Encoding

omitField :: IV -> Bool

Show IV Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> IV -> ShowS

show :: IV -> String

showList :: [IV] -> ShowS

Eq IV Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: IV -> IV -> Bool

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

Encoding IV Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: IV -> ByteString Source #

smpDecode :: ByteString -> Either String IV Source #

smpP :: Parser IV Source #

data GCMIV Source #

GCMIV bytes newtype.

newtype AuthTag Source #

Constructors

AuthTag 

Fields

Instances

Instances details
Encoding AuthTag Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: AuthTag -> ByteString Source #

smpDecode :: ByteString -> Either String AuthTag Source #

smpP :: Parser AuthTag Source #

encryptAEAD :: Key -> IV -> Int -> ByteString -> ByteString -> ExceptT CryptoError IO (AuthTag, ByteString) Source #

AEAD-GCM encryption with associated data.

Used as part of double ratchet encryption. This function requires 16 bytes IV, it transforms IV in cryptonite_aes_gcm_init here: https://github.com/haskell-crypto/cryptonite/blob/master/cbits/cryptonite_aes.c

decryptAEAD :: Key -> IV -> ByteString -> ByteString -> AuthTag -> ExceptT CryptoError IO ByteString Source #

AEAD-GCM decryption with associated data.

Used as part of double ratchet encryption. This function requires 16 bytes IV, it transforms IV in cryptonite_aes_gcm_init here: https://github.com/haskell-crypto/cryptonite/blob/master/cbits/cryptonite_aes.c To make it compatible with WebCrypto we will need to start using initAEADGCM.

encryptAESNoPad :: Key -> GCMIV -> ByteString -> ExceptT CryptoError IO (AuthTag, ByteString) Source #

decryptAESNoPad :: Key -> GCMIV -> ByteString -> AuthTag -> ExceptT CryptoError IO ByteString Source #

randomAesKey :: TVar ChaChaDRG -> STM Key Source #

Random AES256 key.

randomGCMIV :: TVar ChaChaDRG -> STM GCMIV Source #

ivSize :: forall c. BlockCipher c => Int Source #

gcmIV :: ByteString -> Either CryptoError GCMIV Source #

NaCl crypto_box

data CbNonce Source #

Instances

Instances details
FromJSON CbNonce Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

parseJSON :: Value -> Parser CbNonce

parseJSONList :: Value -> Parser [CbNonce]

omittedField :: Maybe CbNonce

ToJSON CbNonce Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toJSON :: CbNonce -> Value

toEncoding :: CbNonce -> Encoding

toJSONList :: [CbNonce] -> Value

toEncodingList :: [CbNonce] -> Encoding

omitField :: CbNonce -> Bool

Show CbNonce Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> CbNonce -> ShowS

show :: CbNonce -> String

showList :: [CbNonce] -> ShowS

Eq CbNonce Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: CbNonce -> CbNonce -> Bool

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

Encoding CbNonce Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: CbNonce -> ByteString Source #

smpDecode :: ByteString -> Either String CbNonce Source #

smpP :: Parser CbNonce Source #

StrEncoding CbNonce Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: CbNonce -> ByteString Source #

strDecode :: ByteString -> Either String CbNonce Source #

strP :: Parser CbNonce Source #

FromField CbNonce Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser CbNonce #

ToField CbNonce Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: CbNonce -> SQLData #

pattern CbNonce :: ByteString -> CbNonce Source #

cbEncrypt :: DhSecret X25519 -> CbNonce -> ByteString -> Int -> Either CryptoError ByteString Source #

NaCl crypto_box encrypt with padding with a shared DH secret and 192-bit nonce.

cbEncryptNoPad :: DhSecret X25519 -> CbNonce -> ByteString -> ByteString Source #

NaCl crypto_box encrypt with a shared DH secret and 192-bit nonce (without padding).

cbEncryptMaxLenBS :: KnownNat i => DhSecret X25519 -> CbNonce -> MaxLenBS i -> ByteString Source #

NaCl crypto_box encrypt with a shared DH secret and 192-bit nonce.

cbDecrypt :: DhSecret X25519 -> CbNonce -> ByteString -> Either CryptoError ByteString Source #

NaCl crypto_box decrypt with a shared DH secret and 192-bit nonce.

cbDecryptNoPad :: DhSecret X25519 -> CbNonce -> ByteString -> Either CryptoError ByteString Source #

NaCl crypto_box decrypt with a shared DH secret and 192-bit nonce (without unpadding).

sbDecrypt_ :: ByteArrayAccess key => key -> CbNonce -> ByteString -> Either CryptoError ByteString Source #

NaCl crypto_box decrypt with a shared DH secret and 192-bit nonce.

sbEncrypt_ :: ByteArrayAccess key => key -> CbNonce -> ByteString -> Int -> Either CryptoError ByteString Source #

sbEncryptNoPad :: SbKey -> CbNonce -> ByteString -> ByteString Source #

sbDecryptNoPad :: SbKey -> CbNonce -> ByteString -> Either CryptoError ByteString Source #

cbNonce :: ByteString -> CbNonce Source #

randomCbNonce :: TVar ChaChaDRG -> STM CbNonce Source #

NaCl crypto_secretbox

data SbKey Source #

Instances

Instances details
FromJSON SbKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

parseJSON :: Value -> Parser SbKey

parseJSONList :: Value -> Parser [SbKey]

omittedField :: Maybe SbKey

ToJSON SbKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toJSON :: SbKey -> Value

toEncoding :: SbKey -> Encoding

toJSONList :: [SbKey] -> Value

toEncodingList :: [SbKey] -> Encoding

omitField :: SbKey -> Bool

Show SbKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> SbKey -> ShowS

show :: SbKey -> String

showList :: [SbKey] -> ShowS

Eq SbKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: SbKey -> SbKey -> Bool

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

StrEncoding SbKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: SbKey -> ByteString Source #

strDecode :: ByteString -> Either String SbKey Source #

strP :: Parser SbKey Source #

FromField SbKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser SbKey #

ToField SbKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: SbKey -> SQLData #

pattern SbKey :: ByteString -> SbKey Source #

sbEncrypt :: SbKey -> CbNonce -> ByteString -> Int -> Either CryptoError ByteString Source #

NaCl secret_box encrypt with a symmetric 256-bit key and 192-bit nonce.

sbDecrypt :: SbKey -> CbNonce -> ByteString -> Either CryptoError ByteString Source #

NaCl secret_box decrypt with a symmetric 256-bit key and 192-bit nonce.

sbKey :: ByteString -> Either String SbKey Source #

unsafeSbKey :: ByteString -> SbKey Source #

randomSbKey :: TVar ChaChaDRG -> STM SbKey Source #

secret_box chains

data SbChainKey Source #

Instances

Instances details
Show SbChainKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> SbChainKey -> ShowS

show :: SbChainKey -> String

showList :: [SbChainKey] -> ShowS

Eq SbChainKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: SbChainKey -> SbChainKey -> Bool

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

sbcInit :: ByteArrayAccess secret => ByteString -> secret -> (SbChainKey, SbChainKey) Source #

hkdf :: ByteArrayAccess secret => ByteString -> secret -> ByteString -> Int -> ByteString Source #

pseudo-random bytes

randomBytes :: Int -> TVar ChaChaDRG -> STM ByteString Source #

digests

sha256Hash :: ByteString -> ByteString Source #

SHA256 digest.

sha512Hash :: ByteString -> ByteString Source #

SHA512 digest.

sha3_256 :: ByteString -> ByteString Source #

SHA3-256 digest.

sha3_384 :: ByteString -> ByteString Source #

SHA3-384 digest.

Message padding / un-padding

canPad :: Int -> Int -> Bool Source #

pad :: ByteString -> Int -> Either CryptoError ByteString Source #

unPad :: ByteString -> Either CryptoError ByteString Source #

X509 Certificates

signCertificate :: APrivateSignKey -> Certificate -> SignedCertificate Source #

signX509 :: (ASN1Object o, Eq o, Show o) => APrivateSignKey -> o -> SignedExact o Source #

verifyX509 :: (ASN1Object o, Eq o, Show o) => APublicVerifyKey -> SignedExact o -> Either String o Source #

certificateFingerprint :: SignedCertificate -> KeyHash Source #

signedFingerprint :: (ASN1Object o, Eq o, Show o) => SignedExact o -> KeyHash Source #

class SignatureAlgorithmX509 a where Source #

Methods

signatureAlgorithmX509 :: a -> SignatureALG Source #

Instances

Instances details
SignatureAlgorithmX509 APrivateSignKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

SignatureAlgorithmX509 APublicVerifyKey Source # 
Instance details

Defined in Simplex.Messaging.Crypto

SignatureAlgorithm a => SignatureAlgorithmX509 (SAlgorithm a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureAlgorithmX509 :: SAlgorithm a -> SignatureALG Source #

SignatureAlgorithmX509 pk => SignatureAlgorithmX509 (a, pk) Source #

An instance for ASignatureKeyPair / (PublicKeyType pk, pk), without touching its type family.

Instance details

Defined in Simplex.Messaging.Crypto

Methods

signatureAlgorithmX509 :: (a, pk) -> SignatureALG Source #

newtype SignedObject a Source #

A wrapper to marshall signed ASN1 objects, like certificates.

Constructors

SignedObject 

Fields

Instances

Instances details
(Eq a, Show a, ASN1Object a) => Encoding (SignedObject a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: SignedObject a -> ByteString Source #

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

smpP :: Parser (SignedObject a) Source #

(Typeable a, Eq a, Show a, ASN1Object a) => FromField (SignedObject a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

fromField :: FieldParser (SignedObject a) #

(Eq a, Show a, ASN1Object a) => ToField (SignedObject a) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toField :: SignedObject a -> SQLData #

encodeCertChain :: CertificateChain -> NonEmpty Large Source #

certChainP :: Parser CertificateChain Source #

Cryptography error type

data CryptoError Source #

Various cryptographic or related errors.

Constructors

AESCipherError CryptoError

AES initialization error

CryptoIVError

IV generation error

AESDecryptError

AES decryption error

CBDecryptError 
CryptoPoly1305Error CryptoError 
CryptoLargeMsgError

message is larger that allowed padded length minus 2 (to prepend message length) (or required un-padded length is larger than the message length)

CryptoInvalidMsgError

padded message is shorter than 2 bytes

CryptoHeaderError String

failure parsing message header

CERatchetState

no sending chain key in ratchet state

CERatchetKEMState

no decapsulation key in ratchet state

CERatchetHeader

header decryption error (could indicate that another key should be tried)

CERatchetTooManySkipped Word32

too many skipped messages

CERatchetEarlierMessage Word32

earlier message number (or, possibly, skipped message that failed to decrypt?)

CERatchetDuplicateMessage

duplicate message number

Instances

Instances details
Exception CryptoError Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

toException :: CryptoError -> SomeException

fromException :: SomeException -> Maybe CryptoError

displayException :: CryptoError -> String

Show CryptoError Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

showsPrec :: Int -> CryptoError -> ShowS

show :: CryptoError -> String

showList :: [CryptoError] -> ShowS

Eq CryptoError Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

(==) :: CryptoError -> CryptoError -> Bool

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

Limited size ByteStrings

data MaxLenBS (i :: Nat) Source #

Instances

Instances details
KnownNat i => Encoding (MaxLenBS i) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

smpEncode :: MaxLenBS i -> ByteString Source #

smpDecode :: ByteString -> Either String (MaxLenBS i) Source #

smpP :: Parser (MaxLenBS i) Source #

KnownNat i => StrEncoding (MaxLenBS i) Source # 
Instance details

Defined in Simplex.Messaging.Crypto

Methods

strEncode :: MaxLenBS i -> ByteString Source #

strDecode :: ByteString -> Either String (MaxLenBS i) Source #

strP :: Parser (MaxLenBS i) Source #

pattern MaxLenBS :: ByteString -> MaxLenBS i Source #

maxLenBS :: forall i. KnownNat i => ByteString -> Either CryptoError (MaxLenBS i) Source #

unsafeMaxLenBS :: forall i. KnownNat i => ByteString -> MaxLenBS i Source #

appendMaxLenBS :: (KnownNat i, KnownNat j) => MaxLenBS i -> MaxLenBS j -> MaxLenBS (i + j) Source #