You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.7 KiB
86 lines
2.7 KiB
From d24f26b1650156b1da4fced389559cee17805910 Mon Sep 17 00:00:00 2001
|
|
From: Artyom Pavlov <newpavlov@gmail.com>
|
|
Date: Wed, 10 Jun 2020 20:11:36 +0300
|
|
Subject: [PATCH] Update block-buffer to v0.9 (#164)
|
|
|
|
---
|
|
src/lib.rs | 15 +++++++--------
|
|
src/utils.rs | 7 ++++---
|
|
2 files changed, 11 insertions(+), 11 deletions(-)
|
|
|
|
diff --git a/src/lib.rs b/src/lib.rs
|
|
index fce2081..3a02898 100644
|
|
--- a/src/lib.rs
|
|
+++ b/src/lib.rs
|
|
@@ -44,7 +44,6 @@ pub use digest::{self, Digest};
|
|
|
|
use crate::utils::compress;
|
|
|
|
-use block_buffer::byteorder::{ByteOrder, LE};
|
|
use block_buffer::BlockBuffer;
|
|
use digest::generic_array::typenum::{U16, U64};
|
|
use digest::generic_array::GenericArray;
|
|
@@ -82,10 +81,9 @@ fn convert(d: &GenericArray<u8, U64>) -> &[u8; 64] {
|
|
impl Md5 {
|
|
#[inline]
|
|
fn finalize_inner(&mut self) {
|
|
- let state = &mut self.state;
|
|
+ let s = &mut self.state;
|
|
let l = (self.length_bytes << 3) as u64;
|
|
- self.buffer
|
|
- .len64_padding::<LE, _>(l, |d| compress(state, convert(d)));
|
|
+ self.buffer.len64_padding_le(l, |d| compress(s, convert(d)));
|
|
}
|
|
}
|
|
|
|
@@ -100,9 +98,8 @@ impl Update for Md5 {
|
|
// Unlike Sha1 and Sha2, the length value in MD5 is defined as
|
|
// the length of the message mod 2^64 - ie: integer overflow is OK.
|
|
self.length_bytes = self.length_bytes.wrapping_add(input.len() as u64);
|
|
- let self_state = &mut self.state;
|
|
- self.buffer
|
|
- .input(input, |d| compress(self_state, convert(d)));
|
|
+ let s = &mut self.state;
|
|
+ self.buffer.input_block(input, |d| compress(s, convert(d)));
|
|
}
|
|
}
|
|
|
|
@@ -112,7 +109,9 @@ impl FixedOutputDirty for Md5 {
|
|
#[inline]
|
|
fn finalize_into_dirty(&mut self, out: &mut GenericArray<u8, U16>) {
|
|
self.finalize_inner();
|
|
- LE::write_u32_into(&self.state, out);
|
|
+ for (chunk, v) in out.chunks_exact_mut(4).zip(self.state.iter()) {
|
|
+ chunk.copy_from_slice(&v.to_le_bytes());
|
|
+ }
|
|
}
|
|
}
|
|
|
|
diff --git a/src/utils.rs b/src/utils.rs
|
|
index 8a946e7..9cd0259 100644
|
|
--- a/src/utils.rs
|
|
+++ b/src/utils.rs
|
|
@@ -1,7 +1,6 @@
|
|
#![allow(clippy::many_single_char_names)]
|
|
-
|
|
use crate::consts::RC;
|
|
-use block_buffer::byteorder::{ByteOrder, LE};
|
|
+use core::convert::TryInto;
|
|
|
|
#[inline(always)]
|
|
fn op_f(w: u32, x: u32, y: u32, z: u32, m: u32, c: u32, s: u32) -> u32 {
|
|
@@ -50,7 +49,9 @@ pub fn compress(state: &mut [u32; 4], input: &[u8; 64]) {
|
|
let mut d = state[3];
|
|
|
|
let mut data = [0u32; 16];
|
|
- LE::read_u32_into(input, &mut data);
|
|
+ for (o, chunk) in data.iter_mut().zip(input.chunks_exact(4)) {
|
|
+ *o = u32::from_le_bytes(chunk.try_into().unwrap());
|
|
+ }
|
|
|
|
// round 1
|
|
a = op_f(a, b, c, d, data[0], RC[0], 7);
|
|
--
|
|
2.27.0
|
|
|