Skip to content

Commit fe889e8

Browse files
authored
Update MSRV to 1.91.1 (#365)
1 parent e0c34a4 commit fe889e8

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ authors = ["Tancrède Lepoint"]
88
edition = "2024"
99
repository = "https://github.com/tlepoint/fhe.rs"
1010
license = "MIT"
11-
rust-version = "1.88"
11+
rust-version = "1.91.1"
1212

1313
[workspace.lints.rust]
1414
missing_docs = "warn"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fhe-traits = "0.1.1"
3434

3535
## Minimum supported version / toolchain
3636

37-
Rust **1.85** or newer (Rust 2024 edition).
37+
Rust **1.91.1** or newer (Rust 2024 edition).
3838

3939
## ⚠️ Security / Stability
4040

crates/fhe/src/bfv/keys/secret_key.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ impl SecretKey {
8585
*c.as_mut() -= &m;
8686
let ctx = c.ctx().clone();
8787
let c_inner = std::mem::replace(c.as_mut(), Poly::<Ntt>::zero(&ctx));
88-
let c = c_inner.into_power_basis();
88+
let c = Zeroizing::new(c_inner.into_power_basis());
8989

9090
let ciphertext_modulus = ct[0].ctx().modulus();
9191
let mut noise = 0usize;
92-
for coeff in Vec::<BigUint>::from(&c) {
92+
for coeff in Vec::<BigUint>::from(c.as_ref()) {
9393
noise = std::cmp::max(
9494
noise,
9595
std::cmp::min(coeff.bits(), (ciphertext_modulus - &coeff).bits()) as usize,
@@ -227,8 +227,8 @@ impl FheDecrypter<Plaintext, Ciphertext> for SecretKey {
227227
let ctx_lvl = self.par.context_level_at(ct.level).unwrap();
228228
let ctx = c.ctx().clone();
229229
let c_inner = std::mem::replace(c.as_mut(), Poly::<Ntt>::zero(&ctx));
230-
let c_pb = c_inner.into_power_basis();
231-
let d = Zeroizing::new(c_pb.scale(&ctx_lvl.cipher_plain_context.scaler)?);
230+
let c_pb = Zeroizing::new(c_inner.into_power_basis());
231+
let d = Zeroizing::new(c_pb.as_ref().scale(&ctx_lvl.cipher_plain_context.scaler)?);
232232

233233
let value = match self.par.plaintext {
234234
PlaintextModulus::Small { .. } => {
@@ -334,6 +334,27 @@ mod tests {
334334
Ok(())
335335
}
336336

337+
#[test]
338+
fn measure_noise_within_modulus_bits() -> Result<(), Box<dyn Error>> {
339+
let mut rng = rng();
340+
let params = BfvParameters::default_arc(1, 16);
341+
let sk = SecretKey::random(&params, &mut rng);
342+
let q = fhe_math::zq::Modulus::new(params.plaintext()).unwrap();
343+
344+
let pt = Plaintext::try_encode(
345+
&q.random_vec(params.degree(), &mut rng),
346+
Encoding::poly_at_level(0),
347+
&params,
348+
)?;
349+
let ct = sk.try_encrypt(&pt, &mut rng)?;
350+
let noise = unsafe { sk.measure_noise(&ct)? };
351+
352+
let modulus_bits = ct[0].ctx().modulus().bits() as usize;
353+
assert!(noise <= modulus_bits);
354+
355+
Ok(())
356+
}
357+
337358
#[test]
338359
fn serialize_roundtrip() -> Result<(), Box<dyn Error>> {
339360
let mut rng = rng();

0 commit comments

Comments
 (0)