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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (C) 2024 Stanislav Zhevachevskyi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//! # Passring
//!
//! Cryptographic library for secure voting systems.
//!
//! Passring is a cryptographic library for secure voting systems. It provides a set of cryptographic primitives for
//! secure voting systems, including key generation, encryption, decryption, and signature generation.
//!
//! For more information, see the [Passring whitepaper](https://docs.nau-digital.com/passring/whitepaper).
//! ## Features
//!
//! - **Secure**: Passring uses the latest cryptographic algorithms to ensure the security of the voting system.
//! - **Fast**: Passring is optimized for performance and can handle large volumes of data.
//! - **Easy to use**: Passring provides a simple and easy-to-use API for developers.
//!
//! ## Algorithms
//!
//! Passring uses the following cryptographic algorithms:
//!
//! - **ChaCha20-Poly1305**: For encryption and decryption of payloads.
//! - **Curve25519 and Ristretto**: For key generation.
//! - **bLSAG**: For signature generation. bLSAG is a ring signature scheme described in the Chapter 3 of [Zero to Monero 2.0 (Z2M2)](https://www.getmonero.org/library/Zero-to-Monero-2-0-0.pdf).
//!
//! ## Usage
//!
//! To use Passring in your project, add it as dependency using Cargo:
//!
//! ```bash
//! cargo add passring
//! ```
//!
//! NOTE: If you want to serialize and deserialize keys/signatures, you need to enable the `serde` feature:
//!
//! ```bash
//! cargo add passring --features=serde
//! ```
//!
//! Here is an example of how to use Passring to create a new voting system:
//!
//! ```rust
//! use chacha20poly1305::{ChaCha20Poly1305, KeyInit};
//! use passring::{Passring, PrivateKey, PublicKey};
//! use passring::payload::ClearPayload;
//! use passring::traits::Random;
//! use rand_core::OsRng;
//! use passring::choices::{BasicVotingChoice, VotingChoice};
//!
//! // Generate a new voting ID
//! let voting_id = uuid::Uuid::new_v4();
//!
//! // Generate a new private key and public key
//! let private_key = PrivateKey::random(&mut OsRng);
//! let public_key = PublicKey::from(private_key);
//!
//! // Ring must be retrieved from the Verifier
//! let ring: Vec<PublicKey> = (0..9).map(|_| PublicKey::random(&mut OsRng)).chain(std::iter::once(public_key)).collect();
//!
//! // Create a new Passring instance
//! let passring = Passring::new(voting_id, ring);
//!
//! // Create a new clear payload
//!
//! let choice = VotingChoice::Basic { choice: BasicVotingChoice::For }; // The choice of the voter
//! let clear_payload = ClearPayload::new_random(voting_id, choice, &mut OsRng);
//!
//! // Encrypt the clear payload
//! let key = ChaCha20Poly1305::generate_key(&mut OsRng); // Generate a new key
//! let payload = clear_payload.encrypt(&key, &mut OsRng).expect("Failed to encrypt payload");
//!
//! // Issue a new signature
//! let full_signature = passring.issue::<OsRng>(payload, private_key).expect("Failed to issue signature");
//!
//! // Verify the signature
//! passring.verify(&full_signature).expect("Failed to verify signature");
//!
//! // validate the signature (when the key is known)
//! passring.validate(&full_signature, &key).expect("Failed to validate signature");
//!
//! println!("Signature is valid");
//! ```
pub use crate;
pub use cratePassring;
/// Result type for Passring operations.
type Result<T> = Result;
pub const VERSION: &str = env!;