mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
fix sext
This commit is contained in:
@@ -426,7 +426,7 @@ impl<D: DataMut, T: UnsignedInteger> FheUint<D, T> {
|
|||||||
assert!(byte < (1 << T::LOG_BYTES));
|
assert!(byte < (1 << T::LOG_BYTES));
|
||||||
|
|
||||||
let log_gap: usize = module.log_n() - T::LOG_BITS as usize;
|
let log_gap: usize = module.log_n() - T::LOG_BITS as usize;
|
||||||
let rot: i64 = (T::bit_index(byte << 3) << log_gap) as i64;
|
let rot: i64 = (T::bit_index((byte << 3) + 7) << log_gap) as i64;
|
||||||
|
|
||||||
let (mut sext, scratch_1) = scratch.take_glwe(self);
|
let (mut sext, scratch_1) = scratch.take_glwe(self);
|
||||||
|
|
||||||
@@ -443,7 +443,7 @@ impl<D: DataMut, T: UnsignedInteger> FheUint<D, T> {
|
|||||||
|
|
||||||
// Splice sext
|
// Splice sext
|
||||||
let (mut tmp, scratch_2) = scratch_1.take_glwe(self);
|
let (mut tmp, scratch_2) = scratch_1.take_glwe(self);
|
||||||
for i in byte..(1 << T::LOG_BYTES) as usize {
|
for i in (byte + 1)..(1 << T::LOG_BYTES) as usize {
|
||||||
FheUint::<&mut [u8], T>::from_glwe_to_mut(&mut tmp).splice_u8(module, i, 0, &self.bits, &sext, keys, scratch_2);
|
FheUint::<&mut [u8], T>::from_glwe_to_mut(&mut tmp).splice_u8(module, i, 0, &self.bits, &sext, keys, scratch_2);
|
||||||
module.glwe_copy(&mut self.bits, &tmp);
|
module.glwe_copy(&mut self.bits, &tmp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,29 +37,52 @@ where
|
|||||||
let mut a_enc: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&glwe_infos);
|
let mut a_enc: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&glwe_infos);
|
||||||
|
|
||||||
for j in 0..3 {
|
for j in 0..3 {
|
||||||
for i in 0..32 {
|
let a: u32 = 0x8483_8281;
|
||||||
let a: u32 = 0xFFFFFFFF >> i;
|
a_enc.encrypt_sk(
|
||||||
|
module,
|
||||||
|
a,
|
||||||
|
sk,
|
||||||
|
&mut source_xa,
|
||||||
|
&mut source_xe,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
a_enc.encrypt_sk(
|
a_enc.sext(module, j, keys, scratch.borrow());
|
||||||
module,
|
|
||||||
a,
|
|
||||||
sk,
|
|
||||||
&mut source_xa,
|
|
||||||
&mut source_xe,
|
|
||||||
scratch.borrow(),
|
|
||||||
);
|
|
||||||
|
|
||||||
a_enc.sext(module, j, keys, scratch.borrow());
|
// println!("{:08x} -> {:08x} {:08x}", a, sext(a, j), a_enc.decrypt(module, sk, scratch.borrow()));
|
||||||
|
|
||||||
// println!("{:08x} -> {:08x} {:08x}", a, sext(a, j), a_enc.decrypt(module, sk, scratch.borrow()));
|
assert_eq!(
|
||||||
|
sext(a, ((1 + j as u32) << 3) - 1),
|
||||||
|
a_enc.decrypt(module, sk, scratch.borrow())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
assert_eq!(sext(a, j), a_enc.decrypt(module, sk, scratch.borrow()));
|
for j in 0..3 {
|
||||||
}
|
let a: u32 = 0x4443_4241;
|
||||||
|
a_enc.encrypt_sk(
|
||||||
|
module,
|
||||||
|
a,
|
||||||
|
sk,
|
||||||
|
&mut source_xa,
|
||||||
|
&mut source_xe,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
|
a_enc.sext(module, j, keys, scratch.borrow());
|
||||||
|
|
||||||
|
// println!("{:08x} -> {:08x} {:08x}", a, sext(a, j), a_enc.decrypt(module, sk, scratch.borrow()));
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
sext(a, ((1 + j as u32) << 3) - 1),
|
||||||
|
a_enc.decrypt(module, sk, scratch.borrow())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sext(x: u32, byte: usize) -> u32 {
|
pub(crate) fn sext(x: u32, bits: u32) -> u32 {
|
||||||
x | (((x >> (byte << 3)) & 1) * (0xFFFF_FFFF << (byte << 3)))
|
let lo: u32 = x << (u32::BITS - bits) >> (u32::BITS - bits);
|
||||||
|
let hi: u32 = ((x >> bits) & 1) * (0xFFFF_FFFF << bits);
|
||||||
|
hi | lo
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_fhe_uint_splice_u8<BRA: BlindRotationAlgo, BE: Backend>(test_context: &TestContext<BRA, BE>)
|
pub fn test_fhe_uint_splice_u8<BRA: BlindRotationAlgo, BE: Backend>(test_context: &TestContext<BRA, BE>)
|
||||||
|
|||||||
Reference in New Issue
Block a user