| Crates.io | bellare-micali |
| lib.rs | bellare-micali |
| version | 0.1.2 |
| created_at | 2025-01-30 16:54:39.481239+00 |
| updated_at | 2025-01-30 19:53:30.348689+00 |
| description | Implementation of Bellare-Micali 1-out-of-2 Oblivious Transfer Protocol |
| homepage | |
| repository | https://github.com/Cozy03/bellare-micali |
| max_upload_size | |
| id | 1536603 |
| size | 353,319 |
Bellare-Micali 1-out-of-2 Oblivious Transfer (OT) is a cryptographic protocol that enables a sender to send one of two messages to a receiver, who selects a message without revealing their choice. This ensures privacy and security in multi-party computations, secure voting, and private information retrieval.
The Bellare-Micali Oblivious Transfer Protocol allows:
This implementation uses Ristretto group operations for strong security and efficient computation, making it ideal for privacy-preserving cryptographic protocols.
βοΈ Secure OT Protocol β Strong privacy guarantees for sender and receiver.
β‘ Batch Processing β Perform multiple OT transfers in parallel.
π‘οΈ Cryptographic Utilities β Secure random scalars, hashing, and more.
π Comprehensive Documentation β Includes Rustdoc and usage examples.
π Error Handling β Custom OTError for clear debugging.
π Zeroization β Ensures cryptographic secrets are wiped from memory.
This implementation follows a modular approach:
batch β Handles parallel OT executions for efficiency.crypto β Provides cryptographic tools like hashing.error β Defines OTError for exception handling.protocol β Implements sender/receiver OT operations.types β Defines fundamental types like Message, Sender, and Receiver.pub struct Message(Vec<u8>);
Stores and manages OT messages securely.
pub struct Sender {
u: Scalar,
c: RistrettoPoint,
}
Represents the senderβs cryptographic state.
pub struct Receiver {
k: Scalar,
choice: bool,
}
Handles the receiverβs private key and message choice.
pub struct Ciphertext {
v1: RistrettoPoint,
v2: Vec<u8>,
}
Stores encrypted messages securely.
Add this crate to your Rust project:
[dependencies]
bellare_micali = "0.1.2"
Include it in your Rust code:
use bellare_micali::{OTProtocol, Message, OTError};
use bellare_micali::{OTProtocol, Message};
use rand::rngs::OsRng;
fn main() -> Result<(), OTError> {
let mut rng = OsRng;
let sender = OTProtocol::new_sender(&mut rng);
let msg0 = Message::new(b"Secret 1".to_vec());
let msg1 = Message::new(b"Secret 2".to_vec());
let receiver = OTProtocol::new_receiver(&mut rng, true, sender.c);
let (pk0, pk1) = OTProtocol::receiver_generate_keys(&receiver, sender.c);
let (c0, c1) = OTProtocol::sender_encrypt(&mut rng, &sender, pk0, pk1, &msg0, &msg1)?;
let decrypted = OTProtocol::receiver_decrypt(&receiver, &c0, &c1)?;
println!("Decrypted: {:?}", String::from_utf8(decrypted.as_bytes()).unwrap());
Ok(())
}
For handling multiple messages efficiently:
use bellare_micali::{BatchOTProtocol, OTProtocol, Message};
use rand::rngs::OsRng;
fn main() -> Result<(), OTError> {
let mut rng = OsRng;
let sender = OTProtocol::new_sender(&mut rng);
let msgs0 = vec![Message::new(b"Batch 1".to_vec()), Message::new(b"Batch 2".to_vec())];
let msgs1 = vec![Message::new(b"Batch A".to_vec()), Message::new(b"Batch B".to_vec())];
let choices = vec![false, true];
let decrypted_messages = BatchOTProtocol::batch_transfer(&mut rng, &msgs0, &msgs1, &choices)?;
for (i, msg) in decrypted_messages.iter().enumerate() {
println!("Decrypted Message {}: {:?}", i + 1, String::from_utf8(msg.as_bytes()).unwrap());
}
Ok(())
}
β
Zeroization of sensitive data using zeroize.
β
Elliptic curve security via the Ristretto group.
β
Secure randomness using rand::rngs::OsRng.
β
Strict error handling to prevent protocol misuse.
Run tests:
cargo test
The OTError enum provides clear error handling:
pub enum OTError {
InvalidPublicKey,
ProtocolError(String),
}
I have included additional notes and theoretical explanations regarding Oblivious Transfer and Multi-Party Computation (MPC) in the document Bellare_Micali_Oblivious_Transfer.pdf.
These notes provide:
Contributions are welcome! To contribute:
feature/your-feature-name).This project is licensed under the MIT License.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction...
(Full license text available in the LICENSE file.)