HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulelibsodium-bindings-0.0.1.1Haskell2010

LibSodium.Bindings.Utils

These are bindings to some of libsodium's utils.h. Included are Hex and Base64 encoding/decoding functions along with a constant-time memcmp for handling secret data.

  • 7 values

Low-level binding

3 declarations
valuesodiumMemcmp
  1. :: Ptr CUChar

    First pointer to some secret data.

  2. -> Ptr CUChar

    Second pointer to some secret data. Must be the same length as the first pointer.

  3. -> CSize

    The length of bytes that pointed to by both previous arguments.

  4. -> IO CInt

    0 if successful, -1 on failure.

#

Constant-time comparison function.

This function is not a lexicographic comparator and should be never used for this purpose. It should only be used when comparing two pieces of secret data, such as keys or authentication tags.

valuesodiumBin2Hex
  1. :: CString

    hex, The output buffer.

  2. -> CSize

    hex_len, The maximum number of bytes this function is allowed to write to the output buffer. Must be at least bin_len * 2 + 1 bytes long.

  3. -> Ptr CUChar

    bin, The input buffer.

  4. -> CSize

    bin_len, The length of the input buffer.

  5. -> IO CString

    The return string, terminated with a null byte.

#

Encode bytes to a hexidecimal string. Constant-time.

valuesodiumBin2Base64
  1. :: CString

    b64, The output buffer.

  2. -> CSize

    b64_maxlen, The maximum length of the output buffer. Choosing a correct size is not straightforward and depends on the variant. The sodium_base64_ENCODED_LEN(BIN_LEN, VARIANT) macro computes the minimum amount of bytes needed to encode BIN_LEN bytes with a chosen VARIANT.

  3. -> Ptr CUChar

    bin, The input buffer.

  4. -> CSize

    bin_len, The length of the input buffer.

  5. -> CInt

    variant, Which Base64 variant to use. None of the variants provide any encryption.

  6. -> IO CString

    The returned Base64 string, terminated with a null byte.

#

Encode bytes to a Base64 string. Constant-time.

Constants

4 declarations

The original variant of Base64 with padding. This ensures that the length of the encoded data will always be a multiple of four bytes.