zkryptium/lib.rs
1// Copyright 2025 Fondazione LINKS
2
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6
7// http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//!# ZKryptium
16//! 
17//! [](https://crates.io/crates/zkryptium)
18//! [](https://docs.rs/zkryptium/)
19//! ## Description
20//! ZKryptium library provides an implementation of:
21//! * **BBS+**([draft-irtf-cfrg-bbs-signatures-09](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bbs-signatures-09)) signature scheme
22//! * **Blind BBS Signatures** ([draft-irtf-cfrg-bbs-blind-signatures-01](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bbs-blind-signatures-01)) signature scheme with some fixes taken from [grotto-bbs-signatures](https://github.com/Wind4Greg/grotto-bbs-signatures)
23//! * **BBS per Verifier Linkability** ([draft-irtf-cfrg-bbs-blind-signatures-01](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bbs-per-verifier-linkability-01))
24//! * **CL2003** (https://link.springer.com/chapter/10.1007/3-540-36413-7_20) signature scheme
25//! This library enables the creation of zero-knowledge proofs, exposing cryptographic primitives facilitating the development of a Verifiable Credentials (VCs) system capable of handling both Anonymous Credentials and Selective Disclosure Credentials.
26//! **WARNING:** for CL2003 use a version from v0.3.2 onwards that uses a new secure cryptographic implementation of the Pseudo Random Number Generator [ThreadRng](https://rust-random.github.io/rand/rand/rngs/struct.ThreadRng.html)
27//! ## Getting Started
28//! ### Requirements
29//! - [Rust](https://www.rust-lang.org/) (>= 1.65)
30//! - [Cargo](https://doc.rust-lang.org/cargo/) (>= 1.65)
31//! - The ZKryptium **CL03** implementation also depends on the [Rug crate](https://crates.io/crates/rug) which depends on GMP, MPFR and MPC libraries through the low-level FFI bindings in the [gmp-mpfr-sys crate](https://crates.io/crates/gmp-mpfr-sys), which needs some setup to build; the [gmp-mpfr-sys documentation](https://docs.rs/gmp-mpfr-sys/1.6.1/gmp_mpfr_sys/index.html) has some details on usage under [GNU/Linux](https://docs.rs/gmp-mpfr-sys/1.6.1/gmp_mpfr_sys/index.html#building-on-gnulinux), [macOS](https://docs.rs/gmp-mpfr-sys/1.6.1/gmp_mpfr_sys/index.html#building-on-macos) and [Windows](https://docs.rs/gmp-mpfr-sys/1.6.1/gmp_mpfr_sys/index.html#building-on-windows).
32//! ### Usage
33//! ##### BBS+:
34//! ```toml
35//! [dependencies]
36//! zkryptium = { version = "0.6.0", default-features = false, features = ["bbsplus"] }
37//! ```
38//!
39//! ##### BBS+ Blind signature:
40//! ```toml
41//! [dependencies]
42//! zkryptium = { version = "0.6.0", default-features = false, features = ["bbsplus", "bbsplus_blind"] }
43//! ```
44//!
45//! ##### BBS+ per Verifier Linkability:
46//!
47//! ```toml
48//! [dependencies]
49//! zkryptium = { version = "0.6.0", default-features = true}
50//! ```
51//!
52//! ##### CL2003:
53//! ```toml
54//! [dependencies]
55//! zkryptium = { version = "0.6.0", default-features = false, features = ["cl03"] }
56//! ```
57//!
58//! ### Examples
59//!
60//! Take a look at the [examples](https://github.com/Cybersecurity-LINKS/ZKryptium/tree/main/examples).
61//!
62//! You can run the examples based on the [BBS+](https://identity.foundation/bbs-signature/draft-irtf-cfrg-bbs-signatures.html) Signature Scheme with:
63//! ```sh
64//! cargo run --example bbsplus <ciphersuite>
65//! cargo run --example bbsplus_blind <ciphersuite>
66//! cargo run --example bbsplus_nym <ciphersuite>
67//! ```
68//!
69//! ##### Available Ciphersuites:
70//! - BLS12-381-SHA-256
71//! - BLS12-381-SHAKE-256
72//!
73//! You can run the examples based on the [CL2003](https://link.springer.com/chapter/10.1007/3-540-36413-7_20) Signature Scheme with:
74//! ```sh
75//! cargo run --features="cl03" --example cl03 <ciphersuite>
76//! cargo run --features="cl03" --example cl03_multiattr <ciphersuite>
77//! ```
78//!
79//! ##### Available Ciphersuites:
80//! - CL1024-SHA-256
81//! - CL2048-SHA-256
82//! - CL3072-SHA-256
83//! ## Test
84//!
85//! To test the library you can launch the test vectors with:
86//!
87//! ```sh
88//! cargo test
89//! ```
90//!
91#![warn(missing_docs)]
92
93
94#![allow(non_snake_case)]
95#![allow(non_upper_case_globals)]
96#![allow(non_camel_case_types)]
97
98/// Errors module
99pub mod errors;
100/// Keys module
101pub mod keys;
102/// Schemes module
103pub mod schemes;
104/// Utils module
105pub mod utils;
106
107#[cfg(feature = "bbsplus")]
108/// BBS+ signature scheme module
109pub mod bbsplus;
110#[cfg(feature = "cl03")]
111#[doc(hidden)]
112pub mod cl03;