Skip to content

Commit 7d53206

Browse files
authored
Weakly activate zeroize?/alloc; MSRV 1.60 (#485)
Previously `alloc` implicitly activated `zeroize` via `zeroize/alloc`. This commit switches to weak feature activation as added in Rust 1.60, only activating `zeroize/alloc` if the `zeroize` dependency is explicitly activated (which it is by default).
1 parent 39dbaea commit 7d53206

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

.github/workflows/rust.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
- run: rustup target add ${{ matrix.target }}
2929
- run: ${{ matrix.deps }}
3030
- run: cargo test --target ${{ matrix.target }} --no-default-features
31+
- run: cargo test --target ${{ matrix.target }} --no-default-features --features alloc
3132
- run: cargo test --target ${{ matrix.target }} --no-default-features --features zeroize
3233
- run: cargo test --target ${{ matrix.target }}
3334
- run: cargo test --target ${{ matrix.target }} --features serde
@@ -110,7 +111,7 @@ jobs:
110111
- run: cargo fmt --all -- --check
111112

112113
msrv:
113-
name: Current MSRV is 1.56.1
114+
name: Current MSRV is 1.60.0
114115
runs-on: ubuntu-latest
115116
steps:
116117
- uses: actions/checkout@v3
@@ -120,7 +121,7 @@ jobs:
120121
- run: cargo -Z minimal-versions check --no-default-features --features serde
121122
# Now check that `cargo build` works with respect to the oldest possible
122123
# deps and the stated MSRV
123-
- uses: dtolnay/rust-toolchain@1.56.1
124+
- uses: dtolnay/rust-toolchain@1.60.0
124125
- run: cargo build --no-default-features --features serde
125126

126127
bench:

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ major series.
99

1010
#### Breaking changes
1111

12-
* Update the MSRV from 1.41 to 1.56.1
12+
* Update the MSRV from 1.41 to 1.60
1313
* Make `digest` an optional feature
1414
* Make `rand_core` an optional feature
1515
* Add target u32/u64 backend overrides

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "curve25519-dalek"
77
# - if README was updated, also update module documentation in src/lib.rs
88
version = "4.0.0-pre.5"
99
edition = "2021"
10-
rust-version = "1.56.1"
10+
rust-version = "1.60.0"
1111
authors = ["Isis Lovecruft <[email protected]>",
1212
"Henry de Valence <[email protected]>"]
1313
readme = "README.md"
@@ -69,7 +69,7 @@ packed_simd = { version = "0.3.4", package = "packed_simd_2", features = ["into_
6969

7070
[features]
7171
default = ["alloc", "zeroize"]
72-
alloc = ["zeroize/alloc"] # TODO: use weak feature activation
72+
alloc = ["zeroize?/alloc"]
7373

7474
[profile.dev]
7575
opt-level = 2

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ latest breaking changes are below:
6868

6969
### Breaking changes in 4.0.0
7070

71-
* Update the MSRV from 1.41 to 1.56.1
71+
* Update the MSRV from 1.41 to 1.60
7272
* Update backend selection to be more automatic. See [backends](#backends)
7373
* Remove `std` feature flag
7474
* Remove `nightly` feature flag
@@ -185,8 +185,8 @@ for MSRV and public API.
185185
## Minimum Supported Rust Version
186186

187187
| Releases | MSRV |
188-
| :--- | :--- |
189-
| 4.x | 1.56.1 |
188+
| :--- |:-------|
189+
| 4.x | 1.60.0 |
190190
| 3.x | 1.41.0 |
191191

192192
From 4.x and on, MSRV changes will be accompanied by a minor version bump.

src/backend/serial/scalar_mul/straus.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ impl MultiscalarMul for Straus {
107107
J: IntoIterator,
108108
J::Item: Borrow<EdwardsPoint>,
109109
{
110-
use zeroize::Zeroizing;
111-
112110
use crate::backend::serial::curve_models::ProjectiveNielsPoint;
113111
use crate::traits::Identity;
114112
use crate::window::LookupTable;
@@ -121,11 +119,11 @@ impl MultiscalarMul for Straus {
121119
// This puts the scalar digits into a heap-allocated Vec.
122120
// To ensure that these are erased, pass ownership of the Vec into a
123121
// Zeroizing wrapper.
124-
let scalar_digits_vec: Vec<_> = scalars
122+
#[cfg_attr(not(feature = "zeroize"), allow(unused_mut))]
123+
let mut scalar_digits: Vec<_> = scalars
125124
.into_iter()
126125
.map(|s| s.borrow().as_radix_16())
127126
.collect();
128-
let scalar_digits = Zeroizing::new(scalar_digits_vec);
129127

130128
let mut Q = EdwardsPoint::identity();
131129
for j in (0..64).rev() {
@@ -139,6 +137,9 @@ impl MultiscalarMul for Straus {
139137
}
140138
}
141139

140+
#[cfg(feature = "zeroize")]
141+
zeroize::Zeroize::zeroize(&mut scalar_digits);
142+
142143
Q
143144
}
144145
}

src/scalar.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -793,15 +793,10 @@ impl Scalar {
793793
// externally, but there's no corresponding distinction for
794794
// field elements.
795795

796-
use zeroize::Zeroizing;
797-
798796
let n = inputs.len();
799797
let one: UnpackedScalar = Scalar::ONE.unpack().as_montgomery();
800798

801-
// Place scratch storage in a Zeroizing wrapper to wipe it when
802-
// we pass out of scope.
803-
let scratch_vec = vec![one; n];
804-
let mut scratch = Zeroizing::new(scratch_vec);
799+
let mut scratch = vec![one; n];
805800

806801
// Keep an accumulator of all of the previous products
807802
let mut acc = Scalar::ONE.unpack().as_montgomery();
@@ -835,6 +830,9 @@ impl Scalar {
835830
acc = tmp;
836831
}
837832

833+
#[cfg(feature = "zeroize")]
834+
zeroize::Zeroize::zeroize(&mut scratch);
835+
838836
ret
839837
}
840838

0 commit comments

Comments
 (0)