crypto-async-rs 0.1.3

High-performance pure Rust cryptographic library with async streaming support
Documentation
//! Example demonstrating SHA hashing
//!
//! This example shows how to use the SHA implementations for
//! high-performance hashing.

use crypto_async_rs::sha512;

fn main() {
    println!("SHA Hashing Example");
    println!("===================");

    // Test data
    let data = b"Hello, World! This is a test message for SHA hashing.";
    println!("Input data: {}", String::from_utf8_lossy(data));
    println!("Data length: {} bytes", data.len());

    // SHA512 hashing (best performance: 393 MiB/s)
    println!("\nComputing SHA512 hash...");
    let hash = sha512::encode(data);
    
    println!("SHA512 hash: {:02x?}", hash);
    println!("SHA512 hash (hex): {:02x?}", hash);

    // Test with different data sizes
    println!("\nTesting with different data sizes...");
    
    let test_cases = vec![
        ("Empty", b"" as &[u8]),
        ("Small", b"Hi" as &[u8]),
        ("Medium", b"This is a medium-sized message for testing SHA hashing performance." as &[u8]),
        ("Large", b"This is a much larger message that will test the streaming capabilities of the SHA implementation. It contains multiple sentences and should demonstrate the efficiency of the implementation when processing larger amounts of data." as &[u8]),
    ];

    for (name, test_data) in test_cases {
        let hash = sha512::encode(test_data);
        println!("{} ({} bytes): {:02x?}", name, test_data.len(), &hash[..8]);
    }

    println!("\nDemonstrating with large data...");
    let large_data = vec![0x42u8; 1024 * 1024]; // 1MB of data
    println!("Large data size: {} bytes (1MB)", large_data.len());
    
    let start = std::time::Instant::now();
    let hash = sha512::encode(&large_data);
    let duration = start.elapsed();
    
    let throughput = (large_data.len() as f64) / (duration.as_secs_f64() * 1024.0 * 1024.0);
    
    println!("SHA512 hash: {:02x?}", &hash[..8]);
    println!("Time taken: {:?}", duration);
    println!("Throughput: {:.2} MiB/s", throughput);

    println!("\n✅ SHA hashing completed successfully!");
}