evp library

A small idiomatic layer over the raw bindings, sized for at_chops and NoPorts: enough to replace their *FfiAlgo classes, no more.

  • Aead: AES-256-GCM, AES-128-GCM, ChaCha20-Poly1305 (seal / open).
  • Cipher: AES-CTR with 128/192/256-bit keys, one-shot and streaming.
  • X25519: key pairs and agreement.
  • MlKem768: key pairs (optionally from a 64-byte seed), encaps, decaps.
  • MlDsa65: key pairs (optionally from a 32-byte seed), sign, verify.
  • Random: RAND_bytes / RAND_priv_bytes.
  • Digest: SHA-2 / SHA-3, one-shot and streaming.
  • Hmac: HMAC over SHA-2 with constant-time verification.
  • Hkdf: HKDF (RFC 5869) key derivation.

Keys are plain byte strings in OpenSSL's raw encodings, so they round-trip with at_chops and with any other OpenSSL-based implementation. Errors from libcrypto surface as OpenSSLException; failed AEAD authentication as AuthenticationException.

The raw C API in package:openssl3/openssl3.dart remains the primary surface; this library exists so common operations need no dart:ffi.

Classes

Aead
An AEAD cipher bound to a key.
Cipher
An unauthenticated block-cipher mode fetched by name from the default provider, e.g. AES-256-CTR.
CipherStream
Incremental encryption/decryption state (an EVP_CIPHER_CTX).
Digest
A digest algorithm fetched by name from the default provider.
DigestStream
Incremental digest state (an EVP_MD_CTX). Call finish exactly once.
Encapsulation
Result of MlKem768.encaps.
Hkdf
Hmac
HMAC with a SHA-2 digest, keyed once and reusable.
MlDsa65
MlDsa65KeyPair
An ML-DSA-65 key pair. seed is the 32-byte FIPS 204 seed that fully determines the pair; privateKey is the 4032-byte expanded key.
MlKem768
MlKem768KeyPair
An ML-KEM-768 key pair.
Random
RAND_bytes / RAND_priv_bytes as Dart.
SealedBox
Ciphertext plus its authentication tag, kept separate so callers can pick their own wire format. combined is ciphertext || tag, the layout at_chops' AesGcm256FfiAlgo and most protocols use.
X25519
X25519KeyPair
A raw X25519 key pair: 32-byte public and private keys.

Exceptions / Errors

AuthenticationException
Thrown by Aead.open when the tag does not verify. Deliberately carries no detail: the data or the key/nonce/AAD are wrong, and that is all a caller should learn.
OpenSSLException
An error reported by libcrypto, taken from ERR_get_error().