Formatting
This commit is contained in:
parent
9ae5b58a57
commit
35ca1dcfb4
|
@ -0,0 +1,66 @@
|
||||||
|
max_width = 200
|
||||||
|
hard_tabs = false
|
||||||
|
tab_spaces = 4
|
||||||
|
newline_style = "Auto"
|
||||||
|
use_small_heuristics = "Default"
|
||||||
|
indent_style = "Block"
|
||||||
|
wrap_comments = false
|
||||||
|
format_code_in_doc_comments = false
|
||||||
|
comment_width = 80
|
||||||
|
normalize_comments = false
|
||||||
|
normalize_doc_attributes = false
|
||||||
|
license_template_path = ""
|
||||||
|
format_strings = false
|
||||||
|
format_macro_matchers = false
|
||||||
|
format_macro_bodies = true
|
||||||
|
empty_item_single_line = true
|
||||||
|
struct_lit_single_line = true
|
||||||
|
fn_single_line = false
|
||||||
|
where_single_line = false
|
||||||
|
imports_indent = "Block"
|
||||||
|
imports_layout = "Mixed"
|
||||||
|
merge_imports = false
|
||||||
|
reorder_imports = true
|
||||||
|
reorder_modules = true
|
||||||
|
reorder_impl_items = false
|
||||||
|
type_punctuation_density = "Wide"
|
||||||
|
space_before_colon = false
|
||||||
|
space_after_colon = true
|
||||||
|
spaces_around_ranges = false
|
||||||
|
binop_separator = "Front"
|
||||||
|
remove_nested_parens = true
|
||||||
|
combine_control_expr = true
|
||||||
|
overflow_delimited_expr = false
|
||||||
|
struct_field_align_threshold = 0
|
||||||
|
enum_discrim_align_threshold = 0
|
||||||
|
match_arm_blocks = true
|
||||||
|
force_multiline_blocks = false
|
||||||
|
fn_args_layout = "Tall"
|
||||||
|
brace_style = "SameLineWhere"
|
||||||
|
control_brace_style = "AlwaysSameLine"
|
||||||
|
trailing_semicolon = true
|
||||||
|
trailing_comma = "Vertical"
|
||||||
|
match_block_trailing_comma = false
|
||||||
|
blank_lines_upper_bound = 1
|
||||||
|
blank_lines_lower_bound = 0
|
||||||
|
edition = "2015"
|
||||||
|
version = "One"
|
||||||
|
inline_attribute_width = 0
|
||||||
|
merge_derives = true
|
||||||
|
use_try_shorthand = false
|
||||||
|
use_field_init_shorthand = false
|
||||||
|
force_explicit_abi = true
|
||||||
|
condense_wildcard_suffixes = false
|
||||||
|
color = "Auto"
|
||||||
|
required_version = "1.4.21"
|
||||||
|
unstable_features = false
|
||||||
|
disable_all_formatting = false
|
||||||
|
skip_children = false
|
||||||
|
hide_parse_errors = false
|
||||||
|
error_on_line_overflow = false
|
||||||
|
error_on_unformatted = false
|
||||||
|
report_todo = "Never"
|
||||||
|
report_fixme = "Never"
|
||||||
|
ignore = []
|
||||||
|
emit_mode = "Files"
|
||||||
|
make_backup = false
|
63
src/lib.rs
63
src/lib.rs
|
@ -1,32 +1,38 @@
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
use std::ops::{Mul, Sub, Add};
|
|
||||||
use curve25519_dalek::scalar::Scalar;
|
|
||||||
use curve25519_dalek::ristretto::RistrettoPoint;
|
|
||||||
use rand::rngs::OsRng;
|
|
||||||
use curve25519_dalek::digest::Digest;
|
|
||||||
use sha3::{Sha3_512};
|
|
||||||
use curve25519_dalek::constants::RISTRETTO_BASEPOINT_POINT;
|
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
use bit_vec::BitVec;
|
use bit_vec::BitVec;
|
||||||
|
use curve25519_dalek::constants::RISTRETTO_BASEPOINT_POINT;
|
||||||
|
use curve25519_dalek::digest::Digest;
|
||||||
|
use curve25519_dalek::ristretto::RistrettoPoint;
|
||||||
|
use curve25519_dalek::scalar::Scalar;
|
||||||
|
use rand::rngs::OsRng;
|
||||||
|
use sha3::Sha3_512;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
|
use std::ops::{Add, Mul, Sub};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FuzzyMetaTag {
|
pub struct FuzzyMetaTag {
|
||||||
u: RistrettoPoint,
|
u: RistrettoPoint,
|
||||||
y: Scalar,
|
y: Scalar,
|
||||||
ciphertexts: BitVec
|
ciphertexts: BitVec,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for FuzzyMetaTag {
|
impl Display for FuzzyMetaTag {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{} {} {}", hex::encode(self.u.compress().as_bytes()), hex::encode(self.y.as_bytes()), hex::encode(self.ciphertexts.to_bytes()))
|
write!(
|
||||||
|
f,
|
||||||
|
"{} {} {}",
|
||||||
|
hex::encode(self.u.compress().as_bytes()),
|
||||||
|
hex::encode(self.y.as_bytes()),
|
||||||
|
hex::encode(self.ciphertexts.to_bytes())
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FuzzyMetaTagKey {
|
pub struct FuzzyMetaTagKey {
|
||||||
s_keys: Vec<Scalar>,
|
s_keys: Vec<Scalar>,
|
||||||
p_keys: Vec<RistrettoPoint>
|
p_keys: Vec<RistrettoPoint>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FuzzyMetaTagKey {
|
impl FuzzyMetaTagKey {
|
||||||
|
@ -41,15 +47,20 @@ impl FuzzyMetaTagKey {
|
||||||
s_keys.push(sk_i);
|
s_keys.push(sk_i);
|
||||||
p_keys.push(pk_i);
|
p_keys.push(pk_i);
|
||||||
}
|
}
|
||||||
FuzzyMetaTagKey {
|
FuzzyMetaTagKey { s_keys, p_keys }
|
||||||
s_keys,
|
|
||||||
p_keys
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn h(u: RistrettoPoint, h: RistrettoPoint, w: RistrettoPoint) -> u8 {
|
fn h(u: RistrettoPoint, h: RistrettoPoint, w: RistrettoPoint) -> u8 {
|
||||||
let hash = sha3::Sha3_256::digest(format!("{}{}{}", hex::encode(u.compress().as_bytes()), hex::encode(h.compress().as_bytes()), hex::encode(w.compress().as_bytes())).as_bytes());
|
let hash = sha3::Sha3_256::digest(
|
||||||
return hash.as_slice()[0] & 0x01
|
format!(
|
||||||
|
"{}{}{}",
|
||||||
|
hex::encode(u.compress().as_bytes()),
|
||||||
|
hex::encode(h.compress().as_bytes()),
|
||||||
|
hex::encode(w.compress().as_bytes())
|
||||||
|
)
|
||||||
|
.as_bytes(),
|
||||||
|
);
|
||||||
|
return hash.as_slice()[0] & 0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn g(u: RistrettoPoint, points: &BitVec) -> Scalar {
|
fn g(u: RistrettoPoint, points: &BitVec) -> Scalar {
|
||||||
|
@ -73,11 +84,7 @@ impl FuzzyMetaTagKey {
|
||||||
let m = FuzzyMetaTagKey::g(u, &ciphertexts);
|
let m = FuzzyMetaTagKey::g(u, &ciphertexts);
|
||||||
let y = r.invert().mul(z.sub(m));
|
let y = r.invert().mul(z.sub(m));
|
||||||
|
|
||||||
return FuzzyMetaTag {
|
return FuzzyMetaTag { u, y, ciphertexts };
|
||||||
u,
|
|
||||||
y,
|
|
||||||
ciphertexts
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test(&self, tag: &FuzzyMetaTag) -> bool {
|
pub fn test(&self, tag: &FuzzyMetaTag) -> bool {
|
||||||
|
@ -94,15 +101,13 @@ impl FuzzyMetaTagKey {
|
||||||
};
|
};
|
||||||
let b_i = k_i ^ c_i;
|
let b_i = k_i ^ c_i;
|
||||||
if b_i != 1 {
|
if b_i != 1 {
|
||||||
return false
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
@ -133,6 +138,10 @@ mod tests {
|
||||||
false_positives += 1;
|
false_positives += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("Expected False Positive Rate: {}\nActual False Positive Rate: {}", (2.0_f64).powi(-3), (false_positives as f64 / number_of_messages as f64));
|
println!(
|
||||||
|
"Expected False Positive Rate: {}\nActual False Positive Rate: {}",
|
||||||
|
(2.0_f64).powi(-3),
|
||||||
|
(false_positives as f64 / number_of_messages as f64)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue