Skip to content

Commit 989e811

Browse files
authored
crypto_box: rename CryptoBox::new_from_clamped (#186)
Uses a name similar to the other constructor Also places the function after `CryptoBox::new` to give that constructor priority in e.g. rustdoc
1 parent bcc561b commit 989e811

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

crypto_box/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ impl<C> CryptoBox<C> {
257257
/// Create a new [`CryptoBox`], performing X25519 Diffie-Hellman to derive
258258
/// a shared secret from the provided public and secret keys.
259259
///
260-
/// Assumes that the scalar has alread been clamped. Eg like `ed25519-dalek` does.
261-
pub fn from_clamped(public_key: &PublicKey, secret_key: &SecretKey) -> Self
260+
/// Internally performs clamping.
261+
pub fn new(public_key: &PublicKey, secret_key: &SecretKey) -> Self
262262
where
263263
C: Kdf,
264264
{
265-
let shared_secret = Zeroizing::new(public_key.0 * secret_key.scalar);
265+
let shared_secret = Zeroizing::new(public_key.0.mul_clamped(secret_key.bytes));
266266

267267
// Use HChaCha20 to create a uniformly random key from the shared secret
268268
let key = Zeroizing::new(C::kdf((&shared_secret.0).into(), &Array::default()));
@@ -275,12 +275,12 @@ impl<C> CryptoBox<C> {
275275
/// Create a new [`CryptoBox`], performing X25519 Diffie-Hellman to derive
276276
/// a shared secret from the provided public and secret keys.
277277
///
278-
/// Internally performs clamping.
279-
pub fn new(public_key: &PublicKey, secret_key: &SecretKey) -> Self
278+
/// Assumes that the scalar has alread been clamped. Eg like `ed25519-dalek` does.
279+
pub fn new_from_clamped(public_key: &PublicKey, secret_key: &SecretKey) -> Self
280280
where
281281
C: Kdf,
282282
{
283-
let shared_secret = Zeroizing::new(public_key.0.mul_clamped(secret_key.bytes));
283+
let shared_secret = Zeroizing::new(public_key.0 * secret_key.scalar);
284284

285285
// Use HChaCha20 to create a uniformly random key from the shared secret
286286
let key = Zeroizing::new(C::kdf((&shared_secret.0).into(), &Array::default()));

crypto_box/tests/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn seal_open_roundtrip(this: &ed25519_dalek::SigningKey, other: &ed25519_dalek::
279279
let secret_key = crypto_box::SecretKey::from(this.to_scalar());
280280
let public_key = crypto_box::PublicKey::from(other.verifying_key().to_montgomery());
281281

282-
crypto_box::ChaChaBox::from_clamped(&public_key, &secret_key)
282+
crypto_box::ChaChaBox::new_from_clamped(&public_key, &secret_key)
283283
};
284284

285285
let mut sealed_message = msg.clone();
@@ -291,7 +291,7 @@ fn seal_open_roundtrip(this: &ed25519_dalek::SigningKey, other: &ed25519_dalek::
291291
let secret_key = crypto_box::SecretKey::from(other.to_scalar());
292292
let public_key = crypto_box::PublicKey::from(this.verifying_key().to_montgomery());
293293

294-
crypto_box::ChaChaBox::from_clamped(&public_key, &secret_key)
294+
crypto_box::ChaChaBox::new_from_clamped(&public_key, &secret_key)
295295
};
296296
let mut decrypted_message = sealed_message.clone();
297297

0 commit comments

Comments
 (0)