From aa5502d3f21c1856819fd15de85a037060426f5e Mon Sep 17 00:00:00 2001 From: FishmanL Date: Fri, 3 Apr 2020 15:32:29 -0400 Subject: [PATCH 1/5] Adding GSL for laplacian noise --- enclave/safetrace/enclave/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/enclave/safetrace/enclave/Cargo.toml b/enclave/safetrace/enclave/Cargo.toml index 66ab019..d5c6539 100644 --- a/enclave/safetrace/enclave/Cargo.toml +++ b/enclave/safetrace/enclave/Cargo.toml @@ -12,6 +12,7 @@ crate-type = ["staticlib"] default = [] [dependencies] +GSL = "*" 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" } From dbe67650c77f578cd93bcab823f22854260bddc8 Mon Sep 17 00:00:00 2001 From: FishmanL Date: Fri, 3 Apr 2020 15:37:58 -0400 Subject: [PATCH 2/5] First-pass DP --- enclave/safetrace/enclave/src/data.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/enclave/safetrace/enclave/src/data.rs b/enclave/safetrace/enclave/src/data.rs index 359ed5f..a4bf2bc 100644 --- a/enclave/safetrace/enclave/src/data.rs +++ b/enclave/safetrace/enclave/src/data.rs @@ -12,6 +12,8 @@ use serde_json::{Value, json}; use serde::{Deserialize, Serialize}; use rmp_serde::{Deserializer, Serializer}; +extern crate rgsl; + use sgx_tseal::{SgxSealedData}; use sgx_types::marker::ContiguousMemory; use std::untrusted::fs::File; @@ -247,9 +249,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 r = Rng::new(gsl_rng_taus); + let lapnoise = rgsl::randist::laplace::laplace(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()); } } @@ -265,4 +270,4 @@ pub fn find_match_internal( let encrypted_output = encrypt(array_u8_results, dhKey)?; Ok(encrypted_output) -} \ No newline at end of file +} From 46c62f7ce961674416ef6090548d1557e16e929d Mon Sep 17 00:00:00 2001 From: FishmanL Date: Fri, 3 Apr 2020 15:44:22 -0400 Subject: [PATCH 3/5] bugfix --- enclave/safetrace/enclave/src/data.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/enclave/safetrace/enclave/src/data.rs b/enclave/safetrace/enclave/src/data.rs index a4bf2bc..c472930 100644 --- a/enclave/safetrace/enclave/src/data.rs +++ b/enclave/safetrace/enclave/src/data.rs @@ -251,8 +251,8 @@ pub fn find_match_internal( // 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 { - let r = Rng::new(gsl_rng_taus); - let lapnoise = rgsl::randist::laplace::laplace(r, 0.87).abs()*2.0; + let mut r = Rng::new(gsl_rng_taus); + 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 - lapnoise < DISTANCE { results.push(d.clone()); From 89235677c18f2cda8b46d4fe51b3553f6b3a9a2f Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 8 Apr 2020 16:14:08 -0600 Subject: [PATCH 4/5] MAINT: update Cargo.toml, lock dep version --- enclave/safetrace/enclave/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enclave/safetrace/enclave/Cargo.toml b/enclave/safetrace/enclave/Cargo.toml index d5c6539..ea45cbf 100644 --- a/enclave/safetrace/enclave/Cargo.toml +++ b/enclave/safetrace/enclave/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["staticlib"] default = [] [dependencies] -GSL = "*" +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" } From 495c9772838e201bacabb285dd50735c36ccdd30 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 8 Apr 2020 16:15:11 -0600 Subject: [PATCH 5/5] BLD: bring mod in scope, handle errors --- enclave/safetrace/enclave/src/data.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/enclave/safetrace/enclave/src/data.rs b/enclave/safetrace/enclave/src/data.rs index c472930..02ce587 100644 --- a/enclave/safetrace/enclave/src/data.rs +++ b/enclave/safetrace/enclave/src/data.rs @@ -12,7 +12,7 @@ use serde_json::{Value, json}; use serde::{Deserialize, Serialize}; use rmp_serde::{Deserializer, Serializer}; -extern crate rgsl; +use rgsl::types::Rng; use sgx_tseal::{SgxSealedData}; use sgx_types::marker::ContiguousMemory; @@ -31,6 +31,7 @@ pub enum Error { SliceError, UnsealError(sgx_status_t), SerializeError, + RandomGeneratorError, Other } @@ -251,7 +252,7 @@ pub fn find_match_internal( // 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 { - let mut r = Rng::new(gsl_rng_taus); + 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 - lapnoise < DISTANCE {