summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-06-03 22:34:51 -0400
committerOri Bernstein <ori@eigenstate.org>2015-08-24 22:10:06 -0700
commitd7340a02cef50b6f3ae1344b71a6f78922002652 (patch)
treee900fb31c44e2705e472347c4d06cbb0dc86689a
parent515b8e89c1a6c0859eaefbf7835a4e6497a57e0b (diff)
downloadmc-d7340a02cef50b6f3ae1344b71a6f78922002652.tar.gz
Add support for sha384.
-rw-r--r--libcryptohash/sha512.myr67
-rw-r--r--libcryptohash/test/data/sha384-test-expected4
-rw-r--r--libcryptohash/test/tests1
3 files changed, 72 insertions, 0 deletions
diff --git a/libcryptohash/sha512.myr b/libcryptohash/sha512.myr
index 3b7b02f..e287d4b 100644
--- a/libcryptohash/sha512.myr
+++ b/libcryptohash/sha512.myr
@@ -7,6 +7,11 @@ pkg cryptohash =
const sha512init : (st : sha512# -> void)
const sha512add : (st : sha512#, data : byte[:] -> void)
const sha512fin : (st : sha512# -> byte[64])
+
+ const sha384 : (data : byte[:] -> byte[48])
+ const sha384init : (st : sha384# -> void)
+ const sha384add : (st : sha384#, data : byte[:] -> void)
+ const sha384fin : (st : sha384# -> byte[48])
;;
@@ -16,6 +21,12 @@ type sha512 = struct
msglen : uint64
;;
+type sha384 = struct
+ x : uint64[8]
+ tail : byte[128]
+ msglen : uint64
+;;
+
const sha512 = {data
var st
@@ -73,6 +84,62 @@ const sha512fin = {st
-> r
}
+const sha384 = {data
+ var st
+
+ sha384init(&st)
+ sha384add(&st, data)
+ -> sha384fin(&st)
+}
+
+const sha384init = {st
+ st.x[0] = 0xCBBB9D5DC1059ED8ul
+ st.x[1] = 0x629A292A367CD507ul
+ st.x[2] = 0x9159015A3070DD17ul
+ st.x[3] = 0x152FECD8F70E5939ul
+ st.x[4] = 0x67332667FFC00B31ul
+ st.x[5] = 0x8EB44A8768581511ul
+ st.x[6] = 0xDB0C2E0D64F98FA7ul
+ st.x[7] = 0x47B5481DBEFA4FA4ul
+ st.msglen = 0
+}
+
+const sha384add = {st, data
+ var n, ntail
+
+ ntail = st.msglen % 128
+ st.msglen += data.len
+ if ntail > 0
+ n = 128 - ntail
+ std.slcp(st.tail[n:], data[:n])
+ data = data[n:]
+ step(st.x[:], st.tail[:])
+ ;;
+
+ while data.len >= 128
+ step(st.x[:], data[:128])
+ data = data[128:]
+ ;;
+
+ ntail = st.msglen % 128
+ std.slcp(st.tail[:ntail], data)
+}
+
+const sha384fin = {st
+ var r : byte[48]
+
+ tail(st.x[:], st.msglen, st.tail[:])
+
+ pack(r[ 0: 8], st.x[0])
+ pack(r[ 8:16], st.x[1])
+ pack(r[16:24], st.x[2])
+ pack(r[24:32], st.x[3])
+ pack(r[32:40], st.x[4])
+ pack(r[40:48], st.x[5])
+ -> r
+}
+
+
const tail = {x, msglen, tail
var ntail
diff --git a/libcryptohash/test/data/sha384-test-expected b/libcryptohash/test/data/sha384-test-expected
new file mode 100644
index 0000000..dbe951a
--- /dev/null
+++ b/libcryptohash/test/data/sha384-test-expected
@@ -0,0 +1,4 @@
+38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
+a4eb0778c79fce94c02126543cba398d645b2fd4c6ff6a02eecc026bbe0cc0dd666279722b7615bc15b4c9126b941c04
+2e404b9339da795776e510d96930b3be2904c500395b8cb7413334b82d4dec413b4b8113045a05bbbcff846f027423f6
+f8f4b55a0fb1ac8506d2e5195c714a1ad16c3bf61ad8b2d544344b105a49a77ff3b8eb61e8f970a71864e9dad87042b1
diff --git a/libcryptohash/test/tests b/libcryptohash/test/tests
index b2b7c72..4717565 100644
--- a/libcryptohash/test/tests
+++ b/libcryptohash/test/tests
@@ -25,3 +25,4 @@ B sha1-test C
B sha256-test C
B sha224-test C
B sha512-test C
+B sha384-test C