Skip to content

A basic implementation of the SHA-256 hashing algorithm in pure Rust

Notifications You must be signed in to change notification settings

ArchSpaceman/SHA-256

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A basic Implementation of Sha-256 Hashing algorithm in Rust

This crate is used to generate a sha-256 hash given a string, simply bring the crate into scope and use the function hash_256 that takes a String as an input.
The return type of the function is a Result< [u32,8] , String>

Usage/Examples

pub mod spacesha256;

let compressed_message = spacesha256::hash_256(String::from("Hello, World!")).expect("Failed to hash");
    
println!("{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", compressed_message[0],compressed_message[1],compressed_message[2],compressed_message[3],compressed_message[4],compressed_message[5],compressed_message[6],compressed_message[7]);

Notes

The bitwise operations in SHA-256 algorithm might result in an overflow , however Rust's compiler panics on overflow in Debug mode. So I've appended overflow-checks = false to Cargo.toml . A possible improvment to make is to handle possible overflows during hashing.

About

A basic implementation of the SHA-256 hashing algorithm in pure Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages