Manuscript Documentation
v0.1.0

@std/crypto.ms#

Import each required symbol with import Name from "@std/crypto.ms".

CryptoError Alternative#

Errors returned when cryptographic input is invalid or an algorithm is unavailable.

Manuscript
type CryptoError:
    case InvalidInput
    case Unsupported
    case AuthenticationFailed
Manuscript
impl Error for CryptoError:
    fn message() -> String:

CryptoError.AuthenticationFailed#

AES-GCM authentication failed, including a wrong key, nonce, associated data or altered ciphertext.

Manuscript
case AuthenticationFailed

CryptoError.InvalidInput#

Key/seed/nonce length, derivation iteration/count arguments or AES key size is invalid.

Manuscript
case InvalidInput

CryptoError.Unsupported#

The HMAC String selector is not exactly sha256, sha384 or sha512.

Manuscript
case Unsupported

CryptoError.Error.message#

Returns a cryptography-prefixed diagnostic without exposing keys, plaintext or ciphertext.

Manuscript
fn message() -> String:

HashAlgorithm Alternative#

Selects a supported SHA-2 algorithm without a runtime string spelling check. Existing hash functions and hmac(algorithm: String) remain available.

Manuscript
type HashAlgorithm:
    case Sha256
    case Sha384
    case Sha512
    fn digest(data: Bytes) -> Bytes:
    fn hmac(key: Bytes, data: Bytes) -> Result[Bytes, CryptoError]:

HashAlgorithm.Sha256#

SHA-256, producing a 32-byte digest or HMAC.

Manuscript
case Sha256

HashAlgorithm.Sha384#

SHA-384, producing a 48-byte digest or HMAC.

Manuscript
case Sha384

HashAlgorithm.Sha512#

SHA-512, producing a 64-byte digest or HMAC.

Manuscript
case Sha512

HashAlgorithm.digest#

Computes this algorithm’s digest, checking cancellation between chunks.

Manuscript
fn digest(data: Bytes) -> Bytes:

HashAlgorithm.hmac#

Computes HMAC with this algorithm and retains CryptoError results.

Manuscript
fn hmac(key: Bytes, data: Bytes) -> Result[Bytes, CryptoError]:

constant_time_equal Function#

Compares byte strings without making the comparison time depend on their contents.

Manuscript
fn constant_time_equal(left: Bytes, right: Bytes) -> Bool:

derive_key Function#

Derives a key with PBKDF2-HMAC-SHA-256 using the supplied iteration count and length.

Manuscript
fn derive_key(password: Bytes, salt: Bytes, iterations: Int, length: Int) -> Result[Bytes, CryptoError]:

hmac Function#

Computes an HMAC using exactly sha256, sha384, or sha512 (case-sensitive). Other algorithms return CryptoError.Unsupported.

Manuscript
fn hmac(key: Bytes, data: Bytes, algorithm: String) -> Result[Bytes, CryptoError]:

open Function#

Authenticates and decrypts a value produced by seal using AES-GCM.

Manuscript
fn open(key: Bytes, nonce: Bytes, ciphertext: Bytes, associated_data: Bytes) -> Result[Bytes, CryptoError]:

public_key Function#

Derives the Ed25519 public key corresponding to a 32-byte private seed.

Manuscript
fn public_key(seed: Bytes) -> Result[Bytes, CryptoError]:

seal Function#

Encrypts and authenticates plaintext with AES-GCM. The caller supplies a unique nonce.

Manuscript
fn seal(key: Bytes, nonce: Bytes, plaintext: Bytes, associated_data: Bytes) -> Result[Bytes, CryptoError]:

sha256 Function#

Returns the SHA-256 digest of the input.

Manuscript
fn sha256(data: Bytes) -> Bytes:

sha384 Function#

Returns the SHA-384 digest of the input.

Manuscript
fn sha384(data: Bytes) -> Bytes:

sha512 Function#

Returns the SHA-512 digest of the input.

Manuscript
fn sha512(data: Bytes) -> Bytes:

sign Function#

Signs data with an Ed25519 private seed.

Manuscript
fn sign(seed: Bytes, data: Bytes) -> Result[Bytes, CryptoError]:

verify Function#

Verifies an Ed25519 signature with a public key.

Manuscript
fn verify(key: Bytes, data: Bytes, signature: Bytes) -> Bool: