| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cardano.Crypto.Libsodium
Synopsis
- sodiumInit :: IO ()
- data MLockedForeignPtr a
- withMLockedForeignPtr :: forall a b. MonadSodium m => MLockedForeignPtr a -> (Ptr a -> m b) -> m b
- mlockedAllocForeignPtr :: forall a m. (MonadSodium m, Storable a) => m (MLockedForeignPtr a)
- finalizeMLockedForeignPtr :: forall a. MonadSodium m => MLockedForeignPtr a -> m ()
- traceMLockedForeignPtr :: (MonadSodium m, Storable a, Show a) => MLockedForeignPtr a -> m ()
- data MLockedSizedBytes (n :: Nat)
- mlsbFromByteString :: forall n m. (KnownNat n, MonadSodium m, MonadST m) => ByteString -> m (MLockedSizedBytes n)
- mlsbFromByteStringCheck :: forall n m. (KnownNat n, MonadSodium m, MonadST m) => ByteString -> m (Maybe (MLockedSizedBytes n))
- mlsbAsByteString :: forall n. KnownNat n => MLockedSizedBytes n -> ByteString
- mlsbToByteString :: forall n m. (KnownNat n, MonadSodium m, MonadST m) => MLockedSizedBytes n -> m ByteString
- mlsbFinalize :: MonadSodium m => MLockedSizedBytes n -> m ()
- mlsbCopy :: forall n m. (KnownNat n, MonadSodium m) => MLockedSizedBytes n -> m (MLockedSizedBytes n)
- class HashAlgorithm h => SodiumHashAlgorithm h where
- naclDigestPtr :: proxy h -> Ptr a -> Int -> IO (MLockedSizedBytes (SizeHash h))
- 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))
- expandHash :: forall h m proxy. (SodiumHashAlgorithm h, MonadSodium m, MonadST m, MonadThrow m) => proxy h -> MLockedSizedBytes (SizeHash h) -> m (MLockedSizedBytes (SizeHash h), MLockedSizedBytes (SizeHash h))
Initialization
sodiumInit :: IO () #
MLocked memory management
data MLockedForeignPtr a #
Foreign pointer to securely allocated memory.
Instances
| NFData (MLockedForeignPtr a) # | |
Defined in Cardano.Crypto.Libsodium.Memory.Internal Methods rnf :: MLockedForeignPtr a -> () Source # | |
| NoThunks (MLockedForeignPtr a) # | |
Defined in Cardano.Crypto.Libsodium.Memory.Internal | |
withMLockedForeignPtr :: forall a b. MonadSodium m => MLockedForeignPtr a -> (Ptr a -> m b) -> m b #
mlockedAllocForeignPtr :: forall a m. (MonadSodium m, Storable a) => m (MLockedForeignPtr a) #
finalizeMLockedForeignPtr :: forall a. MonadSodium m => MLockedForeignPtr a -> m () #
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
| (MonadSodium m, MonadST m, KnownNat n) => MEq m (MLockedSizedBytes n) # | |
Defined in Cardano.Crypto.Libsodium.MLockedBytes.Internal Methods equalsM :: MLockedSizedBytes n -> MLockedSizedBytes n -> m Bool # | |
| 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. |
| NFData (MLockedSizedBytes n) # | |
Defined in Cardano.Crypto.Libsodium.MLockedBytes.Internal Methods rnf :: MLockedSizedBytes n -> () Source # | |
| NoThunks (MLockedSizedBytes n) # | |
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
Arguments
| :: proxy h | |
| -> Ptr a | input |
| -> Int | input length |
| -> IO (MLockedSizedBytes (SizeHash h)) |
Instances
| SodiumHashAlgorithm Blake2b_256 # | |
Defined in Cardano.Crypto.Libsodium.Hash.Class Methods naclDigestPtr :: proxy Blake2b_256 -> Ptr a -> Int -> IO (MLockedSizedBytes (SizeHash Blake2b_256)) # | |
| SodiumHashAlgorithm SHA256 # | |
Defined in Cardano.Crypto.Libsodium.Hash.Class Methods naclDigestPtr :: proxy SHA256 -> Ptr a -> Int -> IO (MLockedSizedBytes (SizeHash SHA256)) # | |
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)) #
expandHash :: forall h m proxy. (SodiumHashAlgorithm h, MonadSodium m, MonadST m, MonadThrow m) => proxy h -> MLockedSizedBytes (SizeHash h) -> m (MLockedSizedBytes (SizeHash h), MLockedSizedBytes (SizeHash h)) #