]> gitweb.factorcode.org Git - factor.git/blob - basis/checksums/common/common.factor
Merge commit 'origin/master'
[factor.git] / basis / checksums / common / common.factor
1 ! Copyright (C) 2006, 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.bitwise strings io.binary namespaces
4 make grouping byte-arrays ;
5 IN: checksums.common
6
7 SYMBOL: bytes-read
8
9 : calculate-pad-length ( length -- length' )
10     [ 56 < 55 119 ? ] keep - ;
11
12 : pad-last-block ( str big-endian? length -- str )
13     [
14         [ % ] 2dip HEX: 80 ,
15         [ HEX: 3f bitand calculate-pad-length <byte-array> % ]
16         [ 3 shift 8 rot [ >be ] [ >le ] if % ] bi
17     ] B{ } make 64 group ;
18
19 : update-old-new ( old new -- )
20     [ [ get ] bi@ w+ dup ] 2keep [ set ] bi@ ; inline