assets: use blake3 instead of md5 (#10208)
# Objective - Replace md5 by another hasher, as suggested in https://github.com/bevyengine/bevy/pull/8624#discussion_r1359291028 - md5 is not secure, and is slow. use something more secure and faster ## Solution - Replace md5 by blake3 Putting this PR in the 0.12 as once it's released, changing the hash algorithm will be a painful breaking change
This commit is contained in:
parent
e59085a67f
commit
d938275b9c
@ -33,7 +33,7 @@ crossbeam-channel = "0.5"
|
|||||||
downcast-rs = "1.2"
|
downcast-rs = "1.2"
|
||||||
futures-io = "0.3"
|
futures-io = "0.3"
|
||||||
futures-lite = "1.12"
|
futures-lite = "1.12"
|
||||||
md5 = "0.7"
|
blake3 = "1.5"
|
||||||
parking_lot = { version = "0.12", features = ["arc_lock", "send_guard"] }
|
parking_lot = { version = "0.12", features = ["arc_lock", "send_guard"] }
|
||||||
ron = "0.8"
|
ron = "0.8"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
|||||||
@ -225,15 +225,14 @@ pub(crate) fn loader_settings_meta_transform<S: Settings>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type AssetHash = [u8; 16];
|
pub type AssetHash = [u8; 32];
|
||||||
|
|
||||||
/// NOTE: changing the hashing logic here is a _breaking change_ that requires a [`META_FORMAT_VERSION`] bump.
|
/// NOTE: changing the hashing logic here is a _breaking change_ that requires a [`META_FORMAT_VERSION`] bump.
|
||||||
pub(crate) fn get_asset_hash(meta_bytes: &[u8], asset_bytes: &[u8]) -> AssetHash {
|
pub(crate) fn get_asset_hash(meta_bytes: &[u8], asset_bytes: &[u8]) -> AssetHash {
|
||||||
let mut context = md5::Context::new();
|
let mut hasher = blake3::Hasher::new();
|
||||||
context.consume(meta_bytes);
|
hasher.update(meta_bytes);
|
||||||
context.consume(asset_bytes);
|
hasher.update(asset_bytes);
|
||||||
let digest = context.compute();
|
*hasher.finalize().as_bytes()
|
||||||
digest.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// NOTE: changing the hashing logic here is a _breaking change_ that requires a [`META_FORMAT_VERSION`] bump.
|
/// NOTE: changing the hashing logic here is a _breaking change_ that requires a [`META_FORMAT_VERSION`] bump.
|
||||||
@ -241,11 +240,10 @@ pub(crate) fn get_full_asset_hash(
|
|||||||
asset_hash: AssetHash,
|
asset_hash: AssetHash,
|
||||||
dependency_hashes: impl Iterator<Item = AssetHash>,
|
dependency_hashes: impl Iterator<Item = AssetHash>,
|
||||||
) -> AssetHash {
|
) -> AssetHash {
|
||||||
let mut context = md5::Context::new();
|
let mut hasher = blake3::Hasher::new();
|
||||||
context.consume(asset_hash);
|
hasher.update(&asset_hash);
|
||||||
for hash in dependency_hashes {
|
for hash in dependency_hashes {
|
||||||
context.consume(hash);
|
hasher.update(&hash);
|
||||||
}
|
}
|
||||||
let digest = context.compute();
|
*hasher.finalize().as_bytes()
|
||||||
digest.0
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user