wrapper.sodium.utils

Utility functions and unittests.

Public Imports

deimos.sodium.utils
public import deimos.sodium.utils : sodium_stackzero, sodium_base64_VARIANT_ORIGINAL, sodium_base64_VARIANT_ORIGINAL_NO_PADDING, sodium_base64_VARIANT_URLSAFE, sodium_base64_VARIANT_URLSAFE_NO_PADDING, sodium_base64_ENCODED_LEN, sodium_base64_encoded_len, sodium_mlock, sodium_munlock, sodium_malloc, sodium_allocarray, sodium_free, sodium_mprotect_noaccess, sodium_mprotect_readonly, sodium_mprotect_readwrite;

Members

Aliases

sodium_add
alias sodium_add = deimos.sodium.utils.sodium_add
sodium_base642bin
alias sodium_base642bin = deimos.sodium.utils.sodium_base642bin
sodium_bin2base64
alias sodium_bin2base64 = deimos.sodium.utils.sodium_bin2base64
sodium_bin2hex
alias sodium_bin2hex = deimos.sodium.utils.sodium_bin2hex
sodium_compare
alias sodium_compare = deimos.sodium.utils.sodium_compare

Comparing large numbers.

sodium_hex2bin
alias sodium_hex2bin = deimos.sodium.utils.sodium_hex2bin
sodium_increment
alias sodium_increment = deimos.sodium.utils.sodium_increment
sodium_is_zero
alias sodium_is_zero = deimos.sodium.utils.sodium_is_zero

Testing for all zeros.

sodium_memcmp
alias sodium_memcmp = deimos.sodium.utils.sodium_memcmp

Constant-time test for equality

sodium_memzero
alias sodium_memzero = deimos.sodium.utils.sodium_memzero

Zeroing memory.

sodium_pad
alias sodium_pad = deimos.sodium.utils.sodium_pad
sodium_sub
alias sodium_sub = deimos.sodium.utils.sodium_sub
sodium_unpad
alias sodium_unpad = deimos.sodium.utils.sodium_unpad

Functions

sodium_add
void sodium_add(ubyte[] a, ubyte[] b)

Adding large numbers

sodium_base642bin
bool sodium_base642bin(ubyte[] bin, char[] b64, string ignore_nullterminated, size_t bin_len, size_t pos_b64_non_parsed, int variant)
sodium_bin2base64
void sodium_bin2base64(char[] b64, ubyte[] bin, int variant)
sodium_bin2hex
void sodium_bin2hex(char[] hex, ubyte[] bin)

Hexadecimal encoding. The sodium_bin2hex() function converts the bytes stored at bin into a hexadecimal string.

sodium_compare
int sodium_compare(ubyte[] b1_, ubyte[] b2_)

Comparing large numbers.

sodium_hex2bin
bool sodium_hex2bin(ubyte[] bin, char[] hex, string ignore_nullterminated, size_t bin_len, size_t pos_hex_non_parsed)

Hexadecimal decoding. The sodium_hex2bin() function parses a hexadecimal string hex and converts it to a byte sequence bin. ignore_nullterminated is a string of characters to skip. ignore_nullterminated's last character MUST be '\0' in order to save allocating a new C string and thus be @nogc For example, the string ": \0" allows colons and spaces to be present at any locations in the hexadecimal string. These characters will just be ignored. As a result, "69:FC", "69 FC", "69 : FC" and "69FC" will be valid inputs, and will produce the same output. ignore_nullterminated can be set to null in order to disallow any non-hexadecimal character. bin.length is the maximum number of bytes to put into bin, thus bin has to be sized appropriately in advance as >= hex.length/2, otherwise the function throws. The parser stops when a non-hexadecimal, non-ignored character is found or when bin.length bytes have been written. bin_len is the number of bytes that actually got written into bin. @returns always true (success) and sets pos_hex_non_parsed to the position within hex following the last parsed character. It evaluates in constant time for a given length and format.

sodium_increment
void sodium_increment(ubyte[] n)

Incrementing large numbers. The sodium_increment() function takes an ubyte array representing an arbitrary-long unsigned number, and increments it. It runs in constant-time for a given length, and considers the number to be encoded in little- endian format. sodium_increment() can be used to increment nonces in constant time. This function was introduced in libsodium 1.0.4. Does nothing if the array is null

sodium_is_zero
bool sodium_is_zero(ubyte[] a)

Testing for all zeros.

sodium_memcmp
bool sodium_memcmp(ubyte[] b1_, ubyte[] b2_)

Constant-time test for equality

sodium_memzero
void sodium_memzero(ubyte[] a)

Zeroing memory.

sodium_pad
bool sodium_pad(size_t padded_buflen, ubyte[] buf, size_t unpadded_buflen, size_t blocksize)
sodium_sub
void sodium_sub(ubyte[] a, ubyte[] b)

Substracting large numbers The sodium_sub() function accepts two arrays of unsigned numbers encoded in little- endian format, a and b, both of size len bytes. It computes (a - b) mod 2^(8*len) in constant time for a given length, and overwrites a with the result.

sodium_unpad
bool sodium_unpad(size_t unpadded_buflen, ubyte[] buf, size_t padded_buflen, size_t blocksize)

Meta