umbral_pre/
params.rs

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