Repository navigation
Description
Summary
Export NaCl/libsodium-compatible crypto_box, sealed boxes, secretbox, kx and secretstream from cas-lib over cas-core-lib's C ABI, so cas-dotnet-sdk can bind it.
Blocked by: Cryptographic-API-Services/cas-lib#166 and the cas-lib release that contains it.
Upstream
cas-lib: Cryptographic-API-Services/cas-lib#166 (NaCl/libsodium compatibility: crypto_box, sealed boxes, crypto_secretbox, crypto_kx, secretstream). Not implemented in cas-lib yet; this issue tracks exposing it once it ships.
API shape in cas-lib: Byte-compatible with libsodium. secretstream is stateful (push / pull with tags), like the STREAM issue.
Scope
-
crypto_boxkeygen, seal / open (XSalsa20 and XChaCha20) - Sealed boxes
-
crypto_secretboxseal / open -
crypto_kxclient / server session keys -
crypto_secretstream_xchacha20poly1305push / pull
Feature-specific notes
- Stateful API: an opaque handle (
*_newreturning 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. - Add an interop test against the platform's libsodium binding (TS:
libsodium-wrappersas a dev dependency; .NET: a libsodium vector file), since byte compatibility is the point.secretstreamneeds the same stateful-handle design as the STREAM issue.
Tests
Run the same vectors cas-lib uses through this repo's harness: Wycheproof xchacha20_poly1305_secretstream_test.json; cross-compatibility vectors generated with libsodium / PyNaCl.
Implementation notes (cas-core-lib FFI conventions, see CLAUDE.md)
#[no_mangle] pub extern "C"functions; bytes cross as pointer +usizelength, never slices orVecs.- Results are
#[repr(C)]structs in the module'stypes.rswith anerror_code; buffers are handed out withexport_bytes(neveras_mut_ptr+forget), strings withCString::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
CasErrorvariant, 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 (
--lockedbuilds). - PR title follows Conventional Commits. Don't bump the version or edit
CHANGELOG.mdby hand; release-please does that.
Activity