Skip to content

Integrate DR into PrivateV1#32

Merged
jazzz merged 3 commits intomainfrom
jazzz/dh_integrate
Feb 3, 2026
Merged

Integrate DR into PrivateV1#32
jazzz merged 3 commits intomainfrom
jazzz/dh_integrate

Conversation

@jazzz
Copy link
Collaborator

@jazzz jazzz commented Jan 29, 2026

This PR incorporates the double ratchet into the PrivateV1 by initializing sessions and wiring up Encrypt and Decrypt.

Comment on lines +34 to +39
pub fn new_responder(seed_key: SecretKey, dh_self: InstallationKeyPair) -> Self {
Self {
// TODO: Danger - Fix double-ratchets types to Accept SecretKey
dr_state: RatchetState::init_receiver(seed_key.as_bytes().to_owned(), dh_self),
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

double-ratchets requires a InstallationKey struct to be passed in.

As InstallationKey is just a thin wrapper around StaticKey @kaichaosun would you be ok if I refactored double-ratchets to use a common keyType as the rest of the cryptography? It would be a StructWrapper around StaticKey which would have the effect:

  • Keys can be passed without extra copies for clearer memory hygiene.
  • Remove DR direct dependence on x25519 in our entire codebase.
  • Avoid Needless copies

We can add an AbstractType or Trait Generics if we really want it to be completely independent in the future.

Copy link
Contributor

@kaichaosun kaichaosun Jan 30, 2026

Choose a reason for hiding this comment

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

That would be great! thanks @jazzz

Comment on lines +79 to +83
let header = Header {
dh_pub,
msg_num: dr_header.msg_num,
prev_chain_len: dr_header.prev_chain_len,
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Orphan rule is making handling these DR types kind of annoying. I'll look at using Newtype and implementing the conversions there

pub fn new_responder(seed_key: SecretKey, dh_self: InstallationKeyPair) -> Self {
Self {
// TODO: Danger - Fix double-ratchets types to Accept SecretKey
dr_state: RatchetState::init_receiver(seed_key.as_bytes().to_owned(), dh_self),
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to make roles name consistent in different crates.

}

fn encrypt(&mut self, frame: PrivateV1Frame) -> EncryptedPayload {
let encoded_bytes = frame.encode_to_vec();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the name can be shorter like to_bytes or something similar

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what do you mean @kaichaosun ? I don't follow.

Copy link
Contributor

Choose a reason for hiding this comment

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

It just looks so strange to use encode_to_vec other than something like to_bytes, since it comes from generated code, seems we can do nothing about it.

@jazzz
Copy link
Collaborator Author

jazzz commented Feb 3, 2026

I wanted to wait for #37 to land, before integrating this. However to keep things simple I'll push this through and then comeback to it.

@jazzz jazzz merged commit d5c16f5 into main Feb 3, 2026
@jazzz jazzz deleted the jazzz/dh_integrate branch February 3, 2026 23:17
This was referenced Feb 12, 2026
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.

2 participants