concrete_integer/ciphertext/
mod.rs1use concrete_shortint;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
7pub struct KeyId(pub usize);
8
9#[derive(Serialize, Clone, Deserialize)]
11pub struct RadixCiphertext {
12 pub(crate) blocks: Vec<concrete_shortint::Ciphertext>,
14}
15
16pub trait IntegerCiphertext: Clone {
17 fn from_blocks(blocks: Vec<concrete_shortint::Ciphertext>) -> Self;
18 fn blocks(&self) -> &[concrete_shortint::Ciphertext];
19 fn blocks_mut(&mut self) -> &mut [concrete_shortint::Ciphertext];
20 fn moduli(&self) -> Vec<u64> {
21 self.blocks()
22 .iter()
23 .map(|x| x.message_modulus.0 as u64)
24 .collect()
25 }
26}
27
28impl IntegerCiphertext for RadixCiphertext {
29 fn blocks(&self) -> &[concrete_shortint::Ciphertext] {
30 &self.blocks
31 }
32 fn blocks_mut(&mut self) -> &mut [concrete_shortint::Ciphertext] {
33 &mut self.blocks
34 }
35 fn from_blocks(blocks: Vec<concrete_shortint::Ciphertext>) -> Self {
36 Self { blocks }
37 }
38}
39
40impl IntegerCiphertext for CrtCiphertext {
41 fn blocks(&self) -> &[concrete_shortint::Ciphertext] {
42 &self.blocks
43 }
44 fn blocks_mut(&mut self) -> &mut [concrete_shortint::Ciphertext] {
45 &mut self.blocks
46 }
47 fn from_blocks(blocks: Vec<concrete_shortint::Ciphertext>) -> Self {
48 let moduli = blocks.iter().map(|x| x.message_modulus.0 as u64).collect();
49 Self { blocks, moduli }
50 }
51}
52
53#[derive(Serialize, Clone, Deserialize)]
58pub struct CrtCiphertext {
59 pub(crate) blocks: Vec<concrete_shortint::Ciphertext>,
60 pub(crate) moduli: Vec<u64>,
61}
62
63#[derive(Serialize, Clone, Deserialize)]
68pub struct CrtMultiCiphertext {
69 pub(crate) blocks: Vec<concrete_shortint::Ciphertext>,
70 pub(crate) moduli: Vec<u64>,
71 pub(crate) key_ids: Vec<KeyId>,
72}