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    { () => { "19.0.0" }}
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, 9, 4);
94
95/// # Tag, which can be used for logging...
96pub const TAG: &str = concat!(code_name!(), "::85ede580::", version!());
97
98// ╔════════════════════╗
99// ║   IMPLEMENTATION   ║
100// ╚════════════════════╝
101
102extern crate alloc;
103
104#[cfg(feature="std")]
105extern crate std;
106
107#[cfg(test)]
108extern crate test;
109
110/// # Makes new Error
111macro_rules! e {
112    () => {
113        $crate::Error::new(line!(), module_path!(), None)
114    };
115    ($($s: tt)+) => {
116        $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Borrowed(concat!($($s)+))))
117    };
118}
119
120/// # Makes new Error
121macro_rules! err {
122    ($($arg: tt)*) => {
123        $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Owned(alloc::format!($($arg)*))))
124    };
125}
126
127#[test]
128fn test_macro_err() {
129    use alloc::borrow::Cow;
130
131    macro_rules! s_test { () => { "test" }}
132
133    fn eq(first: Error, second: Error) -> bool {
134        first.line() == second.line() && first.module_path() == second.module_path() && first.msg() == second.msg()
135    }
136
137    assert!(eq(e!(), Error::new(line!(), module_path!(), None)));
138    assert!(eq(e!(s_test!(), s_test!()), Error::new(line!(), module_path!(), Some(Cow::Borrowed(concat!(s_test!(), s_test!()))))));
139    assert!(eq(e!("test"), Error::new(line!(), module_path!(), Some(Cow::Borrowed(s_test!())))));
140    assert!(eq(err!("{s:?}", s=s_test!()), Error::new(line!(), module_path!(), Some(Cow::Owned(alloc::format!("{:?}", s_test!()))))));
141
142    let some = "===";
143    assert_eq!(err!("{some}").msg(), Error::new(line!(), module_path!(), Some(Cow::Borrowed(some))).msg());
144}
145
146#[macro_use]
147mod error;
148
149mod bytes;
150mod str;
151mod zeros;
152
153pub mod argon2;
154pub mod chacha;
155pub mod io;
156pub mod keccak;
157pub mod poly1305;
158pub mod prg;
159pub mod version_info;
160
161pub use crate::{
162    bytes::*,
163    error::*,
164    zeros::*,
165};
166
167/// # Result type used in this crate
168pub type Result<T> = core::result::Result<T, Error>;
169
170/// # Result for I/O functions
171#[cfg(feature="std")]
172#[doc(cfg(feature="std"))]
173pub type IoResult<T> = core::result::Result<T, std::io::Error>;
174
175#[cfg(all(feature="std", test))]
176const TEST_LOOPS: usize = 999;
177
178#[test]
179fn test_crate_version() {
180    assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
181}