🧰 Functions

âš™ rotr32

Rotate right (32-bit unsigned)

FunctionType
rotr32(x: number, n: number) => number

âš™ rotl32

Rotate left (32-bit unsigned)

FunctionType
rotl32(x: number, n: number) => number

âš™ stringToBytes

Converts a UTF-8 string into an array of byte values (0-255)

FunctionType
stringToBytes(str: string) => number[]

âš™ bytesToString

Converts an array of byte values (0-255) into a UTF-8 string

FunctionType
bytesToString(bytes: number[]) => string

âš™ bytesToHex

Converts byte array to Hex string

FunctionType
bytesToHex(bytes: number[]) => string

âš™ hexToBytes

Converts Hex string to byte array

FunctionType
hexToBytes(hex: string) => number[]

âš™ constantTimeCompare

Compares two strings in constant time to prevent timing attacks

FunctionType
constantTimeCompare(a: string, b: string) => boolean

âš™ generateRandomHex

Generates pseudo-random hex string of specified byte length

FunctionType
generateRandomHex(byteCount: number) => string

âš™ generateKey

Generates a 128-bit (16-byte) random hex key suitable for SPECK-64/128

FunctionType
generateKey() => string

âš™ generateIV

Generates a 64-bit (8-byte) random hex IV suitable for SPECK-64/128 CTR

FunctionType
generateIV() => string

âš™ generateSalt

Generates a 128-bit (16-byte) random hex salt

FunctionType
generateSalt() => string

âš™ speckExpandKey

SPECK-64/128 key expansion algorithm. Takes 128-bit key (4 x 32-bit words) and yields 27 round keys.

FunctionType
speckExpandKey(k: number[]) => number[]

âš™ speckEncryptBlock

Encrypts a single 64-bit block (two 32-bit words x, y) using SPECK-64/128

FunctionType
speckEncryptBlock(x: number, y: number, rk: number[]) => [number, number]

âš™ speckCTR

SPECK-64/128 Counter (CTR) Mode Cipher. Encrypts/Decrypts arbitrary data using 128-bit key and 64-bit IV.

FunctionType
speckCTR(dataBytes: number[], keyHex: string, ivHex: string) => number[]

âš™ blake2s

Computes BLAKE2s-256 hash or keyed MAC over arbitrary input

FunctionType
blake2s(inputStrOrBytes: string or number[], keyHex?: string or undefined) => string

âš™ deriveKey

Derives a 128-bit Key Encryption Key (KEK) from a passphrase and salt. Performs iterated BLAKE2s passes to slow down offline password cracking attempts.

FunctionType
deriveKey(passphrase: string, saltHex: string, rounds?: number) => string

âš™ encryptText

Encrypts a text string with SPECK-64/128 CTR and returns a Hex string

FunctionType
encryptText(plaintext: string, keyHex: string, ivHex: string) => string

âš™ decryptText

Decrypts a Hex ciphertext string with SPECK-64/128 CTR and returns text

FunctionType
decryptText(ciphertextHex: string, keyHex: string, ivHex: string) => string

🔧 Constants

âš™ SPECK_KEY_BYTES

Standard key, IV, salt, and digest byte lengths

ConstantType
SPECK_KEY_BYTES16

âš™ SPECK_IV_BYTES

ConstantType
SPECK_IV_BYTES8

âš™ SALT_BYTES

ConstantType
SALT_BYTES16

âš™ BLAKE2S_DIGEST_BYTES

ConstantType
BLAKE2S_DIGEST_BYTES32

âš™ DEFAULT_KEY_DERIVATION_ROUNDS

ConstantType
DEFAULT_KEY_DERIVATION_ROUNDS500