Skip to content

Commit

Permalink
Change sector ID derivation to use hashing instead of XOR
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Aug 15, 2023
1 parent 34bf29d commit 44940ab
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions crates/subspace-core-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,14 +969,11 @@ impl AsRef<[u8]> for SectorId {

impl SectorId {
/// Create new sector ID by deriving it from public key and sector index
pub fn new(mut public_key_hash: Blake2b256Hash, sector_index: SectorIndex) -> Self {
public_key_hash
.iter_mut()
.zip(&sector_index.to_le_bytes())
.for_each(|(a, b)| {
*a ^= *b;
});
Self(public_key_hash)
pub fn new(public_key_hash: Blake2b256Hash, sector_index: SectorIndex) -> Self {
Self(blake2b_256_hash_with_key(
&public_key_hash,
&sector_index.to_le_bytes(),
))
}

/// Derive piece index that should be stored in sector at `piece_offset` for specified size of
Expand Down

0 comments on commit 44940ab

Please sign in to comment.