Crates.io | chalametpir_server |
lib.rs | chalametpir_server |
version | 0.8.0 |
created_at | 2025-05-11 18:26:49.536392+00 |
updated_at | 2025-07-11 06:03:29.125465+00 |
description | Server Implementation of ChalametPIR: Simple, Stateful, Single-Server Private Information Retrieval for Key-Value Databases |
homepage | |
repository | https://github.com/itzmeanjan/ChalametPIR.git |
max_upload_size | |
id | 1669607 |
size | 67,744 |
Server Implementation of ChalametPIR: Simple, Stateful, Single-Server Private Information Retrieval for Key-Value Databases.
This crate provides the server-side implementation for the ChalametPIR protocol. It includes functionality for:
Key components:
Server
: The main struct for handling PIR requests. It contains the encoded database and methods for responding to client queries.Add these dependencies to your Cargo.toml
:
rand = "=0.9.1"
rand_chacha = "=0.9.0"
chalametpir_server = "=0.8.0"
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;
}
}
[!IMPORTANT] This crate allows you to offload compute-heavy server-setup phase to a GPU, if you enable
gpu
feature.
[!NOTE] More documentation on ChalametPIR here.