Plaintext

Struct Plaintext 

Source
pub struct Plaintext { /* private fields */ }
Expand description

Class to store a plaintext encoded items. The data encoded for the plaintext is a polynomial with coefficients modulo the plaintext modulus. The degree of the plaintext polynomial must be one less than the degree of the polynomial modulus. The backing array always allocates one 64-bit word per each coefficient of the polynomial.

§Memory Management

The coefficient count of a plaintext refers to the number of word-size coefficients in the plaintext, whereas its capacity refers to the number of word-size coefficients that fit in the current memory allocation. In high-performance applications unnecessary re-allocations should be avoided by reserving enough memory for the plaintext to begin with either by providing the desired capacity to the constructor as an extra argument, or by calling the reserve function at any time.

When the scheme is SchemeType.BFV each coefficient of a plaintext is a 64-bit word, but when the scheme is SchemeType.CKKS the plaintext is by default stored in an NTT transformed form with respect to each of the primes in the coefficient modulus. Thus, the size of the allocation that is needed is the size of the coefficient modulus (number of primes) times the degree of the polynomial modulus. In addition, a valid CKKS plaintext will also store the ParmsId for the corresponding encryption parameters.

Implementations§

Source§

impl Plaintext

Source

pub fn new() -> Result<Self>

Constructs an empty plaintext allocating no memory.

Source

pub fn new_with_pool(memory: &MemoryPool) -> Result<Self>

Constructs an empty plaintext in a memory pool.

Source

pub fn from_hex_string(hex_str: &str) -> Result<Self>

Constructs a plaintext from a given hexadecimal string describing the plaintext polynomial.

The string description of the polynomial must adhere to the format returned by ToString(), which is of the form “7FFx^3 + 1x^1 + 3” and summarized by the following rules:

  1. Terms are listed in order of strictly decreasing exponent
  2. Coefficient values are non-negative and in hexadecimal format (upper and lower case letters are both supported)
  3. Exponents are positive and in decimal format
  4. Zero coefficient terms (including the constant term) may be (but do not have to be) omitted
  5. Term with the exponent value of one must be exactly written as x^1
  6. Term with the exponent value of zero (the constant term) must be written as just a hexadecimal number without exponent
  7. Terms must be separated by exactly [space]+[space] and minus is not allowed
  8. Other than the +, no other terms should have whitespace
  • hex_str: The formatted polynomial string specifying the plaintext polynomial.
§Panics

Panics if hex_str contains a null character anywhere but the end of the string.

Source

pub fn get_coefficient(&self, index: usize) -> u64

Gets the coefficient at the given location. Coefficients are ordered from lowest to highest degree, with the first value being the constant coefficient.

§Panics

Panics if index is greater than len().

Source

pub fn set_coefficient(&mut self, index: usize, value: u64)

Sets the coefficient at the given location. Coefficients are ordered from lowest to highest degree, with the first value being the constant coefficient.

§Panics

Panics if index is greater than len().

Source

pub fn resize(&mut self, count: usize)

Sets the number of coefficients this plaintext can hold.

Source

pub fn len(&self) -> usize

Returns the number of coefficients this plaintext can hold.

Source

pub fn is_empty(&self) -> bool

Returns true if the plaintext is empty.

Source

pub fn is_ntt_form(&self) -> bool

Returns whether the plaintext is in NTT form.

Trait Implementations§

Source§

impl AsRef<Plaintext> for Plaintext

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Plaintext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Plaintext

Source§

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

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

impl Drop for Plaintext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl FromBytes for Plaintext

Source§

fn from_bytes(context: &Context, data: &[u8]) -> Result<Self>

Deserializes a byte stream into a plaintext. This requires a context, which is why Plaintext doesn’t impl Deserialize.

Source§

type State = Context

State used to deserialize an object from bytes.
Source§

impl Hash for Plaintext

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Plaintext

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Plaintext

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToBytes for Plaintext

Source§

fn as_bytes(&self) -> Result<Vec<u8>>

Returns the object as a byte array.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.