why2/
lib.rs

1/*
2This is part of WHY2
3Copyright (C) 2022-2026 Václav Šmejkal
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program.  If not, see <https://www.gnu.org/licenses/>.
17*/
18
19//! # WHY2
20//!
21//! WHY2 is a modern, fast, and secure encryption crate designed for privacy-first applications.
22//!
23//! ## Design Overview
24//! The WHY2 encryption algorithm is loosely inspired by AES, but with a twist. Instead of relying on S-boxes,
25//! WHY2 uses a nonlinear ARX-style transformation (Addition, Rotation, XOR) for symmetric diffusion.
26//!
27//! Key mechanics include:
28//! - **Grid-based State**: Input and key data are formatted into 2D grids of 64-bit cells.
29//! - **Key Expansion**: The key grid is shuffled and seeded to generate round keys.
30//! - **Nonlinear Mixing**: Each round applies a transformation to the input grids using round tweaks to ensure variability.
31//!
32//! WHY2 also powers a minimalist text and voice chat application built for maximal privacy, designed for self-hosting
33//! by individuals or small groups.
34//!
35//! ## Features
36//! - Grid-based encryption with customizable layout
37//! - ARX-style nonlinear mixing instead of S-boxes
38//! - Round-key generation from seeded, shuffled keys
39//! - Lightweight encrypted text and voice chat backend for private deployments
40//! - Maximal customization
41//!
42//! ## Cargo Features
43//!
44//! This crate allows selective enabling of components to keep the build lightweight.
45//!
46//! - **`constant-time`** (default):
47//!   Enables constant-time comparison for cryptographic operations using the [`subtle`] crate.
48//!   Disabling this may improve performance on non-sensitive data but opens the system to timing attacks.
49//!
50//! - **`client`**:
51//!   Enables the terminal-based client application with interactive interface and real-time voice chat support.
52//!
53//! - **`server`**:
54//!   Enables the relay server logic for routing encrypted messages between clients.
55//!   *Use this if you are building a custom node or hosting a relay.*
56//!
57//! - **`legacy`**:
58//!   Enables the deprecated `legacy` module containing older, insecure versions of the encryption routines.
59//!   This feature should only be used for migration or compatibility testing.
60//!
61//! ## Philosophy
62//! - **Privacy is a right**, not a subscription feature.
63//! - **No government insight**: no telemetry, no backdoors, no metadata leakage.
64//! - **No payment required**: encryption should be free as in freedom.
65//!
66//! ## Terminology
67//!
68//! The codebase is organized to distinguish between the current implementation and deprecated versions:
69//!
70//! * **REX**: Refers to the modern, secure implementation of the WHY2 algorithm.
71//! These are the modules exposed directly at the crate root (e.g., [`encrypter`], [`decrypter`]).
72//! * **Legacy**: Refers to older, deprecated encryption routines found in the [`legacy`] module.
73//! These are retained for compatibility but are considered insecure.
74//!
75//! ## Examples
76//!
77//! For comprehensive usage examples, including global algorithm usage and specific edge cases,
78//! please refer to the [examples directory](https://git.satan.red/ENGO150/WHY2/-/tree/stable/examples)
79//! in the official repository.
80//!
81//! ## Security Disclaimer
82//!
83//! WHY2 is an experimental encryption algorithm. While it draws inspiration from established designs like AES,
84//! **it has not undergone formal cryptographic review or extensive academic analysis**.
85//!
86//! As such, it should **not be considered suitable for high-assurance or production-grade cryptographic applications** where
87//! proven security guarantees are required. Use at your own discretion, and always evaluate your threat model carefully.
88//!
89//! ## License
90//! WHY2 is licensed under the GNU GPLv3. You are free to use, modify, and redistribute it
91//! under the terms of the license. See <https://www.gnu.org/licenses/> for details.
92
93//DOCS
94#![doc(html_logo_url = "https://why2.satan.red/apple-icon.png")]
95#![doc(html_favicon_url = "https://why2.satan.red/icon-dark-32x32.png")]
96
97//MODULES
98#[cfg(feature = "auth")]
99pub mod auth;
100pub mod consts;
101pub mod crypto;
102pub mod decrypter;
103pub mod encrypter;
104pub mod grid;
105pub mod types;
106
107#[cfg(feature = "legacy")]
108#[deprecated(since = "0.2.0-rex", note = "Legacy encryption is unsecure. Use REX module (why2::core) instead.")]
109pub mod legacy;