From a8143dc0ec29bff92787be1abfa580109cca139c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 13 May 2015 19:01:04 -0400 Subject: this also needs to allow user-specified length --- src/sha1.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sha1.rs b/src/sha1.rs index e2c86b1..24186ea 100644 --- a/src/sha1.rs +++ b/src/sha1.rs @@ -9,15 +9,16 @@ pub fn sha1 (bytes: &[u8]) -> [u8; 20] { 0x98BADCFE, 0x10325476, 0xC3D2E1F0, - ] + ], + bytes.len() as u64 ) } -pub fn pad_sha1 (bytes: &[u8]) -> Vec { +pub fn pad_sha1 (bytes: &[u8], len: u64) -> Vec { return bytes .iter() .map(|x| *x) - .chain(sha1_padding(bytes.len() as u64)) + .chain(sha1_padding(len)) .collect(); } @@ -34,8 +35,8 @@ pub fn sha1_padding (len: u64) -> Vec { .collect(); } -pub fn sha1_with_state (bytes: &[u8], mut h: [u32; 5]) -> [u8; 20] { - for chunk in pad_sha1(bytes).chunks(64) { +pub fn sha1_with_state (bytes: &[u8], mut h: [u32; 5], len: u64) -> [u8; 20] { + for chunk in pad_sha1(bytes, len).chunks(64) { let chunk_words: &[u32; 16] = unsafe { ::std::mem::transmute(chunk.as_ptr()) }; -- cgit v1.2.3-54-g00ecf