Pārlūkot izejas kodu

oram: add initial oram crate

Lennart Braun 2 gadi atpakaļ
vecāks
revīzija
b4498fc283
6 mainītis faili ar 149 papildinājumiem un 0 dzēšanām
  1. 1 0
      Cargo.toml
  2. 9 0
      oram/Cargo.toml
  3. 30 0
      oram/src/common.rs
  4. 3 0
      oram/src/lib.rs
  5. 67 0
      oram/src/oram.rs
  6. 39 0
      oram/src/stash.rs

+ 1 - 0
Cargo.toml

@@ -3,6 +3,7 @@
 members = [
     "cuckoo",
     "dpf",
+    "oram",
     "utils",
 ]
 

+ 9 - 0
oram/Cargo.toml

@@ -0,0 +1,9 @@
+[package]
+name = "oram"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+ff = "0.13.0"

+ 30 - 0
oram/src/common.rs

@@ -0,0 +1,30 @@
+use ff::PrimeField;
+
+pub enum Operation {
+    Read,
+    Write,
+}
+
+impl Operation {
+    pub fn encode<F: PrimeField>(&self) -> F {
+        match self {
+            Self::Read => F::ZERO,
+            Self::Write => F::ONE,
+        }
+    }
+    pub fn decode<F: PrimeField>(encoded_op: F) -> Self {
+        if encoded_op == F::ZERO {
+            Self::Read
+        } else if encoded_op == F::ONE {
+            Self::Write
+        } else {
+            panic!("invalid value")
+        }
+    }
+}
+
+pub struct InstructionShare<F: PrimeField> {
+    operation_share: F,
+    address_share: F,
+    value: F,
+}

+ 3 - 0
oram/src/lib.rs

@@ -0,0 +1,3 @@
+mod common;
+pub mod oram;
+mod stash;

+ 67 - 0
oram/src/oram.rs

@@ -0,0 +1,67 @@
+use crate::stash::Stash;
+use ff::PrimeField;
+use std::marker::PhantomData;
+
+type Address = usize;
+
+pub struct DistributedOram<F: PrimeField> {
+    party_id: usize,
+    log_db_size: usize,
+    stash_size: usize,
+    memory_size: usize,
+    memory_share: Vec<F>,
+    is_initialized: bool,
+    access_counter: usize,
+    addresses_read: Vec<Address>,
+    stash: Stash<F>,
+    _phantom: PhantomData<F>,
+}
+
+impl<F: PrimeField> DistributedOram<F> {
+    pub fn new(party_id: usize, log_db_size: usize) -> Self {
+        assert!(party_id < 3);
+        assert_eq!(log_db_size % 1, 0);
+        let stash_size = 1 << (log_db_size / 2);
+        let memory_size = (1 << log_db_size) + stash_size;
+
+        Self {
+            party_id,
+            log_db_size,
+            stash_size,
+            memory_size,
+            memory_share: Default::default(),
+            is_initialized: false,
+            access_counter: 0,
+            addresses_read: Default::default(),
+            stash: Stash::new(stash_size),
+            _phantom: PhantomData,
+        }
+    }
+
+    pub fn init(&mut self, share: &[F]) {
+        // - 3x DOPRF key generation
+        // - 3x p-OT initialization
+        // - randomize DB
+        self.is_initialized = true;
+        panic!("not implemented");
+    }
+
+    pub fn read_from_database(&mut self) -> F {
+        panic!("not implemented");
+    }
+
+    pub fn refresh(&mut self) {
+        panic!("not implemented");
+        assert!(self.is_initialized);
+    }
+
+    pub fn access(&mut self) {
+        panic!("not implemented");
+        assert!(self.is_initialized);
+    }
+
+    pub fn get_db(&self) -> Vec<F> {
+        panic!("not implemented");
+        assert!(self.is_initialized);
+    }
+}

+ 39 - 0
oram/src/stash.rs

@@ -0,0 +1,39 @@
+use ff::PrimeField;
+use std::marker::PhantomData;
+
+pub struct Stash<F: PrimeField> {
+    stash_size: usize,
+    stash_share: Vec<StashEntryShare<F>>,
+    _phantom: PhantomData<F>,
+}
+
+#[derive(Clone, Copy, Debug, Default)]
+struct StashEntryShare<F: PrimeField> {
+    pub address_share: F,
+    pub value_share: F,
+    pub old_value_share: F,
+}
+
+impl<F: PrimeField> Stash<F> {
+
+    pub fn new(stash_size: usize) -> Self {
+
+        Self {
+            stash_size,
+            stash_share: Default::default(),
+            _phantom: PhantomData,
+        }
+    }
+
+    pub fn init(&mut self, stash_share: &[F]) {
+        panic!("not implemented");
+    }
+
+    pub fn read(&self, counter: usize) {
+        panic!("not implemented");
+    }
+
+    pub fn write(&self) {
+        panic!("not implemented");
+    }
+}