Replace 'blake2-rfc' with rust-crypto 'blake2' crate (#12266)

* Replace 'blake2-rfc with rust-crypto 'blake2' crate
* Bump blake2 to 0.10.4
This commit is contained in:
Davide Galassi
2022-09-15 17:12:55 +02:00
committed by GitHub
parent bba345f8ed
commit a4ebb6d31c
5 changed files with 34 additions and 18 deletions
+3 -3
View File
@@ -593,9 +593,9 @@ dependencies = [
[[package]]
name = "blake2"
version = "0.10.2"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b94ba84325db59637ffc528bbe8c7f86c02c57cff5c0e2b9b00f9a851f42f309"
checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388"
dependencies = [
"digest 0.10.3",
]
@@ -9751,7 +9751,7 @@ version = "6.0.0"
dependencies = [
"base58",
"bitflags",
"blake2-rfc",
"blake2",
"byteorder",
"criterion",
"dyn-clonable",
@@ -19,7 +19,7 @@ proc-macro = true
quote = "1.0.10"
syn = { version = "1.0.98", features = ["full", "fold", "extra-traits", "visit"] }
proc-macro2 = "1.0.37"
blake2 = { version = "0.10.2", default-features = false }
blake2 = { version = "0.10.4", default-features = false }
proc-macro-crate = "1.1.3"
# Required for the doc tests
+3 -3
View File
@@ -48,7 +48,7 @@ bitflags = "1.3"
# full crypto
ed25519-zebra = { version = "3.0.0", default-features = false, optional = true}
blake2-rfc = { version = "0.2.18", default-features = false, optional = true }
blake2 = { version = "0.10.4", default-features = false, optional = true }
schnorrkel = { version = "0.9.1", features = [
"preaudit_deprecated",
"u64_backend",
@@ -98,7 +98,7 @@ std = [
"hash-db/std",
"sp-std/std",
"serde",
"blake2-rfc/std",
"blake2/std",
"ed25519-zebra",
"hex/std",
"base58",
@@ -130,7 +130,7 @@ std = [
# For the regular wasm runtime builds this should not be used.
full_crypto = [
"ed25519-zebra",
"blake2-rfc",
"blake2",
"schnorrkel",
"hex",
"libsecp256k1",
+1 -1
View File
@@ -13,7 +13,7 @@ documentation = "https://docs.rs/sp-core-hashing"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
blake2 = { version = "0.10.2", default-features = false }
blake2 = { version = "0.10.4", default-features = false }
byteorder = { version = "1.3.2", default-features = false }
digest = { version = "0.10.3", default-features = false }
sha2 = { version = "0.10.2", default-features = false }
+26 -10
View File
@@ -132,9 +132,7 @@ impl DeriveJunction {
let mut cc: [u8; JUNCTION_ID_LEN] = Default::default();
index.using_encoded(|data| {
if data.len() > JUNCTION_ID_LEN {
let hash_result = blake2_rfc::blake2b::blake2b(JUNCTION_ID_LEN, &[], data);
let hash = hash_result.as_bytes();
cc.copy_from_slice(hash);
cc.copy_from_slice(&sp_core_hashing::blake2_256(data));
} else {
cc[0..data.len()].copy_from_slice(data);
}
@@ -292,7 +290,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + ByteArray {
}
let hash = ss58hash(&data[0..body_len + prefix_len]);
let checksum = &hash.as_bytes()[0..CHECKSUM_LEN];
let checksum = &hash[0..CHECKSUM_LEN];
if data[body_len + prefix_len..body_len + prefix_len + CHECKSUM_LEN] != *checksum {
// Invalid checksum.
return Err(PublicError::InvalidChecksum)
@@ -333,7 +331,7 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + ByteArray {
};
v.extend(self.as_ref());
let r = ss58hash(&v);
v.extend(&r.as_bytes()[0..2]);
v.extend(&r[0..2]);
v.to_base58()
}
@@ -366,11 +364,13 @@ pub trait Derive: Sized {
const PREFIX: &[u8] = b"SS58PRE";
#[cfg(feature = "std")]
fn ss58hash(data: &[u8]) -> blake2_rfc::blake2b::Blake2bResult {
let mut context = blake2_rfc::blake2b::Blake2b::new(64);
context.update(PREFIX);
context.update(data);
context.finalize()
fn ss58hash(data: &[u8]) -> Vec<u8> {
use blake2::{Blake2b512, Digest};
let mut ctx = Blake2b512::new();
ctx.update(PREFIX);
ctx.update(data);
ctx.finalize().to_vec()
}
/// Default prefix number
@@ -1311,6 +1311,14 @@ mod tests {
path: vec![DeriveJunction::soft("DOT")]
})
);
assert_eq!(
TestPair::from_string("hello world/0123456789012345678901234567890123456789", None),
Ok(TestPair::Standard {
phrase: "hello world".to_owned(),
password: None,
path: vec![DeriveJunction::soft("0123456789012345678901234567890123456789")]
})
);
assert_eq!(
TestPair::from_string("hello world//1", None),
Ok(TestPair::Standard {
@@ -1327,6 +1335,14 @@ mod tests {
path: vec![DeriveJunction::hard("DOT")]
})
);
assert_eq!(
TestPair::from_string("hello world//0123456789012345678901234567890123456789", None),
Ok(TestPair::Standard {
phrase: "hello world".to_owned(),
password: None,
path: vec![DeriveJunction::hard("0123456789012345678901234567890123456789")]
})
);
assert_eq!(
TestPair::from_string("hello world//1/DOT", None),
Ok(TestPair::Standard {