concrete_core/specification/
parameters.rs

1#![allow(deprecated)]
2#[cfg(feature = "__commons_serialization")]
3use serde::{Deserialize, Serialize};
4
5/// The number plaintexts in a plaintext list.
6#[derive(Copy, Clone, Eq, PartialEq, Debug)]
7#[cfg_attr(feature = "__commons_serialization", 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 = "__commons_serialization", 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 = "__commons_serialization", 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 = "__commons_serialization", 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 = "__commons_serialization", 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 = "__commons_serialization", 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 = "__commons_serialization", 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 = "__commons_serialization", 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 = "__commons_serialization", 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 = "__commons_serialization", 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, PartialOrd, Ord, Copy, Clone)]
63#[cfg_attr(feature = "__commons_serialization", 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, PartialEq, Eq, PartialOrd, Ord, Debug)]
75#[cfg_attr(feature = "__commons_serialization", 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 LWE encryptions of 0 in an LWE public key.
86#[derive(Copy, Clone, Eq, PartialEq, Debug)]
87#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
88pub struct LwePublicKeyZeroEncryptionCount(pub usize);
89
90/// The number of polynomials in a GLWE ciphertext, i.e. the number of polynomials in a GLWE mask
91/// plus one.
92#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
93#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
94pub struct GlweSize(pub usize);
95
96impl GlweSize {
97    /// Returns the associated [`GlweDimension`].
98    pub fn to_glwe_dimension(&self) -> GlweDimension {
99        GlweDimension(self.0 - 1)
100    }
101}
102
103/// The number of polynomials of an GLWE mask, or the size of an GLWE secret key.
104#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
105#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
106pub struct GlweDimension(pub usize);
107
108impl GlweDimension {
109    /// Returns the associated [`GlweSize`].
110    pub fn to_glwe_size(&self) -> GlweSize {
111        GlweSize(self.0 + 1)
112    }
113}
114
115/// The number of coefficients of a polynomial.
116///
117/// Assuming a polynomial $a\_0 + a\_1X + /dots + a\_{N-1}X^{N-1}$, this returns $N$.
118#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
119#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
120pub struct PolynomialSize(pub usize);
121
122impl PolynomialSize {
123    /// Returns the associated [`PolynomialSizeLog`].
124    pub fn log2(&self) -> PolynomialSizeLog {
125        PolynomialSizeLog((self.0 as f64).log2().ceil() as usize)
126    }
127}
128
129/// The logarithm of the number of coefficients of a polynomial.
130///
131/// Assuming a polynomial $a\_0 + a\_1X + /dots + a\_{N-1}X^{N-1}$, this returns $\log\_2(N)$.
132#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
133#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
134pub struct PolynomialSizeLog(pub usize);
135
136impl PolynomialSizeLog {
137    /// Returns the associated [`PolynomialSizeLog`].
138    pub fn to_polynomial_size(&self) -> PolynomialSize {
139        PolynomialSize(1 << self.0)
140    }
141}
142
143/// The number of polynomials in a polynomial list.
144///
145/// Assuming a polynomial list, this return the number of polynomials.
146#[derive(Debug, Clone, Copy, PartialEq, Eq)]
147#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
148pub struct PolynomialCount(pub usize);
149
150/// The degree of a monomial.
151///
152/// Assuming a monomial $aX^N$, this returns the $N$ value.
153#[derive(Debug, Clone, Copy, PartialEq, Eq)]
154#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
155#[deprecated(note = "MonomialDegree is not used anymore in the API. You should not use it.")]
156pub struct MonomialDegree(pub usize);
157
158/// The index of a monomial in a polynomial.
159#[derive(Debug, Clone, Copy, PartialEq, Eq)]
160#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
161pub struct MonomialIndex(pub usize);
162
163/// The logarithm of the base used in a decomposition.
164///
165/// When decomposing an integer over powers of the $2^B$ basis, this type represents the $B$ value.
166#[derive(Debug, PartialEq, Eq, Copy, Clone)]
167#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
168pub struct DecompositionBaseLog(pub usize);
169
170/// The number of levels used in a decomposition.
171///
172/// When decomposing an integer over the $l$ largest powers of the basis, this type represents
173/// the $l$ value.
174#[derive(Debug, PartialEq, Eq, Copy, Clone)]
175#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
176pub struct DecompositionLevelCount(pub usize);
177
178/// The logarithm of the number of LUT evaluated in a PBS.
179#[derive(Debug, PartialEq, Eq, Copy, Clone)]
180#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
181pub struct LutCountLog(pub usize);
182
183/// The number of MSB shifted in a Modulus Switch.
184///
185/// When performing a Modulus Switch, this type represents the number of MSB that will be
186/// discarded.
187#[derive(Debug, PartialEq, Eq, Copy, Clone)]
188#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
189pub struct ModulusSwitchOffset(pub usize);
190
191/// The base 2 logarithm of the scaling factor (generally written $\Delta$) used to store the
192/// message in the MSB of ciphertexts.
193#[derive(Debug, PartialEq, Eq, Copy, Clone)]
194#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
195pub struct DeltaLog(pub usize);
196
197/// The number of bits to extract in a bit extraction.
198#[derive(Debug, PartialEq, Eq, Copy, Clone)]
199#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
200pub struct ExtractedBitsCount(pub usize);
201
202/// The number of functional packing keyswitch key in a functional packing keyswitch key list.
203#[derive(Debug, PartialEq, Eq, Copy, Clone)]
204#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
205pub struct FunctionalPackingKeyswitchKeyCount(pub usize);
206
207/// The number of bits used for the mask coefficients and the body of a ciphertext
208#[derive(Debug, PartialEq, Eq, Copy, Clone)]
209#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
210pub struct CiphertextModulusLog(pub usize);