diff --git a/tfhe/src/integer/ciphertext/utils.rs b/tfhe/src/integer/ciphertext/utils.rs index 57171e8a3..b2dbeb503 100644 --- a/tfhe/src/integer/ciphertext/utils.rs +++ b/tfhe/src/integer/ciphertext/utils.rs @@ -25,6 +25,9 @@ impl DataKind { Self::Unsigned(n) | Self::Signed(n) => n.get(), Self::Boolean => 1, Self::String { n_chars, .. } => { + if message_modulus.0 == 0 { + return 0; + } let blocks_per_char = 7u32.div_ceil(message_modulus.0.ilog2()); (n_chars * blocks_per_char) as usize } @@ -95,3 +98,20 @@ impl Expandable for BooleanBlock { } } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_string_num_blocks() { + let kind = DataKind::String { + n_chars: 10, + padded: true, + }; + + let num_blocks = kind.num_blocks(MessageModulus(0)); + + assert_eq!(num_blocks, 0); + } +}