zeroize: potetial redesign ideas
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 20/100
- Type d'issue
- Fonctionnalité
- Clarté
- À clarifier
- Activité
- À l'abandon
- Stack technique
- rust
- Domaine
- cryptography, security
Piste de recherche
Commencez par examiner l’API proposée dans cette issue et la discussion sur la mise à zéro à plat dans #1045. Déterminez si le projet souhaite une refonte, un ajout rétrocompatible ou une modification pour v2.0 ; le travail est terminé lorsque l’orientation de l’API et la portée de la migration sont convenues.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Rust
- Étoiles
- 674
- Forks
- 170
- Merge moyen
- 1 j 12 h
- PR mergées (30 j)
- 10
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de RustCrypto/utils
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
RustCrypto/utils#1546 · 1 commentaire ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
RustCrypto/utils#1537 · 7 commentaires ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
RustCrypto/utils#1534 · 2 commentaires ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 45/100
RustCrypto/utils#1529 · 4 commentaires ·
-
x86: guard CPUID leaf 7 by the maximum basic leaf; AVX detection may need XMM+YMM XCR0 state Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
RustCrypto/utils#1510 · 1 commentaire ·
Toutes les issues de RustCrypto/utils
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
-
bug core
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
-
JIT-compiled number -> Decimal conversion silently overflows instead of raising DECIMAL_OVERFLOW Ouvertefuzz
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
ClickHouse/ClickHouse#122114 ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
linebender/vello_svg#90 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100