Skip to main content

Crate hyper64

Crate hyper64 

Source
Expand description

ยงGLASTOR Logo hyper64 โšก

GLASTOR hyper64 Banner

Next-Generation, Ultra-High-Throughput, Zero-Allocation Base64 Engine for Rust

Crates.io Documentation CI Status License MSRV 1.89+ no_std Zero Dependencies


ยง๐Ÿ“– 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 Sizebase64 crate 0.22hyper64Speedup / Improvement
64 Bytes863 MiB/s (70.6 ns)1.23 GiB/s (48.3 ns)+42% throughput
1 KiB2.15 GiB/s (442.4 ns)7.22 GiB/s (132.1 ns)3.35x faster (+235%)
64 KiB2.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 Sizebase64 crate 0.22hyper64-in-place (0 Heap)hyper64 (Alloc)CPU Latency Reduction
1 KiB2.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 KiB1.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

CapabilityStandard base64 Cratehyper64Production 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 WriterCuts memory bus saturation in half on multi-megabyte blobs
no_std Dynamic CPUIDโŒ Scalar fallbackโœ… Hardware CPUID / OSXSAVENative vectorization on bare metal, microVMs & SGX enclaves
Timing Attack ResistanceโŒ Vulnerable (memory LUTs)โœ… Branchless Constant-TimePrevents cache-timing leaks in HMAC, JWT & auth tokens
PEM & MIME Whitespace ParserโŒ Hard fails on newlinesโœ… SWAR In-Place ParserDirect 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 & MacrosPrecomputes tokens and cryptographic keys at compile-time
Asynchronous I/OโŒ Blocking onlyโœ… Tokio AsyncWrite / AsyncReadNon-blocking chunked streaming for web services
Drop-in Compatibility Layerโ€”โœ… base64::Engine APISeamless replacement without rewriting application code
Core DependenciesModerateโœ… 0 DependenciesZero supply-chain attack surface in default builds

ยง๐Ÿ“ฆ Installation & Feature Flags

Add hyper64 to your Cargo.toml:

[dependencies]
hyper64 = "0.2"

ยงCargo Features

FeatureDefaultDescription
stdYesEnables std::io::Write/Read streams and standard runtime CPU feature queries.
allocYes (via std)Enables String and Vec<u8> returning convenience APIs (encode, decode).
simdNoExplicit flag reserved for target-specific intrinsics.
serdeNoEnables zero-copy Serde wrappers (#[serde(with = "...")] and Base64<T>).
tokioNoEnables non-blocking streaming adapters (AsyncEncoderWriter, AsyncDecoderReader).

For embedded and bare-metal environments:

[dependencies]
hyper64 = { version = "0.2", default-features = false }

ยง๐Ÿ’ก Quick Start & Usage Examples

ยง1. High-Level Convenience API

use hyper64::{encode, decode};

let raw_data = b"Rust 2026 High Performance Base64 Engine";
let encoded_str = encode(raw_data);
assert_eq!(encoded_str, "UnVzdCAyMDI2IEhpZ2ggUGVyZm9ybWFuY2UgQmFzZTY0IEVuZ2luZQ==");

let decoded_bytes = decode(&encoded_str).unwrap();
assert_eq!(decoded_bytes, raw_data);

ยง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 hyper64::{decode_in_place, STANDARD};

let mut packet = *b"SGVsbG8gV29ybGQh"; // 16 bytes on stack
let decoded = decode_in_place(&mut packet, &STANDARD).unwrap();

assert_eq!(decoded, b"Hello World!");

ยง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 hyper64::decode_pem_in_place;

let mut cert = *b"-----BEGIN CERTIFICATE-----\r\nSGVsbG8gV29ybGQh\r\n-----END CERTIFICATE-----\r\n";
let block = decode_pem_in_place(&mut cert).unwrap();

assert_eq!(block.label, "CERTIFICATE");
assert_eq!(block.contents, b"Hello World!");

ยง4. Zero-Allocation Display Streaming

Format binary hashes and tokens into loggers, HTTP headers, or JSON serializations without allocating temporary intermediate Strings:

use hyper64::display;

let token_hash = [0x42u8; 32];

// Formats directly into the output stream using an internal 64-byte L1 stack buffer!
let header = format!("Authorization: Bearer {}", display(&token_hash));
assert!(header.starts_with("Authorization: Bearer QkJC"));

ยง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 hyper64::{encode_constant_time, decode_constant_time, ct_eq};

let secret = [0x5au8; 32];
let mut safe_buffer = [0u8; 44];
encode_constant_time(&secret, &mut safe_buffer);

let mut recovered = [0u8; 32];
decode_constant_time(&safe_buffer, &mut recovered).unwrap();

// Constant-time equality comparison
assert!(ct_eq(&secret, &recovered));

ยง6. Compile-Time (const fn) Evaluation

Embed pre-encoded assets or pre-decoded binary configurations directly into your compiled executable:

use hyper64::{encode_const, decode_const};

const ENCODED_ASSET: &[u8] = &encode_const!(b"static-compile-time-asset");
const DECODED_KEY: [u8; 12] = decode_const!(b"SGVsbG8gV29ybGQh");

assert_eq!(&DECODED_KEY, b"Hello World!");

ยง7. Drop-In Replacement for crates.io/crates/base64

Migrate existing codebases instantly by replacing the dependency with hyper64:

use hyper64::engine::{Engine, general_purpose::STANDARD};

let encoded = STANDARD.encode(b"Drop-in replacement for base64 crate");
let decoded = STANDARD.decode(&encoded).unwrap();
assert_eq!(decoded, b"Drop-in replacement for base64 crate");

ยง8. Asynchronous Streaming with Tokio

Stream multi-gigabyte files or network sockets without loading the entire payload into RAM:

โ“˜
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use hyper64::{AsyncEncoderWriter, AsyncDecoderReader};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut encoded_stream = Vec::new();
    {
        let mut encoder = AsyncEncoderWriter::new(&mut encoded_stream);
        encoder.write_all(b"Non-blocking stream data").await?;
        encoder.shutdown().await?;
    }

    let mut decoder = AsyncDecoderReader::new(&encoded_stream[..]);
    let mut result = Vec::new();
    decoder.read_to_end(&mut result).await?;
    assert_eq!(result, b"Non-blocking stream data");
    Ok(())
}

ยง๐Ÿ”’ Safety & Formal Invariants

hyper64 is built under a strict zero-undefined-behavior mandate:

  1. 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.
  2. Zero Double-Write Memory Initialization: hyper64 writes directly into spare vector capacity before calling set_len, eliminating zero-filling overhead without reading uninitialized memory.
  3. Unaligned Memory Primitives: Employs explicit core::ptr::read_unaligned and _mm256_loadu_si256 avoiding strict-aliasing violations.
  4. Hardware CPUID Gating: Dynamic CPU feature detection inspects CPUID and validates that the OS kernel has enabled YMM register saving (_xgetbv(0) check for XCR0[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), and cargo-deny (license and vulnerability tracking).

ยง๐Ÿ“„ License

Licensed under either of:

at your option.

Re-exportsยง

pub use alphabet::Config;
pub use alphabet::STANDARD_DECODE_TABLE;
pub use alphabet::STANDARD_ENCODE_TABLE;
pub use alphabet::URL_SAFE_DECODE_TABLE;
pub use alphabet::URL_SAFE_ENCODE_TABLE;
pub use constant_time::ct_eq;
pub use constant_time::decode_slice_ct as decode_constant_time;
pub use decode::decode_in_place;
pub use decode::decode_to_slice;
pub use display::Base64Display;
pub use display::display;
pub use display::display_config;
pub use display::display_url_safe;
pub use encode::Base64ChunkIter;
pub use encode::encode_iter;
pub use encode::encode_to_slice;
pub use engine::Engine;
pub use error::DecodeError;
pub use permissive::PemBlock;
pub use permissive::decode_pem_in_place;
pub use permissive::decode_permissive_in_place;
pub use permissive::decode_pem;
pub use permissive::decode_permissive;
pub use scalar::encoded_len;
pub use simd::has_avx2;
pub use simd::has_avx512;
pub use simd::has_neon;
pub use simd::has_ssse3;
pub use simd::has_wasm_simd128;
pub use io::DecoderReader;
pub use io::EncoderWriter;
pub use io::AsyncDecoderReader;
pub use io::AsyncEncoderWriter;
pub use crate::serde::Base64;

Modulesยง

alphabet
Base64 Alphabet definitions and lookup tables.
const_fn
Compile-time (const fn) Base64 encoding and decoding.
constant_time
Constant-time Base64 implementation.
decode
Base64 decoding implementations, including zero-alloc in-place decoding.
display
Zero-allocation Base64 formatting for core::fmt.
encode
Base64 encoding implementations with SIMD acceleration and zero-alloc slices.
engine
Drop-in compatibility layer with crates.io/crates/base64 (v0.22).
error
Error types for hyper64 encoding and decoding operations.
io
Streaming I/O adapters for std::io::Write and std::io::Read.
permissive
Permissive and PEM/MIME Base64 decoder.
scalar
Ultra-fast scalar Base64 encoder and decoder.
serde
First-class serde integration for zero-copy and zero-allocation Base64 serialization.
simd
Vectorized SIMD implementations for x86_64 (AVX2).

Macrosยง

decode_const
Helper macro to decode a Base64 literal at compile time.
encode_const
Helper macro to encode a literal string or byte slice at compile time.

Constantsยง

STANDARD
STANDARD_NO_PAD
URL_SAFE
URL_SAFE_NO_PAD

Functionsยง

decode
Decodes standard Base64 bytes or string into a alloc::vec::Vec<u8>.
decode_config
Decodes Base64 data using the specified configuration into a alloc::vec::Vec<u8>.
encode
Encodes input bytes to a standard Base64 alloc::string::String.
encode_config
Encodes input bytes using the specified configuration.
encode_constant_time
Constant-time encode for cryptographic/secret data (mitigates cache-timing attacks).