Skip to content

Commit

Permalink
refactor: backport to 0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Mar 13, 2024
1 parent 6a0da53 commit 417110e
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 39 deletions.
120 changes: 92 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions sha1-checked/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sha1-checked"
version = "0.11.0"
version = "0.10.0"
description = "SHA-1 hash function with collision detection"
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
Expand All @@ -13,18 +13,18 @@ categories = ["cryptography", "no-std"]
rust-version = "1.72"

[dependencies]
digest = "=0.11.0-pre.8"
sha1 = { version = "=0.11.0-pre.3", default-features = false, path = "../sha1" }
digest = "0.10.7"
sha1 = { version = "0.10.6", default-features = false, features = ["compress"] }

[dev-dependencies]
digest = { version = "=0.11.0-pre.8", features = ["dev"] }
digest = { version = "0.10.7", features = ["dev"] }
hex-literal = "0.4"

[features]
default = ["oid", "std"]
std = ["digest/std", "sha1/std"]
oid = ["digest/oid", "sha1/oid"] # Enable OID support
zeroize = ["digest/zeroize", "sha1/zeroize"]
zeroize = []


[package.metadata.docs.rs]
Expand Down
9 changes: 5 additions & 4 deletions sha1-checked/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extern crate std;
#[cfg(feature = "zeroize")]
use digest::zeroize::{Zeroize, ZeroizeOnDrop};
use digest::{
array::Array,
block_buffer::{BlockBuffer, Eager},
core_api::BlockSizeUser,
typenum::{Unsigned, U20, U64},
Expand Down Expand Up @@ -115,7 +114,7 @@ impl Sha1 {
compress::finalize(h, bs * self.block_len, last_block, ctx);
} else {
let bit_len = 8 * (buffer.get_pos() as u64 + bs * self.block_len);
buffer.len64_padding_be(bit_len, |b| sha1::compress(h, from_ref(&b.0)));
buffer.len64_padding_be(bit_len, |b| sha1::compress(h, from_ref(b)));
}

for (chunk, v) in out.chunks_exact_mut(4).zip(h.iter()) {
Expand Down Expand Up @@ -181,9 +180,11 @@ impl Update for Sha1 {
} = self;
buffer.digest_blocks(input, |blocks| {
self.block_len += blocks.len() as u64;
let blocks = Array::cast_slice_to_core(blocks);

if let Some(ref mut ctx) = detection {
// SAFETY: GenericArray<u8, U64> and [u8; 64] have
// exactly the same memory layout
let blocks: &[[u8; BLOCK_SIZE]] =
unsafe { &*(blocks as *const _ as *const [[u8; BLOCK_SIZE]]) };
compress::compress(h, ctx, blocks);
} else {
sha1::compress(h, blocks);
Expand Down
Loading

0 comments on commit 417110e

Please sign in to comment.