libsodium-bindings-0.0.1.1: FFI bindings to libsodium
Copyright(C) Seth Livy 2022
LicenseBSD-3-Clause
MaintainerThe Haskell Cryptography Group
StabilityStable
PortabilityGHC only
Safe HaskellTrustworthy
LanguageHaskell2010

LibSodium.Bindings.Utils

Description

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.

Synopsis

Low-level binding

sodiumMemcmp Source #

Arguments

:: Ptr CUChar

First pointer to some secret data.

-> Ptr CUChar

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

-> CSize

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

-> 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.

Since: 0.0.1.0

sodiumBin2Hex Source #

Arguments

:: CString

hex, The output buffer.

-> 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.

-> Ptr CUChar

bin, The input buffer.

-> CSize

bin_len, The length of the input buffer.

-> IO CString

The return string, terminated with a null byte.

Encode bytes to a hexidecimal string. Constant-time.

Since: 0.0.1.0

sodiumBin2Base64 Source #

Arguments

:: CString

b64, The output buffer.

-> 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.

-> Ptr CUChar

bin, The input buffer.

-> CSize

bin_len, The length of the input buffer.

-> CInt

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

-> IO CString

The returned Base64 string, terminated with a null byte.

Encode bytes to a Base64 string. Constant-time.

Constants

sodiumBase64VariantOriginal :: CInt Source #

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

sodiumBase64VariantOriginalNoPadding :: CInt Source #

The original variant of Base64. No variant offers any security advantages over the other.

sodiumBase64VariantURLSafe :: CInt Source #

The URL-safe variant of Base64 with padding.

sodiumBase64VariantURLSafeNoPadding :: CInt Source #

The URL-safe variant of Base64. This is the same as the original variant, except + and / are replaced with - and '_'.