zeros/lib.rs
1/*
2==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
3
4Zeros
5
6Copyright (C) 2019-2025 Anonymous
7
8There are several releases over multiple years,
9they are listed as ranges, such as: "2019-2025".
10
11This program is free software: you can redistribute it and/or modify
12it under the terms of the GNU Lesser General Public License as published by
13the Free Software Foundation, either version 3 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU Lesser General Public License for more details.
20
21You should have received a copy of the GNU Lesser General Public License
22along with this program. If not, see <https://www.gnu.org/licenses/>.
23
24::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--
25*/
26
27//! # Zeros
28//!
29//! ## Project
30//!
31//! - License: GNU Lesser General Public License, either version 3, or (at your option) any later version.
32//! - _This project follows [Semantic Versioning 2.0.0]_
33//!
34//! ## Features
35//!
36//! This project provides:
37//!
38//! - _Some_ [hash functions][mod:keccak] from [Keccak][site:keccak].
39//! - Some cryptographic implementations: [Chacha][mod:chacha], [Poly1305][mod:poly1305], [Argon2][mod:argon2]...
40//!
41//! ## Notes
42//!
43//! - Currently only little-endian systems are supported. We don't have access or knowledge to test on big-endian systems.
44//! - Internal state stores data on [`u64`]. So it works best on systems supporting `u64` natively.
45//! - Accuracy/correctness is highest priority. Speed is second. Currently, it's slower than well-known implementations, such as
46//! [OpenSSL][site:openssl].
47//! - Documentation is built with all features. Some of them are optional. If you see components from other crates, you can view source to see
48//! what features are required.
49//! - Night Rust is required to build.
50//!
51//! [Semantic Versioning 2.0.0]: https://semver.org/spec/v2.0.0.html
52//!
53//! [site:keccak]: https://keccak.team
54//! [site:openssl]: https://www.openssl.org
55//!
56//! [mod:argon2]: argon2/index.html
57//! [mod:chacha]: chacha/index.html
58//! [mod:keccak]: keccak/index.html
59//! [mod:poly1305]: poly1305/index.html
60
61#![warn(missing_docs)]
62#![no_std]
63
64#![cfg_attr(feature="simd", feature(portable_simd))]
65
66#![feature(bigint_helper_methods)]
67#![feature(doc_cfg)]
68#![feature(test)]
69
70// ╔═════════════════╗
71// ║ IDENTIFIERS ║
72// ╚═════════════════╝
73
74macro_rules! code_name { () => { "zeros" }}
75macro_rules! version { () => { "17.3.1" }}
76
77/// # Crate name
78pub const NAME: &str = "Zeros";
79
80/// # Crate code name
81pub const CODE_NAME: &str = code_name!();
82
83/// # ID of this crate
84pub const ID: &str = concat!(
85 "85ede580-25ef8822-72185cb5-6608f8ae-3c960bc1-75e3ab78-6d1f8a8a-55eb5c40-",
86 "f0b681d6-13275f82-d587a89e-9de72f64-3951a1b0-79f48b29-de4a6330-817a600f",
87);
88
89/// # Crate version
90pub const VERSION: &str = version!();
91
92/// # Crate release date (year/month/day)
93pub const RELEASE_DATE: (u16, u8, u8) = (2025, 6, 1);
94
95/// # Tag, which can be used for logging...
96pub const TAG: &str = concat!(code_name!(), "::85ede580::", version!());
97
98// ╔════════════════════╗
99// ║ IMPLEMENTATION ║
100// ╚════════════════════╝
101
102#[macro_use]
103extern crate alloc;
104
105#[cfg(feature="std")]
106extern crate std;
107
108#[cfg(test)]
109extern crate test;
110
111/// # Makes new Error
112macro_rules! e {
113 () => {
114 $crate::Error::new(line!(), module_path!(), None)
115 };
116 ($($s: tt)+) => {
117 $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Borrowed(concat!($($s)+))))
118 };
119}
120
121/// # Makes new Error
122macro_rules! err {
123 ($($arg: tt)*) => {
124 $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Owned(alloc::format!($($arg)*))))
125 };
126}
127
128#[test]
129fn test_macro_err() {
130 use alloc::borrow::Cow;
131
132 macro_rules! s_test { () => { "test" }}
133
134 fn eq(first: Error, second: Error) -> bool {
135 first.line() == second.line() && first.module_path() == second.module_path() && first.msg() == second.msg()
136 }
137
138 assert!(eq(e!(), Error::new(line!(), module_path!(), None)));
139 assert!(eq(e!(s_test!(), s_test!()), Error::new(line!(), module_path!(), Some(Cow::Borrowed(concat!(s_test!(), s_test!()))))));
140 assert!(eq(e!("test"), Error::new(line!(), module_path!(), Some(Cow::Borrowed(s_test!())))));
141 assert!(eq(err!("{s:?}", s=s_test!()), Error::new(line!(), module_path!(), Some(Cow::Owned(alloc::format!("{:?}", s_test!()))))));
142
143 let some = "===";
144 assert_eq!(err!("{some}").msg(), Error::new(line!(), module_path!(), Some(Cow::Borrowed(some))).msg());
145}
146
147#[macro_use]
148mod error;
149
150mod bytes;
151mod str;
152mod zeros;
153
154pub mod argon2;
155pub mod chacha;
156pub mod io;
157pub mod keccak;
158pub mod poly1305;
159pub mod prg;
160pub mod version_info;
161
162pub use crate::{
163 bytes::*,
164 error::*,
165 zeros::*,
166};
167
168/// # Result type used in this crate
169pub type Result<T> = core::result::Result<T, Error>;
170
171/// # Result for I/O functions
172#[cfg(feature="std")]
173#[doc(cfg(feature="std"))]
174pub type IoResult<T> = core::result::Result<T, std::io::Error>;
175
176#[cfg(all(feature="std", test))]
177const TEST_LOOPS: usize = 999;
178
179#[test]
180fn test_crate_version() {
181 assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
182}