Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP WASM demo #24

Merged
merged 26 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
161a077
WIP WASM demo
jschneider-bensch Sep 5, 2023
53aa922
Nonsense workspace member snuck in
jschneider-bensch Sep 5, 2023
501582a
Commit actual demo code
jschneider-bensch Sep 5, 2023
79775e6
Update `index.html`
jschneider-bensch Sep 5, 2023
b783163
Demo WIP Fixes
jschneider-bensch Sep 6, 2023
72946fb
Readme instructions how to run demo
jschneider-bensch Sep 6, 2023
8e39b36
Run `cargo fmt` on the workspace...
jschneider-bensch Sep 6, 2023
eee5b84
Update hacspec-scrambledb/scrambledb/wasm_demo/index.html
jschneider-bensch Sep 6, 2023
2ae8d19
Just to be sure: Test PRP inversion
jschneider-bensch Sep 7, 2023
114b9e9
coPRF tests
jschneider-bensch Sep 7, 2023
769b63d
coPRF: fix `derive_key`
jschneider-bensch Sep 7, 2023
bc5a41a
WIP Bug hunting
jschneider-bensch Sep 7, 2023
2d8fbed
Merge branch 'jonas/wasm-demo' of github.com:cryspen/atlas into jonas…
jschneider-bensch Sep 7, 2023
9c75048
Test utility
jschneider-bensch Sep 7, 2023
cb3b0f9
fix test deps
franziskuskiefer Sep 7, 2023
29cca5e
Fix test condition for `join`
jschneider-bensch Sep 7, 2023
963c546
Bug Fix: Use the right keys for blinding and enc/dec
jschneider-bensch Sep 7, 2023
0e58bf9
Merge branch 'jonas/wasm-demo' of github.com:cryspen/atlas into jonas…
jschneider-bensch Sep 7, 2023
1ffe049
Demo latest state
jschneider-bensch Sep 15, 2023
9a49e9d
Update hacspec-scrambledb/scrambledb/src/finalize.rs
jschneider-bensch Sep 26, 2023
0d4608b
Update hacspec-scrambledb/scrambledb/src/split.rs
jschneider-bensch Sep 26, 2023
366af60
Update hacspec-scrambledb/scrambledb/src/split.rs
jschneider-bensch Sep 26, 2023
a0cd6f5
Fix syntax error
jschneider-bensch Sep 26, 2023
7fb067f
Remove debug logs
jschneider-bensch Sep 26, 2023
131831e
Move feature switch
jschneider-bensch Sep 26, 2023
df13ded
Fmt
jschneider-bensch Sep 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions hacspec-scrambledb/oprf/src/coprf/coprf_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub type BlindingPrivateKey = elgamal::DecryptionKey;
/// `Nsk` bytes of entropy is provided to the key derivation
/// algorithm, where `Nsk` is the number of bytes to represent a valid
/// private key, i.e. a P256 scalar in our case.
pub type CoPRFMasterSecret = [u8; 32];
pub type CoPRFMasterSecret = Vec<u8>;
const COPRF_MSK_BYTES: usize = 32;

/// A coPRF evaluation key is identified by a bytestring of arbitrary
/// length.
Expand Down Expand Up @@ -78,8 +79,9 @@ impl CoPRFEvaluatorContext {
/// ### E.1.2. Evaluator Setup
/// The coPRF evaluator holds the master secret as well as any PRF
/// evaluation keys derived from it.
pub fn new(msk: CoPRFMasterSecret) -> Self {
CoPRFEvaluatorContext { msk }
pub fn new(randomness: &mut Randomness) -> Result<Self, Error> {
let msk = randomness.bytes(COPRF_MSK_BYTES)?.to_vec();
Ok(CoPRFEvaluatorContext { msk })
}
}

Expand Down
7 changes: 7 additions & 0 deletions hacspec-scrambledb/oprf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub enum Error {
CurveError,
HashToCurveError,
ElgamalError,
RandomnessError,
jschneider-bensch marked this conversation as resolved.
Show resolved Hide resolved
}

impl From<p256::Error> for Error {
Expand All @@ -27,6 +28,12 @@ impl From<elgamal::Error> for Error {
}
}

impl From<hacspec_lib::Error> for Error {
fn from(_value: hacspec_lib::Error) -> Self {
Self::RandomnessError
}
}

// 3. Protocol
pub mod protocol;

Expand Down
24 changes: 24 additions & 0 deletions hacspec-scrambledb/scrambledb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,33 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["rlib", "cdylib"]

[dependencies]
oprf.workspace = true
elgamal.workspace = true
prp.workspace = true
p256.workspace = true
hacspec_lib.workspace = true
hash-to-curve.workspace = true

wasm-bindgen = { version = "0.2.87", optional = true }
rand = { version = "0.8.5", optional = true }
getrandom = { version = "0.2.10", features = ["js"], optional = true }
hex = { version = "0.4.3", optional = true }
[dependencies.web-sys]
franziskuskiefer marked this conversation as resolved.
Show resolved Hide resolved
version = "0.3.4"
optional = true
features = [
'Document',
'Element',
'HtmlElement',
'Node',
'Window',
'console',
'HtmlTableElement',
'HtmlTableRowElement',
]
[features]
wasm = ["wasm-bindgen", "getrandom", "web-sys", "rand", "hex"]
1 change: 1 addition & 0 deletions hacspec-scrambledb/scrambledb/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impl From<oprf::Error> for Error {
oprf::Error::CurveError => Self::CorruptedData,
oprf::Error::HashToCurveError => Self::CorruptedData,
oprf::Error::ElgamalError => Self::RandomnessError,
oprf::Error::RandomnessError => Self::RandomnessError,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion hacspec-scrambledb/scrambledb/src/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
/// In addition the encrypted values need to be decrypted to be available
/// for future conversions towards other data stores.
pub fn finalize_conversion(
store_context: StoreContext,
store_context: &StoreContext,
converted_tables: Vec<ConvertedTable>,
) -> Result<Vec<PseudonymizedTable>, Error> {
let mut pseudonymized_tables = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions hacspec-scrambledb/scrambledb/src/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use crate::{
/// return blind_tables
/// ```
pub fn prepare_join_conversion(
origin_context: StoreContext,
origin_context: &StoreContext,
bpk_target: BlindingPublicKey,
ek_target: EncryptionKey,
pseudonymized_tables: Vec<PseudonymizedTable>,
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn join_identifier(identifier: String, attribute: String) -> String {
/// evaluation key.
///
pub fn join_conversion(
converter_context: ConverterContext,
converter_context: &ConverterContext,
bpk_target: BlindingPublicKey,
ek_target: EncryptionKey,
tables: Vec<BlindTable>,
Expand Down
1 change: 1 addition & 0 deletions hacspec-scrambledb/scrambledb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,4 @@ pub mod join;
pub mod finalize;

pub mod error;
pub mod wasm_demo;
14 changes: 7 additions & 7 deletions hacspec-scrambledb/scrambledb/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ impl ConverterContext {
/// fn setup_converter_context(msk) -> ConverterContext:
/// return coPRFEvaluatorContext::new(msk)
/// ```
pub fn setup(msk: [u8; 32]) -> Self {
ConverterContext {
coprf_context: CoPRFEvaluatorContext::new(msk),
}
pub fn setup(randomness: &mut Randomness) -> Result<Self, Error> {
Ok(ConverterContext {
coprf_context: CoPRFEvaluatorContext::new(randomness)?,
})
}
}

Expand Down Expand Up @@ -76,10 +76,10 @@ impl StoreContext {
/// k_prp
/// }
/// ```
pub fn setup(mut randomness: Randomness) -> Result<Self, Error> {
let receiver_context = CoPRFReceiverContext::new(&mut randomness);
pub fn setup(randomness: &mut Randomness) -> Result<Self, Error> {
let receiver_context = CoPRFReceiverContext::new(randomness);

let (dk, ek) = generate_keys(&mut randomness)?;
let (dk, ek) = generate_keys(randomness)?;

let k_prp = randomness.bytes(32)?.try_into()?;

Expand Down
2 changes: 1 addition & 1 deletion hacspec-scrambledb/scrambledb/src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn prepare_split_conversion(
/// have been shuffled to prevent correlation of the incoming with the
/// outgoing table data.
pub fn split_conversion(
converter_context: ConverterContext,
converter_context: &ConverterContext,
bpk_store: BlindingPublicKey,
ek_store: EncryptionKey,
table: BlindTable,
Expand Down
59 changes: 59 additions & 0 deletions hacspec-scrambledb/scrambledb/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,32 @@ impl<K, V> Column<K, V> {
Self { attribute, data }
}

pub fn len(&self) -> usize {
self.data.len()
}

pub fn attribute(&self) -> String {
self.attribute.clone()
}

pub fn keys(&self) -> Vec<K>
where
K: Clone,
{
self.data.iter().map(|(k, _v)| k.clone()).collect()
}

pub fn get(&self, key: &K) -> Option<V>
where
K: PartialEq,
V: Clone,
{
self.data
.iter()
.find(|(k, _v)| k == key)
jschneider-bensch marked this conversation as resolved.
Show resolved Hide resolved
.map(|(_k, v)| v.clone())
}

pub fn data(&self) -> Vec<(K, V)>
where
K: Clone,
Expand Down Expand Up @@ -77,6 +99,14 @@ impl<K, V> SingleColumnTable<K, V> {
{
self.column.clone()
}

pub fn len(&self) -> usize
where
K: Clone,
V: Clone,
{
self.column.data().len()
}
}

impl<K, V> MultiColumnTable<K, V> {
Expand All @@ -90,11 +120,40 @@ impl<K, V> MultiColumnTable<K, V> {
self.identifier.clone()
}

pub fn num_columns(&self) -> usize {
self.columns.len()
}

pub fn num_rows(&self) -> usize
where
K: Clone,
V: Clone,
{
self.columns()[0].len()
}

pub fn columns(&self) -> Vec<Column<K, V>>
where
K: Clone,
V: Clone,
{
self.columns.clone()
}

pub fn rows(&self) -> Vec<Vec<(K, V)>>
where
K: Clone + PartialEq,
V: Clone,
{
let mut rows = Vec::new();
for i in 0..self.num_rows() {
let mut row = Vec::new();
for column in self.columns() {
row.push(column.data()[i].clone());
}
rows.push(row)
}

rows
}
}
Loading