Skip to content

Commit

Permalink
Merge pull request #1154 from zama-ai/update-tfhers
Browse files Browse the repository at this point in the history
Update TFHE-rs to 0.10.0 and use safe serialization for secret keys
  • Loading branch information
BourgerieQuentin authored Dec 16, 2024
2 parents cee1b3a + ccf491e commit 72d653d
Show file tree
Hide file tree
Showing 112 changed files with 327 additions and 28,031 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
[submodule "lattice-estimator"]
path = third_party/lattice-estimator
url = https://github.com/malb/lattice-estimator
[submodule "third_party/tfhe-rs"]
path = third_party/tfhe-rs
url = https://github.com/zama-ai/tfhe-rs.git
1 change: 1 addition & 0 deletions .linelint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ autofix: false
# list of paths to ignore, uses gitignore syntaxes (executes before any rule)
ignore:
- compilers/concrete-compiler/llvm-project
- backends/concrete-cuda/implementation

rules:
# checks if file ends in a newline character
Expand Down
12 changes: 6 additions & 6 deletions backends/concrete-cpu/implementation/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions backends/concrete-cpu/implementation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ serde = "~1"
rayon = { version = "1.6", optional = true }
once_cell = { version = "1.16", optional = true }

tfhe = { version = "0.8.6", features = ["integer"] }
tfhe = { version = "0.10.0", features = ["integer"] }

[target.x86_64-unknown-unix-gnu.dependencies]
tfhe = { version = "0.8.6", features = ["integer", "x86_64-unix"] }
tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] }

[target.aarch64-unknown-unix-gnu.dependencies]
tfhe = { version = "0.8.6", features = ["integer", "aarch64-unix"] }
tfhe = { version = "0.10.0", features = ["integer", "aarch64-unix"] }

[target.x86_64-pc-windows-gnu.dependencies]
tfhe = { version = "0.8.6", features = ["integer", "x86_64"] }
tfhe = { version = "0.10.0", features = ["integer", "x86_64"] }

[features]
default = ["parallel", "std", "csprng"]
Expand Down
22 changes: 12 additions & 10 deletions backends/concrete-cpu/implementation/src/c_api/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,11 @@ pub unsafe extern "C" fn concrete_cpu_serialize_lwe_secret_key_u64(
out_buffer: *mut u8,
out_buffer_len: usize,
) -> usize {
let lwe_sk = LweSecretKey::from_container(slice::from_raw_parts(
lwe_sk,
concrete_cpu_lwe_secret_key_size_u64(lwe_dimension),
));
let lwe_sk: LweSecretKey<Vec<u64>> = LweSecretKey::from_container(
slice::from_raw_parts(lwe_sk, concrete_cpu_lwe_secret_key_size_u64(lwe_dimension)).to_vec(),
);

super::utils::unsafe_serialize(&lwe_sk, out_buffer, out_buffer_len)
super::utils::safe_serialize(&lwe_sk, out_buffer, out_buffer_len)
}

#[no_mangle]
Expand All @@ -233,7 +232,7 @@ pub unsafe extern "C" fn concrete_cpu_unserialize_lwe_secret_key_u64(
lwe_sk: *mut u64,
lwe_sk_size: usize,
) -> usize {
let sk: LweSecretKey<Vec<u64>> = super::utils::unsafe_deserialize(buffer, buffer_len);
let sk: LweSecretKey<Vec<u64>> = super::utils::safe_deserialize(buffer, buffer_len);
let container = sk.into_container();
assert!(container.len() <= lwe_sk_size);
let lwe_sk_slice = slice::from_raw_parts_mut(lwe_sk, lwe_sk_size);
Expand All @@ -249,15 +248,16 @@ pub unsafe extern "C" fn concrete_cpu_serialize_glwe_secret_key_u64(
out_buffer: *mut u8,
out_buffer_len: usize,
) -> usize {
let glwe_sk = GlweSecretKey::from_container(
let glwe_sk: GlweSecretKey<Vec<u64>> = GlweSecretKey::from_container(
slice::from_raw_parts(
glwe_sk,
concrete_cpu_glwe_secret_key_size_u64(glwe_dimension, polynomial_size),
),
)
.to_vec(),
PolynomialSize(polynomial_size),
);

super::utils::unsafe_serialize(&glwe_sk, out_buffer, out_buffer_len)
super::utils::safe_serialize(&glwe_sk, out_buffer, out_buffer_len)
}

#[no_mangle]
Expand All @@ -267,7 +267,7 @@ pub unsafe extern "C" fn concrete_cpu_unserialize_glwe_secret_key_u64(
glwe_sk: *mut u64,
glwe_sk_size: usize,
) -> usize {
let sk: GlweSecretKey<Vec<u64>> = super::utils::unsafe_deserialize(buffer, buffer_len);
let sk: GlweSecretKey<Vec<u64>> = super::utils::safe_deserialize(buffer, buffer_len);
assert!(sk.glwe_dimension().0 == 1);
let container = sk.into_container();
assert!(container.len() <= glwe_sk_size);
Expand Down Expand Up @@ -326,6 +326,7 @@ pub unsafe extern "C" fn concrete_cpu_glwe_secret_key_size_u64(
pub extern "C" fn concrete_cpu_lwe_secret_key_buffer_size_u64(lwe_dimension: usize) -> usize {
let metadata = core::mem::size_of::<LweSecretKey<&[u64]>>();
metadata + concrete_cpu_lwe_secret_key_size_u64(lwe_dimension) * 8 /*u64*/
+ 100 /*serialization headers (fragile)*/
}

#[no_mangle]
Expand All @@ -335,6 +336,7 @@ pub extern "C" fn concrete_cpu_glwe_secret_key_buffer_size_u64(
) -> usize {
let metadata = core::mem::size_of::<GlweSecretKey<&[u64]>>();
metadata + glwe_dimension * polynomial_size * 8 /*u64*/
+ 100 /*serialization headers (fragile)*/
}

#[no_mangle]
Expand Down
1 change: 1 addition & 0 deletions backends/concrete-cuda/implementation
86 changes: 0 additions & 86 deletions backends/concrete-cuda/implementation/CMakeLists.txt

This file was deleted.

3 changes: 0 additions & 3 deletions backends/concrete-cuda/implementation/CPPLINT.cfg

This file was deleted.

53 changes: 0 additions & 53 deletions backends/concrete-cuda/implementation/README.md

This file was deleted.

22 changes: 0 additions & 22 deletions backends/concrete-cuda/implementation/check_cuda.cu

This file was deleted.

7 changes: 0 additions & 7 deletions backends/concrete-cuda/implementation/format_concrete_cuda.sh

This file was deleted.

48 changes: 0 additions & 48 deletions backends/concrete-cuda/implementation/include/bit_extraction.h

This file was deleted.

Loading

0 comments on commit 72d653d

Please sign in to comment.