Skip to content

First-pass DP PR #43

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions enclave/safetrace/enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ crate-type = ["staticlib"]
default = []

[dependencies]
GSL = "0.4"
enigma-types = { git = "https://github.com/enigmampc/enigma-core.git", branch="develop", default-features = false, features = ["sgx"] }
enigma-crypto = { git = "https://github.com/enigmampc/enigma-core.git", branch="develop", default-features = false, features = ["sgx", "asymmetric"] }
enigma-tools-t = { git = "https://github.com/enigmampc/enigma-core.git", branch="develop" }
Expand Down
12 changes: 9 additions & 3 deletions enclave/safetrace/enclave/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use serde_json::{Value, json};
use serde::{Deserialize, Serialize};
use rmp_serde::{Deserializer, Serializer};

use rgsl::types::Rng;

use sgx_tseal::{SgxSealedData};
use sgx_types::marker::ContiguousMemory;
use std::untrusted::fs::File;
Expand All @@ -29,6 +31,7 @@ pub enum Error {
SliceError,
UnsealError(sgx_status_t),
SerializeError,
RandomGeneratorError,
Other
}

Expand Down Expand Up @@ -247,9 +250,12 @@ pub fn find_match_internal(
// their latitudes (or the distance between lats will be smaller than the distance * cos(45))
// Source:
// https://stackoverflow.com/questions/5031268/algorithm-to-find-all-latitude-longitude-locations-within-a-certain-distance-fro
if (e.lat - d.lat).abs() * 111000.0 < DISTANCE * 0.71 {

if (e.lat - d.lat).abs() * 111000.0 < DISTANCE * 0.71 {
let mut r = Rng::new(&rgsl::types::rng::algorithms::taus()).ok_or(Error::RandomGeneratorError)?;
let lapnoise = rgsl::randist::laplace::laplace(&mut r, 0.87).abs()*2.0;
// then we can run a more computationally expensive and precise comparison
if (e.lat.sin()*d.lat.sin()+e.lat.cos()*d.lat.cos()*(e.lng-d.lng).cos()).acos() * EARTH_RADIUS < DISTANCE {
if (e.lat.sin()*d.lat.sin()+e.lat.cos()*d.lat.cos()*(e.lng-d.lng).cos()).acos() * EARTH_RADIUS - lapnoise < DISTANCE {
results.push(d.clone());
}
}
Expand All @@ -265,4 +271,4 @@ pub fn find_match_internal(
let encrypted_output = encrypt(array_u8_results, dhKey)?;

Ok(encrypted_output)
}
}