bellare_micali/lib.rs
1//! # Bellare-Micali 1-out-of-2 Oblivious Transfer (OT) Protocol Implementation
2//!
3//! This crate provides a secure and efficient implementation of the Bellare-Micali
4//! 1-out-of-2 Oblivious Transfer (OT) protocol. The OT protocol is a fundamental
5//! cryptographic primitive used in various secure multi-party computations and
6//! protocols, including secure voting systems, private information retrieval, and
7//! secure two-party computation.
8//!
9//! The implementation leverages the **Ristretto** group for elliptic curve operations,
10//! ensuring strong security guarantees and efficient performance.
11//!
12//! ## Features
13//!
14//! - **Secure OT Protocol**: Implements the Bellare-Micali OT protocol with rigorous
15//! security measures.
16//! - **Batch Processing**: Supports batch processing of OT operations for enhanced
17//! efficiency.
18//! - **Comprehensive Error Handling**: Provides detailed error types to facilitate
19//! robust error handling.
20//! - **Cryptographic Utilities**: Includes a suite of cryptographic utility functions
21//! essential for protocol operations.
22//! - **Modular Design**: Organized into distinct modules for clarity, maintainability,
23//! and ease of extension.
24//!
25//! ## Modules
26//!
27//! - [`batch`](batch/index.html): Contains implementations for batch processing of OT
28//! operations, allowing multiple OT instances to be handled simultaneously for improved
29//! performance.
30//! - [`crypto`](crypto/index.html): Houses cryptographic utility functions and structures
31//! used throughout the protocol, such as random scalar generation and hashing functions.
32//! - [`error`](error/index.html): Defines the `OTError` enum, encapsulating all possible
33//! errors that can occur during the OT protocol execution.
34//! - [`protocol`](protocol/index.html): Implements the core OT protocol logic, including
35//! the `OTProtocol` struct that manages the protocol's state and operations.
36//! - [`types`](types/index.html): Defines fundamental types used across the crate, such
37//! as `Message` and `Ciphertext`, ensuring type safety and clarity.
38//!
39//! ## Re-Exports
40//!
41//! For convenience, the crate re-exports several commonly used items, allowing users to
42//! access them directly from the crate root without needing to navigate through
43//! individual modules.
44//!
45//! - [`OTError`](error::OTError): The primary error type for handling OT protocol errors.
46//! - [`OTProtocol`](protocol::OTProtocol): The main struct managing the OT protocol's state
47//! and operations.
48//! - [`Message`](types::Message): Represents messages transmitted within the OT protocol.
49//! - [`BatchOTProtocol`](batch::BatchOTProtocol): Facilitates batch processing of multiple OT
50//! instances.
51//!
52//! ## Example
53//!
54//! Below is a simple example demonstrating how to initialize and execute the OT protocol.
55//!
56//! ```rust
57//! use bellare_micali::{Message, OTProtocol};
58//! use rand::rngs::OsRng;
59//!
60//! // Initialize RNG
61//! let mut rng = OsRng;
62//!
63//! // Initialize sender
64//! let sender = OTProtocol::new_sender(&mut rng);
65//! println!("Sender initialized");
66//!
67//! // Create test messages
68//! let msg0 = Message::new(b"First secret message".to_vec());
69//! let msg1 = Message::new(b"Second secret message".to_vec());
70//!
71//! // Initialize receiver with choice bit (true = 1, false = 0)
72//! let choice_bit = true;
73//! let receiver = OTProtocol::new_receiver(&mut rng, choice_bit, sender.c);
74//! println!("Receiver initialized with choice bit {}", choice_bit);
75//!
76//! // Generate receiver's keys
77//! let (pk0, pk1) = OTProtocol::receiver_generate_keys(&receiver, sender.c);
78//! println!("Receiver keys generated");
79//!
80//! // Sender encrypts messages
81//! let (c0, c1) = OTProtocol::sender_encrypt(&mut rng, &sender, pk0, pk1, &msg0, &msg1)
82//! .expect("Encryption failed");
83//! println!("Messages encrypted");
84//!
85//! // Receiver decrypts chosen message
86//! let decrypted = OTProtocol::receiver_decrypt(&receiver, &c0, &c1).expect("Decryption failed");
87//! println!(
88//! "Decrypted message: {:?}",
89//! String::from_utf8_lossy(decrypted.as_bytes())
90//! );
91//! ```
92//!
93//! ## Security Considerations
94//!
95//! - **Randomness**: The protocol relies on cryptographically secure random number generators.
96//! Ensure that a secure RNG is used to prevent potential vulnerabilities.
97//! - **Key Management**: Properly manage and protect all cryptographic keys and scalars to
98//! maintain protocol security.
99//! - **Dependencies**: Keep all dependencies up-to-date to benefit from the latest security
100//! patches and improvements.
101//!
102
103pub mod batch;
104pub mod crypto;
105pub mod error;
106pub mod protocol;
107pub mod types;
108
109// Re-export commonly used items for easier access
110pub use crate::batch::BatchOTProtocol;
111pub use crate::error::OTError;
112pub use crate::protocol::OTProtocol;
113pub use crate::types::Message;