From 0219553ab0834ef7a2326c277abc3a6c2d3ca5db Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 18 May 2021 00:00:39 -0700 Subject: [PATCH] In-memory mixing for prototype --- niwl-rem/src/lib.rs | 21 ++++++++++++++++++++- niwl-rem/src/main.rs | 1 - 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/niwl-rem/src/lib.rs b/niwl-rem/src/lib.rs index f7143b3..dc757ed 100644 --- a/niwl-rem/src/lib.rs +++ b/niwl-rem/src/lib.rs @@ -3,6 +3,8 @@ use chrono::{DateTime, Duration, Local, NaiveDateTime}; use fuzzytags::{RootSecret, Tag, TaggingKey}; use niwl::encrypt::{PrivateKey, TaggedCiphertext}; use niwl::Profile; +use rand::rngs::OsRng; +use rand::Rng; use serde::{Deserialize, Serialize}; use std::fmt::Error; @@ -15,13 +17,25 @@ pub enum MixMessage { pub struct RandomEjectionMix { heartbeat_id: Tag<24>, last_heartbeat: DateTime, + store: Vec, } impl RandomEjectionMix { pub fn init(tag: Tag<24>) -> RandomEjectionMix { + let mut store = vec![]; + for i in 0..10 { + let random_tag = RootSecret::<24>::generate().tagging_key().generate_tag(); + let random_secret = PrivateKey::generate(); + let random_encryption = random_secret + .public_key() + .encrypt(&random_tag, &String::new()); + store.push(random_encryption); + } + RandomEjectionMix { heartbeat_id: tag, last_heartbeat: Local::now(), + store, } } @@ -75,6 +89,11 @@ impl RandomEjectionMix { // Actually do the Random Ejection Mixing... fn random_ejection_mix(&mut self, ciphertext: &TaggedCiphertext) -> TaggedCiphertext { - ciphertext.clone() + let mut rng = OsRng::default(); + let random_index = rng.gen_range(0..10); + println!("[DEBUG] Ejecting {} ", random_index); + let ejection = self.store[random_index].clone(); + self.store[random_index] = ciphertext.clone(); + ejection } } diff --git a/niwl-rem/src/main.rs b/niwl-rem/src/main.rs index 0fe15b1..4f6ce6e 100644 --- a/niwl-rem/src/main.rs +++ b/niwl-rem/src/main.rs @@ -85,7 +85,6 @@ fn main() { let mut latest_tag = None; for (tag, ciphertext) in detected_tags.detected_tags.iter() { if detection_key.test_tag(&tag) { - random_delay().await; let plaintext = profile.private_key.decrypt(ciphertext); match plaintext { Some(plaintext) => match rem.push(tag, &plaintext) {