 
 : byte-array>sha2 ( byte-array -- string )
     pad-initial-bytes
-    block-size get <sliced-groups>
+    sha2 get block-size>> <sliced-groups>
     [
         prepare-message-schedule
-        block-size get H get clone process-chunk
+        sha2 get [ block-size>> ] [ H>> clone ] bi process-chunk
     ] each
-    H get 4 seq>byte-array ;
+    sha2 get H>> 4 seq>byte-array ;
 
 PRIVATE>
 

    [ [ bitand ] [ bitor ] 2bi ] dip bitand bitor ;

: prepare-message-schedule ( seq -- w-seq )
    word-size get <sliced-groups> [ be> ] map block-size get 0 pad-tail
    16 64 [a,b) over '[ _ process-M-256 ] each ;

: slice3 ( n seq -- a b c )


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
    <sha-256-state> sha2 [
        byte-array>sha2
    ] with-variable ;
