| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cardano.Crypto.Libsodium
Synopsis
- sodiumInit ∷ IO ()
- data MLockedForeignPtr a
- data MLockedAllocator m
- finalizeMLockedForeignPtr ∷ MonadST m ⇒ MLockedForeignPtr a → m ()
- mlockedAllocForeignPtr ∷ ∀ a m. (MonadST m, Storable a) ⇒ m (MLockedForeignPtr a)
- mlockedMalloc ∷ MonadST m ⇒ MLockedAllocator m
- traceMLockedForeignPtr ∷ (Storable a, Show a, MonadST m) ⇒ MLockedForeignPtr a → m ()
- withMLockedForeignPtr ∷ MonadST m ⇒ MLockedForeignPtr a → (Ptr a → m b) → m b
- data MLockedSizedBytes (n ∷ Nat)
- mlsbAsByteString ∷ ∀ n. KnownNat n ⇒ MLockedSizedBytes n → ByteString
- mlsbCompare ∷ ∀ n m. (MonadST m, KnownNat n) ⇒ MLockedSizedBytes n → MLockedSizedBytes n → m Ordering
- mlsbCopy ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedSizedBytes n → m (MLockedSizedBytes n)
- mlsbCopyWith ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedAllocator m → MLockedSizedBytes n → m (MLockedSizedBytes n)
- mlsbEq ∷ ∀ n m. (MonadST m, KnownNat n) ⇒ MLockedSizedBytes n → MLockedSizedBytes n → m Bool
- mlsbFinalize ∷ MonadST m ⇒ MLockedSizedBytes n → m ()
- mlsbFromByteString ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ ByteString → m (MLockedSizedBytes n)
- mlsbFromByteStringCheck ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ ByteString → m (Maybe (MLockedSizedBytes n))
- mlsbFromByteStringCheckWith ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedAllocator m → ByteString → m (Maybe (MLockedSizedBytes n))
- mlsbFromByteStringWith ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedAllocator m → ByteString → m (MLockedSizedBytes n)
- mlsbNew ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ m (MLockedSizedBytes n)
- mlsbNewWith ∷ ∀ n m. MLockedAllocator m → (KnownNat n, MonadST m) ⇒ m (MLockedSizedBytes n)
- mlsbNewZero ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ m (MLockedSizedBytes n)
- mlsbNewZeroWith ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedAllocator m → m (MLockedSizedBytes n)
- mlsbToByteString ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedSizedBytes n → m ByteString
- mlsbUseAsCPtr ∷ MonadST m ⇒ MLockedSizedBytes n → (Ptr Word8 → m r) → m r
- mlsbUseAsSizedPtr ∷ ∀ n r m. MonadST m ⇒ MLockedSizedBytes n → (SizedPtr n → m r) → m r
- mlsbZero ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedSizedBytes n → m ()
- digestMLockedBS ∷ ∀ h proxy. SodiumHashAlgorithm h ⇒ proxy h → ByteString → IO (MLockedSizedBytes (SizeHash h))
- digestMLockedStorable ∷ ∀ h a proxy. (SodiumHashAlgorithm h, Storable a) ⇒ proxy h → Ptr a → IO (MLockedSizedBytes (SizeHash h))
- expandHash ∷ ∀ h m proxy. (SodiumHashAlgorithm h, MonadST m, MonadThrow m) ⇒ proxy h → MLockedSizedBytes (SizeHash h) → m (MLockedSizedBytes (SizeHash h), MLockedSizedBytes (SizeHash h))
- expandHashWith ∷ ∀ h m proxy. (SodiumHashAlgorithm h, MonadST m, MonadThrow m) ⇒ MLockedAllocator m → proxy h → MLockedSizedBytes (SizeHash h) → m (MLockedSizedBytes (SizeHash h), MLockedSizedBytes (SizeHash h))
- class HashAlgorithm h ⇒ SodiumHashAlgorithm h where
- naclDigestPtr ∷ proxy h → Ptr a → Int → IO (MLockedSizedBytes (SizeHash h))
Initialization
sodiumInit ∷ IO () Source #
MLocked memory management
data MLockedForeignPtr a Source #
Foreign pointer to securely allocated memory.
Instances
| NFData (MLockedForeignPtr a) Source # | |
Defined in Cardano.Crypto.Libsodium.Memory.Internal Methods rnf ∷ MLockedForeignPtr a → () # | |
| NoThunks (MLockedForeignPtr a) Source # | |
Defined in Cardano.Crypto.Libsodium.Memory.Internal | |
data MLockedAllocator m Source #
finalizeMLockedForeignPtr ∷ MonadST m ⇒ MLockedForeignPtr a → m () Source #
mlockedAllocForeignPtr ∷ ∀ a m. (MonadST m, Storable a) ⇒ m (MLockedForeignPtr a) Source #
mlockedMalloc ∷ MonadST m ⇒ MLockedAllocator m Source #
traceMLockedForeignPtr ∷ (Storable a, Show a, MonadST m) ⇒ MLockedForeignPtr a → m () Source #
Warning: Do not use traceMLockedForeignPtr in production
withMLockedForeignPtr ∷ MonadST 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
| 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. |
Defined in Cardano.Crypto.Libsodium.MLockedBytes.Internal Methods showsPrec ∷ Int → MLockedSizedBytes n → ShowS # show ∷ MLockedSizedBytes n → String # showList ∷ [MLockedSizedBytes n] → ShowS # | |
| NFData (MLockedSizedBytes n) Source # | |
Defined in Cardano.Crypto.Libsodium.MLockedBytes.Internal Methods rnf ∷ MLockedSizedBytes n → () # | |
| NoThunks (MLockedSizedBytes n) Source # | |
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.
mlsbCompare ∷ ∀ n m. (MonadST m, KnownNat n) ⇒ MLockedSizedBytes n → MLockedSizedBytes n → m Ordering Source #
compareM on MLockedSizedBytes
mlsbCopy ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedSizedBytes n → m (MLockedSizedBytes n) Source #
Create a deep mlocked copy of an MLockedSizedBytes.
mlsbCopyWith ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedAllocator m → MLockedSizedBytes n → m (MLockedSizedBytes n) Source #
mlsbEq ∷ ∀ n m. (MonadST m, KnownNat n) ⇒ MLockedSizedBytes n → MLockedSizedBytes n → m Bool Source #
equalsM on MLockedSizedBytes
mlsbFinalize ∷ MonadST 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)
mlsbFromByteStringCheckWith ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedAllocator m → ByteString → m (Maybe (MLockedSizedBytes n)) Source #
mlsbFromByteStringWith ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedAllocator m → ByteString → m (MLockedSizedBytes n) Source #
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.
mlsbNewWith ∷ ∀ n m. MLockedAllocator m → (KnownNat n, MonadST m) ⇒ m (MLockedSizedBytes n) Source #
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).
mlsbNewZeroWith ∷ ∀ n m. (KnownNat n, MonadST m) ⇒ MLockedAllocator m → m (MLockedSizedBytes n) Source #
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.
mlsbUseAsCPtr ∷ MonadST 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 → ByteString → IO (MLockedSizedBytes (SizeHash h)) Source #
digestMLockedStorable ∷ ∀ h a proxy. (SodiumHashAlgorithm h, Storable a) ⇒ proxy h → Ptr a → IO (MLockedSizedBytes (SizeHash h)) Source #
expandHash ∷ ∀ h m proxy. (SodiumHashAlgorithm h, MonadST m, MonadThrow m) ⇒ proxy h → MLockedSizedBytes (SizeHash h) → m (MLockedSizedBytes (SizeHash h), MLockedSizedBytes (SizeHash h)) Source #
expandHashWith ∷ ∀ h m proxy. (SodiumHashAlgorithm h, MonadST m, MonadThrow m) ⇒ MLockedAllocator m → proxy h → MLockedSizedBytes (SizeHash h) → m (MLockedSizedBytes (SizeHash h), MLockedSizedBytes (SizeHash h)) Source #
class HashAlgorithm h ⇒ SodiumHashAlgorithm h where Source #
Methods
Arguments
| ∷ proxy h | |
| → Ptr a | input |
| → Int | input length |
| → IO (MLockedSizedBytes (SizeHash h)) |
Instances
| SodiumHashAlgorithm Blake2b_256 Source # | |
Defined in Cardano.Crypto.Libsodium.Hash.Class Methods naclDigestPtr ∷ proxy Blake2b_256 → Ptr a → Int → IO (MLockedSizedBytes (SizeHash Blake2b_256)) Source # | |
| SodiumHashAlgorithm SHA256 Source # | |
Defined in Cardano.Crypto.Libsodium.Hash.Class Methods naclDigestPtr ∷ proxy SHA256 → Ptr a → Int → IO (MLockedSizedBytes (SizeHash SHA256)) Source # | |