|
40 | 40 | //! |
41 | 41 | //! assert_eq!(k, k2); |
42 | 42 | //! ``` |
| 43 | +//! |
| 44 | +//! # Zeroizing secret material |
| 45 | +//! |
| 46 | +//! When the `zeroize` feature is enabled, the secret types in this crate — the |
| 47 | +//! [`SharedSecret`](crate::kem::SharedSecret) produced by the KEMs, and the |
| 48 | +//! `SecretKey` and `UserSecretKey` of every scheme — derive |
| 49 | +//! [`Zeroize`](https://docs.rs/zeroize), but **not** `ZeroizeOnDrop`. |
| 50 | +//! |
| 51 | +//! These types are `Copy`, and a `Copy` type cannot implement `Drop` (Rust |
| 52 | +//! forbids `Copy` and `Drop` on the same type), so `ZeroizeOnDrop` cannot be |
| 53 | +//! derived for them. As a consequence **secret key material is not wiped from |
| 54 | +//! memory automatically when a value goes out of scope**. If you care about |
| 55 | +//! clearing secrets, you **MUST** call `.zeroize()` explicitly once you are |
| 56 | +//! done with each secret value: |
| 57 | +//! |
| 58 | +//! ```ignore |
| 59 | +//! use ibe::kem::{IBKEM, cgw_kv::CGWKV}; |
| 60 | +//! use ibe::Derive; |
| 61 | +//! use zeroize::Zeroize; |
| 62 | +//! |
| 63 | +//! let mut rng = rand::thread_rng(); |
| 64 | +//! let id = <CGWKV as IBKEM>::Id::derive_str("alice@example.com"); |
| 65 | +//! let (pk, mut sk) = CGWKV::setup(&mut rng); |
| 66 | +//! let mut usk = CGWKV::extract_usk(Some(&pk), &sk, &id, &mut rng); |
| 67 | +//! let (_ct, mut ss) = CGWKV::encaps(&pk, &id, &mut rng); |
| 68 | +//! |
| 69 | +//! // ... use sk / usk / ss ... |
| 70 | +//! |
| 71 | +//! // Wipe the secret material once you are done with it. |
| 72 | +//! sk.zeroize(); |
| 73 | +//! usk.zeroize(); |
| 74 | +//! ss.zeroize(); |
| 75 | +//! ``` |
| 76 | +//! |
| 77 | +//! Making these types `!Copy` so that `ZeroizeOnDrop` can be derived (and the |
| 78 | +//! wiping happens automatically) is a breaking API change; it is deferred to a |
| 79 | +//! future major release. |
43 | 80 |
|
44 | 81 | #![no_std] |
45 | 82 | #![deny(missing_debug_implementations, rust_2018_idioms, missing_docs)] |
|
0 commit comments