mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-07 20:50:39 +00:00
Make static_secrets optional (#122)
* Make `static_secrets` optional * Added more feature combinations to CI
This commit is contained in:
parent
02a5ce20ca
commit
84158337af
4 changed files with 18 additions and 6 deletions
6
.github/workflows/rust.yml
vendored
6
.github/workflows/rust.yml
vendored
|
|
@ -13,7 +13,7 @@ env:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: Test all features
|
name: Test with multiple feature combinations
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
|
@ -29,6 +29,10 @@ jobs:
|
||||||
with:
|
with:
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
- run: ${{ matrix.deps }}
|
- run: ${{ matrix.deps }}
|
||||||
|
- run: cargo test --target ${{ matrix.target }} --no-default-features
|
||||||
|
- run: cargo test --target ${{ matrix.target }} --no-default-features --features reusable_secrets
|
||||||
|
- run: cargo test --target ${{ matrix.target }} --no-default-features --features static_secrets
|
||||||
|
- run: cargo test --target ${{ matrix.target }}
|
||||||
- run: cargo test --target ${{ matrix.target }} --all-features
|
- run: cargo test --target ${{ matrix.target }} --all-features
|
||||||
|
|
||||||
build-simd:
|
build-simd:
|
||||||
|
|
|
||||||
|
|
@ -60,3 +60,4 @@ serde = ["dep:serde", "curve25519-dalek/serde"]
|
||||||
alloc = ["curve25519-dalek/alloc", "serde?/alloc", "zeroize?/alloc"]
|
alloc = ["curve25519-dalek/alloc", "serde?/alloc", "zeroize?/alloc"]
|
||||||
precomputed-tables = ["curve25519-dalek/precomputed-tables"]
|
precomputed-tables = ["curve25519-dalek/precomputed-tables"]
|
||||||
reusable_secrets = []
|
reusable_secrets = []
|
||||||
|
static_secrets = []
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@ use rand_core::RngCore;
|
||||||
#[cfg(feature = "zeroize")]
|
#[cfg(feature = "zeroize")]
|
||||||
use zeroize::Zeroize;
|
use zeroize::Zeroize;
|
||||||
|
|
||||||
/// A Diffie-Hellman public key, corresponding to an [`EphemeralSecret`] or
|
/// A Diffie-Hellman public key
|
||||||
/// [`StaticSecret`] key.
|
|
||||||
///
|
///
|
||||||
/// We implement `Zeroize` so that downstream consumers may derive it for `Drop`
|
/// We implement `Zeroize` so that downstream consumers may derive it for `Drop`
|
||||||
/// should they wish to erase public keys from memory. Note that this erasure
|
/// should they wish to erase public keys from memory. Note that this erasure
|
||||||
|
|
@ -68,7 +67,7 @@ impl AsRef<[u8]> for PublicKey {
|
||||||
/// A short-lived Diffie-Hellman secret key that can only be used to compute a single
|
/// A short-lived Diffie-Hellman secret key that can only be used to compute a single
|
||||||
/// [`SharedSecret`].
|
/// [`SharedSecret`].
|
||||||
///
|
///
|
||||||
/// This type is identical to the [`StaticSecret`] type, except that the
|
/// This type is identical to the `StaticSecret` type, except that the
|
||||||
/// [`EphemeralSecret::diffie_hellman`] method consumes and then wipes the secret key, and there
|
/// [`EphemeralSecret::diffie_hellman`] method consumes and then wipes the secret key, and there
|
||||||
/// are no serialization methods defined. This means that [`EphemeralSecret`]s can only be
|
/// are no serialization methods defined. This means that [`EphemeralSecret`]s can only be
|
||||||
/// generated from fresh randomness where the compiler statically checks that the resulting
|
/// generated from fresh randomness where the compiler statically checks that the resulting
|
||||||
|
|
@ -125,7 +124,7 @@ impl<'a> From<&'a EphemeralSecret> for PublicKey {
|
||||||
///
|
///
|
||||||
/// Similarly to [`EphemeralSecret`], this type does _not_ have serialisation
|
/// Similarly to [`EphemeralSecret`], this type does _not_ have serialisation
|
||||||
/// methods, in order to discourage long-term usage of secret key material. (For
|
/// methods, in order to discourage long-term usage of secret key material. (For
|
||||||
/// long-term secret keys, see [`StaticSecret`].)
|
/// long-term secret keys, see `StaticSecret`.)
|
||||||
///
|
///
|
||||||
/// # Warning
|
/// # Warning
|
||||||
///
|
///
|
||||||
|
|
@ -195,6 +194,7 @@ impl<'a> From<&'a ReusableSecret> 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 = "static_secrets")]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[cfg_attr(feature = "zeroize", derive(Zeroize))]
|
#[cfg_attr(feature = "zeroize", derive(Zeroize))]
|
||||||
#[cfg_attr(feature = "zeroize", zeroize(drop))]
|
#[cfg_attr(feature = "zeroize", zeroize(drop))]
|
||||||
|
|
@ -203,6 +203,7 @@ pub struct StaticSecret(
|
||||||
#[cfg_attr(feature = "serde", serde(with = "AllowUnreducedScalarBytes"))] pub(crate) Scalar,
|
#[cfg_attr(feature = "serde", serde(with = "AllowUnreducedScalarBytes"))] pub(crate) Scalar,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(feature = "static_secrets")]
|
||||||
impl StaticSecret {
|
impl StaticSecret {
|
||||||
/// 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`.
|
||||||
|
|
@ -247,6 +248,7 @@ impl StaticSecret {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "static_secrets")]
|
||||||
impl From<[u8; 32]> for StaticSecret {
|
impl From<[u8; 32]> for StaticSecret {
|
||||||
/// Load a secret key from a byte array.
|
/// Load a secret key from a byte array.
|
||||||
fn from(bytes: [u8; 32]) -> StaticSecret {
|
fn from(bytes: [u8; 32]) -> StaticSecret {
|
||||||
|
|
@ -254,6 +256,7 @@ impl From<[u8; 32]> for StaticSecret {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "static_secrets")]
|
||||||
impl<'a> From<&'a StaticSecret> for PublicKey {
|
impl<'a> From<&'a StaticSecret> for PublicKey {
|
||||||
/// Given an x25519 [`StaticSecret`] key, compute its corresponding [`PublicKey`].
|
/// Given an x25519 [`StaticSecret`] key, compute its corresponding [`PublicKey`].
|
||||||
fn from(secret: &'a StaticSecret) -> PublicKey {
|
fn from(secret: &'a StaticSecret) -> PublicKey {
|
||||||
|
|
@ -261,6 +264,7 @@ impl<'a> From<&'a StaticSecret> for PublicKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "static_secrets")]
|
||||||
impl AsRef<[u8]> for StaticSecret {
|
impl AsRef<[u8]> for StaticSecret {
|
||||||
/// View this key as a byte array.
|
/// View this key as a byte array.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -343,7 +347,8 @@ impl AsRef<[u8]> for SharedSecret {
|
||||||
/// cannot use the better, safer, and faster ephemeral DH API.
|
/// cannot use the better, safer, and faster ephemeral DH API.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
#[cfg_attr(feature = "static_secrets", doc = "```")]
|
||||||
|
#[cfg_attr(not(feature = "static_secrets"), doc = "```ignore")]
|
||||||
/// use rand_core::OsRng;
|
/// use rand_core::OsRng;
|
||||||
/// use rand_core::RngCore;
|
/// use rand_core::RngCore;
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,7 @@ mod rand_core {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "static_secrets")]
|
||||||
fn static_from_rng() {
|
fn static_from_rng() {
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
StaticSecret::new(OsRng);
|
StaticSecret::new(OsRng);
|
||||||
|
|
@ -226,6 +227,7 @@ mod getrandom {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "static_secrets")]
|
||||||
fn static_random() {
|
fn static_random() {
|
||||||
StaticSecret::random();
|
StaticSecret::random();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue