1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use crate::ciphertext::RadixCiphertext;
use crate::ServerKey;
impl ServerKey {
/// Computes homomorphically a bitand between two ciphertexts encrypting integer values.
///
/// # Warning
///
/// - Multithreaded
///
/// # Example
///
/// ```rust
/// use concrete_integer::gen_keys_radix;
/// use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
///
/// // Generate the client key and the server key:
/// let num_blocks = 4;
/// let (cks, sks) = gen_keys_radix(&PARAM_MESSAGE_2_CARRY_2, num_blocks);
///
/// let msg1 = 14;
/// let msg2 = 97;
///
/// let mut ct1 = cks.encrypt(msg1);
/// let mut ct2 = cks.encrypt(msg2);
///
/// let ct_res = sks.smart_bitand_parallelized(&mut ct1, &mut ct2);
///
/// // Decrypt:
/// let dec_result = cks.decrypt(&ct_res);
/// assert_eq!(dec_result, msg1 & msg2);
/// ```
pub fn smart_bitand_parallelized(
&self,
ct_left: &mut RadixCiphertext,
ct_right: &mut RadixCiphertext,
) -> RadixCiphertext {
if !self.is_functional_bivariate_pbs_possible(ct_left, ct_right) {
rayon::join(
|| self.full_propagate_parallelized(ct_left),
|| self.full_propagate_parallelized(ct_right),
);
}
self.unchecked_bitand(ct_left, ct_right)
}
pub fn smart_bitand_assign_parallelized(
&self,
ct_left: &mut RadixCiphertext,
ct_right: &mut RadixCiphertext,
) {
if !self.is_functional_bivariate_pbs_possible(ct_left, ct_right) {
rayon::join(
|| self.full_propagate_parallelized(ct_left),
|| self.full_propagate_parallelized(ct_right),
);
}
self.unchecked_bitand_assign(ct_left, ct_right);
}
/// Computes homomorphically a bitor between two ciphertexts encrypting integer values.
///
/// # Warning
///
/// - Multithreaded
///
/// # Example
///
/// ```rust
/// use concrete_integer::gen_keys_radix;
/// use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
///
/// // Generate the client key and the server key:
/// let num_blocks = 4;
/// let (cks, sks) = gen_keys_radix(&PARAM_MESSAGE_2_CARRY_2, num_blocks);
///
/// let msg1 = 14;
/// let msg2 = 97;
///
/// let mut ct1 = cks.encrypt(msg1);
/// let mut ct2 = cks.encrypt(msg2);
///
/// let ct_res = sks.smart_bitor(&mut ct1, &mut ct2);
///
/// // Decrypt:
/// let dec_result = cks.decrypt(&ct_res);
/// assert_eq!(dec_result, msg1 | msg2);
/// ```
pub fn smart_bitor_parallelized(
&self,
ct_left: &mut RadixCiphertext,
ct_right: &mut RadixCiphertext,
) -> RadixCiphertext {
if !self.is_functional_bivariate_pbs_possible(ct_left, ct_right) {
rayon::join(
|| self.full_propagate_parallelized(ct_left),
|| self.full_propagate_parallelized(ct_right),
);
}
self.unchecked_bitor(ct_left, ct_right)
}
pub fn smart_bitor_assign_parallelized(
&self,
ct_left: &mut RadixCiphertext,
ct_right: &mut RadixCiphertext,
) {
if !self.is_functional_bivariate_pbs_possible(ct_left, ct_right) {
rayon::join(
|| self.full_propagate_parallelized(ct_left),
|| self.full_propagate_parallelized(ct_right),
);
}
self.unchecked_bitor_assign(ct_left, ct_right);
}
/// Computes homomorphically a bitxor between two ciphertexts encrypting integer values.
///
/// # Warning
///
/// - Multithreaded
///
/// # Example
///
/// ```rust
/// use concrete_integer::gen_keys_radix;
/// use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
///
/// // Generate the client key and the server key:
/// let num_blocks = 4;
/// let (cks, sks) = gen_keys_radix(&PARAM_MESSAGE_2_CARRY_2, num_blocks);
///
/// let msg1 = 14;
/// let msg2 = 97;
///
/// let mut ct1 = cks.encrypt(msg1);
/// let mut ct2 = cks.encrypt(msg2);
///
/// let ct_res = sks.smart_bitxor_parallelized(&mut ct1, &mut ct2);
///
/// // Decrypt:
/// let dec_result = cks.decrypt(&ct_res);
/// assert_eq!(dec_result, msg1 ^ msg2);
/// ```
pub fn smart_bitxor_parallelized(
&self,
ct_left: &mut RadixCiphertext,
ct_right: &mut RadixCiphertext,
) -> RadixCiphertext {
if !self.is_functional_bivariate_pbs_possible(ct_left, ct_right) {
rayon::join(
|| self.full_propagate_parallelized(ct_left),
|| self.full_propagate_parallelized(ct_right),
);
}
self.unchecked_bitxor(ct_left, ct_right)
}
pub fn smart_bitxor_assign_parallelized(
&self,
ct_left: &mut RadixCiphertext,
ct_right: &mut RadixCiphertext,
) {
if !self.is_functional_bivariate_pbs_possible(ct_left, ct_right) {
rayon::join(
|| self.full_propagate_parallelized(ct_left),
|| self.full_propagate_parallelized(ct_right),
);
}
self.unchecked_bitxor_assign(ct_left, ct_right);
}
}