pvss/
pdleq.rs

1// Parallel DLEQ proofs
2use super::crypto::*;
3use super::dleq;
4
5type Challenge = Scalar;
6
7#[derive(Clone)]
8pub struct Proof {
9    c: Challenge,
10    zs: Vec<Scalar>,
11}
12
13impl Proof {
14    pub fn create(params: &[(Scalar, &Scalar, dleq::DLEQ)]) -> Proof {
15        let mut zs = Vec::with_capacity(params.len());
16
17        let mut hasher = PointHasher::new();
18
19        // create the list [h1_1 ,h2_1 , h1_2 , h2_2, ... h2_n, a1_1, a2_1, .., a1_n, a2_n ]
20        // to compute the challenge
21        for param in params.iter() {
22            let &(ref w, _, ref dleq) = param;
23            hasher = hasher
24                .update(&dleq.h1)
25                .update(&dleq.h2)
26                .update(&dleq.g1.mul(&w))
27                .update(&dleq.g2.mul(&w));
28        }
29
30        // compute the challenge
31        let c = hasher.finalize();
32
33        // finally create each proofs
34        for (w, a, _) in params.iter() {
35            let z = w + &(*a * &c);
36            zs.push(z);
37        }
38        Proof { c, zs }
39    }
40
41    pub fn verify(&self, dleqs: &[dleq::DLEQ]) -> bool {
42        if dleqs.len() != self.zs.len() {
43            // FIXME probably an Err() .. instead of silent verify failure
44            return false;
45        };
46
47        let mut hasher = PointHasher::new();
48
49        // recompute the challenge
50        for (i, z) in self.zs.iter().enumerate() {
51            let dleq = &dleqs[i];
52            let r1 = dleq.g1.mul(z);
53            let r2 = dleq.g2.mul(z);
54            let a1 = r1 - dleq.h1.mul(&self.c);
55            let a2 = r2 - dleq.h2.mul(&self.c);
56
57            hasher = hasher
58                .update(&dleq.h1)
59                .update(&dleq.h2)
60                .update(&a1)
61                .update(&a2);
62        }
63
64        let c = hasher.finalize();
65
66        self.c == c
67    }
68}