mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-10 21:21:13 +00:00
Feature gate reusable secrets and make the name more intuitive.
This commit is contained in:
parent
0a1023f4db
commit
27c73fdb57
2 changed files with 11 additions and 7 deletions
|
|
@ -30,7 +30,7 @@ travis-ci = { repository = "dalek-cryptography/x25519-dalek", branch = "master"}
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[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"]
|
#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]
|
[dependencies]
|
||||||
curve25519-dalek = { version = "3", default-features = false }
|
curve25519-dalek = { version = "3", default-features = false }
|
||||||
|
|
@ -53,5 +53,6 @@ default = ["std", "u64_backend"]
|
||||||
serde = ["our_serde", "curve25519-dalek/serde"]
|
serde = ["our_serde", "curve25519-dalek/serde"]
|
||||||
std = ["curve25519-dalek/std"]
|
std = ["curve25519-dalek/std"]
|
||||||
nightly = ["curve25519-dalek/nightly"]
|
nightly = ["curve25519-dalek/nightly"]
|
||||||
|
reusable_secrets = []
|
||||||
u64_backend = ["curve25519-dalek/u64_backend"]
|
u64_backend = ["curve25519-dalek/u64_backend"]
|
||||||
u32_backend = ["curve25519-dalek/u32_backend"]
|
u32_backend = ["curve25519-dalek/u32_backend"]
|
||||||
|
|
|
||||||
|
|
@ -107,11 +107,13 @@ impl<'a> From<&'a EphemeralSecret> for PublicKey {
|
||||||
/// [`EphemeralSecret`] at all times, as that type enforces at compile-time that
|
/// [`EphemeralSecret`] at all times, as that type enforces at compile-time that
|
||||||
/// secret keys are never reused, which can have very serious security
|
/// secret keys are never reused, which can have very serious security
|
||||||
/// implications for many protocols.
|
/// implications for many protocols.
|
||||||
|
#[cfg(feature = "reusable_secrets")]
|
||||||
#[derive(Zeroize)]
|
#[derive(Zeroize)]
|
||||||
#[zeroize(drop)]
|
#[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
|
/// Perform a Diffie-Hellman key agreement between `self` and
|
||||||
/// `their_public` key to produce a [`SharedSecret`].
|
/// `their_public` key to produce a [`SharedSecret`].
|
||||||
pub fn diffie_hellman(&self, their_public: &PublicKey) -> SharedSecret {
|
pub fn diffie_hellman(&self, their_public: &PublicKey) -> SharedSecret {
|
||||||
|
|
@ -124,13 +126,14 @@ impl NonSerializeableSecret {
|
||||||
|
|
||||||
csprng.fill_bytes(&mut bytes);
|
csprng.fill_bytes(&mut bytes);
|
||||||
|
|
||||||
NonSerializeableSecret(clamp_scalar(bytes))
|
ReusableSecret(clamp_scalar(bytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a NonSerializeableSecret> for PublicKey {
|
#[cfg(feature = "reusable_secrets")]
|
||||||
/// Given an x25519 [`NonSerializeableSecret`] key, compute its corresponding [`PublicKey`].
|
impl<'a> From<&'a ReusableSecret> for PublicKey {
|
||||||
fn from(secret: &'a NonSerializeableSecret) -> PublicKey {
|
/// Given an x25519 [`ReusableSecret`] key, compute its corresponding [`PublicKey`].
|
||||||
|
fn from(secret: &'a ReusableSecret) -> PublicKey {
|
||||||
PublicKey((&ED25519_BASEPOINT_TABLE * &secret.0).to_montgomery())
|
PublicKey((&ED25519_BASEPOINT_TABLE * &secret.0).to_montgomery())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue