License | BSD3 |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Given a value of a serializable type (like Int
) we perform serialization and
compute a cryptographic hash of the associated namespace (carried as a phantom
type of kind Symbol
).
The serialized payload is then encrypted using the symmetric cipher in CBC mode
using the hashed namespace as an initialization vector (IV).
The probability of detecting a namespace mismatch is thus \(1 - 2^{128-l}\) where \(l\) is the length of the serialized payload.
- newtype CryptoID namespace a :: Symbol -> * -> * = CryptoID {
- ciphertext :: a
- data CryptoIDKey
- genKey :: MonadIO m => m CryptoIDKey
- encrypt :: forall m namespace. (KnownSymbol namespace, MonadError CryptoIDError m) => CryptoIDKey -> ByteString -> m (CryptoID namespace ByteString)
- decrypt :: forall m namespace. (KnownSymbol namespace, MonadError CryptoIDError m) => CryptoIDKey -> CryptoID namespace ByteString -> m ByteString
- data CryptoIDError
- type CryptoCipher = Blowfish
- type CryptoHash = SHAKE128 64
Documentation
newtype CryptoID namespace a :: Symbol -> * -> * #
CryptoID | |
|
Eq a => Eq (CryptoID namespace a) | |
(Data a, KnownSymbol namespace) => Data (CryptoID namespace a) | |
Ord a => Ord (CryptoID namespace a) | |
Read a => Read (CryptoID namespace a) | |
Show a => Show (CryptoID namespace a) | |
Generic (CryptoID namespace a) | |
Storable a => Storable (CryptoID namespace a) | |
Binary a => Binary (CryptoID namespace a) | |
ToHttpApiData a => ToHttpApiData (CryptoID namespace a) | |
FromHttpApiData a => FromHttpApiData (CryptoID namespace a) | |
PathPiece a => PathPiece (CryptoID namespace a) | |
type Rep (CryptoID namespace a) | |
data CryptoIDKey Source #
This newtype ensures only keys of the correct length can be created
Use genKey
to securely generate keys.
Use the Binary
instance to save and restore values of CryptoIDKey
across
executions.
Show CryptoIDKey Source # | Does not actually show any key material |
Binary CryptoIDKey Source # | |
ByteArrayAccess CryptoIDKey Source # | |
genKey :: MonadIO m => m CryptoIDKey Source #
Securely generate a new key using system entropy
When CryptoCipher
accepts keys of varying lengths this function generates a
key of the largest accepted size.
encrypt :: forall m namespace. (KnownSymbol namespace, MonadError CryptoIDError m) => CryptoIDKey -> ByteString -> m (CryptoID namespace ByteString) Source #
Encrypt an arbitrary serializable value
decrypt :: forall m namespace. (KnownSymbol namespace, MonadError CryptoIDError m) => CryptoIDKey -> CryptoID namespace ByteString -> m ByteString Source #
Decrypt an arbitrary serializable value
data CryptoIDError Source #
AlgorithmError CryptoError | One of the underlying cryptographic algorithms
( |
NamespaceHashIsWrongLength ByteString | The length of the digest produced by The offending digest is included. This error should not occur and is included primarily for sake of totality. |
CiphertextConversionFailed | The produced |
DeserializationError (ByteString, ByteOffset, String) | The plaintext obtained by decrypting a ciphertext with the given
This is expected behaviour if the |
InvalidNamespaceDetected | We have determined that, allthough deserializion succeded, the ciphertext was likely modified during transit or created using a different namespace. |
type CryptoCipher = Blowfish Source #
The symmetric cipher BlockCipher
this module uses
type CryptoHash = SHAKE128 64 Source #
The cryptographic HashAlgorithm
this module uses
We expect the block size of CryptoCipher
to be exactly the size of the
Digest
generated by CryptoHash
(since a Digest
is used as an IV
).
Violation of this expectation causes runtime errors.