summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-30 13:57:21 -0400
committerOri Bernstein <ori@eigenstate.org>2015-08-24 22:10:06 -0700
commit011368e3394ba7691d7f4f9ca61bebf82d53ecfc (patch)
tree065e50764779ad248b1262be40d99183f274d910
parent7680e160787aad4408be9535856f4c3a2ba72337 (diff)
downloadmc-011368e3394ba7691d7f4f9ca61bebf82d53ecfc.tar.gz
Fix tail packing on hashes.
-rw-r--r--libcryptohash/md5.myr10
-rw-r--r--libcryptohash/sha1.myr10
-rw-r--r--libcryptohash/sha256.myr14
-rw-r--r--libcryptohash/sha512.myr14
-rw-r--r--libcryptohash/test/printhash.usebin94 -> 0 bytes
5 files changed, 32 insertions, 16 deletions
diff --git a/libcryptohash/md5.myr b/libcryptohash/md5.myr
index 414f336..5f4b600 100644
--- a/libcryptohash/md5.myr
+++ b/libcryptohash/md5.myr
@@ -41,17 +41,19 @@ const md5add = {st, data
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
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
diff --git a/libcryptohash/sha1.myr b/libcryptohash/sha1.myr
index 132ccd9..ecf0ec3 100644
--- a/libcryptohash/sha1.myr
+++ b/libcryptohash/sha1.myr
@@ -42,9 +42,12 @@ const sha1add = {st, data
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 @@ const sha1add = {st, data
data = data[64:]
;;
- ntail = st.msglen % 64
- std.slcp(st.tail[:ntail], data)
+ std.slcp(st.tail[:data.len], data)
}
const sha1fin = {st
diff --git a/libcryptohash/sha256.myr b/libcryptohash/sha256.myr
index 2f48119..5939fa8 100644
--- a/libcryptohash/sha256.myr
+++ b/libcryptohash/sha256.myr
@@ -47,9 +47,12 @@ const sha256add = {st, data
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 @@ const sha224add = {st, data
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[:])
;;
diff --git a/libcryptohash/sha512.myr b/libcryptohash/sha512.myr
index e287d4b..ceab5a5 100644
--- a/libcryptohash/sha512.myr
+++ b/libcryptohash/sha512.myr
@@ -53,9 +53,12 @@ const sha512add = {st, data
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 @@ const sha384add = {st, data
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[:])
;;
diff --git a/libcryptohash/test/printhash.use b/libcryptohash/test/printhash.use
deleted file mode 100644
index 0131d30..0000000
--- a/libcryptohash/test/printhash.use
+++ /dev/null
Binary files differ