Repository navigation
Description
Summary
Export ECDSA and ECDH (P-256, P-384, P-521, secp256k1) from cas-lib over cas-core-lib's C ABI, so cas-dotnet-sdk can bind it.
Blocked by: Cryptographic-API-Services/cas-lib#162 and the cas-lib release that contains it.
Upstream
cas-lib: Cryptographic-API-Services/cas-lib#162 (ECDSA and ECDH over P-256, P-384, P-521 and secp256k1). Not implemented in cas-lib yet; this issue tracks exposing it once it ships.
API shape in cas-lib: Keys are PEM strings (PKCS#8 private, SPKI public); signatures are bytes; ECDH returns a shared secret.
Scope
- ECDSA P-256 / SHA-256 (ES256): keygen, sign, verify
- ECDSA P-384 / SHA-384 (ES384)
- ECDSA P-521 / SHA-512 (ES512)
- ECDSA secp256k1 / SHA-256 (ES256K)
- Signature encodings: P1363 (fixed size) and DER
- ECDH on all four curves
Feature-specific notes
- PEM keys cross as C strings: take
*const c_char, return*mut c_charviaCString::into_raw(freed withfree_cstring). Key-pair results with two strings need afree_<struct>. - The ECDH shared secret is a secret: zeroize every copy and recommend HKDF over using it directly. For .NET, add an interop test against
System.Security.Cryptography.ECDsa; for TS, against WebCrypto.
Tests
Run the same vectors cas-lib uses through this repo's harness: Wycheproof ecdsa_secp256r1_sha256_test.json, ecdsa_secp384r1_sha384_test.json, ecdsa_secp521r1_sha512_test.json, ecdsa_secp256k1_sha256_test.json (+ _p1363 variants), ecdh_secp256r1/384r1/521r1/256k1_test.json; NIST CAVP ECDSA SigVer / KAS ECC KATs.
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