2 stable releases
1.1.0 | Feb 13, 2025 |
---|---|
1.0.0 | Feb 13, 2025 |
#1170 in Cryptography
247 downloads per month
14KB
122 lines
lonesha256
Rust bindings for the lonesha256 C library - a portable, endian-proof, single-file SHA256 implementation
About
This crate provides Rust bindings for lonesha256, making it easy to use this lightweight SHA256 implementation in your Rust projects.
Installation
Add this to your Cargo.toml
:
[dependencies]
lonesha256 = "1.0"
or run this command in your terminal:
cargo add lonesha256
Usage
use lonesha256::lonesha256;
fn main() {
let input = b"Hello, world!";
let mut hash = [0u8; 32];
lonesha256(&mut hash, input).expect("Failed to compute hash");
println!("Hash: {}",
hash.iter()
.map(|b| format!("{:02x}", b))
.collect::<String>());
}
Documentation
Library documentation can be found here
Features
- Lightweight SHA256 implementation
- No external dependencies
- Safe Rust wrapper around C code
- Comprehensive test suite
- Multiple usage examples
Building from Source
- Install
clang
, as said here - Clone the repository:
git clone https://github.com/ankddev/lonesha256
cd lonesha256
- Build:
cargo build --release
Examples
Run the included examples:
cargo run --example sample # Basic usage
cargo run --example file_hash # File hashing
cargo run --example streaming # Process data in chunks
cargo run --example hex_output # Different output formats
cargo run --example benchmark # Performance testing
Testing
Run the test suite:
cargo test
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Acknowledgments
- lonesha256 - Original C implementation by BareRose
Dependencies
~0–2.3MB
~46K SLoC