use openssl for faster hashing

This commit is contained in:
Dietmar Maurer 2018-12-22 14:31:59 +01:00
parent e95950e40a
commit 7b2b40a893
2 changed files with 8 additions and 8 deletions

View File

@ -24,10 +24,9 @@ http = "0.1.13"
hyper = "0.12.14" hyper = "0.12.14"
lazy_static = "1.1.0" lazy_static = "1.1.0"
regex = "1.0.6" regex = "1.0.6"
rust-crypto = "0.2.36"
libc = "0.2" libc = "0.2"
nix = "0.12.0" nix = "0.12.0"
shellwords = "1.0.0" shellwords = "1.0.0"
uuid = { version = "0.7", features = ["v4"] } uuid = { version = "0.7", features = ["v4"] }
chrono = "0.4.6" # Date and time library for Rust chrono = "0.4.6" # Date and time library for Rust
openssl = "0.10.16"

View File

@ -3,8 +3,7 @@ use std::path::{Path, PathBuf};
use std::io::Write; use std::io::Write;
use std::time::Duration; use std::time::Duration;
use crypto::digest::Digest; use openssl::sha;
use crypto::sha2::Sha512Trunc256;
use std::sync::Mutex; use std::sync::Mutex;
use std::fs::File; use std::fs::File;
@ -218,11 +217,13 @@ impl ChunkStore {
} }
pub fn insert_chunk(&self, chunk: &[u8]) -> Result<(bool, [u8; 32]), Error> { pub fn insert_chunk(&self, chunk: &[u8]) -> Result<(bool, [u8; 32]), Error> {
let mut hasher = Sha512Trunc256::new();
hasher.input(chunk);
let mut digest = [0u8; 32]; // fixme: use Sha512/256 when available
hasher.result(&mut digest); let mut hasher = sha::Sha256::new();
hasher.update(chunk);
let digest = hasher.finish();
//println!("DIGEST {}", digest_to_hex(&digest)); //println!("DIGEST {}", digest_to_hex(&digest));
let mut chunk_path = self.chunk_dir.clone(); let mut chunk_path = self.chunk_dir.clone();