Skip to content

Expand crypto parity coverage - #1419

Merged
TheHypnoo merged 8 commits into
mainfrom
feat/crypto-parity-expansion
May 23, 2026
Merged

Expand crypto parity coverage#1419
TheHypnoo merged 8 commits into
mainfrom
feat/crypto-parity-expansion

Conversation

@TheHypnoo

Copy link
Copy Markdown
Member

Summary

Expands Perry's node:crypto parity coverage with a broad deterministic test suite curated from Node.js, Bun, and Deno crypto compatibility coverage, and closes the compatibility gaps discovered while porting those cases.

This PR adds granular TypeScript parity tests for the main crypto surfaces and documents the intentionally deferred gaps in test-parity/node-suite/crypto/README.md.

Covered areas

  • Module import shapes, inventory helpers, constants, FIPS/secure heap API shape, and function/method name parity.
  • Hash/HMAC coverage including algorithm aliases, encodings, buffer output, XOF output length, update input encodings, digest reuse, crypto.hash(), and legacy callable constructors.
  • PBKDF2, HKDF, scrypt, random bytes/fill/int/UUID, prime generation/checking, and timing-safe equality.
  • AES-CBC/ECB/GCM/KW coverage including auto-padding, AAD options, auth tags, SecretKey input, and getCipherInfo().
  • RSA/RSA-PSS sign/verify/encrypt/decrypt, EC P-256, DH/ECDH/X25519, key generation, KeyObject/JWK coverage, and async callback APIs.
  • WebCrypto coverage for digest, HMAC, AES-CBC/CTR/GCM/KW, ECDSA/ECDH P-256, Ed25519, X25519, RSA-OAEP/RSA-PSS/RSASSA, JWK import/export, deriveBits/deriveKey, and wrap/unwrap.

Runtime/codegen changes

  • Extends node:crypto native support for the parity suite areas above.
  • Adds handle property dispatch for crypto method-as-value reads.
  • Adds SecretKey, KeyObject, cipher, WebCrypto, asymmetric, random, and async callback compatibility behavior needed by the new tests.
  • Propagates Hash.update() / Hmac.update() input encodings through the codegen fallback path.

Validation

Latest local run:

find test-parity/node-suite/crypto -type d -name .perry-cache -prune -exec rm -rf {} + && ./run_parity_tests.sh --suite node-suite --module crypto

Parity Pass:   181
Parity Fail:   0
Compile Fail:  0
Skipped:       0
Parity Rate:   100.0%

Report generated locally at:

test-parity/reports/parity_report_20260522_200142.json

Known follow-up gaps

These are intentionally left for future PRs:

  • X509Certificate and crypto.Certificate / SPKAC APIs.
  • Full Node stream-backed crypto transform semantics.
  • Exact DER/PEM encrypted key import/export variants and OpenSSL-specific error codes.
  • WebCrypto P-384/P-521, Ed448/X448, AES-OCB, ChaCha20-Poly1305, PQC/KMAC/Argon2 surfaces.
  • AES-GCM 4-byte and 8-byte auth tags; the current RustCrypto backend supports the 12-16 byte tag sizes covered here.
  • Exact CryptoKey/KeyObject.toCryptoKey() asymmetric object identity/prototype behavior.
  • Large-prime/BigInt prime generation parity beyond the practical deterministic coverage in this suite.

@TheHypnoo

Copy link
Copy Markdown
Member Author

Note on CI flake: the cargo-test job is intermittently failing with signal: 11, SIGSEGV: invalid memory reference in the perry-runtime test binary, on the same test binary hash (perry_runtime-cdd58eada73e5edc) that other unrelated PRs hit at the same time. Sample affected PRs:

  • fix/perf-measure-missing-mark-1403 (commit 1e11ff75) — failed at 21:14
  • feat/fs-parity-expansion (commit 89036aad) — failed at 21:10
  • feat/crypto-parity-expansion (this PR) — failed at 20:51, 20:30

Other PRs that ran in between (fix/perf-observer-no-cb-1388, fix/perf-resource-timing-1339, fix/perf-tojson-1338) passed cleanly. No GC files changed in this PR vs main (git diff origin/main..HEAD -- crates/perry-runtime/src/gc/ is empty), so the SIGSEGV is not introduced by these changes. Local reproduction shows multiple gc::tests::oldgen::* tests deadlocking on a shared Mutex, consistent with a recently-introduced parallel-test ordering issue rather than memory corruption.

Will retry the Tests workflow once if it fails again on the latest push (commit ca761af9).

@TheHypnoo
TheHypnoo force-pushed the feat/crypto-parity-expansion branch from ca761af to 04225ca Compare May 23, 2026 07:44
@TheHypnoo
TheHypnoo marked this pull request as ready for review May 23, 2026 07:53
TheHypnoo added 2 commits May 23, 2026 09:53
The PR-side .export/.equals routing fix plus main's process-module
additions pushed crates/perry-runtime/src/object/field_get_set.rs to
2035 lines (over the 2000 threshold). Splitting is tracked under #1435;
allowlist with a one-line rationale until then.
…pansion

# Conflicts:
#	docs/api/perry.d.ts
#	docs/src/api/reference.md
proggeramlug added a commit that referenced this pull request May 23, 2026
…#1511)

The named-import path (`import { randomBytes } from "node:crypto";
randomBytes(16)`, lowered in `globals.rs`) and the dotted path
(`crypto.randomBytes(16)`, lowered in `module_static.rs`) used to
inline the same `Expr::CryptoRandom*` constructions side-by-side.
Each new crypto method added required parallel edits at both sites,
and #1419 had to keep the two lists manually in sync.

New `expr_call/crypto.rs` submodule with
`lower_crypto_passthrough(method, args)` (and a cheap
`is_passthrough_method(method)` pre-check so the caller can avoid
moving `args` into the helper when the method isn't ours). Both call
sites delegate to it.

Today's covered set: `randomBytes`, `randomUUID`, `randomFillSync`.
Methods whose lowering shape diverges between sites — dotted-only
`sha256` / `md5` (dedicated shortcuts), dotted-only `getRandomValues`
(rewrites into an instance method on the buffer), named-import-only
`createSecretKey` (synthetic PropertyGet through NativeModuleRef) —
stay at their call site. The shared helper grows naturally when a
method's shape lines up across both sites.

Pure refactor: behavior identical, verified by exercising
`randomBytes(n)` / `randomUUID()` / `randomFillSync(buf)` through
both shapes and confirming identical output.
TheHypnoo added 4 commits May 23, 2026 14:43
…pansion

# Conflicts:
#	crates/perry-codegen/src/type_analysis.rs
#	crates/perry-hir/src/lower/expr_call/globals.rs
#	crates/perry-hir/src/lower/expr_call/module_static.rs
#	docs/api/perry.d.ts
#	docs/src/api/reference.md
…pansion

# Conflicts:
#	docs/api/perry.d.ts
#	docs/src/api/reference.md
The #1419 fast-path gate refinements combined with main's process /
fs / perf_hooks Expr additions pushed
crates/perry-codegen/src/expr/calls.rs to 2059 lines.
Splitting tracked under #1435.
The PR's earlier amend that converted aes_gcm_rejects_192_bit_key into
aes_gcm_round_trip_192 was lost during the latest merge with main.
Restore the round-trip assertion so cargo-test stays green for the
AES-192-GCM support added in #1419.
@TheHypnoo
TheHypnoo merged commit d3668ee into main May 23, 2026
9 checks passed
@TheHypnoo
TheHypnoo deleted the feat/crypto-parity-expansion branch May 23, 2026 13:17
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