Skip to content

feat: export HKDF-SHA256 and HKDF-SHA512 (extract, expand, derive) #146

Backlog

Description

@WingZer0o

Summary

cas-lib 0.7.1 added cas_lib::kdf (Cryptographic-API-Services/cas-lib#152) with CASHkdfSha256 / CASHkdfSha512 implementing CASHKDF (extract, expand, derive). cas-core-lib doesn't export it yet. cas-typescript-sdk already wraps it; this brings cas-core-lib (and through it cas-dotnet-sdk) level.

Blocked by: #145 (HKDF needs cas-lib 0.7.1 or later).

Work

  • New src/hkdf/ module (mod.rs + types.rs), registered in src/lib.rs.
  • hkdf_sha256_extract / hkdf_sha256_expand / hkdf_sha256_derive and the SHA-512 equivalents. Inputs: salt, ikm, prk, info as pointer + length; output length as usize.
  • Return the PRK / OKM through export_bytes (ZeroAlloc wipes it on free_bytes).
  • Out-of-range output lengths (0, or above 255 × hash length) and a PRK shorter than the hash length come back as cas-lib's InvalidParameters / InvalidKey codes, not a panic.

Tests

  • Wycheproof hkdf_sha256_test.json / hkdf_sha512_test.json run in cas-lib and cas-typescript-sdk; here, add inline tests that extract-then-expand equals derive, plus the length-limit errors.

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