Skip to content

feat: export streaming AEAD (STREAM-BE32 over AES-256-GCM and ChaCha20-Poly1305) over the C FFI #151

Backlog

Description

@WingZer0o

Summary

Export streaming AEAD (STREAM-BE32 over AES-256-GCM and ChaCha20-Poly1305) from cas-lib over cas-core-lib's C ABI, so cas-dotnet-sdk can bind it.

Blocked by: Cryptographic-API-Services/cas-lib#156 and the cas-lib release that contains it.

Upstream

cas-lib: Cryptographic-API-Services/cas-lib#156 (Streaming AEAD (STREAM) for chunked encryption). Not implemented in cas-lib yet; this issue tracks exposing it once it ships.

API shape in cas-lib: Design first. The API is stateful, so whatever shape cas-lib picks (opaque handle or explicit per-chunk functions) has to cross the FFI without Rust lifetimes. Post the proposed API in this issue before implementing.

Scope

Feature-specific notes

  • Stateful API: an opaque handle (*_new returning a boxed state pointer, *_push / *_next, *_finish / *_last, and *_free), with the state zeroized on free. Freeing twice or passing a null handle must be harmless or return an error code.
  • It must be impossible to forget the last-chunk flag, and decryption must fail on truncation.

Tests

Run the same vectors cas-lib uses through this repo's harness: The round-trip / reorder / drop / truncate tests cas-lib adds, reproduced here.

Implementation notes (cas-core-lib FFI conventions, see CLAUDE.md)

  • #[no_mangle] pub extern "C" functions; bytes cross as pointer + usize length, never slices or Vecs.
  • Results are #[repr(C)] structs in the module's types.rs with an error_code; buffers are handed out with export_bytes (never as_mut_ptr + forget), strings with CString::into_raw.
  • Result structs that hold more than one buffer get a free_<struct> and a row in the CLAUDE.md "Ownership of returned memory" table; every new struct gets the ownership rustdoc (csbindgen copies it into the C# bindings).
  • Null or bad pointers return an error code instead of panicking (fix!: reject bad FFI pointers instead of panicking, and report keygen failures #144 pattern); the body delegates straight to cas-lib, with no crypto decisions here.
  • If cas-lib adds a CasError variant, map it to the next appended numeric code (the mapping is an append-only ABI contract consumed by cas-dotnet-sdk).
  • Inline #[test] round-trip, error-path and free tests in the module.

Acceptance criteria

  • CI green on Linux, Windows and macOS (--locked builds).
  • PR title follows Conventional Commits. Don't bump the version or edit CHANGELOG.md by hand; release-please does that.

Activity

  1. added
    enhancement
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions