From 8f7cb9fbc53f85a664764f9f2fe9a254b283b4ef Mon Sep 17 00:00:00 2001 From: Pro7ech Date: Sat, 8 Nov 2025 12:07:00 +0100 Subject: [PATCH] Add decrypt on fhe_uint_prepared --- .../ciphertexts/fhe_uint_prepared.rs | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs index b348f11..32a03c5 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs @@ -1,12 +1,15 @@ use std::marker::PhantomData; -use poulpy_core::LWEFromGLWE; use poulpy_core::layouts::{ Base2K, Dnum, Dsize, GGSWInfos, GGSWPreparedFactory, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::GGSWPrepared, }; -use poulpy_core::layouts::{GGSWPreparedToMut, GGSWPreparedToRef, LWE}; +use poulpy_core::layouts::{ + GGLWEInfos, GGLWEPreparedToRef, GGSWPreparedToMut, GGSWPreparedToRef, GLWEAutomorphismKeyHelper, GetGaloisElement, LWE, +}; +use poulpy_core::{GLWECopy, GLWEDecrypt, GLWEPacking, LWEFromGLWE}; use poulpy_core::{GGSWEncryptSk, ScratchTakeCore, layouts::GLWESecretPreparedToRef}; +use poulpy_hal::api::ModuleLogN; use poulpy_hal::layouts::{Backend, Data, DataRef, Module}; use poulpy_hal::{ @@ -15,8 +18,8 @@ use poulpy_hal::{ source::Source, }; -use crate::tfhe::bdd_arithmetic::UnsignedInteger; use crate::tfhe::bdd_arithmetic::{BDDKey, BDDKeyHelper, BDDKeyInfos, BDDKeyPrepared, BDDKeyPreparedFactory, FheUint, ToBits}; +use crate::tfhe::bdd_arithmetic::{Cmux, FromBits, ScratchTakeBDD, UnsignedInteger}; use crate::tfhe::blind_rotation::BlindRotationAlgo; use crate::tfhe::circuit_bootstrapping::CirtuitBootstrappingExecute; @@ -160,6 +163,21 @@ impl FheUintPrepared FheUintPrepared { + pub fn decrypt(&self, module: &M, sk: &S, keys: &H, scratch: &mut Scratch) -> T + where + M: ModuleLogN + GLWEDecrypt + Cmux + GLWEPacking + GLWECopy, + S: GLWESecretPreparedToRef + GLWEInfos, + Scratch: ScratchTakeCore, + K: GGLWEPreparedToRef + GetGaloisElement + GGLWEInfos, + H: GLWEAutomorphismKeyHelper, + { + let (mut tmp, scratch_1) = scratch.take_fhe_uint(self); + tmp.from_fhe_uint_prepared(module, self, keys, scratch_1); + tmp.decrypt(module, sk, scratch_1) + } +} + impl LWEInfos for FheUintPrepared { fn base2k(&self) -> poulpy_core::layouts::Base2K { self.bits[0].base2k()