Skip to content

Commit 37245c7

Browse files
authored
Merge pull request #111 from paritytech/davxy/replace-blake2-rfc
Replace blake2-rfc with blake2
2 parents 4bd409b + a02139e commit 37245c7

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repository = "https://github.com/paritytech/parity-db/"
99
description = "Key-value database for the blockchain"
1010

1111
[dependencies]
12-
blake2-rfc = "0.2.18"
12+
blake2 = "0.10.4"
1313
crc32fast = "1.2.0"
1414
fs2 = "0.4.3"
1515
hex = "0.4.2"

src/column.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ enum IterStateOrCorrupted {
125125

126126
#[inline]
127127
pub fn hash_key(key: &[u8], salt: &Salt, uniform: bool, db_version: u32) -> Key {
128+
use blake2::{
129+
digest::{typenum::U32, FixedOutput, Update},
130+
Blake2bMac,
131+
};
132+
128133
let mut k = Key::default();
129134
if uniform {
130135
if db_version <= 5 {
@@ -137,7 +142,11 @@ pub fn hash_key(key: &[u8], salt: &Salt, uniform: bool, db_version: u32) -> Key
137142
}
138143
}
139144
} else {
140-
k.copy_from_slice(blake2_rfc::blake2b::blake2b(32, salt, key).as_bytes());
145+
let mut ctx = Blake2bMac::<U32>::new_with_salt_and_personal(salt, &[], &[])
146+
.expect("Salt length (32) is a valid key length (<= 64)");
147+
ctx.update(key);
148+
let hash = ctx.finalize_fixed();
149+
k.copy_from_slice(&hash);
141150
}
142151
k
143152
}
@@ -684,6 +693,8 @@ impl HashColumn {
684693
start_chunk: u64,
685694
skip_preimage_indexes: bool,
686695
) -> Result<()> {
696+
use blake2::{digest::typenum::U32, Blake2b, Digest};
697+
687698
let tables = self.tables.read();
688699
let source = &tables.index;
689700

@@ -702,8 +713,8 @@ impl HashColumn {
702713
} else {
703714
value
704715
};
705-
let key = blake2_rfc::blake2b::blake2b(32, &[], &value);
706-
let key = self.hash_key(key.as_bytes());
716+
let key = Blake2b::<U32>::digest(&value);
717+
let key = self.hash_key(&key);
707718
let state = IterStateOrCorrupted::Item(IterState {
708719
chunk_index: index,
709720
key,

src/table.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,10 @@ mod test {
11471147
}
11481148

11491149
fn key(k: u32) -> Key {
1150+
use blake2::{digest::typenum::U32, Blake2b, Digest};
11501151
let mut key = Key::default();
1151-
key.copy_from_slice(blake2_rfc::blake2b::blake2b(32, &[], &k.to_le_bytes()).as_bytes());
1152+
let hash = Blake2b::<U32>::digest(&k.to_le_bytes());
1153+
key.copy_from_slice(&hash);
11521154
key
11531155
}
11541156

0 commit comments

Comments
 (0)