mirror of https://github.com/dswd/zvault
Using Blake2 instead of Sha3 which is too slow
This commit is contained in:
parent
231aa9fb58
commit
c549af635f
|
@ -8,7 +8,6 @@ serde = "0.9"
|
||||||
rmp-serde = "0.12"
|
rmp-serde = "0.12"
|
||||||
serde_yaml = "0.6"
|
serde_yaml = "0.6"
|
||||||
serde_utils = "0.5.1"
|
serde_utils = "0.5.1"
|
||||||
rust-crypto = "0.2"
|
|
||||||
squash-sys = "0.9"
|
squash-sys = "0.9"
|
||||||
mmap = "*"
|
mmap = "*"
|
||||||
quick-error = "1.1"
|
quick-error = "1.1"
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl BundleId {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
let mut buf = String::with_capacity(self.0.len()*2);
|
let mut buf = String::with_capacity(self.0.len()*2);
|
||||||
for b in &self.0 {
|
for b in &self.0 {
|
||||||
write!(&mut buf, "{:2x}", b).unwrap()
|
write!(&mut buf, "{:02x}", b).unwrap()
|
||||||
}
|
}
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ impl Default for BundleHeader {
|
||||||
id: BundleId(vec![]),
|
id: BundleId(vec![]),
|
||||||
compression: None,
|
compression: None,
|
||||||
encryption: None,
|
encryption: None,
|
||||||
checksum: (ChecksumType::Sha3_256, ByteBuf::new()),
|
checksum: (ChecksumType::Blake2_256, ByteBuf::new()),
|
||||||
raw_size: 0,
|
raw_size: 0,
|
||||||
encoded_size: 0,
|
encoded_size: 0,
|
||||||
chunk_count: 0,
|
chunk_count: 0,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate rmp_serde;
|
extern crate rmp_serde;
|
||||||
#[macro_use] extern crate serde_utils;
|
#[macro_use] extern crate serde_utils;
|
||||||
extern crate crypto;
|
|
||||||
extern crate squash_sys as squash;
|
extern crate squash_sys as squash;
|
||||||
extern crate mmap;
|
extern crate mmap;
|
||||||
extern crate blake2_rfc as blake2;
|
extern crate blake2_rfc as blake2;
|
||||||
|
@ -34,10 +33,10 @@ fn main() {
|
||||||
Repository::open(path).unwrap()
|
Repository::open(path).unwrap()
|
||||||
} else {
|
} else {
|
||||||
Repository::create(path, Config {
|
Repository::create(path, Config {
|
||||||
bundle_size: 1024*1024,
|
bundle_size: 25*1024*1024,
|
||||||
checksum: ChecksumType::Sha3_256,
|
checksum: ChecksumType::Blake2_256,
|
||||||
chunker: ChunkerType::FastCdc((8*1024, 0)),
|
chunker: ChunkerType::FastCdc((8*1024, 0)),
|
||||||
compression: Some(Compression::Brotli(5)),
|
compression: Some(Compression::Brotli(1)),
|
||||||
hash: HashMethod::Blake2
|
hash: HashMethod::Blake2
|
||||||
}).unwrap()
|
}).unwrap()
|
||||||
};
|
};
|
||||||
|
|
|
@ -119,7 +119,7 @@ impl Default for ConfigYaml {
|
||||||
compression: Some(CompressionYaml { codec: "brotli".to_string(), level: Some(5) }),
|
compression: Some(CompressionYaml { codec: "brotli".to_string(), level: Some(5) }),
|
||||||
bundle_size: 25*1024*1024,
|
bundle_size: 25*1024*1024,
|
||||||
chunker: ChunkerYaml::default(),
|
chunker: ChunkerYaml::default(),
|
||||||
checksum: "sha3-256".to_string(),
|
checksum: "blake2_256".to_string(),
|
||||||
hash: "blake2".to_string()
|
hash: "blake2".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
use serde::bytes::ByteBuf;
|
use serde::bytes::ByteBuf;
|
||||||
use crypto::sha3;
|
|
||||||
use crypto::digest::Digest;
|
|
||||||
|
|
||||||
|
use blake2::blake2b::Blake2b;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Copy)]
|
#[derive(Clone, Debug, Copy)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
pub enum ChecksumType {
|
pub enum ChecksumType {
|
||||||
Sha3_256
|
Blake2_256
|
||||||
}
|
}
|
||||||
serde_impl!(ChecksumType(u64) {
|
serde_impl!(ChecksumType(u64) {
|
||||||
Sha3_256 => 1
|
Blake2_256 => 1
|
||||||
});
|
});
|
||||||
|
|
||||||
impl ChecksumType {
|
impl ChecksumType {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from(name: &str) -> Result<Self, &'static str> {
|
pub fn from(name: &str) -> Result<Self, &'static str> {
|
||||||
match name {
|
match name {
|
||||||
"sha3-256" => Ok(ChecksumType::Sha3_256),
|
"blake2_256" => Ok(ChecksumType::Blake2_256),
|
||||||
_ => Err("Unsupported checksum type")
|
_ => Err("Unsupported checksum type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +23,7 @@ impl ChecksumType {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn name(&self) -> &'static str {
|
pub fn name(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
ChecksumType::Sha3_256 => "sha3-256",
|
ChecksumType::Blake2_256 => "blake2_256",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,32 +33,31 @@ pub type Checksum = (ChecksumType, ByteBuf);
|
||||||
|
|
||||||
#[allow(non_camel_case_types, unknown_lints, large_enum_variant)]
|
#[allow(non_camel_case_types, unknown_lints, large_enum_variant)]
|
||||||
pub enum ChecksumCreator {
|
pub enum ChecksumCreator {
|
||||||
Sha3_256(sha3::Sha3)
|
Blake2_256(Blake2b)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChecksumCreator {
|
impl ChecksumCreator {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(type_: ChecksumType) -> Self {
|
pub fn new(type_: ChecksumType) -> Self {
|
||||||
match type_ {
|
match type_ {
|
||||||
ChecksumType::Sha3_256 => ChecksumCreator::Sha3_256(sha3::Sha3::sha3_256())
|
ChecksumType::Blake2_256 => ChecksumCreator::Blake2_256(Blake2b::new(32))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn update(&mut self, data: &[u8]) {
|
pub fn update(&mut self, data: &[u8]) {
|
||||||
match *self {
|
match *self {
|
||||||
ChecksumCreator::Sha3_256(ref mut state) => state.input(data)
|
ChecksumCreator::Blake2_256(ref mut state) => state.update(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn finish(self) -> Checksum {
|
pub fn finish(self) -> Checksum {
|
||||||
match self {
|
match self {
|
||||||
ChecksumCreator::Sha3_256(mut state) => {
|
ChecksumCreator::Blake2_256(state) => {
|
||||||
let mut buf = Vec::with_capacity(state.output_bytes());
|
let mut buf = Vec::with_capacity(32);
|
||||||
buf.resize(state.output_bytes(), 0);
|
buf.extend_from_slice(state.finalize().as_bytes());
|
||||||
state.result(&mut buf);
|
(ChecksumType::Blake2_256, buf.into())
|
||||||
(ChecksumType::Sha3_256, buf.into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue