rust-bitcoin-unsafe-fast/hashes/src
Tobin C. Harding dcb18bfa7a
Add length to sha256::Midstate
In a `HashEngine` the `length` field represents number of bytes
input into the hash engine.

Note also:

> the midstate bytes are only updated when the compression function is
run, which only happens every 64 bytes.

Currently our midstate API allows extracting the midstate after any
amount of input bytes, this is probably not what users want.

Note also that most users should not be using the midstate API anyways.

With all this in mind, add a private `length` field to the `Midstate`
struct and enforce an invariant that it is modulo 64.

Add a single const `Midstate` constructor that panics if the invariant
is violated. The `Midstate` is niche enough that panic is acceptable.

Remove the `from_slice`, `from_byte_array`, and `to_byte_array`
functions because they no longer make sense. Keep `AsRef<[u8]>` for
cheap access to the midstate's inner byte slice.

Note change to `Debug`: `bytes` field now does not include the `0x`
prefix because `as_hex` because of the use of `debug_struct`.

Enjoy nice warm fuzzy feeling from hacking on crypto code.
2024-07-18 06:16:45 +10:00
..
cmp.rs hashes: Introduce SPDX license identifiers 2023-05-01 09:26:36 +10:00
hash160.rs Remove midstate from the GeneralHash and HashEngine traits 2024-07-13 07:59:33 +10:00
hkdf.rs 2024-07-07 automated rustfmt nightly 2024-07-07 01:10:59 +00:00
hmac.rs Remove midstate from the GeneralHash and HashEngine traits 2024-07-13 07:59:33 +10:00
impls.rs hashes: Strongly type the hash160::HashEngine 2024-07-09 13:30:20 +10:00
internal_macros.rs hashes: Use $crate in macro 2024-07-12 12:55:22 +10:00
lib.rs Merge rust-bitcoin/rust-bitcoin#2981: Remove to/from/as_raw_hash functions 2024-07-15 13:53:37 +00:00
ripemd160.rs Remove midstate from the GeneralHash and HashEngine traits 2024-07-13 07:59:33 +10:00
serde_macros.rs Removed //! spare line at end of headers 2024-05-22 12:00:25 +01:00
sha1.rs Remove midstate from the GeneralHash and HashEngine traits 2024-07-13 07:59:33 +10:00
sha256.rs Add length to sha256::Midstate 2024-07-18 06:16:45 +10:00
sha256d.rs Remove midstate from the GeneralHash and HashEngine traits 2024-07-13 07:59:33 +10:00
sha256t.rs Add length to sha256::Midstate 2024-07-18 06:16:45 +10:00
sha384.rs Remove midstate from the GeneralHash and HashEngine traits 2024-07-13 07:59:33 +10:00
sha512.rs Remove midstate from the GeneralHash and HashEngine traits 2024-07-13 07:59:33 +10:00
sha512_256.rs Remove midstate from the GeneralHash and HashEngine traits 2024-07-13 07:59:33 +10:00
siphash24.rs Remove midstate from the GeneralHash and HashEngine traits 2024-07-13 07:59:33 +10:00
util.rs Merge rust-bitcoin/rust-bitcoin#3019: Fix error messages 2024-07-16 15:30:26 +00:00