 
 INSTANCE: sha-256 checksum
 
+TUPLE: sha2-state K H word-size block-size ;
+
+TUPLE: sha-256-state < sha2-state ;
+
+: <sha-256-state> ( -- sha2-state )
+    sha-256-state new
+        K-256 >>K
+        initial-H-256 >>H
+        4 >>word-size
+        64 >>block-size ; 
+
 M: sha-256 checksum-bytes
-    drop [
-        initial-H-256 H set
-        4 word-size set
-        64 block-size set
+    drop
+    <sha-256-state> sha2 [
         byte-array>sha2
-
-    ] with-scope ;
+    ] with-variable ;


<PRIVATE

SYMBOLS: H word-size block-size ;

CONSTANT: a 0
CONSTANT: b 1

: T1 ( W n H -- T1 )
    [
        [ swap nth ] keep
        sha2 get K>> nth +
    ] dip
    [ e swap slice3 ch w+ ]
    [ e swap nth S1-256 w+ ]
