Skip to content

Commit

Permalink
fix: fix the atomic pattern used to cast in trivium and a test in sho…
Browse files Browse the repository at this point in the history
…rtint

- parameters are optimized for a clean ciphertext, the ciphertext being
keyswitched was noisy
  • Loading branch information
IceTDrinker committed Mar 3, 2025
1 parent b6370c9 commit 014af86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 7 additions & 4 deletions apps/trivium/src/trans_ciphering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ fn transcipher_from_1_1_stream(
) -> FheUint64 {
assert_eq!(stream.len(), 64);

let id_lut = internal_server_key.generate_lookup_table(|x| x);

let pairs = (0..32)
.into_par_iter()
.map(|i| {
Expand All @@ -57,10 +59,11 @@ fn transcipher_from_1_1_stream(
let b0 = &stream[8 * byte_idx + 2 * pair_idx];
let b1 = &stream[8 * byte_idx + 2 * pair_idx + 1];

casting_key.cast(
&internal_server_key
.unchecked_add(b0, &internal_server_key.unchecked_scalar_mul(b1, 2)),
)
let mut combined = internal_server_key
.unchecked_add(b0, &internal_server_key.unchecked_scalar_mul(b1, 2));
internal_server_key.apply_lookup_table_assign(&mut combined, &id_lut);

casting_key.cast(&combined)
})
.collect::<Vec<_>>();

Expand Down
7 changes: 6 additions & 1 deletion tfhe/src/shortint/key_switching_key/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ fn gen_multi_keys_test_add_with_overflow_ci_run_filter() {
let c3 = sk1.unchecked_scalar_mul(&c1, 2);
let c4 = sk1.unchecked_add(&c3, &c2);

let output_of_cast = ksk.cast(&c4);
// The optimized atomic pattern requires a ciphertext with NoiseLevel::NOMINAL, i.e. a
// ciphertext fresh out of a bootstrap
let id_lut = sk1.generate_lookup_table(|x| x);
let c5 = sk1.apply_lookup_table(&c4, &id_lut);

let output_of_cast = ksk.cast(&c5);
let clear = ck2.decrypt(&output_of_cast);
assert_eq!(clear, 3);
let ct_carry = sk2.carry_extract(&output_of_cast);
Expand Down

0 comments on commit 014af86

Please sign in to comment.