! Copyright (C) 2006 Doug Coleman
! See http://factorcode.org/license.txt for BSD license.
-USING: checksums io.binary kernel math sequences
-sequences.private ;
+USING: checksums kernel math sequences sequences.private ;
IN: checksums.crc32
CONSTANT: crc32-polynomial 0xedb88320
: (crc32) ( crc ch -- crc )
dupd bitxor
- mask-byte crc32-table nth-unsafe
+ 0xff bitand crc32-table nth-unsafe
swap -8 shift bitxor ; inline
SINGLETON: crc32
: init-crc32 ( input checksum -- x y input )
drop [ 0xffffffff dup ] dip ; inline
+<PRIVATE
+: 4>be ( n -- byte-array ) ! duplicated from io.binary, but in core
+ { -24 -16 -8 0 } [ shift 0xff bitand ] with B{ } map-as ;
+PRIVATE>
+
: finish-crc32 ( x y -- bytes )
- bitxor 4 >be ; inline
+ bitxor 4>be ; inline
M: crc32 checksum-bytes
init-crc32