diff options
author | Jesse Luehrs <doy@tozt.net> | 2015-05-13 19:01:04 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2015-05-13 19:01:04 -0400 |
commit | a8143dc0ec29bff92787be1abfa580109cca139c (patch) | |
tree | 9c94fbca3da9891af64b1b77c20baea8eab5996f | |
parent | 64819557db1955d3eaccf855e4b37d7dc08d94b4 (diff) | |
download | matasano-a8143dc0ec29bff92787be1abfa580109cca139c.tar.gz matasano-a8143dc0ec29bff92787be1abfa580109cca139c.zip |
this also needs to allow user-specified length
-rw-r--r-- | src/sha1.rs | 11 |
1 files 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<u8> { +pub fn pad_sha1 (bytes: &[u8], len: u64) -> Vec<u8> { 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<u8> { .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()) }; |