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
impl Plaintext
Sourcepub fn new_with_pool(memory: &MemoryPool) -> Result<Self>
pub fn new_with_pool(memory: &MemoryPool) -> Result<Self>
Constructs an empty plaintext in a memory pool.
Sourcepub fn from_hex_string(hex_str: &str) -> Result<Self>
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:
- Terms are listed in order of strictly decreasing exponent
- Coefficient values are non-negative and in hexadecimal format (upper and lower case letters are both supported)
- Exponents are positive and in decimal format
- Zero coefficient terms (including the constant term) may be (but do not have to be) omitted
- Term with the exponent value of one must be exactly written as x^1
- Term with the exponent value of zero (the constant term) must be written as just a hexadecimal number without exponent
- Terms must be separated by exactly [space]+[space] and minus is not allowed
- 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.
Sourcepub fn get_coefficient(&self, index: usize) -> u64
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().
Sourcepub fn set_coefficient(&mut self, index: usize, value: u64)
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().
Sourcepub fn resize(&mut self, count: usize)
pub fn resize(&mut self, count: usize)
Sets the number of coefficients this plaintext can hold.
Sourcepub fn is_ntt_form(&self) -> bool
pub fn is_ntt_form(&self) -> bool
Returns whether the plaintext is in NTT form.