Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion program/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
//! [SHA-256]: https://en.wikipedia.org/wiki/SHA-2
//! [`Hash`]: struct@Hash

#[allow(deprecated)]
pub use solana_sha256_hasher::extend_and_hash;
#[cfg(not(target_os = "solana"))]
pub use solana_sha256_hasher::Hasher;
pub use {
solana_hash::{Hash, ParseHashError, HASH_BYTES},
solana_sha256_hasher::{extend_and_hash, hash, hashv},
solana_sha256_hasher::{hash, hashv},
};
1 change: 1 addition & 0 deletions sha256-hasher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub fn hash(val: &[u8]) -> Hash {
}

/// Return the hash of the given hash extended with the given value.
#[deprecated(since = "2.3.0", note = "Use `hashv(&[hash.as_ref(), val])` directly")]
pub fn extend_and_hash(id: &Hash, val: &[u8]) -> Hash {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to replace the implementation with hashv(&[id.as_ref(), &val]) given that it is what people should be doing directly?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. If there were more users of this function, we probably should. But in this case, I'm happier to limit the API surface 😅

let mut hash_data = id.as_ref().to_vec();
hash_data.extend_from_slice(val);
Expand Down
4 changes: 2 additions & 2 deletions shred-version/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! [shred]: https://solana.com/docs/terminology#shred

use {solana_hard_forks::HardForks, solana_hash::Hash, solana_sha256_hasher::extend_and_hash};
use {solana_hard_forks::HardForks, solana_hash::Hash, solana_sha256_hasher::hashv};

pub fn version_from_hash(hash: &Hash) -> u16 {
let hash = hash.as_ref();
Expand All @@ -27,7 +27,7 @@ pub fn compute_shred_version(genesis_hash: &Hash, hard_forks: Option<&HardForks>
if let Some(hard_forks) = hard_forks {
for &(slot, count) in hard_forks.iter() {
let buf = [slot.to_le_bytes(), (count as u64).to_le_bytes()].concat();
hash = extend_and_hash(&hash, &buf);
hash = hashv(&[hash.as_ref(), &buf]);
}
}

Expand Down
Loading