Fix const-generics related deserialization issue with RootSecret
RootSecret.tagging_key() now rederives the tagging key from the root secret instead of caching it. This decomplicates the RootSecret struct and fixes a const_generics related error when building for fuzzing
This commit is contained in:
parent
1147c4f6d5
commit
5a61d9461a
|
@ -29,4 +29,4 @@ name = "fuzzy_tags_benches"
|
|||
harness = false
|
||||
|
||||
[features]
|
||||
entangled = ["brute-force"]
|
||||
entangled = ["brute-force"]
|
21
src/lib.rs
21
src/lib.rs
|
@ -170,13 +170,11 @@ impl<const GAMMA: u8> Display for Tag<{ GAMMA }> {
|
|||
|
||||
/// The complete secret. Can't directly be used for testing. Instead you will need to generate
|
||||
/// a DetectionKey using `extract_detection_key`
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct RootSecret<const GAMMA: u8> {
|
||||
/// the detection key - this can be given to adversarial servers to help probabilistically
|
||||
/// filter messages (with a false-positive rate derived from γ and a 0% false negative rate)
|
||||
secret: Vec<Scalar>,
|
||||
/// the tagging key - this can be given to people who you want to contact you
|
||||
tagging_key: TaggingKey<{ GAMMA }>,
|
||||
}
|
||||
|
||||
impl<const GAMMA: u8> RootSecret<{ GAMMA }> {
|
||||
|
@ -190,18 +188,13 @@ impl<const GAMMA: u8> RootSecret<{ GAMMA }> {
|
|||
/// ```
|
||||
pub fn generate() -> RootSecret<{ GAMMA }> {
|
||||
let mut rng = OsRng::default();
|
||||
let g = RISTRETTO_BASEPOINT_POINT;
|
||||
let mut secret = vec![];
|
||||
let mut p_keys = vec![];
|
||||
for _i in 0..GAMMA {
|
||||
let sk_i = Scalar::random(&mut rng);
|
||||
let pk_i = g.mul(sk_i);
|
||||
secret.push(sk_i);
|
||||
p_keys.push(pk_i);
|
||||
}
|
||||
RootSecret::<GAMMA> {
|
||||
secret,
|
||||
tagging_key: TaggingKey { 0: p_keys },
|
||||
secret: secret
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,7 +221,15 @@ impl<const GAMMA: u8> RootSecret<{ GAMMA }> {
|
|||
/// let tagging_key = secret.tagging_key();
|
||||
/// ```
|
||||
pub fn tagging_key(&self) -> TaggingKey<{ GAMMA }> {
|
||||
self.tagging_key.clone()
|
||||
let g = RISTRETTO_BASEPOINT_POINT;
|
||||
let mut tagging_key = vec![];
|
||||
for sk_i in self.secret.iter() {
|
||||
let pk_i = g.mul(sk_i);
|
||||
tagging_key.push(pk_i);
|
||||
}
|
||||
TaggingKey::<GAMMA>{
|
||||
0: tagging_key
|
||||
}
|
||||
}
|
||||
|
||||
/// a hash function that takes 3 ristretto points as a parameter and outputs 0 or 1.
|
||||
|
|
Loading…
Reference in New Issue