ref: 011368e3394ba7691d7f4f9ca61bebf82d53ecfc
parent: 7680e160787aad4408be9535856f4c3a2ba72337
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Sep 30 09:57:21 EDT 2014
Fix tail packing on hashes.
--- a/libcryptohash/md5.myr
+++ b/libcryptohash/md5.myr
@@ -41,9 +41,12 @@
ntail = st.msglen % 64
st.msglen += data.len
if ntail > 0
- n = 64 - ntail
- std.slcp(st.tail[n:], data[:n])
+ n = std.min(64 - ntail, data.len)
+ std.slcp(st.tail[ntail:ntail + n], data[:n])
data = data[n:]
+ if n + ntail < 64
+ ->
+ ;;
step(st, st.tail[:])
;;
while data.len >= 64
@@ -50,8 +53,7 @@
step(st, data[:64])
data = data[64:]
;;
- ntail = st.msglen % 64
- std.slcp(st.tail[:ntail], data)
+ std.slcp(st.tail[:data.len], data)
}
const md5fin = {st
--- a/libcryptohash/sha1.myr
+++ b/libcryptohash/sha1.myr
@@ -42,9 +42,12 @@
ntail = st.msglen % 64
st.msglen += data.len
if ntail > 0
- n = 64 - ntail
- std.slcp(st.tail[n:], data[:n])
+ n = std.min(64 - ntail, data.len)
+ std.slcp(st.tail[ntail:ntail + n], data[:n])
data = data[n:]
+ if n + ntail < 64
+ ->
+ ;;
step(st, st.tail[:])
;;
@@ -53,8 +56,7 @@
data = data[64:]
;;
- ntail = st.msglen % 64
- std.slcp(st.tail[:ntail], data)
+ std.slcp(st.tail[:data.len], data)
}
const sha1fin = {st
--- a/libcryptohash/sha256.myr
+++ b/libcryptohash/sha256.myr
@@ -47,9 +47,12 @@
ntail = st.msglen % 64
st.msglen += data.len
if ntail > 0
- n = 64 - ntail
- std.slcp(st.tail[n:], data[:n])
+ n = std.min(64 - ntail, data.len)
+ std.slcp(st.tail[ntail:ntail + n], data[:n])
data = data[n:]
+ if n + ntail < 64
+ ->
+ ;;
step(st.x[:], st.tail[:])
;;
@@ -110,9 +113,12 @@
ntail = st.msglen % 64
st.msglen += data.len
if ntail > 0
- n = 64 - ntail
- std.slcp(st.tail[n:], data[:n])
+ n = std.min(64 - ntail, data.len)
+ std.slcp(st.tail[ntail:ntail + n], data[:n])
data = data[n:]
+ if n + ntail < 64
+ ->
+ ;;
step(st.x[:], st.tail[:])
;;
--- a/libcryptohash/sha512.myr
+++ b/libcryptohash/sha512.myr
@@ -53,9 +53,12 @@
ntail = st.msglen % 128
st.msglen += data.len
if ntail > 0
- n = 128 - ntail
- std.slcp(st.tail[n:], data[:n])
+ n = std.min(128 - ntail, data.len)
+ std.slcp(st.tail[ntail:ntail+n], data[:n])
data = data[n:]
+ if n + ntail < 128
+ ->
+ ;;
step(st.x[:], st.tail[:])
;;
@@ -110,9 +113,12 @@
ntail = st.msglen % 128
st.msglen += data.len
if ntail > 0
- n = 128 - ntail
- std.slcp(st.tail[n:], data[:n])
+ n = std.min(128 - ntail, data.len)
+ std.slcp(st.tail[ntail:ntail+n], data[:n])
data = data[n:]
+ if n + ntail < 128
+ ->
+ ;;
step(st.x[:], st.tail[:])
;;
binary files a/libcryptohash/test/printhash.use /dev/null differ