crypto/core
sourcecrypto/core.sx
pub enum CryptoError = { InvalidHexLength, InvalidHexDigit, InvalidBase64Length, InvalidBase64Char, InvalidBase64Padding, OutOfMemory, FileOpenFailed, FileReadFailed }
Cryptography related failure enumeration.
Variants
InvalidHexLengthInvalidHexDigitInvalidBase64LengthInvalidBase64CharInvalidBase64PaddingOutOfMemoryFileOpenFailedFileReadFailed
pub fn hash_fnv(key: usize) usize = trust { ... }
FNV-1a hash.
This is for pointer-sized keys treated as raw integers.
fn bytes_ptr[T](data: T) ref void
fn bytes_len[T](data: T) i64
fn alloc_in[A: allocators.Allocator](ac: A, len: i64) ref void
fn alloc_heap_string(len: i64) str.String = trust { ... }
fn alloc_string[A: allocators.Allocator](ac: A, len: i64) str.String
fn copy_string[A: allocators.Allocator](ac: A, src: str.String) str.String
fn store_u32_slot(buf: ref void, idx: i64, value: u64) void = trust { ... }
fn load_u32_slot(buf: ref void, idx: i64) u64 = trust { ... }
fn read_be_u32(buf: ref void, offset: i64) u64 = trust { ... }
fn write_be_u32(buf: ref void, offset: i64, value: u64) void = trust { ... }
fn rotr32(x: u64, n: i64) u64
fn sha256_ch(x: u64, y: u64, z: u64) u64
fn sha256_maj(x: u64, y: u64, z: u64) u64
fn sha256_big_sigma0(x: u64) u64
fn sha256_big_sigma1(x: u64) u64
fn sha256_small_sigma0(x: u64) u64
fn sha256_small_sigma1(x: u64) u64
fn add32(a: u64, b: u64) u64
fn add32_4(a: u64, b: u64, c: u64, d: u64) u64
fn add32_5(a: u64, b: u64, c: u64, d: u64, e: u64) u64
fn add32_6(a: u64, b: u64, c: u64, d: u64, e: u64, f: u64) u64
fn sha256_heap[T](data: T) str.String
Compute the SHA-256 digest of a string or byte str.
Returns a 32-byte String allocated with the provided allocator.
pub fn sha256[A: allocators.Allocator, T](ac: A, data: T) str.String
Compute the SHA-256 digest of a string or byte str.
Returns a 32-byte String allocated with the provided allocator.
fn rotl32(x: u64, n: i64) u64
fn sha1_compute(src_ptr: ref u8, src_len: i64, out_buf: ref u8) bool = trust { ... }
Write the SHA-1 digest of a byte buffer into out_buf (20 bytes).
pub fn sha1_len[A: allocators.Allocator](ac: A, src_ptr: ref u8, src_len: i64) str.String
Compute the SHA-1 digest of a byte buffer with an explicit length.
This is the length-aware variant of sha1, useful for binary data such as git objects that may contain NUL bytes.
pub fn sha1_cstr[A: allocators.GeneralAllocator](ac: A, src_ptr: ref u8, src_len: i64) option[ref u8]
Compute the raw 20-byte SHA-1 digest of a buffer with an explicit length.
The returned buffer is allocated with the provided allocator and is not NUL-terminated.
pub fn sha1[A: allocators.Allocator, T](ac: A, data: T) str.String
Compute the SHA-1 digest of a string or byte str.
Returns a 20-byte String allocated with the provided allocator.
fn hex_char(nibble: u8) u8
pub fn hex_encode[A: allocators.Allocator, T](ac: A, data: T) ref u8
Hex-encode a string or byte str.
Returns a newly allocated lowercase C string from the provided allocator.
pub fn hex_decode[A: allocators.Allocator](ac: A, text: ref u8) result[str.String, CryptoError]
Decode a hexadecimal C str.
Returns an owned byte String from the provided allocator on success.
pub fn base64_encode[A: allocators.Allocator, T](ac: A, data: T) ref u8
Base64-encode a string or byte string using the standard alphabet.
Returns a newly allocated C string with padding from the provided allocator.
pub fn base64_decode[A: allocators.Allocator](ac: A, text: ref u8) result[str.String, CryptoError]
Decode a standard base64 C string with = padding.
Returns an owned byte String from the provided allocator on success.
pub fn ct_eq[T](a: T, b: T) bool
Compare two strings or byte strings without early exit.
fn hmac_sha256_heap[T](key: T, data: T) str.String
Compute HMAC-SHA256 for the given key and data.
Returns a 32-byte String allocated with the provided allocator.
pub fn hmac_sha256[A: allocators.Allocator, T](ac: A, key: T, data: T) str.String
Compute HMAC-SHA256 for the given key and data.
Returns a 32-byte String allocated with the provided allocator.
pub fn unique_nonce[A: allocators.Allocator](ac: A) ref u8
Generate a nonce-safe random str.
Returns 24 random bytes encoded as lowercase hex (48 chars) from the provided allocator.
pub fn hash_file_sha256[A: allocators.Allocator](ac: A, path: ref u8) result[str.String, CryptoError]
Compute the SHA-256 digest of an entire file.
Returns the 32-byte digest as a String allocated with the provided allocator.