Skip to content

Commit 29de876

Browse files
authored
block-buffer: add optional Zeroize implementation (#963)
1 parent e70943c commit 29de876

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

block-buffer/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- `ReadBuffer` type ([#823])
1010
- `serialize` and `deserialize` methods ([#823])
11+
- Optional implementation of the `Zeroize` trait ([#963])
1112

1213
### Changed
1314
- Supported block sizes are now bounded by the `crypto_common::BlockSizes` trait,
@@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2021
- `EagerBuffer::set_data` method. Use the `ReadBuffer` type instead. ([#823])
2122

2223
[#823]: https://github.com/RustCrypto/utils/pull/823
24+
[#963]: https://github.com/RustCrypto/utils/pull/963
2325

2426
## 0.10.3 (2022-09-04)
2527
### Added

block-buffer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ readme = "README.md"
1414
[dependencies]
1515
crypto-common = "0.2.0-pre"
1616
generic-array = "0.14"
17+
zeroize = { version = "1.4", optional = true, default-features = false }
1718

1819
[dev-dependencies]
1920
hex-literal = "0.3.3"

block-buffer/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use generic_array::{
1515
typenum::{Add1, B1},
1616
ArrayLength, GenericArray,
1717
};
18+
#[cfg(feature = "zeroize")]
19+
use zeroize::Zeroize;
1820

1921
mod read;
2022
mod sealed;
@@ -333,3 +335,12 @@ impl<BS: BlockSizes> BlockBuffer<BS, Lazy> {
333335
})
334336
}
335337
}
338+
339+
#[cfg(feature = "zeroize")]
340+
impl<BS: BlockSizes, K: BufferKind> Zeroize for BlockBuffer<BS, K> {
341+
#[inline]
342+
fn zeroize(&mut self) {
343+
self.buffer.zeroize();
344+
self.pos.zeroize();
345+
}
346+
}

block-buffer/src/read.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use super::{Block, Error};
22
use core::{fmt, slice};
33
use crypto_common::{BlockSizeUser, BlockSizes};
4+
#[cfg(feature = "zeroize")]
5+
use zeroize::Zeroize;
46

57
/// Buffer for reading block-generated data.
68
pub struct ReadBuffer<BS: BlockSizes> {
@@ -146,3 +148,11 @@ impl<BS: BlockSizes> ReadBuffer<BS> {
146148
(blocks, right)
147149
}
148150
}
151+
152+
#[cfg(feature = "zeroize")]
153+
impl<BS: BlockSizes> Zeroize for ReadBuffer<BS> {
154+
#[inline]
155+
fn zeroize(&mut self) {
156+
self.buffer.zeroize();
157+
}
158+
}

block-buffer/src/sealed.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use generic_array::{ArrayLength, GenericArray};
33

44
/// Sealed trait for buffer kinds.
55
pub trait Sealed {
6+
#[cfg(not(feature = "zeroize"))]
67
type Pos: Default + Clone;
8+
#[cfg(feature = "zeroize")]
9+
type Pos: Default + Clone + zeroize::Zeroize;
710

811
fn get_pos(buf: &[u8], pos: &Self::Pos) -> usize;
912

0 commit comments

Comments
 (0)