Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we're utilizing full SHA256 digests in our Address types #364

Closed
james-chf opened this issue Aug 21, 2022 · 0 comments · Fixed by #1510
Closed

Ensure we're utilizing full SHA256 digests in our Address types #364

james-chf opened this issue Aug 21, 2022 · 0 comments · Fixed by #1510

Comments

@james-chf
Copy link
Contributor

Currently we only use the first 40 bytes of the 64 byte hex encoding of the 32 byte SHA256 digest. We should instead use all of the digest i.e. the entire 32 bytes, not hex encoded.

e.g. when generating an EstablishedAddress

pub fn generate_address(
&mut self,
rng_source: impl AsRef<[u8]>,
) -> Address {
let gen_bytes = self
.try_to_vec()
.expect("Encoding established addresses generator shouldn't fail");
let mut hasher = Sha256::new();
let bytes = [&gen_bytes, rng_source.as_ref()].concat();
hasher.update(bytes);
// hex of the first 40 chars of the hash
let hash = format!("{:.width$X}", hasher.finalize(), width = HASH_LEN);
self.last_hash = hash.clone();
Address::Established(EstablishedAddress { hash })
}

Also see #112 for extra context

@james-chf james-chf changed the title Use the full SHA256 digest in our Address types Ensure we're utilizing the full SHA256 digest in our Address types Aug 21, 2022
@james-chf james-chf changed the title Ensure we're utilizing the full SHA256 digest in our Address types Ensure we're utilizing full SHA256 digests in our Address types Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants