Adding a constant to a ciphertext
Adding a constant to an LWE ciphertext is a leveled operation that does not increase noise and does not consume padding, but can optionally change the interval of the encoder, depending on the method being used.
Operation | |
Type | Leveled |
Side effects | Potentially modifies encoding |
Adding a constant to an LWE
There are two ways to add a constant to a ciphertext:
using the
add
method which adds a constant to a ciphertext and shift the interval of the encoder by that constant, thus going from an interval of to an interval of . Note that with this method, the ciphertext itself is not modified, as we only need to change the encoding to get the correct value. This is a convenience alias of theadd_constant_dynamic_encoder
method.using the
add_constant_static_encoder
method that adds a constant to a ciphertext without changing the encoding. With this method, the ciphertext itself is changed by adding the constant to its body, while the encoding remains the same.
Both methods also exist in mutable form that modify the current ciphertext: add_inplace
(or its verbose form add_constant_dynamic_encoder_inplace
) and add_constant_static_encoder_inplace
.
The value of the constant being added in the dynamic method does not have to be in the interval of the original encoder.
If the result of adding a constant to a ciphertext using the static method ends up outside the interval of the original ciphertext, the result will wrap around the interval with undefined behavior.
The example below shows how to add a constant to an LWE:
Adding a vector of constant to a VectorLWE
Both dynamic and static methods, as well as their mutable counterparts, exist in vectorized form when operating with a VectorLWE
struct. In this case, constants in the vector are added element wise to the vector of ciphertexts:
Last updated