zeroize: potetial redesign ideas
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 20/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- rust
- 領域
- cryptography, security
調査の方向性
まず、この issue で提案されている API と、#1045 のフラットなゼロ化に関する議論を確認してください。プロジェクトが再設計、後方互換性のある追加、または v2.0 での変更のどれを望んでいるのかを明確にしてください。API の方向性と移行範囲について合意できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Right now I see the following issues with public API of zeroize:
- Derived and manually implemented
Zeroizecan be inefficient since they rely on zeroization of fields one by one or on zeroizingDropimpls. - Procedural macros are relatively heavy compile time-wise, so usually we do not derive
Zeroizead rely on manual implementations. ZeroizeOnDropis a somewhat useless trait, I haven't seen it used in practice.Zeroizingusefulness is limited. It can be used only for "primitive" types (e.g. raw keys), complex types do not implementZeroizeand instead implement zeroizingDrop.- Zeroization is enabled for a whole crate using features. It's not possible to use selective zeroization and zeroization is not reflected in any way in user code.
I think most structures should be zeroized using the "flat" zeroization (see #1045) and that it can be useful to have explicit indication in user code of structs being zeroized on drop.
So I would like to suggest roughly this API:
/// Zeroizes memory pointed by `data_ptr`, but not memory
/// potentially reference by `T`.
pub unsafe fn zeroize_flat<T>(data_ptr: *mut T) {
// ...
}
/// Zeroize-on-drop wrapper.
///
/// Note that this wrapper zeroizes only data owned by `T`
/// and does nothing with data referenced by it.
#[repr(transparent)]
pub struct ZeroizeOnDrop<T, const IS_ENABLED: bool = true>(T);
/// Abbreviated alias for `ZeroizeOnDrop`.
pub type Zod<T, const IS_ENABLED: bool = true> = ZeroizeOnDrop<T, IS_ENABLED>;
impl<T, const IS_ENABLED: bool> Drop for ZeroizeOnDrop<T, IS_ENABLED> {
fn drop (&mut self) {
unsafe {
std::ptr::drop_in_place(&mut self.0);
if IS_ENABLED { zeroize_flat(&mut self.0); }
}
}
}
// Impl Deref and DerefMut for `ZeroizeOnDrop`
UPD: FlatPod and FlatZod are removed.
It can be introduced in a backward-compatible way, but for clarity it's probably worth to release it as v2.0.
Users would write code like this:
pub struct Foo {
secret_cipher: Zod<Aes128>,
secret_key: Box<Zod<[u8; 16]>>,
non_secret_hasher: Sha256,
// other fields
}
const ZOD: bool = cfg!(feature = "zeroize");
pub struct Bar1 {
// This field will be zeroized only if `zeroize` feature is enabled
cipher: Zod<Aes128, ZOD>,
}
// Alternatively:
pub struct Bar2<const ZOD: bool = true> {
cipher: Zod<Aes128, ZOD>,
}
While it will be a bit less convinient, I think it's useful to have explicit indication in source code that secret types will be zeroized on drop. We may provide aliases like type ZodAes128 = Zod<Aes128> to improve visibility, but I don't think they are worth the trouble and it should be sufficient to simply references zeroize in docs.
- 主要言語
- Rust
- スター
- 674
- フォーク
- 170
- 平均マージ
- 1日 12時間
- マージ済み PR(30日)
- 10
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
RustCrypto/utils のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
RustCrypto/utils#1546 · コメント 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
RustCrypto/utils#1537 · コメント 7 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
RustCrypto/utils#1534 · コメント 2 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
RustCrypto/utils#1529 · コメント 4 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
RustCrypto/utils#1510 · コメント 1 件 ·
RustCrypto/utils の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
TheLarkInn/aipm#2413 ·
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
alexgorbatchev/simple-ptt#15 ·
-
tooling
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
todo:ticket
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
taikoxyz/taiko-mono#22168 · コメント 1 件 ·