hyper64 โก
๐ Executive Summary
hyper64 is an industrial-grade Base64 engine designed from the hardware up to solve the real-world performance, memory allocation, and side-channel security bottlenecks of the standard base64 crate.
By combining multi-tier SIMD vectorization (AVX-512BW, AVX2, SSSE3, AArch64 NEON, WebAssembly SIMD128), mathematically proven in-place zero-copy decoding, constant-time cryptographic execution, and zero-double-write memory initialization, hyper64 achieves sustained throughput exceeding 10โ25 GiB/s while guaranteeing zero heap allocations and 100% API drop-in compatibility with the base64 0.22 crate.
๐ Empirical Benchmarks
Benchmarks measured on standard x86_64 hardware via Criterion.rs comparing hyper64 against crates.io/crates/base64 (v0.22):
โก Encoding Throughput (Higher is Better)
64 B | [hyper64] 1.23 GiB/s (+42% faster)
| [base64] 863 MiB/s
1 KiB | [hyper64] 7.22 GiB/s (3.35x faster, +235%)
| [base64] 2.15 GiB/s
64 KiB | [hyper64] 10.20 GiB/s (4.40x faster, +340%)
| [base64] 2.32 GiB/s
| Payload Size | base64 crate 0.22 |
hyper64 |
Speedup / Improvement |
|---|---|---|---|
| 64 Bytes | 863 MiB/s (70.6 ns) | 1.23 GiB/s (48.3 ns) | +42% throughput |
| 1 KiB | 2.15 GiB/s (442.4 ns) | 7.22 GiB/s (132.1 ns) | 3.35x faster (+235%) |
| 64 KiB | 2.32 GiB/s (26.2 ยตs) | 10.20 GiB/s (5.98 ยตs) | 4.40x faster (+340%) |
โก Decoding Throughput & Latency (Lower CPU Time is Better)
| Payload Size | base64 crate 0.22 |
hyper64-in-place (0 Heap) |
hyper64 (Alloc) |
CPU Latency Reduction |
|---|---|---|---|---|
| 1 KiB | 2.12 GiB/s (448.3 ns) | 6.84 GiB/s (139.3 ns) | 7.15 GiB/s (134.2 ns) | -76.7% CPU Time |
| 64 KiB | 1.96 GiB/s (31.0 ยตs) | 6.78 GiB/s (8.99 ยตs) | 7.91 GiB/s (7.71 ยตs) | -80.6% CPU Time |
๐ Architectural Advantages
| Capability | Standard base64 Crate |
hyper64 |
Production Engineering Value |
|---|---|---|---|
| Vectorized SIMD Engine | โ Scalar only (~2 GB/s) | โ AVX-512 / AVX2 / SSSE3 / NEON / WASM (>10โ25 GB/s) | 4xโ10x lower server CPU utilization in JSON/gRPC APIs & Edge |
| Zero-Alloc In-Place Decoding | โ Dest buffer required | โ
decode_in_place(&mut [u8]) |
0 heap allocations in network proxies, TLS & mesh routers |
| Zero Double-Write Memory | โ Zero-fills entire Vec first | โ Spare Capacity Writer | Cuts memory bus saturation in half on multi-megabyte blobs |
no_std Dynamic CPUID |
โ Scalar fallback | โ Hardware CPUID / OSXSAVE | Native vectorization on bare metal, microVMs & SGX enclaves |
| Timing Attack Resistance | โ Vulnerable (memory LUTs) | โ Branchless Constant-Time | Prevents cache-timing leaks in HMAC, JWT & auth tokens |
| PEM & MIME Whitespace Parser | โ Hard fails on newlines | โ SWAR In-Place Parser | Direct parsing of X.509 certs, SSH keys & MIME emails |
Zero-Alloc Display Stream |
โ Allocates intermediate String | โ
hyper64::display(&slice) |
Streams Base64 directly into formatters, logs, or JSON |
| Compile-Time Evaluation | โ No const fn |
โ
const fn & Macros |
Precomputes tokens and cryptographic keys at compile-time |
| Asynchronous I/O | โ Blocking only | โ
Tokio AsyncWrite / AsyncRead |
Non-blocking chunked streaming for web services |
| Drop-in Compatibility Layer | โ | โ
base64::Engine API |
Seamless replacement without rewriting application code |
| Core Dependencies | Moderate | โ 0 Dependencies | Zero supply-chain attack surface in default builds |
๐ฆ Installation & Feature Flags
Add hyper64 to your Cargo.toml:
[]
= "0.2"
Cargo Features
| Feature | Default | Description |
|---|---|---|
std |
Yes | Enables std::io::Write/Read streams and standard runtime CPU feature queries. |
alloc |
Yes (via std) |
Enables String and Vec<u8> returning convenience APIs (encode, decode). |
simd |
No | Explicit flag reserved for target-specific intrinsics. |
serde |
No | Enables zero-copy Serde wrappers (#[serde(with = "...")] and Base64<T>). |
tokio |
No | Enables non-blocking streaming adapters (AsyncEncoderWriter, AsyncDecoderReader). |
For embedded and bare-metal environments:
[]
= { = "0.2", = false }
๐ก Quick Start & Usage Examples
1. High-Level Convenience API
use ;
let raw_data = b"Rust 2026 High Performance Base64 Engine";
let encoded_str = encode;
assert_eq!;
let decoded_bytes = decode.unwrap;
assert_eq!;
2. Zero-Allocation In-Place Decoding (SIMD-Accelerated)
Decodes Base64 data directly inside an existing mutable slice (e.g., packet buffer, pre-allocated arena) without touching the heap:
use ;
let mut packet = *b"SGVsbG8gV29ybGQh"; // 16 bytes on stack
let decoded = decode_in_place.unwrap;
assert_eq!;
3. In-Place PEM Certificate & MIME Whitespace Decoding
Real-world certificates, SSH keys, and emails contain embedded line breaks (\r\n, \n) and headers. hyper64 parses and decodes them directly in-place with zero memory copies:
use decode_pem_in_place;
let mut cert = *b"-----BEGIN CERTIFICATE-----\r\nSGVsbG8gV29ybGQh\r\n-----END CERTIFICATE-----\r\n";
let block = decode_pem_in_place.unwrap;
assert_eq!;
assert_eq!;
4. Zero-Allocation Display Streaming
Format binary hashes and tokens into loggers, HTTP headers, or JSON serializations without allocating temporary intermediate Strings:
use display;
let token_hash = ;
// Formats directly into the output stream using an internal 64-byte L1 stack buffer!
let header = format!;
assert!;
5. Constant-Time Cryptographic Mode (Anti-Side-Channel)
Eliminates cache-timing vulnerabilities and data-dependent memory lookups when handling private keys, cryptographic nonces, or tokens:
use ;
let secret = ;
let mut safe_buffer = ;
encode_constant_time;
let mut recovered = ;
decode_constant_time.unwrap;
// Constant-time equality comparison
assert!;
6. Compile-Time (const fn) Evaluation
Embed pre-encoded assets or pre-decoded binary configurations directly into your compiled executable:
use ;
const ENCODED_ASSET: & = &encode_const!;
const DECODED_KEY: = decode_const!;
assert_eq!;
7. Drop-In Replacement for crates.io/crates/base64
Migrate existing codebases instantly by replacing the dependency with hyper64:
use ;
let encoded = STANDARD.encode;
let decoded = STANDARD.decode.unwrap;
assert_eq!;
8. Asynchronous Streaming with Tokio
Stream multi-gigabyte files or network sockets without loading the entire payload into RAM:
use ;
use ;
async
๐ Safety & Formal Invariants
hyper64 is built under a strict zero-undefined-behavior mandate:
- In-Place Non-Clobbering Proof ($r_k \ge w_k$): Because Base64 expands 3 raw bytes into 4 ASCII bytes, reading 4 bytes before writing 3 guarantees the read cursor $r$ always outpaces the write cursor $w$. Memory corruption is mathematically impossible.
- Zero Double-Write Memory Initialization:
hyper64writes directly into spare vector capacity before callingset_len, eliminating zero-filling overhead without reading uninitialized memory. - Unaligned Memory Primitives: Employs explicit
core::ptr::read_unalignedand_mm256_loadu_si256avoiding strict-aliasing violations. - Hardware CPUID Gating: Dynamic CPU feature detection inspects CPUID and validates that the OS kernel has enabled YMM register saving (
_xgetbv(0)check forXCR0[2:1]).
For complete formal proofs, refer to SAFETY.md.
๐ก๏ธ Continuous Verification & CI/CD
hyper64 is audited on every commit by an exhaustive verification matrix:
- Miri: Continuous memory model validation checking for undefined behavior and aliasing violations under
-Zmiri-symbolic-alignment-check. - Differential Oracle Testing: 2,048 randomized differential tests validating equivalence against
crates.io/crates/base64. - libFuzzer with AddressSanitizer (ASan): Automated fuzzing targets (
fuzz_decode,fuzz_roundtrip,fuzz_pem). - Multi-Architecture Matrix: Validated on Linux x86_64, macOS Apple Silicon (AArch64 NEON), Windows MSVC, Big-Endian s390x, and Cortex-M4 bare metal.
- Supply Chain Guard: Audited with
glastor-core/specter(SemVer stability),glastor-core/byte-gauge(binary hardening), andcargo-deny(license and vulnerability tracking).
๐ License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.