Feature gate reusable secrets and make the name more intuitive.

This commit is contained in:
Isis Lovecruft 2021-04-20 21:33:32 +00:00
parent 0a1023f4db
commit 27c73fdb57
No known key found for this signature in database
GPG key ID: AB41313533E8E812
2 changed files with 11 additions and 7 deletions

View file

@ -30,7 +30,7 @@ travis-ci = { repository = "dalek-cryptography/x25519-dalek", branch = "master"}
[package.metadata.docs.rs]
#rustdoc-args = ["--html-in-header", ".cargo/registry/src/github.com-1ecc6299db9ec823/curve25519-dalek-1.0.1/docs/assets/rustdoc-include-katex-header.html"]
features = ["nightly"]
features = ["nightly", "reusable_secrets", "serde"]
[dependencies]
curve25519-dalek = { version = "3", default-features = false }
@ -53,5 +53,6 @@ default = ["std", "u64_backend"]
serde = ["our_serde", "curve25519-dalek/serde"]
std = ["curve25519-dalek/std"]
nightly = ["curve25519-dalek/nightly"]
reusable_secrets = []
u64_backend = ["curve25519-dalek/u64_backend"]
u32_backend = ["curve25519-dalek/u32_backend"]

View file

@ -107,11 +107,13 @@ impl<'a> From<&'a EphemeralSecret> for PublicKey {
/// [`EphemeralSecret`] at all times, as that type enforces at compile-time that
/// secret keys are never reused, which can have very serious security
/// implications for many protocols.
#[cfg(feature = "reusable_secrets")]
#[derive(Zeroize)]
#[zeroize(drop)]
pub struct NonSerializeableSecret(pub(crate) Scalar);
pub struct ReusableSecret(pub(crate) Scalar);
impl NonSerializeableSecret {
#[cfg(feature = "reusable_secrets")]
impl ReusableSecret {
/// Perform a Diffie-Hellman key agreement between `self` and
/// `their_public` key to produce a [`SharedSecret`].
pub fn diffie_hellman(&self, their_public: &PublicKey) -> SharedSecret {
@ -124,13 +126,14 @@ impl NonSerializeableSecret {
csprng.fill_bytes(&mut bytes);
NonSerializeableSecret(clamp_scalar(bytes))
ReusableSecret(clamp_scalar(bytes))
}
}
impl<'a> From<&'a NonSerializeableSecret> for PublicKey {
/// Given an x25519 [`NonSerializeableSecret`] key, compute its corresponding [`PublicKey`].
fn from(secret: &'a NonSerializeableSecret) -> PublicKey {
#[cfg(feature = "reusable_secrets")]
impl<'a> From<&'a ReusableSecret> for PublicKey {
/// Given an x25519 [`ReusableSecret`] key, compute its corresponding [`PublicKey`].
fn from(secret: &'a ReusableSecret) -> PublicKey {
PublicKey((&ED25519_BASEPOINT_TABLE * &secret.0).to_montgomery())
}
}