Skip to content

chore: add wasm32-unknown-unknown compatibility#20

Merged
27Bslash6 merged 8 commits intomainfrom
feat/wasm32-compat
Mar 15, 2026
Merged

chore: add wasm32-unknown-unknown compatibility#20
27Bslash6 merged 8 commits intomainfrom
feat/wasm32-compat

Conversation

@27Bslash6
Copy link
Contributor

Summary

  • Add wasm32 timing shims (Instant unavailable on wasm32, metrics default to 0)
  • Add Cell<u64> nonce counter fallback for wasm32 (replaces AtomicU64, seeded with getrandom)
  • Add RustCrypto aes-gcm as wasm32 encryption backend (ring requires clang/C asm, doesn't compile on wasm32)
  • Fix: RNG failure now panics instead of silent fallback to seed 0
  • Fix: enable zeroize on aes/aes-gcm deps (scrub round keys on drop)
  • Fix: fold wasm deps into encryption feature (no separate wasm flag needed)
  • Add cross-backend wire format test (ring ↔ aes-gcm roundtrip)

Motivation

The upcoming cachekit-rs Rust SDK targets both native and Cloudflare Workers (wasm32). cachekit-core must compile on wasm32-unknown-unknown with encryption support.

Architecture

  • Native: ring for AES-256-GCM (hardware-accelerated)
  • wasm32: aes-gcm from RustCrypto (pure Rust, compiles on all targets)
  • Same wire format: nonce(12) || ciphertext || tag(16)
  • cfg-gated at function level in encryption/core.rs

Breaking Changes

None. Public API unchanged. Existing consumers (PyO3, N-API) unaffected — they only use native targets.

Test plan

  • 179 native tests pass (cargo test --features encryption)
  • wasm32 compiles (cargo check --target wasm32-unknown-unknown --features encryption --no-default-features)
  • Cross-backend wire format test (ring encrypts → aes-gcm decrypts, and vice versa)
  • wasm32 runtime tests (requires wasm-pack test --node, deferred to CI)

ring doesn't compile on wasm32-unknown-unknown (requires clang for C asm).
Move ring to a target-conditional dep (native only), add aes-gcm from
RustCrypto for wasm32. Both produce identical AES-256-GCM wire format:
[nonce(12)][ciphertext][auth_tag(16)]

Native targets continue using ring for hardware-accelerated performance.
wasm32 targets use aes-gcm (pure Rust) when wasm+encryption features active.

key_derivation.rs unchanged — already uses RustCrypto hkdf/sha2, compiles
on both targets without modification.
- Fold aes-gcm/getrandom into encryption feature (no separate wasm flag needed)
- Enable zeroize on aes/aes-gcm deps (scrub round keys on drop)
- Add cross-backend wire format test (ring <-> aes-gcm roundtrip)
- Remove dead cfg guards inside native-only functions
- Consistency: error messages, min length expression, doc comments
cbindgen 0.29.2 pulls clap 4.6.0 which requires edition2024
(stabilized in Rust 1.85, Feb 2025). Pinning transitive deps
is fragile; bumping MSRV is the correct fix.
aes-gcm brings in getrandom 0.2.x (via crypto-common), proptest
uses 0.3.x, and tempfile/cbindgen uses 0.4.x. Updated skip entries
to use semver ranges instead of exact versions.
@27Bslash6 27Bslash6 merged commit a18730c into main Mar 15, 2026
29 checks passed
@27Bslash6 27Bslash6 deleted the feat/wasm32-compat branch March 15, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant