-
-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rename "djb" type curve to "curve25519" everywhere #475
rename "djb" type curve to "curve25519" everywhere #475
Conversation
847c612
to
4b4964d
Compare
4b4964d
to
73ede63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to check which PRs were still drafts, whoops. Many comments on this one, and I feel a little bad for being like this since this is how we go months without any documentation progress.
* | ||
* Licensed according to the LICENSE file in this repository. | ||
*/ | ||
package org.signal.libsignal.protocol.ecc; | ||
import org.signal.libsignal.protocol.InvalidKeyException; | ||
|
||
public class Curve { | ||
public static final int DJB_TYPE = 0x05; | ||
public static final int CURVE_25519_TYPE = 0x05; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the constant here is public, let's leave the old name here too but mark it deprecated. (You can see the combined annotation + javadoc idiom for that elsewhere in the library.)
@@ -26,7 +26,7 @@ public ECPublicKey(byte[] serialized) { | |||
|
|||
static public ECPublicKey fromPublicKeyBytes(byte[] key) { | |||
byte[] with_type = new byte[33]; | |||
with_type[0] = 0x05; | |||
with_type[0] = Curve.CURVE_25519_TYPE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yuck, good find.
pub const CTR_NONCE_SIZE: usize = aes::BLOCK_SIZE - 4; | ||
|
||
const NONCE_SIZE: usize = Self::CTR_NONCE_SIZE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep unrelated changes out of the diff! :-)
(I don't think we want this change but we can talk about it elsewhere.)
//!``` | ||
//! use libsignal_protocol::KeyPair; | ||
//! use std::collections::HashSet; | ||
//! | ||
//! let alice = KeyPair::generate(&mut rand::thread_rng()); | ||
//! assert!(alice == alice.clone()); | ||
//! let bob = KeyPair::generate(&mut rand::thread_rng()); | ||
//! assert!(alice != bob); | ||
//! | ||
//! // Keys can be hashed and put in sets. | ||
//! let key_set: HashSet<KeyPair> = [alice, bob].iter().cloned().collect(); | ||
//! assert!(key_set.contains(&alice)); | ||
//! assert!(key_set.contains(&bob)); | ||
//!``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I…don't consider these very compelling examples, heh! They don't show any key cryptography things happening. I wouldn't consider that a blocker, though; the module could just have that one line of documentation for now.
|
||
#![warn(missing_docs)] | ||
|
||
pub mod curve25519; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talked about this a bit a while ago, but this is very deliberately not pub
, because we don't want libsignal_protocol
keys to be thought of as using a specific key implementation. All we need is that they support both signatures and key agreement.
@@ -100,6 +131,8 @@ impl PrivateKey { | |||
result | |||
} | |||
|
|||
/// Verify a signature from [`Self::calculate_signature`] against another key pair's public key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a static method, so there's no "another key pair" to worry about.
/// Return the bytes of a [`PublicKey`] that another party can use to validate against | ||
/// [`Self::verify_signature`]. | ||
pub fn derive_public_key_bytes(&self) -> [u8; PUBLIC_KEY_LENGTH] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not the only use, it's also for key agreement! I'd drop the use part completely again.
@@ -25,7 +25,7 @@ | |||
mod address; | |||
mod consts; | |||
mod crypto; | |||
mod curve; | |||
pub mod curve; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still counts as changing the module structure; it's the public surface of the module that matters, not its implementation. I still think we should stay flat until we discuss it properly and as a whole.
} | ||
} | ||
/// Interface for structs that perform operations parameterized by values of [`KeyType`]. | ||
pub trait Keyed { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this isn't really the right name for the trait. Public keys and private keys and key pairs aren't "keyed", they're…"typed"?
That said, though, I think this is a reasonable trait, but until we have a use case for it I'd rather not add it, and that won't happen until we support another key type. It might turn out we need different operations besides just key_type
.
pub fn calculate_agreement( | ||
&self, | ||
their_key: &PublicKey, | ||
) -> Result<[u8; curve25519::AGREEMENT_LENGTH]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the place we talked about before: key agreement can't hardcode an output length, because the keys might (someday) not be curve25519 keys.
- [NON RUST/RENAME] rename "DJB_TYPE" to "CURVE_25519_TYPE" in java and swift - [1+CRYPTO CRATE] make swift/build-ffi.sh --generate-ffi work - [1+CURVE] add docs and the Keyed trait to `curve*.rs`
73ede63
to
49c574e
Compare
- [NON RUST/RENAME] rename "DJB_TYPE" to "CURVE_25519_TYPE" in java and swift - [1+CRYPTO CRATE] make swift/build-ffi.sh --generate-ffi work - [1+CURVE] add docs and the Keyed trait to `curve*.rs`
- [NON RUST/RENAME] rename "DJB_TYPE" to "CURVE_25519_TYPE" in java and swift - [1+CRYPTO CRATE] make swift/build-ffi.sh --generate-ffi work - [1+CURVE] add docs and the Keyed trait to `curve*.rs`
- [NON RUST/RENAME] rename "DJB_TYPE" to "CURVE_25519_TYPE" in java and swift - [1+CRYPTO CRATE] make swift/build-ffi.sh --generate-ffi work - [1+CURVE] add docs and the Keyed trait to `curve*.rs`
49c574e
to
6f7f325
Compare
- [NON RUST/RENAME] rename "DJB_TYPE" to "CURVE_25519_TYPE" in java and swift - [1+CRYPTO CRATE] make swift/build-ffi.sh --generate-ffi work - [1+CURVE] add docs and the Keyed trait to `curve*.rs`
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been closed due to inactivity. |
Broken out from #287.
KeyType::Djb
toKeyType::Curve25519
.Keyed
trait tocurve*.rs
TODO