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

Cardano.Crypto.Libsodium

Synopsis

Initialization

MLocked memory management

data MLockedForeignPtr a Source #

Foreign pointer to securely allocated memory.

traceMLockedForeignPtr ∷ (Storable a, Show a, MonadST m) ⇒ MLockedForeignPtr a → m () Source #

Warning: Do not use traceMLockedForeignPtr in production

withMLockedForeignPtrMonadST m ⇒ MLockedForeignPtr a → (Ptr a → m b) → m b Source #

MLocked bytes (MLockedSizedBytes)

data MLockedSizedBytes (n ∷ Nat) Source #

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

Instances

Instances details
KnownNat n ⇒ Show (MLockedSizedBytes n) Source #

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) Source # 
Instance details

Defined in Cardano.Crypto.Libsodium.MLockedBytes.Internal

Methods

rnfMLockedSizedBytes n → () Source #

NoThunks (MLockedSizedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.Libsodium.MLockedBytes.Internal

mlsbAsByteString ∷ ∀ n. KnownNat n ⇒ MLockedSizedBytes n → ByteString Source #

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.

mlsbCopy ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedSizedBytes n → m (MLockedSizedBytes n) Source #

Create a deep mlocked copy of an MLockedSizedBytes.

mlsbEq ∷ ∀ n m. (MonadST m, KnownNat n) ⇒ MLockedSizedBytes n → MLockedSizedBytes n → m Bool Source #

mlsbFinalizeMonadST m ⇒ MLockedSizedBytes n → m () Source #

Calls finalizeMLockedForeignPtr on underlying pointer. This function invalidates argument.

mlsbFromByteString ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ ByteString → m (MLockedSizedBytes n) Source #

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 ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ ByteString → m (Maybe (MLockedSizedBytes n)) Source #

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)

mlsbNew ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ m (MLockedSizedBytes n) Source #

Allocate a new MLockedSizedBytes. The caller is responsible for deallocating it (mlsbFinalize) when done with it. The contents of the memory block is undefined.

mlsbNewZero ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ m (MLockedSizedBytes n) Source #

Allocate a new MLockedSizedBytes, and pre-fill it with zeroes. The caller is responsible for deallocating it (mlsbFinalize) when done with it. (See also mlsbNew).

mlsbToByteString ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedSizedBytes n → m ByteString Source #

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

mlsbUseAsCPtrMonadST m ⇒ MLockedSizedBytes n → (Ptr Word8 → m r) → m r Source #

Use an MLockedSizedBytes value as a raw C pointer. Care should be taken to never copy the contents of the MLockedSizedBytes value into managed memory through the raw pointer, because that would violate the secure-forgetting property of mlocked memory.

mlsbUseAsSizedPtr ∷ ∀ n r m. MonadST m ⇒ MLockedSizedBytes n → (SizedPtr n → m r) → m r Source #

Use an MLockedSizedBytes value as a SizedPtr of the same size. Care should be taken to never copy the contents of the MLockedSizedBytes value into managed memory through the sized pointer, because that would violate the secure-forgetting property of mlocked memory.

mlsbZero ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedSizedBytes n → m () Source #

Overwrite an existing MLockedSizedBytes with zeroes.

Hashing

digestMLockedBS ∷ ∀ h proxy. SodiumHashAlgorithm h ⇒ proxy h → ByteStringIO (MLockedSizedBytes (SizeHash h)) Source #

digestMLockedStorable ∷ ∀ h a proxy. (SodiumHashAlgorithm h, Storable a) ⇒ proxy h → Ptr a → IO (MLockedSizedBytes (SizeHash h)) Source #

class HashAlgorithm h ⇒ SodiumHashAlgorithm h where Source #

Methods

naclDigestPtr Source #

Arguments

∷ proxy h 
Ptr a

input

Int

input length

IO (MLockedSizedBytes (SizeHash h))