picca/src/hashers.rs

413 lines
10 KiB
Rust
Raw Normal View History

2025-07-20 12:59:49 -06:00
use ascon_hash::AsconHash256;
use belt_hash::BeltHash;
use blake2::{Blake2b512, Blake2s256};
use fsb::{Fsb160, Fsb224, Fsb256, Fsb384, Fsb512};
use gost94::Gost94CryptoPro;
use groestl::{Groestl224, Groestl256, Groestl384, Groestl512};
use jh::{
// digest::{core_api::CoreWrapper, KeyInit},
Jh224,
Jh256,
Jh384,
Jh512,
};
// use k12::KangarooTwelve;
// use kupyna::{Kupyna224, Kupyna256, Kupyna384, Kupyna512};
use md2::Md2;
use md4::Md4;
2025-07-18 01:13:11 -06:00
use md5::Md5;
2025-07-20 12:59:49 -06:00
use ripemd::{Ripemd128, Ripemd160, Ripemd256, Ripemd320};
2025-07-20 14:59:35 -06:00
use sha1::Sha1;
2025-07-20 12:59:49 -06:00
use sha2::{Digest, Sha224, Sha256, Sha384, Sha512};
// use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shake256};
use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512};
use shabal::{Shabal192, Shabal224, Shabal256, Shabal384, Shabal512};
// use skein::{
// digest::{core_api::CoreWrapper, KeyInit},
// Skein1024, Skein256, Skein512,
// };
use sm3::Sm3;
use std::fs::File;
use std::io;
2025-07-20 12:59:49 -06:00
use streebog::{Streebog256, Streebog512};
use tiger::Tiger;
use whirlpool::Whirlpool;
pub fn hash_streebog256(mut file: File) -> String {
let mut hasher = Streebog256::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_streebog512(mut file: File) -> String {
let mut hasher = Streebog512::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_tiger(mut file: File) -> String {
let mut hasher = Tiger::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_whirlpool(mut file: File) -> String {
let mut hasher = Whirlpool::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_sha224(mut file: File) -> String {
let mut hasher = Sha224::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_sm3(mut file: File) -> String {
let mut hasher = Sm3::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_sha3_224(mut file: File) -> String {
let mut hasher = Sha3_224::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_sha3_256(mut file: File) -> String {
let mut hasher = Sha3_256::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_sha3_384(mut file: File) -> String {
let mut hasher = Sha3_384::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_sha3_512(mut file: File) -> String {
let mut hasher = Sha3_512::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
// pub fn hash_shake128(mut file: File) -> String {
// let mut hasher: CoreWrapper<_> = Shake128::new();
// _ = io::copy(&mut file, &mut hasher);
// return format!("{:x}", hasher.finalize());
// }
// pub fn hash_shake256(mut file: File) -> String {
// let mut hasher = Shake256::new();
// _ = io::copy(&mut file, &mut hasher);
// return format!("{:x}", hasher.finalize());
// }
pub fn hash_shabal192(mut file: File) -> String {
let mut hasher = Shabal192::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_shabal224(mut file: File) -> String {
let mut hasher = Shabal224::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_shabal256(mut file: File) -> String {
let mut hasher = Shabal256::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_shabal384(mut file: File) -> String {
let mut hasher = Shabal384::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_shabal512(mut file: File) -> String {
let mut hasher = Shabal512::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
// pub fn hash_skein256(mut file: File) -> String {
// let mut hasher = Skein256::new();
// _ = io::copy(&mut file, &mut hasher);
// return format!("{:x}", hasher.finalize());
// }
// pub fn hash_skein512(mut file: File) -> String {
// let mut hasher = Skein512::new();
// _ = io::copy(&mut file, &mut hasher);
// return format!("{:x}", hasher.finalize());
// }
// pub fn hash_skein1024(mut file: File) -> String {
// let mut hasher = Skein1024::new();
// _ = io::copy(&mut file, &mut hasher);
// return format!("{:x}", hasher.finalize());
// }
pub fn hash_gost94(mut file: File) -> String {
let mut hasher = Gost94CryptoPro::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_groestl224(mut file: File) -> String {
let mut hasher = Groestl224::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_groestl256(mut file: File) -> String {
let mut hasher = Groestl256::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_groestl384(mut file: File) -> String {
let mut hasher = Groestl384::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_groestl512(mut file: File) -> String {
let mut hasher = Groestl512::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_jh224(mut file: File) -> String {
let mut hasher = Jh224::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_jh256(mut file: File) -> String {
let mut hasher = Jh256::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_jh384(mut file: File) -> String {
let mut hasher = Jh384::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_jh512(mut file: File) -> String {
let mut hasher = Jh512::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
// pub fn hash_k12(mut file: File) -> String {
// let mut hasher = KangarooTwelve::new();
// _ = io::copy(&mut file, &mut hasher);
// return format!("{:x}", hasher.finalize());
// }
// pub fn hash_kupyna224(mut file: File) -> String {
// let mut hasher = Kupyna224::new();
// _ = io::copy(&mut file, &mut hasher);
// return format!("{:x}", hasher.finalize());
// }
// pub fn hash_kupyna256(mut file: File) -> String {
// let mut hasher = Kupyna256::new();
// _ = io::copy(&mut file, &mut hasher);
// return format!("{:x}", hasher.finalize());
// }
// pub fn hash_kupyna384(mut file: File) -> String {
// let mut hasher = Kupyna384::new();
// _ = io::copy(&mut file, &mut hasher);
// return format!("{:x}", hasher.finalize());
// }
// pub fn hash_kupyna512(mut file: File) -> String {
// let mut hasher = Kupyna512::new();
// _ = io::copy(&mut file, &mut hasher);
// return format!("{:x}", hasher.finalize());
// }
pub fn hash_md2(mut file: File) -> String {
let mut hasher = Md2::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_md4(mut file: File) -> String {
let mut hasher = Md4::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_ripemd128(mut file: File) -> String {
let mut hasher = Ripemd128::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_ripemd160(mut file: File) -> String {
let mut hasher = Ripemd160::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_ripemd256(mut file: File) -> String {
let mut hasher = Ripemd256::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_ripemd320(mut file: File) -> String {
let mut hasher = Ripemd320::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_ascon(mut file: File) -> String {
let mut hasher = AsconHash256::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_belt(mut file: File) -> String {
let mut hasher = BeltHash::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_blake2b512(mut file: File) -> String {
let mut hasher = Blake2b512::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_blake2s256(mut file: File) -> String {
let mut hasher = Blake2s256::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_fsb160(mut file: File) -> String {
let mut hasher = Fsb160::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_fsb224(mut file: File) -> String {
let mut hasher = Fsb224::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_fsb256(mut file: File) -> String {
let mut hasher = Fsb256::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_fsb384(mut file: File) -> String {
let mut hasher = Fsb384::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_fsb512(mut file: File) -> String {
let mut hasher = Fsb512::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
2025-07-18 01:13:11 -06:00
pub fn hash_md5(mut file: File) -> String {
let mut hasher = Md5::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
2025-07-20 14:59:35 -06:00
pub fn hash_sha1(mut file: File) -> String {
let mut hasher = Sha1::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_sha256(mut file: File) -> String {
let mut hasher = Sha256::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_sha384(mut file: File) -> String {
let mut hasher = Sha384::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}
pub fn hash_sha512(mut file: File) -> String {
let mut hasher = Sha512::new();
_ = io::copy(&mut file, &mut hasher);
return format!("{:x}", hasher.finalize());
}