#[non_exhaustive]pub enum Padding {
None,
PowerOfTwo {
min_bytes: u16,
},
Fixed {
max_bytes: NonZeroU16,
},
}Expand description
How the string encryptors pad a string before encrypting it, so that a ciphertext reveals a length bucket rather than the exact length (see the module docs).
Lengths are in UTF-8 bytes. The policy belongs with the key: stored values and the queries that compare with them must use the same one, and changing it means re-encrypting the stored values. The comparators refuse to compare ciphertexts made under different policies.
Padding hides the exact length in the ciphertext only: the time the encryptor takes still depends on the exact length of the string.
More policies may follow (a growth ratio between buckets, boundaries fitted to the data), so the enum is non-exhaustive.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
None
No padding: the ciphertext reveals the exact length.
PowerOfTwo
Pad to min_bytes if the string fits, and otherwise to the smallest
power of two that holds it. With the default 16-byte floor the
buckets are 16, 32, 64, 128 bytes and so on: a ciphertext reveals
about log₂ L of a length L, every string up to min_bytes long
pads to the same length, and above the floor padding less than
doubles a length. A
string that would pad past MAX_STR_BYTES is refused
(OreError::TooManyBlocks), so with the default floor the longest
bucket is 32768 bytes; the cipher’s own ceiling
(Options::with_max_bytes) is usually far lower.
Chosen over Padmé (Nikitin et al., PETS 2019). Padmé leaves only
O(log log L) bits of the length and adds under 12.5%, but it was
designed for kilobyte-to-gigabyte messages. At database string
lengths its buckets are narrow: below 9 bytes it changes nothing,
from 9 to 31 bytes it rounds only to an even length, and from 32 to
63 to a multiple of 4. Powers of two cost more blocks and leak more
in theory, but their buckets are far wider where strings actually
are. The simulation behind the choice is in
https://github.com/cipherstash/ore.rs/issues/104.
Fixed
Pad every string to max_bytes, so ciphertexts reveal nothing of
the length. Longer strings are refused
(OreError::ExceedsPadding).
Fields
max_bytes: NonZeroU16The length every string pads to. Non-zero: vitaminc puts a marker byte before every text, so no value fits in 0.
Implementations§
Source§impl Padding
impl Padding
Sourcepub fn padded_len(self, len: usize) -> Result<usize, OreError>
pub fn padded_len(self, len: usize) -> Result<usize, OreError>
The length in bytes a string of len bytes pads to, which is what a
ciphertext reveals of it. Errors as the string encryptors do:
OreError::ExceedsPadding if len exceeds a fixed length, and
OreError::TooManyBlocks if the padded string has more blocks than
the wire format can number.