3 releases
0.1.2 | Jan 30, 2025 |
---|---|
0.1.1 | Jan 30, 2025 |
0.1.0 | Jan 30, 2025 |
#391 in Cryptography
403 downloads per month
285KB
282 lines
Bellare-Micali 1-out-of-2 Oblivious Transfer (OT) Protocol π
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.
π Table of Contents
- Overview
- Features
- Architecture
- Installation
- Usage
- Security Considerations
- Testing & Error Handling
- About My Notes
- Contributing
- License
- References
π Overview
The Bellare-Micali Oblivious Transfer Protocol allows:
- A sender to securely send two messages.
- A receiver to choose one message while keeping their choice private.
- Neither party gains additional information beyond their expected outputs.
This implementation uses Ristretto group operations for strong security and efficient computation, making it ideal for privacy-preserving cryptographic protocols.
β¨ Features
βοΈ 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.
π Architecture
This implementation follows a modular approach:
- π
batch
β Handles parallel OT executions for efficiency. - π
crypto
β Provides cryptographic tools like hashing. - β οΈ
error
β DefinesOTError
for exception handling. - π
protocol
β Implements sender/receiver OT operations. - π
types
β Defines fundamental types likeMessage
,Sender
, andReceiver
.
Core Components
Message
pub struct Message(Vec<u8>);
Stores and manages OT messages securely.
Sender
pub struct Sender {
u: Scalar,
c: RistrettoPoint,
}
Represents the senderβs cryptographic state.
Receiver
pub struct Receiver {
k: Scalar,
choice: bool,
}
Handles the receiverβs private key and message choice.
Ciphertext
pub struct Ciphertext {
v1: RistrettoPoint,
v2: Vec<u8>,
}
Stores encrypted messages securely.
π₯ Installation
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};
π‘ Usage
Basic Example
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(())
}
Batch Processing
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(())
}
π‘ Security Considerations
β
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.
π§ͺ Testing & Error Handling
Run tests:
cargo test
The OTError
enum provides clear error handling:
pub enum OTError {
InvalidPublicKey,
ProtocolError(String),
}
π About My Notes
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:
- π An overview of the Bellare-Micali OT Protocol.
- π Explanation of Elliptic Curve Cryptography in the protocol.
- π’ Mathematical formulation of sender and receiver interactions.
- π Practical use cases in secure communication.
π€ Contributing
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
feature/your-feature-name
). - Write tests and ensure existing tests pass.
- Submit a pull request.
π License
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.)
π References
- Bellare & Micali (1989) β Non-Interactive Oblivious Transfer Link.
- curve25519-dalek Docs β Docs.rs.
- Oblivious Transfer (Wikipedia) β Wiki.
Dependencies
~3.5β5MB
~102K SLoC