pub struct GarbledGate {
pub table: [[u64; 2]; 2],
pub labels_a: [u64; 2],
pub labels_b: [u64; 2],
pub labels_out: [u64; 2],
}Expand description
A simple garbled AND/OR gate simulator.
Labels for 0 and 1 on each wire are represented as u64 tokens. The garbled table encrypts the output label for each input pair.
§WARNING
Educational sketch only. Real garbling uses AES-based encryption.
Fields§
§table: [[u64; 2]; 2]Garbled table: indexed [a_bit][b_bit] → output label
labels_a: [u64; 2]Labels for wire A: [label_0, label_1]
labels_b: [u64; 2]Labels for wire B: [label_0, label_1]
labels_out: [u64; 2]Labels for output wire: [label_0, label_1]
Implementations§
Source§impl GarbledGate
impl GarbledGate
Sourcepub fn garble_and(
labels_a: [u64; 2],
labels_b: [u64; 2],
labels_out: [u64; 2],
) -> Self
pub fn garble_and( labels_a: [u64; 2], labels_b: [u64; 2], labels_out: [u64; 2], ) -> Self
Build a garbled AND gate. labels_a, labels_b, labels_out: [label_for_0, label_for_1] on each wire.
Sourcepub fn garble_or(
labels_a: [u64; 2],
labels_b: [u64; 2],
labels_out: [u64; 2],
) -> Self
pub fn garble_or( labels_a: [u64; 2], labels_b: [u64; 2], labels_out: [u64; 2], ) -> Self
Build a garbled OR gate.
Sourcepub fn evaluate(&self, label_a: u64, label_b: u64) -> Option<u64>
pub fn evaluate(&self, label_a: u64, label_b: u64) -> Option<u64>
Evaluate the garbled gate: given input labels, recover the output label.
Sourcepub fn is_output_one(&self, output_label: u64) -> bool
pub fn is_output_one(&self, output_label: u64) -> bool
Check if the recovered output label corresponds to output value 1.
Trait Implementations§
Source§impl Clone for GarbledGate
impl Clone for GarbledGate
Source§fn clone(&self) -> GarbledGate
fn clone(&self) -> GarbledGate
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for GarbledGate
impl RefUnwindSafe for GarbledGate
impl Send for GarbledGate
impl Sync for GarbledGate
impl Unpin for GarbledGate
impl UnsafeUnpin for GarbledGate
impl UnwindSafe for GarbledGate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more