concrete_commons/
parameters.rs

1#![allow(deprecated)]
2#[cfg(feature = "serde_serialize")]
3use serde::{Deserialize, Serialize};
4
5/// The number plaintexts in a plaintext list.
6#[derive(Copy, Clone, Eq, PartialEq, Debug)]
7#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
8pub struct PlaintextCount(pub usize);
9
10/// The number encoder in an encoder list.
11#[derive(Copy, Clone, Eq, PartialEq, Debug)]
12#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
13pub struct EncoderCount(pub usize);
14
15/// The number messages in a messages list.
16#[derive(Copy, Clone, Eq, PartialEq, Debug)]
17#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
18pub struct CleartextCount(pub usize);
19
20/// The number of ciphertexts in a ciphertext list.
21#[derive(Copy, Clone, Eq, PartialEq, Debug)]
22#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
23pub struct CiphertextCount(pub usize);
24
25/// The number of ciphertexts in an lwe ciphertext list.
26#[derive(Copy, Clone, Eq, PartialEq, Debug)]
27#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
28pub struct LweCiphertextCount(pub usize);
29
30/// The index of a ciphertext in an lwe ciphertext list.
31#[derive(Copy, Clone, Eq, PartialEq, Debug)]
32#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
33pub struct LweCiphertextIndex(pub usize);
34
35/// The range of indices of multiple contiguous ciphertexts in an lwe ciphertext list.
36#[derive(Copy, Clone, Eq, PartialEq, Debug)]
37#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
38pub struct LweCiphertextRange(pub usize, pub usize);
39
40impl LweCiphertextRange {
41    pub fn is_ordered(&self) -> bool {
42        self.1 <= self.0
43    }
44}
45
46/// The number of ciphertexts in a glwe ciphertext list.
47#[derive(Copy, Clone, Eq, PartialEq, Debug)]
48#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
49pub struct GlweCiphertextCount(pub usize);
50
51/// The number of ciphertexts in a gsw ciphertext list.
52#[derive(Copy, Clone, Eq, PartialEq, Debug)]
53#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
54pub struct GswCiphertextCount(pub usize);
55
56/// The number of ciphertexts in a ggsw ciphertext list.
57#[derive(Copy, Clone, Eq, PartialEq, Debug)]
58#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
59pub struct GgswCiphertextCount(pub usize);
60
61/// The number of scalars in an LWE ciphertext, i.e. the number of scalar in an LWE mask plus one.
62#[derive(Debug, PartialEq, Eq, Copy, Clone)]
63#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
64pub struct LweSize(pub usize);
65
66impl LweSize {
67    /// Returns the associated [`LweDimension`].
68    pub fn to_lwe_dimension(&self) -> LweDimension {
69        LweDimension(self.0 - 1)
70    }
71}
72
73/// The number of scalar in an LWE mask, or the length of an LWE secret key.
74#[derive(Copy, Clone, Eq, PartialEq, Debug)]
75#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
76pub struct LweDimension(pub usize);
77
78impl LweDimension {
79    /// Returns the associated [`LweSize`].
80    pub fn to_lwe_size(&self) -> LweSize {
81        LweSize(self.0 + 1)
82    }
83}
84
85/// The number of polynomials in a GLWE ciphertext, i.e. the number of polynomials in a GLWE mask
86/// plus one.
87#[derive(Debug, PartialEq, Eq, Ord, PartialOrd, Copy, Clone)]
88#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
89pub struct GlweSize(pub usize);
90
91impl GlweSize {
92    /// Returns the associated [`GlweDimension`].
93    pub fn to_glwe_dimension(&self) -> GlweDimension {
94        GlweDimension(self.0 - 1)
95    }
96}
97
98/// The number of polynomials of an GLWE mask, or the size of an GLWE secret key.
99#[derive(Copy, Clone, Eq, PartialEq, Debug)]
100#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
101pub struct GlweDimension(pub usize);
102
103impl GlweDimension {
104    /// Returns the associated [`GlweSize`].
105    pub fn to_glwe_size(&self) -> GlweSize {
106        GlweSize(self.0 + 1)
107    }
108}
109
110/// The number of coefficients of a polynomial.
111///
112/// Assuming a polynomial $a_0 + a_1X + /dots + a_{N-1}X^{N-1}$, this returns $N$.
113#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
114#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
115pub struct PolynomialSize(pub usize);
116
117impl PolynomialSize {
118    /// Returns the associated [`PolynomialSizeLog`].
119    pub fn log2(&self) -> PolynomialSizeLog {
120        PolynomialSizeLog((self.0 as f64).log2().ceil() as usize)
121    }
122}
123
124/// The logarithm of the number of coefficients of a polynomial.
125///
126/// Assuming a polynomial $a_0 + a_1X + /dots + a_{N-1}X^{N-1}$, this returns $\log_2(N)$.
127#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
128#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
129pub struct PolynomialSizeLog(pub usize);
130
131impl PolynomialSizeLog {
132    /// Returns the associated [`PolynomialSizeLog`].
133    pub fn to_polynomial_size(&self) -> PolynomialSize {
134        PolynomialSize(1 << self.0)
135    }
136}
137
138/// The number of polynomials in a polynomial list.
139///
140/// Assuming a polynomial list, this return the number of polynomials.
141#[derive(Debug, Clone, Copy, PartialEq, Eq)]
142#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
143pub struct PolynomialCount(pub usize);
144
145/// The degree of a monomial.
146///
147/// Assuming a monomial $aX^N$, this returns the $N$ value.
148#[derive(Debug, Clone, Copy, PartialEq, Eq)]
149#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
150#[deprecated(note = "MonomialDegree is not used anymore in the API. You should not use it.")]
151pub struct MonomialDegree(pub usize);
152
153/// The index of a monomial in a polynomial.
154#[derive(Debug, Clone, Copy, PartialEq, Eq)]
155#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
156pub struct MonomialIndex(pub usize);
157
158/// The logarithm of the base used in a decomposition.
159///
160/// When decomposing an integer over powers of the $2^B$ basis, this type represents the $B$ value.
161#[derive(Debug, PartialEq, Eq, Copy, Clone)]
162#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
163pub struct DecompositionBaseLog(pub usize);
164
165/// The number of levels used in a decomposition.
166///
167/// When decomposing an integer over the $l$ largest powers of the basis, this type represents
168/// the $l$ value.
169#[derive(Debug, PartialEq, Eq, Copy, Clone)]
170#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
171pub struct DecompositionLevelCount(pub usize);
172
173/// The logarithm of the number of LUT evaluated in a PBS.
174#[derive(Debug, PartialEq, Eq, Copy, Clone)]
175#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
176pub struct LutCountLog(pub usize);
177
178/// The number of MSB shifted in a Modulus Switch.
179///
180/// When performing a Modulus Switch, this type represents the number of MSB that will be
181/// discarded.
182#[derive(Debug, PartialEq, Eq, Copy, Clone)]
183#[cfg_attr(feature = "serde_serialize", derive(Serialize, Deserialize))]
184pub struct ModulusSwitchOffset(pub usize);