fix(ra-tls): stabilize derive_dh_secret encoding#603
Open
Conversation
8e3a225 to
e1faaf4
Compare
e1faaf4 to
38a20df
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #553.
This changes
derive_dh_secretso that the derived X25519 secret no longer depends on library-defined PKCS#8 encoding details.Previously the function:
SHA256(rcgen::KeyPair::serialized_der())and used that as the X25519 private key material.That approach made the derived secret fragile to changes in
rcgen/pkcs8(for example, adding or removing optional PKCS#8 fields could change the DER without changing the underlying key).The new implementation:
rcgen::KeyPairinto a P-256 scalar,PrivateKeyInfofor prime256v1, where only the 32-byte private key and the 65-byte uncompressed public key vary.We then hash this fixed layout with SHA-256. The layout is chosen to exactly match the previous
p256/pkcs8output for P-256 keys, and a regression test (test_derive_dh_secret_compatible_with_previous_encoding) asserts that the new implementation produces the same output as the oldrcgen::KeyPair::serialized_der()-based path.As a result, updating
rcgenorpkcs8can no longer silently change the derived secret, while existing deployments keep using the same derived keys.