cardano-crypto-class-2.1.1.0: Type classes abstracting over cryptography primitives for Cardano
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Crypto.Libsodium

Synopsis

Initialization

MLocked memory management

data MLockedForeignPtr a #

Foreign pointer to securely allocated memory.

withMLockedForeignPtr :: forall a b. MonadSodium m => MLockedForeignPtr a -> (Ptr a -> m b) -> m b #

traceMLockedForeignPtr :: (MonadSodium m, Storable a, Show a) => MLockedForeignPtr a -> m () #

Deprecated: Do not use traceMLockedForeignPtr in production

MLocked bytes

data MLockedSizedBytes (n :: Nat) #

A block of raw memory of a known size, protected with mlock().

Instances

Instances details
(MonadSodium m, MonadST m, KnownNat n) => MEq m (MLockedSizedBytes n) # 
Instance details

Defined in Cardano.Crypto.Libsodium.MLockedBytes.Internal

KnownNat n => Show (MLockedSizedBytes n) #

This instance is unsafe, it will leak secrets from mlocked memory to the Haskell heap. Do not use outside of testing.

Instance details

Defined in Cardano.Crypto.Libsodium.MLockedBytes.Internal

NFData (MLockedSizedBytes n) # 
Instance details

Defined in Cardano.Crypto.Libsodium.MLockedBytes.Internal

Methods

rnf :: MLockedSizedBytes n -> () Source #

NoThunks (MLockedSizedBytes n) # 
Instance details

Defined in Cardano.Crypto.Libsodium.MLockedBytes.Internal

mlsbFromByteString :: forall n m. (KnownNat n, MonadSodium m, MonadST m) => ByteString -> m (MLockedSizedBytes n) #

Allocate a new MLockedSizedBytes, and fill it with the contents of a ByteString. The size of the input is not checked. Note: since the input ByteString is a plain old Haskell value, it has already violated the secure-forgetting properties afforded by MLockedSizedBytes, so this function is useless outside of testing. Use mlsbNew or mlsbNewZero to create MLockedSizedBytes values, and manipulate them through withMLSB, mlsbUseAsCPtr, or mlsbUseAsSizedPtr. (See also mlsbFromByteStringCheck)

mlsbFromByteStringCheck :: forall n m. (KnownNat n, MonadSodium m, MonadST m) => ByteString -> m (Maybe (MLockedSizedBytes n)) #

Allocate a new MLockedSizedBytes, and fill it with the contents of a ByteString. The size of the input is checked. Note: since the input ByteString is a plain old Haskell value, it has already violated the secure-forgetting properties afforded by MLockedSizedBytes, so this function is useless outside of testing. Use mlsbNew or mlsbNewZero to create MLockedSizedBytes values, and manipulate them through withMLSB, mlsbUseAsCPtr, or mlsbUseAsSizedPtr. (See also mlsbFromByteString)

mlsbAsByteString :: forall n. KnownNat n => MLockedSizedBytes n -> ByteString #

Note: the resulting ByteString will still refer to secure memory, but the types don't prevent it from be exposed. Note further that any subsequent operations (splicing & dicing, copying, conversion, packing/unpacking, etc.) on the resulting ByteString may create copies of the mlocked memory on the unprotected GHC heap, and thus leak secrets, so use this function with extreme care.

mlsbToByteString :: forall n m. (KnownNat n, MonadSodium m, MonadST m) => MLockedSizedBytes n -> m ByteString #

Note: this function will leak mlocked memory to the Haskell heap and should not be used in production code.

mlsbFinalize :: MonadSodium m => MLockedSizedBytes n -> m () #

Calls finalizeMLockedForeignPtr on underlying pointer. This function invalidates argument.

mlsbCopy :: forall n m. (KnownNat n, MonadSodium m) => MLockedSizedBytes n -> m (MLockedSizedBytes n) #

Create a deep mlocked copy of an MLockedSizedBytes.

Hashing

class HashAlgorithm h => SodiumHashAlgorithm h where #

Methods

naclDigestPtr #

Arguments

:: proxy h 
-> Ptr a

input

-> Int

input length

-> IO (MLockedSizedBytes (SizeHash h)) 

Instances

Instances details
SodiumHashAlgorithm Blake2b_256 # 
Instance details

Defined in Cardano.Crypto.Libsodium.Hash.Class

SodiumHashAlgorithm SHA256 # 
Instance details

Defined in Cardano.Crypto.Libsodium.Hash.Class

digestMLockedStorable :: forall h a proxy. (SodiumHashAlgorithm h, Storable a) => proxy h -> Ptr a -> IO (MLockedSizedBytes (SizeHash h)) #

digestMLockedBS :: forall h proxy. SodiumHashAlgorithm h => proxy h -> ByteString -> IO (MLockedSizedBytes (SizeHash h)) #