1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Layer 4 — Decoy bytes.
//!
//! Decoy strategies produce filler bytes that surround real key fragments in
//! storage. The goal is statistical indistinguishability: an attacker
//! scraping memory should not be able to tell which bytes are real and which
//! are filler without the position map.
//!
//! Phase 0.4 ships three implementations covering the standard trade-off
//! axis:
//!
//! | Strategy | Output profile | Strength | Default? |
//! |---------------------------------|-------------------------------|---------------------|----------|
//! | [`RandomDecoy`] | Uniformly random | Weakest, fastest | |
//! | [`KeyDerivedDecoy`] | BLAKE3-XOF (CSPRNG-like) | Medium | |
//! | [`SelfReferenceDecoy`] | Drawn from the key itself | Strongest | ✅ |
//!
//! The strongest built-in strategy ([`SelfReferenceDecoy`]) lifts bytes from
//! the real key, so the filler is by definition drawn from the same
//! distribution as the secret. The weakest ([`RandomDecoy`]) uses raw CSPRNG
//! output, which is easy to compute but tends to stand out from key material
//! that has structure (DER-encoded RSA, ASCII-armored data, etc.).
use Cow;
use Vec;
use crateResult;
use crateRawKey;
pub use KeyDerivedDecoy;
pub use RandomDecoy;
pub use SelfReferenceDecoy;
/// Strategy for producing decoy filler bytes.
///
/// # Implementor contract
///
/// - **Deterministic for a given seed but not for a given key.** Strategies
/// that derive filler from the key ([`SelfReferenceDecoy`],
/// [`KeyDerivedDecoy`]) must mix in fresh CSPRNG bytes per call so that
/// two consecutive `generate` calls on the same key produce different
/// output. Otherwise an attacker who recovers the key can confirm any
/// suspected fragmentation by recomputing the decoy.
/// - **No accidental key recovery.** A decoy strategy must never emit a
/// contiguous run of bytes that matches the real key — verify this in
/// tests for any implementation. `SelfReferenceDecoy` sidesteps this by
/// sampling with replacement instead of shuffling.
/// - **`Send + Sync`.** May be invoked from any thread.