1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::curve::CurvePoint;
/// An object containing shared scheme parameters.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Parameters {
/// The re-encryption parameter `u`.
pub u: CurvePoint,
}
impl Parameters {
/// Creates a new parameter object.
pub fn new() -> Self {
// The goal is to find two distinct points `g` and `u` for which `log_g(u)` is unknown.
// `g` is fixed to be the generator because it has to be the same
// as the one used for secret/public keys, and it is standardized (for a given curve).
// Only fails when the given binary string is too large, which is not the case here,
// so we can safely unwrap.
let u = CurvePoint::from_data(b"PARAMETERS", b"POINT_U").unwrap();
Self { u }
}
}
impl Default for Parameters {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::Parameters;
#[test]
fn test_default() {
let p1 = Parameters::new();
let p2 = Parameters::new();
assert_eq!(p1, p2);
}
}