abla/crypto

Generated from source.

Import with import "abla/crypto".

Source: abla/crypto/entry.ab

ablaBase64Encode (extern)

noescape extern:"intrinsic" fun ablaBase64Encode(value: string): string

Phase-safe entry point: staged execution provides the same byte semantics, while native and Wasm targets bind this symbol to the contiguous Abla runtime implementation in abla/runtime/self.

ablaBase64Decode (extern)

noescape extern:"intrinsic" fun ablaBase64Decode(value: string): string

Returns the bytes decoded from standard Base64, or an empty string for invalid or empty input.

cryptoByteString (fun)

fun cryptoByteString(values: array<int>): string

Returns the byte string in input order, or an empty string if any value is outside 0 through 255.

sha256 (fun)

fun sha256(value: string): string

Returns the 32 raw SHA-256 digest bytes of value.

sha512 (fun)

fun sha512(value: string): string

Returns the 64 raw SHA-512 digest bytes of value.

sha512OfSecret (fun)

fun sha512OfSecret(value: string): string

SHA-512 of a secret value (a key, a seed): as sha512, with the end of the message, which is copied to make the last block, in a buffer that is wiped. The caller still owns value.

sha384OfSecret (fun)

fun sha384OfSecret(value: string): string

SHA-384 of a secret value: as sha384, with the copy of the message's end wiped (see sha512OfSecret).

sha384 (fun)

fun sha384(value: string): string

Returns the 48 raw SHA-384 digest bytes of value.

sha1 (fun)

fun sha1(value: string): string

SHA-1 is provided for protocol compatibility, most notably the RFC 6455 WebSocket opening handshake. Use SHA-256 for new authentication or storage designs. Returns the 20 raw SHA-1 digest bytes of value.

binaryXor (fun)

fun binaryXor(left: string, right: string): string

XORs corresponding bytes of left and right and returns a string as long as the shorter input.

Sha256Stream (class)

class Sha256Stream(
    val state: array<int>,
    val constants: array<int>,
    val schedule: array<int>,
    var pending: string,
    var total: int,
    /** Whether the stream hashes a secret (an HMAC's key pad and message): its pending bytes are then a buffer of its own that is wiped. */
    val secret: bool = false
)

SHA-256 of more bytes than fit in memory, or arrive in pieces. update(), any number of times, then finish(), which gives the same 32 bytes sha256 would. Whole blocks go straight from the string given, with one schedule kept across them.

sha256Stream (fun)

trusted fun sha256Stream(secret: bool = false): Sha256Stream

Creates an empty incremental SHA-256 state.

cryptoOwnedCopy (fun)

trusted fun cryptoOwnedCopy(value: string): string

A copy of value in a buffer of its own, exactly its size: cryptoWipeString may clear it without touching value or anything made from value.

cryptoOwnedJoin (fun)

trusted fun cryptoOwnedJoin(parts: array<string>, length: int): string

The first length bytes of the concatenation of parts, in a buffer of its own (exactly length bytes; no rope, no slice): what an HKDF or PRF output is made into, so that the blocks it came from can be wiped and the output wiped on its own.

cryptoWipeString (fun)

trusted fun cryptoWipeString(secret: string): void

Overwrites the bytes of secret with zeros (volatile stores, which the optimizer keeps). See the rule above: secret must be a string whose buffer this code made, and not read again.

cryptoStringEndsItsBuffer (fun)

trusted fun cryptoStringEndsItsBuffer(value: string): bool

Whether value ends where its buffer ends (the byte after it is the zero every string's buffer has there): false for a slice of something longer, so a function that returns a secret can be tested to return an owned copy and not a view of a bigger secret. A slice that ends at its parent's end is not told apart, and a slice followed by a zero byte is told apart one time in 256: a test runs it on many values.

Sha256Stream.update (extension fun)

fun Sha256Stream.update(value: string): void

Feeds the bytes of value into the digest state. Call this before finish.

Sha256Stream.finish (extension fun)

fun Sha256Stream.finish(): string

Finalizes the state in place and returns the 32 raw digest bytes. Use a fresh stream for another digest.

hmacSha256 (fun)

fun hmacSha256(key: string, message: string): string

Returns the 32 raw HMAC-SHA-256 bytes for message with key.

hmacSha1 (fun)

fun hmacSha1(key: string, message: string): string

HMAC-SHA-1 stands: HMAC doesn't rest on SHA-1's collision resistance. It's here for protocols that require it; new designs use hmacSha256. Returns the 20 raw HMAC-SHA-1 bytes for message with key.

hmacSha384 (fun)

fun hmacSha384(key: string, message: string): string

Returns the 48 raw HMAC-SHA-384 bytes for message with key.

hmacSha512 (fun)

fun hmacSha512(key: string, message: string): string

Returns the 64 raw HMAC-SHA-512 bytes for message with key.

pbkdf2Sha256 (fun)

fun pbkdf2Sha256(password: string, salt: string, iterations: int): string

Derives a 32-byte key from password and salt with PBKDF2-HMAC-SHA-256. Returns an empty string if iterations is outside 1โ€“1000000.

base64Encode (fun)

fun base64Encode(value: string): string

Returns standard Base64 text for the bytes of value.

base64Decode (fun)

fun base64Decode(value: string): string

Decodes standard Base64 value to raw bytes. An empty result can indicate invalid or empty input. Use base64DecodeOrNull to distinguish them.

base64DecodeOrNull (fun)

fun base64DecodeOrNull(value: string): string?

Like base64Decode, but null for invalid input, so it can be told from a valid empty one ("" decodes to "" and base64Decode gives "" for both). Prefer this when the input is not known to be valid.

hexEncode (fun)

fun hexEncode(value: string): string

Returns two lowercase hexadecimal digits per byte of value.

hexDecode (fun)

fun hexDecode(value: string): string

Decodes pairs of hexadecimal digits in value to bytes. Returns an empty string for odd length or invalid digits.

hexDecodeOrNull (fun)

fun hexDecodeOrNull(value: string): string?

Like hexDecode, but null for invalid input, so it can be told from a valid empty one. Prefer this when the input is not known to be valid.

md5 (fun)

fun md5(value: string): string

Returns the 16 raw MD5 digest bytes of value.

constantTimeEquals (fun)

fun constantTimeEquals(left: string, right: string): bool

Compares left and right for byte equality. At runtime equal-length inputs are scanned without an early exit on content differences. Lengths are public.

Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.