Skip to content

Commit

Permalink
Merge pull request #1818 from subspace/change-sector-id-derivation
Browse files Browse the repository at this point in the history
Change sector ID derivation to use hashing instead of XOR
  • Loading branch information
nazar-pc authored Aug 15, 2023
2 parents 9ffd8de + 44940ab commit 4000d82
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 4000d82

Please sign in to comment.