use concrete_shortint;
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
pub struct KeyId(pub usize);
#[derive(Serialize, Clone, Deserialize)]
pub struct RadixCiphertext {
pub(crate) blocks: Vec<concrete_shortint::Ciphertext>,
}
pub trait IntegerCiphertext: Clone {
fn from_blocks(blocks: Vec<concrete_shortint::Ciphertext>) -> Self;
fn blocks(&self) -> &[concrete_shortint::Ciphertext];
fn blocks_mut(&mut self) -> &mut [concrete_shortint::Ciphertext];
fn moduli(&self) -> Vec<u64> {
self.blocks()
.iter()
.map(|x| x.message_modulus.0 as u64)
.collect()
}
}
impl IntegerCiphertext for RadixCiphertext {
fn blocks(&self) -> &[concrete_shortint::Ciphertext] {
&self.blocks
}
fn blocks_mut(&mut self) -> &mut [concrete_shortint::Ciphertext] {
&mut self.blocks
}
fn from_blocks(blocks: Vec<concrete_shortint::Ciphertext>) -> Self {
Self { blocks }
}
}
impl IntegerCiphertext for CrtCiphertext {
fn blocks(&self) -> &[concrete_shortint::Ciphertext] {
&self.blocks
}
fn blocks_mut(&mut self) -> &mut [concrete_shortint::Ciphertext] {
&mut self.blocks
}
fn from_blocks(blocks: Vec<concrete_shortint::Ciphertext>) -> Self {
let moduli = blocks.iter().map(|x| x.message_modulus.0 as u64).collect();
Self { blocks, moduli }
}
}
#[derive(Serialize, Clone, Deserialize)]
pub struct CrtCiphertext {
pub(crate) blocks: Vec<concrete_shortint::Ciphertext>,
pub(crate) moduli: Vec<u64>,
}
#[derive(Serialize, Clone, Deserialize)]
pub struct CrtMultiCiphertext {
pub(crate) blocks: Vec<concrete_shortint::Ciphertext>,
pub(crate) moduli: Vec<u64>,
pub(crate) key_ids: Vec<KeyId>,
}