Replies: 3 comments 8 replies
-
/// A hashing engine which bytes can be serialized into.
pub trait HashEngine: Clone + Default {
/// The digest returned by this hash engine.
///
/// This is expected to be an array.
type Digest: Copy
+ Clone
+ PartialEq
+ Eq
+ PartialOrd
+ Ord
+ hash::Hash
+ borrow::Borrow<[u8]>;
/// Byte array representing the internal state of the hash engine.
type Midstate;
/// Length of the hash's internal block size, in bytes.
const BLOCK_SIZE: usize;
/// Creates a new hash engine.
fn new() -> Self { Default::default() }
/// Add data to the hash engine.
fn input(&mut self, data: &[u8]);
/// Return the number of bytes already n_bytes_hashed(inputted).
fn n_bytes_hashed(&self) -> usize;
/// Returns the final digest from the current state of the hash engine.
fn finalize(self) -> Self::Digest;
/// Creates a default hash engine, adds `bytes` to it, then finalizes the engine.
///
/// # Returns
///
/// The digest created by hashing `bytes` with engine's hashing algorithm.
fn hash(bytes: &[u8]) -> Self::Digest {
let mut engine = Self::new();
engine.input(bytes);
engine.finalize()
}
/// Hashes all the byte slices retrieved from the iterator together.
fn hash_byte_chunks<B, I>(byte_slices: I) -> Self::Digest
where
B: AsRef<[u8]>,
I: IntoIterator<Item = B>,
{
let mut engine = Self::new();
for slice in byte_slices {
engine.input(slice.as_ref());
}
engine.finalize()
}
/// Outputs the midstate of the hash engine. This function should not be
/// used directly unless you really know what you're doing.
fn midstate(&self) -> Self::Midstate;
/// Create a new [`HashEngine`] from a [`Self::Midstate`].
///
/// Only use this function if you know what you are doing.
fn from_midstate(midstate: Self::Midstate, length: usize) -> Self;
} |
Beta Was this translation helpful? Give feedback.
-
Well, the dependency hole just goes away because you've moved the crate out of this repo :).
I'd have to see this. I'm unconvinced that hash display logic actually belongs in rust-bitcoin and not in the hashing crate, for example. I also don't see anything about tagged hashes in chf, and those are definitely not bitcoin-specific. Once you return those, I'm not sure how different the result would be from bitcoin-hashes?
Well, the |
Beta Was this translation helpful? Give feedback.
-
Just one small note :) |
Beta Was this translation helpful? Give feedback.
-
I have an idea/plan about
hashes
.I've pulled out the cryptographic hash functions from
bitcoin_hashes
(i,e., none of the Bitcoin specific stuff) and released a new crate rust-chf.If this idea gets traction I'd like to move that crate to the
rust-bitcoin
org.In
rust-chf
I've removed theHash
trait and hacked theHashEngine
trait, posted below.What this buys us is:
rust-bitcoin
where it should be (e.g., display backwards logic)We can then:
rust-chf
inrust-secp256k1
(no more dependency hole, ya!)rust-chf
inbitcoin_hashes
I've proofed it all out locally and it seems to work.
Beta Was this translation helpful? Give feedback.
All reactions