99 val (text_len, text) = padded_text str; |
99 val (text_len, text) = padded_text str; |
100 |
100 |
101 (*hash result -- 5 words*) |
101 (*hash result -- 5 words*) |
102 val hash_array : Word32.word Array.array = |
102 val hash_array : Word32.word Array.array = |
103 Array.fromList [0wx67452301, 0wxEFCDAB89, 0wx98BADCFE, 0wx10325476, 0wxC3D2E1F0]; |
103 Array.fromList [0wx67452301, 0wxEFCDAB89, 0wx98BADCFE, 0wx10325476, 0wxC3D2E1F0]; |
104 fun hash i = Array.sub (hash_array, i); |
104 val hash = Array.nth hash_array; |
105 fun add_hash x i = Array.update (hash_array, i, hash i + x); |
105 fun add_hash x i = Array.update (hash_array, i, hash i + x); |
106 |
106 |
107 (*current chunk -- 80 words*) |
107 (*current chunk -- 80 words*) |
108 val chunk_array = Array.array (80, 0w0: Word32.word); |
108 val chunk_array = Array.array (80, 0w0: Word32.word); |
109 fun chunk i = Array.sub (chunk_array, i); |
109 val chunk = Array.nth chunk_array; |
110 fun init_chunk pos = |
110 fun init_chunk pos = |
111 Array.modifyi (fn (i, _) => |
111 Array.modifyi (fn (i, _) => |
112 if i < 16 then text (pos + i) |
112 if i < 16 then text (pos + i) |
113 else rotate 0w1 (chunk (i - 3) xorb chunk (i - 8) xorb chunk (i - 14) xorb chunk (i - 16))) |
113 else rotate 0w1 (chunk (i - 3) xorb chunk (i - 8) xorb chunk (i - 14) xorb chunk (i - 16))) |
114 chunk_array; |
114 chunk_array; |