Created
December 21, 2022 15:57
-
-
Save jamen/1eff58fa371b541e537cdee27be50110 to your computer and use it in GitHub Desktop.
Simple homomorphic encrypted integer idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand_core::RngCore; | |
pub struct Key(i64); | |
pub struct Secret(i64); | |
impl Secret { | |
pub fn new<R: RngCore>(rng: &mut R, value: i64) -> (Key, Self) { | |
let key = rng.next_u64() as i64; | |
(Key(key), Self(key.wrapping_add(value))) | |
} | |
pub fn renew<R: RngCore>(self, rng: &mut R, key: Key) -> (Key, Self) { | |
Secret::new(rng, self.reveal(key)) | |
} | |
pub fn add(self, n: i64) -> Self { | |
Self(self.0.wrapping_add(n)) | |
} | |
pub fn reveal(self, key: Key) -> i64 { | |
self.0.wrapping_sub(key.0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment