Skip to main content

Padding

Enum Padding 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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.

Fields

§min_bytes: u16

Floor below which every string pads to one bucket.

§

Fixed

Pad every string to max_bytes, so ciphertexts reveal nothing of the length. Longer strings are refused (OreError::ExceedsPadding).

Fields

§max_bytes: NonZeroU16

The 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

Source

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.

Trait Implementations§

Source§

impl Clone for Padding

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Padding

Source§

impl Debug for Padding

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Padding

Source§

fn default() -> Self

Powers of two with a 16-byte floor.

Source§

impl Eq for Padding

Source§

impl PartialEq for Padding

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Padding

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<S, T, P> Supports<Nulls<T, P>> for S
where S: Supports<T> + ?Sized, T: FixedWidth, P: NullPolicy,

Source§

fn supports(target: Nulls<T, P>) -> bool

Whether the scheme takes terms of target. For a marker, true (the impl exists); for an OrderTarget, the scheme’s list.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.