1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! ChalametPIR: A Rust library implementation of the Chalamet **P**rivate **I**nformation **R**etrieval (PIR) protocol, described in <https://ia.cr/2024/092>.
//!
//! This crate provides a Rust library implementation of the ChalametPIR Server, enabling efficient and private retrieval of value associated with a key, from encoded key-value database, stored server-side.
//! It leverages Binary Fuse Filters for efficient indexing and storage of key-value database and LWE-based encryption for data confidentiality.
//!
//!
//! ## Features
//!
//! * **Secure Private Information Retrieval:** Allows clients to retrieve value from a PIR server without disclosing corresponding key. Server learns neither the value nor the queried key.
//! * **Error Handling:** Comprehensive error handling to catch and report issues during setup and responding to client queries.
//! * **Flexibility:** Supports both 3-wise and 4-wise XOR Binary Fuse Filters, allowing a choice between trade-offs in client/server computation and communication costs.
//! * **Efficient:** It supports offloading parts of the server-setup phase to a GPU, using Vulkan Compute API, which can drastically reduce time taken to setup PIR server, for large key-value databases. Look for `gpu` feature.
//!
//! ## Usage
//!
//! This crate is designed to be used in conjunction with other crates which provides communication mechanism between PIR clients and server.
//! See examples. You'll typically interact with the `Server` struct to setup PIR server from a key-value database and respond to PIR client queries.
//!
//! Add this crate as dependency to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! chalametpir_server = "=0.8.0"
//! # Or, if you want to offload server-setup to GPU.
//! # chalametpir_server = { version = "=0.8.0", features = ["gpu"] }
//!
//! rand = "=0.9.1"
//! rand_chacha = "=0.9.0"
//! ```
//!
//! Then, you can use it in your code:
//!
//! ```rust
//! use std::collections::HashMap;
//!
//! use chalametpir_server::{SEED_BYTE_LEN, Server};
//!
//! use rand::prelude::*;
//! use rand_chacha::ChaCha8Rng;
//!
//! fn main() {
//! // Can be either 3 or 4, denoting usage of 3-wise or 4-wise xor binary fuse filter for PIR server setup.
//! const ARITY: u32 = 3;
//!
//! let mut rng = ChaCha8Rng::from_os_rng();
//! let mut seed_μ = [0u8; SEED_BYTE_LEN];
//! rng.fill_bytes(&mut seed_μ);
//!
//! let mut db: HashMap<&[u8], &[u8]> = HashMap::new();
//! db.insert(b"key1", b"value1");
//! db.insert(b"key2", b"value2");
//!
//! let (server, hint_bytes, filter_param_bytes) = Server::setup::<ARITY>(&seed_μ, db).expect("Server setup failed");
//!
//! // Start handling client PIR queries
//! loop {
//! // First send seed, hint and filter params to PIR client
//! // so that it can set itself up.
//!
//! // Assume query_bytes is received from the client
//! let query_bytes = vec![0u8; 0];
//!
//! if let Ok(response) = server.respond(&query_bytes) {
//! // Send the response to the client...
//! println!("Generated response of size: {} bytes", response.len());
//! }
//!
//! break;
//! }
//! }
//! ```
//!
//! For more see README in ChalametPIR repository @ <https://github.com/itzmeanjan/ChalametPIR>.
pub use ;
pub use Server;