Skip to content
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

Add subtract to MultiHash #605

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions fastcrypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ pub trait MultisetHash<const DIGEST_LENGTH: usize>: Eq {
/// Add all the elements of another hash function into this hash function.
fn union(&mut self, other: &Self);

/// Remove all the elements of another hash function from this hash function.
fn subtract(&mut self, other: &Self);

// Note that the "remove" operation is safe even if an item has been removed
// more times than it has been inserted. To see why, consider the following
// example: Suppose an adversary has performed two sets of "insert(x)" and
Expand Down Expand Up @@ -302,6 +305,10 @@ impl MultisetHash<32> for EllipticCurveMultisetHash {
self.accumulator += other.accumulator;
}

fn subtract(&mut self, other: &Self) {
self.accumulator -= other.accumulator;
}

fn remove<Data: AsRef<[u8]>>(&mut self, item: Data) {
self.accumulator -= Self::hash_to_point(item);
}
Expand Down