Skip to content

Key types#56

Merged
jazzz merged 12 commits intomainfrom
jazzz/keys
Feb 18, 2026
Merged

Key types#56
jazzz merged 12 commits intomainfrom
jazzz/keys

Conversation

@jazzz
Copy link
Collaborator

@jazzz jazzz commented Feb 16, 2026

This PR provides better handling of key material. It separates the key updates from #37 which have more alignment than the rest of the changes.

  • Renames SecretKeys to SymmetricKey32 keys for added clarity
  • Adds internal type PublicKey to isolate from external dependencies
  • Adds internal type PrivateKey to isolate from external dependencies
  • Cleans up Conversations crate to use new types.
  • Remove InstallationKeypair from PrivateV1Convo constructors.

@jazzz jazzz marked this pull request as ready for review February 16, 2026 17:11
@jazzz jazzz requested a review from osmaczko February 16, 2026 17:54
@osmaczko osmaczko requested a review from Copilot February 17, 2026 18:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors key handling to better encapsulate key material within the crypto crate, reducing direct dependency on x25519-dalek types in downstream crates and clarifying symmetric vs asymmetric key usage.

Changes:

  • Introduces internal PrivateKey, PublicKey, and SymmetricKey32 types in crypto, replacing SecretKey/raw [u8; 32] usage in updated call sites.
  • Updates X3DH and XEdDSA signing APIs to accept the new internal key types.
  • Migrates conversations inbox handshake/intro/identity and PrivateV1Convo initialization to the new key types and removes InstallationKeypair from PrivateV1Convo constructors.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crypto/src/keys.rs Adds internal key newtypes and a generic symmetric key container with zeroize-on-drop.
crypto/src/lib.rs Re-exports new key types from crypto public API.
crypto/src/x3dh.rs Switches X3DH DH outputs/shared secret derivation to SymmetricKey32 and uses PrivateKey/PublicKey.
crypto/src/xeddsa_sign.rs Updates signing/verification to use internal PrivateKey/PublicKey.
conversations/src/crypto.rs Re-exports crypto crate key types for local use.
conversations/src/identity.rs Stores identity secret as PrivateKey and updates accessors.
conversations/src/inbox/introduction.rs Uses internal key types for intro bundle signing/verification and tests.
conversations/src/inbox/handshake.rs Migrates handshake output to SymmetricKey32 and inputs to PrivateKey.
conversations/src/inbox/handler.rs Stores ephemeral keys as PrivateKey and updates responder path to new PrivateV1Convo ctor.
conversations/src/conversation/privatev1.rs Updates convo constructors and DR initialization plumbing to use SymmetricKey32 and PrivateKey.
Comments suppressed due to low confidence (1)

crypto/src/x3dh.rs:46

  • derive_shared_secret concatenates DH outputs into a plain Vec<u8> (km). This leaves sensitive key material in heap memory without zeroization, which undermines the goal of safer key handling. Use a zeroizing container (e.g., zeroize::Zeroizing<Vec<u8>>) or a fixed-size stack buffer and explicitly zero it after HKDF.
        // Concatenate all DH outputs
        let mut km = Vec::new();
        km.extend_from_slice(dh1.as_bytes());
        km.extend_from_slice(dh2.as_bytes());
        km.extend_from_slice(dh3.as_bytes());
        if let Some(dh4) = dh4 {
            km.extend_from_slice(dh4.as_bytes());
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

);
let mut sr_convo = PrivateV1Convo::new_initiator(seed_key_saro, pub_raya);
let mut rs_convo =
PrivateV1Convo::new_responder(SymmetricKey32::from(seed_key_raya), &raya);
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seed_key_raya is already a SymmetricKey32; calling SymmetricKey32::from(seed_key_raya) won’t compile because there’s no From<SymmetricKey32> impl. Pass seed_key_raya directly (or clone it if needed).

Suggested change
PrivateV1Convo::new_responder(SymmetricKey32::from(seed_key_raya), &raya);
PrivateV1Convo::new_responder(seed_key_raya, &raya);

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +90
// TODO: (P3) Rename; This accepts a Ephemeral key in most cases
let dh_self_installation_keypair =
InstallationKeyPair::from_secret_bytes(dh_self.DANGER_to_bytes());
// TODO: Danger - Fix double-ratchets types to Accept SymmetricKey32
let dr_state =
RatchetState::init_receiver(seed_key.DANGER_to_bytes(), dh_self_installation_keypair);
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PrivateV1Convo::new_responder converts dh_self into raw secret bytes via DANGER_to_bytes() to build an InstallationKeyPair, which creates an extra copy of secret material that isn’t obviously zeroized. Consider adding/using an API that can construct InstallationKeyPair without exposing raw bytes (or ensures the temporary byte buffer is zeroized).

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. The plan is to remove InstallationKeypair all together

}

/// Returns internal [u8; N].
/// This function by passes zeroize_on_drop, and will be deprecated once all consumers have been migrated
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in doc comment: “by passes” should be “bypasses”.

Suggested change
/// This function by passes zeroize_on_drop, and will be deprecated once all consumers have been migrated
/// This function bypasses zeroize_on_drop, and will be deprecated once all consumers have been migrated

Copilot uses AI. Check for mistakes.
@jazzz jazzz merged commit 95ddce9 into main Feb 18, 2026
3 checks passed
@jazzz jazzz deleted the jazzz/keys branch February 18, 2026 17:29
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.

3 participants