@@ -12,8 +12,7 @@ use crate::high_level_api::traits::Tagged;
12
12
use crate :: integer:: ciphertext:: { Compactable , DataKind , Expandable } ;
13
13
use crate :: integer:: encryption:: KnowsMessageModulus ;
14
14
use crate :: integer:: parameters:: {
15
- CompactCiphertextListConformanceParams , IntegerCompactCiphertextListCastingMode ,
16
- IntegerCompactCiphertextListUnpackingMode ,
15
+ CompactCiphertextListConformanceParams , IntegerCompactCiphertextListExpansionMode ,
17
16
} ;
18
17
use crate :: named:: Named ;
19
18
use crate :: prelude:: CiphertextList ;
@@ -111,13 +110,7 @@ impl CompactCiphertextList {
111
110
sks : & crate :: ServerKey ,
112
111
) -> crate :: Result < CompactCiphertextListExpander > {
113
112
self . inner
114
- . expand (
115
- IntegerCompactCiphertextListUnpackingMode :: UnpackIfNecessary ( sks. key . pbs_key ( ) ) ,
116
- sks. cpk_casting_key ( ) . map_or (
117
- IntegerCompactCiphertextListCastingMode :: NoCasting ,
118
- IntegerCompactCiphertextListCastingMode :: CastIfNecessary ,
119
- ) ,
120
- )
113
+ . expand ( sks. integer_compact_ciphertext_list_expansion_mode ( ) )
121
114
. map ( |inner| CompactCiphertextListExpander {
122
115
inner,
123
116
tag : self . tag . clone ( ) ,
@@ -129,44 +122,22 @@ impl CompactCiphertextList {
129
122
if !self . inner . is_packed ( ) && !self . inner . needs_casting ( ) {
130
123
// No ServerKey required, short-circuit to avoid the global state call
131
124
return Ok ( CompactCiphertextListExpander {
132
- inner : self . inner . expand (
133
- IntegerCompactCiphertextListUnpackingMode :: NoUnpacking ,
134
- IntegerCompactCiphertextListCastingMode :: NoCasting ,
135
- ) ?,
125
+ inner : self
126
+ . inner
127
+ . expand ( IntegerCompactCiphertextListExpansionMode :: NoCastingAndNoUnpacking ) ?,
136
128
tag : self . tag . clone ( ) ,
137
129
} ) ;
138
130
}
139
131
140
132
global_state:: try_with_internal_keys ( |maybe_keys| match maybe_keys {
141
133
None => Err ( crate :: high_level_api:: errors:: UninitializedServerKey . into ( ) ) ,
142
- Some ( InternalServerKey :: Cpu ( cpu_key) ) => {
143
- let unpacking_mode = if self . inner . is_packed ( ) {
144
- IntegerCompactCiphertextListUnpackingMode :: UnpackIfNecessary ( cpu_key. pbs_key ( ) )
145
- } else {
146
- IntegerCompactCiphertextListUnpackingMode :: NoUnpacking
147
- } ;
148
-
149
- let casting_mode = if self . inner . needs_casting ( ) {
150
- IntegerCompactCiphertextListCastingMode :: CastIfNecessary (
151
- cpu_key. cpk_casting_key ( ) . ok_or_else ( || {
152
- crate :: Error :: new (
153
- "No casting key found in ServerKey, \
154
- required to expand this CompactCiphertextList"
155
- . to_string ( ) ,
156
- )
157
- } ) ?,
158
- )
159
- } else {
160
- IntegerCompactCiphertextListCastingMode :: NoCasting
161
- } ;
162
-
163
- self . inner
164
- . expand ( unpacking_mode, casting_mode)
165
- . map ( |inner| CompactCiphertextListExpander {
166
- inner,
167
- tag : self . tag . clone ( ) ,
168
- } )
169
- }
134
+ Some ( InternalServerKey :: Cpu ( cpu_key) ) => self
135
+ . inner
136
+ . expand ( cpu_key. integer_compact_ciphertext_list_expansion_mode ( ) )
137
+ . map ( |inner| CompactCiphertextListExpander {
138
+ inner,
139
+ tag : self . tag . clone ( ) ,
140
+ } ) ,
170
141
#[ cfg( feature = "gpu" ) ]
171
142
Some ( _) => Err ( crate :: Error :: new ( "Expected a CPU server key" . to_string ( ) ) ) ,
172
143
} )
@@ -261,51 +232,26 @@ mod zk {
261
232
public_params,
262
233
& pk. key . key ,
263
234
metadata,
264
- IntegerCompactCiphertextListUnpackingMode :: NoUnpacking ,
265
- IntegerCompactCiphertextListCastingMode :: NoCasting ,
235
+ IntegerCompactCiphertextListExpansionMode :: NoCastingAndNoUnpacking ,
266
236
) ?,
267
237
tag : self . tag . clone ( ) ,
268
238
} ) ;
269
239
}
270
240
271
241
global_state:: try_with_internal_keys ( |maybe_keys| match maybe_keys {
272
242
None => Err ( crate :: high_level_api:: errors:: UninitializedServerKey . into ( ) ) ,
273
- Some ( InternalServerKey :: Cpu ( cpu_key) ) => {
274
- let unpacking_mode = if self . inner . is_packed ( ) {
275
- IntegerCompactCiphertextListUnpackingMode :: UnpackIfNecessary (
276
- cpu_key. pbs_key ( ) ,
277
- )
278
- } else {
279
- IntegerCompactCiphertextListUnpackingMode :: NoUnpacking
280
- } ;
281
-
282
- let casting_mode = if self . inner . needs_casting ( ) {
283
- IntegerCompactCiphertextListCastingMode :: CastIfNecessary (
284
- cpu_key. cpk_casting_key ( ) . ok_or_else ( || {
285
- crate :: Error :: new (
286
- "No casting key found in ServerKey, \
287
- required to expand this CompactCiphertextList"
288
- . to_string ( ) ,
289
- )
290
- } ) ?,
291
- )
292
- } else {
293
- IntegerCompactCiphertextListCastingMode :: NoCasting
294
- } ;
295
-
296
- self . inner
297
- . verify_and_expand (
298
- public_params,
299
- & pk. key . key ,
300
- metadata,
301
- unpacking_mode,
302
- casting_mode,
303
- )
304
- . map ( |expander| CompactCiphertextListExpander {
305
- inner : expander,
306
- tag : self . tag . clone ( ) ,
307
- } )
308
- }
243
+ Some ( InternalServerKey :: Cpu ( cpu_key) ) => self
244
+ . inner
245
+ . verify_and_expand (
246
+ public_params,
247
+ & pk. key . key ,
248
+ metadata,
249
+ cpu_key. integer_compact_ciphertext_list_expansion_mode ( ) ,
250
+ )
251
+ . map ( |expander| CompactCiphertextListExpander {
252
+ inner : expander,
253
+ tag : self . tag . clone ( ) ,
254
+ } ) ,
309
255
#[ cfg( feature = "gpu" ) ]
310
256
Some ( _) => Err ( crate :: Error :: new ( "Expected a CPU server key" . to_string ( ) ) ) ,
311
257
} )
@@ -321,45 +267,23 @@ mod zk {
321
267
// No ServerKey required, short circuit to avoid the global state call
322
268
return Ok ( CompactCiphertextListExpander {
323
269
inner : self . inner . expand_without_verification (
324
- IntegerCompactCiphertextListUnpackingMode :: NoUnpacking ,
325
- IntegerCompactCiphertextListCastingMode :: NoCasting ,
270
+ IntegerCompactCiphertextListExpansionMode :: NoCastingAndNoUnpacking ,
326
271
) ?,
327
272
tag : self . tag . clone ( ) ,
328
273
} ) ;
329
274
}
330
275
331
276
global_state:: try_with_internal_keys ( |maybe_keys| match maybe_keys {
332
277
None => Err ( crate :: high_level_api:: errors:: UninitializedServerKey . into ( ) ) ,
333
- Some ( InternalServerKey :: Cpu ( cpu_key) ) => {
334
- let unpacking_mode = if self . inner . is_packed ( ) {
335
- IntegerCompactCiphertextListUnpackingMode :: UnpackIfNecessary (
336
- cpu_key. pbs_key ( ) ,
337
- )
338
- } else {
339
- IntegerCompactCiphertextListUnpackingMode :: NoUnpacking
340
- } ;
341
-
342
- let casting_mode = if self . inner . needs_casting ( ) {
343
- IntegerCompactCiphertextListCastingMode :: CastIfNecessary (
344
- cpu_key. cpk_casting_key ( ) . ok_or_else ( || {
345
- crate :: Error :: new (
346
- "No casting key found in ServerKey, \
347
- required to expand this CompactCiphertextList"
348
- . to_string ( ) ,
349
- )
350
- } ) ?,
351
- )
352
- } else {
353
- IntegerCompactCiphertextListCastingMode :: NoCasting
354
- } ;
355
-
356
- self . inner
357
- . expand_without_verification ( unpacking_mode, casting_mode)
358
- . map ( |expander| CompactCiphertextListExpander {
359
- inner : expander,
360
- tag : self . tag . clone ( ) ,
361
- } )
362
- }
278
+ Some ( InternalServerKey :: Cpu ( cpu_key) ) => self
279
+ . inner
280
+ . expand_without_verification (
281
+ cpu_key. integer_compact_ciphertext_list_expansion_mode ( ) ,
282
+ )
283
+ . map ( |expander| CompactCiphertextListExpander {
284
+ inner : expander,
285
+ tag : self . tag . clone ( ) ,
286
+ } ) ,
363
287
#[ cfg( feature = "gpu" ) ]
364
288
Some ( _) => Err ( crate :: Error :: new ( "Expected a CPU server key" . to_string ( ) ) ) ,
365
289
} )
0 commit comments