paillier_common/
lib.rs

1use std::borrow::Cow;
2
3use serde::{Deserialize, Serialize};
4
5pub mod core;
6pub mod encoding;
7pub mod keygen;
8pub mod traits;
9
10pub use crate::core::*;
11pub use encoding::*;
12pub use keygen::*;
13pub use traits::*;
14
15pub use rust_bigint::BigInt;
16
17/// Main struct onto which most operations are added.
18pub struct Paillier;
19
20/// Keypair from which encryption and decryption keys can be derived.
21#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
22pub struct Keypair {
23    #[serde(with = "rust_bigint::serialize::bigint")]
24    pub p: BigInt, // TODO[Morten] okay to make non-public?
25
26    #[serde(with = "rust_bigint::serialize::bigint")]
27    pub q: BigInt, // TODO[Morten] okay to make non-public?
28}
29
30/// Public encryption key with no precomputed values.
31///
32/// Used e.g. for serialization of `EncryptionKey`.
33#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
34pub struct MinimalEncryptionKey {
35    #[serde(with = "rust_bigint::serialize::bigint")]
36    pub n: BigInt,
37}
38
39/// Private decryption key with no precomputed values.
40///
41/// Used e.g. for serialization of `DecryptionKey`.
42#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
43pub struct MinimalDecryptionKey {
44    #[serde(with = "rust_bigint::serialize::bigint")]
45    pub p: BigInt,
46
47    #[serde(with = "rust_bigint::serialize::bigint")]
48    pub q: BigInt,
49}
50
51/// Public encryption key.
52#[derive(Clone, Debug, PartialEq)]
53pub struct EncryptionKey {
54    pub n: BigInt,  // the modulus
55    pub nn: BigInt, // the modulus squared
56}
57
58/// Private decryption key.
59#[derive(Clone, Debug, PartialEq)]
60pub struct DecryptionKey {
61    pub p: BigInt, // first prime
62    pub q: BigInt, // second prime
63}
64
65/// Unencrypted message without type information.
66///
67/// Used mostly for internal purposes and advanced use-cases.
68#[derive(Clone, Debug, PartialEq)]
69pub struct RawPlaintext<'b>(pub Cow<'b, BigInt>);
70
71/// Encrypted message without type information.
72///
73/// Used mostly for internal purposes and advanced use-cases.
74#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
75pub struct RawCiphertext<'b>(pub Cow<'b, BigInt>);