Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion between TFHErs fheint and Concrete ciphertexts/keys #945

Merged
merged 16 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions backends/concrete-cpu/implementation/Cargo.lock

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

9 changes: 5 additions & 4 deletions backends/concrete-cpu/implementation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ bytemuck = "1.14.3"
num-complex = { version = "0.4", default-features = false, features = [
"bytemuck",
] }
bincode = "1.3.3"

rayon = { version = "1.6", optional = true }
once_cell = { version = "1.16", optional = true }

tfhe = { version = "0.7", features = [] }
tfhe = { version = "0.7", features = ["integer"] }

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

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

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

[features]
default = ["parallel", "std", "csprng"]
Expand Down
1 change: 1 addition & 0 deletions backends/concrete-cpu/implementation/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fn main() {
let package_name = env::var("CARGO_PKG_NAME").unwrap();
let output_file = format!("include/{package_name}.h");
println!("cargo:rerun-if-changed={output_file}");
println!("cargo:rerun-if-changed=src");

cbindgen::generate(crate_dir)
.unwrap()
Expand Down
36 changes: 36 additions & 0 deletions backends/concrete-cpu/implementation/include/concrete-cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ typedef struct Uint128 {
uint8_t little_endian_bytes[16];
} Uint128;

typedef struct TfhersFheIntDescription {
size_t width;
bool is_signed;
size_t lwe_size;
size_t n_cts;
size_t degree;
size_t noise_level;
size_t message_modulus;
size_t carry_modulus;
bool ks_first;
} TfhersFheIntDescription;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
Expand Down Expand Up @@ -283,6 +295,8 @@ size_t concrete_cpu_ggsw_ciphertext_size_u64(size_t glwe_dimension,

size_t concrete_cpu_glwe_ciphertext_size_u64(size_t glwe_dimension, size_t polynomial_size);

size_t concrete_cpu_glwe_secret_key_buffer_size_u64(size_t glwe_dimension, size_t polynomial_size);

size_t concrete_cpu_glwe_secret_key_size_u64(size_t lwe_dimension, size_t polynomial_size);

void concrete_cpu_init_lwe_bootstrap_key_u64(uint64_t *lwe_bsk,
Expand Down Expand Up @@ -355,6 +369,11 @@ void concrete_cpu_keyswitch_lwe_ciphertext_u64(uint64_t *ct_out,
size_t input_dimension,
size_t output_dimension);

size_t concrete_cpu_lwe_array_to_tfhers_uint8(const uint64_t *lwe_vec_buffer,
uint8_t *fheuint_buffer,
size_t fheuint_buffer_size,
struct TfhersFheIntDescription fheuint_desc);

size_t concrete_cpu_lwe_ciphertext_size_u64(size_t lwe_dimension);

size_t concrete_cpu_lwe_packing_keyswitch_key_size(size_t output_glwe_dimension,
Expand All @@ -381,6 +400,23 @@ size_t concrete_cpu_seeded_bootstrap_key_size_u64(size_t decomposition_level_cou
size_t concrete_cpu_seeded_keyswitch_key_size_u64(size_t decomposition_level_count,
size_t input_dimension);

size_t concrete_cpu_serialize_glwe_secret_key_u64(const uint64_t *glwe_sk,
size_t glwe_dimension,
size_t polynomial_size,
uint8_t *out_buffer,
size_t out_buffer_len);

size_t concrete_cpu_tfhers_fheint_buffer_size_u64(size_t lwe_size, size_t n_cts);

struct TfhersFheIntDescription concrete_cpu_tfhers_uint8_description(const uint8_t *serialized_data_ptr,
size_t serialized_data_len);

int64_t concrete_cpu_tfhers_uint8_to_lwe_array(const uint8_t *serialized_data_ptr,
size_t serialized_data_len,
uint64_t *lwe_vec_buffer);

size_t concrete_cpu_tfhers_unknown_noise_level(void);

void simulation_circuit_bootstrap_boolean_vertical_packing_lwe_ciphertext_u64(const uint64_t *lwe_list_in,
uint64_t *lwe_list_out,
size_t ct_in_count,
Expand Down
1 change: 1 addition & 0 deletions backends/concrete-cpu/implementation/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod bootstrap;
pub mod csprng;
pub mod encrypt;
pub mod fft;
pub mod fheint;
pub mod keyswitch;
pub mod linear_op;
pub mod secret_key;
Expand Down
Loading
Loading