Expand description
§Zeros
§Project
- License: GNU Lesser General Public License, either version 3, or (at your option) any later version.
- This project follows Semantic Versioning 2.0.0
§Features
This project provides:
- Some hash functions from Keccak.
- Some cryptographic implementations: Chacha, Poly1305, Argon2…
§Notes
- Currently only little-endian systems are supported. We don’t have access or knowledge to test on big-endian systems.
- Internal state stores data on
u64. So it works best on systems supportingu64natively. - Accuracy/correctness is highest priority. Speed is second. Currently, it’s slower than well-known implementations, such as OpenSSL.
- Documentation is built with all features. Some of them are optional. If you see components from other crates, you can view source to see what features are required.
- Night Rust is required to build.
§Async Support: Understanding Your Responsibilities
§Overview
This crate provides optional async support for cryptographic operations via the tokio feature flag. When enabled, it offers
AsyncRead/AsyncWrite implementations that integrate with the tokio async runtime.
§Important: Performance and Runtime Considerations
Cryptographic operations are CPU-bound tasks. Unlike I/O operations that naturally yield control during waiting periods, cryptographic functions perform continuous computation without internal await points.
When using this crate’s async API, you are responsible for managing the balance between computational work and runtime responsiveness.
§Why This Matters
Async runtimes use cooperative scheduling. Tasks are expected to yield control periodically to allow other tasks to make progress. If a single task runs a CPU-intensive operation for too long without yielding, it can:
- Starve other tasks waiting to run
- Delay I/O event processing
- Create noticeable latency spikes
- Potentially deadlock the runtime in extreme cases
§The Chunk Size Principle
The core guideline is: ensure each chunk of data processed in a single operation is small enough that the cryptographic work completes within a reasonable time frame for your runtime.
For example, when calling write_all() or read_exact() on async streams from this crate:
// ❌ Potentially problematic: Processing 1GB in one call
async_writer.write_all(&huge_data[..]).await?;
// ✅ Better: Process in manageable chunks
for chunk in huge_data.chunks(8 * 1024) {
async_writer.write_all(chunk).await?;
}§General Guidance
While specific time limits depend on your runtime and hardware, consider these principles:
§1. Runtime budgets
Most async runtimes expect tasks to yield every few hundred microseconds of CPU time. If your chunks are large enough that cryptographic processing exceeds this, you risk starvation.
§2. Test with your workload
The appropriate chunk size depends on:
- Your CPU speed
- The specific cryptographic operation (SHA-3 is slower than Poly1305-ChaCha20)
- Your runtime’s scheduler behavior
- Your application’s latency requirements
§3. When in doubt, use smaller chunks
Processing in smaller chunks (e.g., 8-64 KB) is almost always safer than processing large blocks.
§Alternative: Using Blocking Threads
If you need to process large amounts of data and cannot or don’t want to manage chunk sizes, consider using the synchronous API on a blocking thread:
// Using tokio as an example, but similar patterns exist for other runtimes
tokio::task::spawn_blocking(move || {
// Use the standard Read/Write API here
hasher.write_all(&large_data)?;
let result = hasher.finish();
// ...
}).await?;§What This Crate Does Not Guarantee
The async API provided by this crate is designed to:
- Follow the
AsyncRead/AsyncWritecontract - Be compatible with async runtime event loops
- Process data correctly regardless of chunk size
However, it does not and cannot guarantee:
- That your operation will run within any specific time limit
- That the runtime will remain responsive regardless of how you use it
- Automatic chunking or yield insertion
These are your responsibility as the user.
§Understanding the Trade-off
When you enable the tokio feature and use this crate’s async API, you are choosing a programming style (async/await) over manual thread
management. This choice gives you better ergonomics and scalability – but with the trade-off that you must be mindful of how long your
tasks run.
This is similar to writing any CPU-intensive operation in an async context: the runtime provides the tools, but you provide the discipline.
§Summary
§✅ Do:
- Process data in reasonably sized chunks
- Test your application’s performance under load
- Use blocking threads for truly large operations
- Monitor task latency in production
§❌ Avoid:
- Processing extremely large buffers in single async operations
- Assuming that “async” makes CPU work free
- Ignoring runtime responsiveness in your performance testing
§
Remember: The async support in this crate is about programming style and API compatibility. The responsibility for runtime behavior lies with you, the user.
Modules§
- argon2
Little-endian - Argon2 (version
1.3) - chacha
Little-endian - Chacha
- debts
- Debts
- io
- I/O
- keccak
Little-endian - Keccak
- poly1305
Little-endian - Poly1305
- prg
Little-endian and ( stdortokio) and (Unix or Windows) - Pseudorandom generator
- version_
info 22.1.0(October 26th, 2026)- xxh3
- XXH3 implementation
Structs§
- Bytes
- Bytes
Enums§
- Error
- Error
Constants§
- CODE_
NAME - Crate code name
- HEX_
STRS - A slice of hexadecimal strings of all
u8values - ID
- ID of this crate
- NAME
- Crate name
- NO_
BYTES - No bytes
- RELEASE_
DATE - Crate release date (year/month/day)
- TAG
- Tag, which can be used for logging…
- VERSION
- Crate version
Functions§
- bytes_
to_ hex - Formats a byte slice as a hexadecimal string, in lower-case
- hex_
to_ bytes - Converts a hexadecimal string into a vector of bytes