perf(auth): use ring for DPoP P-256 signature verification#43
Conversation
|
Please review and let me know if there's anything that should be changed or improved |
|
@CapThunder19 thanks for taking this issue. Please first resolve the conflicts with the main branch after merging this: #41 |
Merging this PR will improve performance by ×2.5
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | dpop_verify_cached_p256 |
1,040.9 µs | 299.3 µs | ×3.5 |
| ⚡ | dpop_sign_verify_p256 |
1,665.7 µs | 937.7 µs | +77.63% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing CapThunder19:perf/dpop-ring-verify (0bc1a3d) with main (b3917a9)
|
Pls review it I have fixed the issue |
m2papierz
left a comment
There was a problem hiding this comment.
The core migration is correct - right algorithm (ECDSA_P256_SHA256_FIXED = raw r||s, matching JWT ES256), security invariants intact, public API unchanged, all existing tests passing. Solid work.
Requesting changes on one high-severity performance issue and a handful of medium/low items. The high item is that the cache-hit hot path now pays for a P256VerifyingKey clone -> to_encoded_point -> ring re-parse round-trip on every request, which partially undermines the stated ~60–70 µs savings goal. The fix is changing the cache value type to raw [u8; 65] - the issue itself anticipated this, and since this PR already touches both the verify path and the cache insertion site, it belongs here rather than in a follow-up.
See inline comments for details on each item.
|
pls review |
m2papierz
left a comment
There was a problem hiding this comment.
@CapThunder19 all resolved correctly. I am merging the PR. Thanks again for your contribution!
Summary
Replace RustCrypto
p256signature verification withringin the DPoP verification hot path.The previous implementation reconstructed a
P256VerifyingKeyfrom the JWK coordinates and verified ES256 signatures usingp256::ecdsa::VerifyingKey::verify. This change switches verification toring::signature::UnparsedPublicKey::verifywithECDSA_P256_SHA256_FIXED.The public API of
verify_dpop_proofremains unchanged. Client-side DPoP signing continues to usep256.Changes
DPoP verification
P256VerifyingKey::verifywithring::signature::UnparsedPublicKey::verify.vk_from_xy()withbuild_sec1_uncompressed().0x04 || x || y).verify_sig().Dependencies
ringas a direct dependency oflatchgate-auth.Benchmarks
dpop_verify_only_p256benchmark to measure server-side DPoP verification cost in isolation.dpop_sign_verify_p256benchmark for round-trip regression tracking.Tests
latchgate-authtest suite passes unchanged.Security
This change does not alter the cryptographic algorithm:
(r || s)formatOnly the verification implementation changes from RustCrypto
p256toring.The DPoP proof is still verified on every request and all existing security checks remain intact.
Validation
cargo check -p latchgate-authcargo test -p latchgate-authsolves #39