concrete_integer/server_key/radix_parallel/neg.rs
1use crate::ciphertext::RadixCiphertext;
2use crate::ServerKey;
3
4impl ServerKey {
5 /// Homomorphically computes the opposite of a ciphertext encrypting an integer message.
6 ///
7 /// The result is returned as a new ciphertext.
8 ///
9 /// # Example
10 ///
11 /// ```rust
12 /// use concrete_integer::gen_keys_radix;
13 /// use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
14 ///
15 /// // We have 4 * 2 = 8 bits of message
16 /// let size = 4;
17 /// let (cks, sks) = gen_keys_radix(&PARAM_MESSAGE_2_CARRY_2, size);
18 ///
19 /// let msg = 1;
20 ///
21 /// // Encrypt two messages:
22 /// let mut ctxt = cks.encrypt(msg);
23 ///
24 /// // Compute homomorphically a negation
25 /// let ct_res = sks.smart_neg_parallelized(&mut ctxt);
26 ///
27 /// // Decrypt
28 /// let dec = cks.decrypt(&ct_res);
29 /// assert_eq!(255, dec);
30 /// ```
31 pub fn smart_neg_parallelized(&self, ctxt: &mut RadixCiphertext) -> RadixCiphertext {
32 if !self.is_neg_possible(ctxt) {
33 self.full_propagate_parallelized(ctxt);
34 }
35 self.unchecked_neg(ctxt)
36 }
37}