concrete_integer/server_key/crt/
add_crt.rs1use crate::{CrtCiphertext, ServerKey};
2
3impl ServerKey {
4 pub fn smart_crt_add(
29 &self,
30 ct_left: &mut CrtCiphertext,
31 ct_right: &mut CrtCiphertext,
32 ) -> CrtCiphertext {
33 if !self.is_crt_add_possible(ct_left, ct_right) {
34 self.full_extract(ct_left);
35 self.full_extract(ct_right);
36 }
37 self.unchecked_crt_add(ct_left, ct_right)
38 }
39
40 pub fn smart_crt_add_assign(&self, ct_left: &mut CrtCiphertext, ct_right: &mut CrtCiphertext) {
41 if !self.is_crt_add_possible(ct_left, ct_right) {
43 self.full_extract(ct_left);
44 self.full_extract(ct_right);
45 }
46 self.unchecked_crt_add_assign(ct_left, ct_right);
47 }
48
49 pub fn is_crt_add_possible(&self, ct_left: &CrtCiphertext, ct_right: &CrtCiphertext) -> bool {
50 for (ct_left_i, ct_right_i) in ct_left.blocks.iter().zip(ct_right.blocks.iter()) {
51 if !self.key.is_add_possible(ct_left_i, ct_right_i) {
52 return false;
53 }
54 }
55 true
56 }
57
58 pub fn unchecked_crt_add_assign(&self, ct_left: &mut CrtCiphertext, ct_right: &CrtCiphertext) {
59 for (ct_left_i, ct_right_i) in ct_left.blocks.iter_mut().zip(ct_right.blocks.iter()) {
60 self.key.unchecked_add_assign(ct_left_i, ct_right_i);
61 }
62 }
63
64 pub fn unchecked_crt_add(
65 &self,
66 ct_left: &CrtCiphertext,
67 ct_right: &CrtCiphertext,
68 ) -> CrtCiphertext {
69 let mut ct_res = ct_left.clone();
70 self.unchecked_crt_add_assign(&mut ct_res, ct_right);
71 ct_res
72 }
73}