Factor handbook ยป Input and output

Prev:Formatted output
Next:ANSI C streams

A checksum is a function mapping sequences of bytes to fixed-length strings. While checksums are not one-to-one, a good checksum should have a low probability of collision. Additionally, some checksum algorithms are designed to be hard to reverse, in the sense that finding an input string which hashes to a given checksum string requires a brute-force search.

Checksums are instances of a class:

Operations on checksums:
checksum-bytes ( bytes checksum -- value )

checksum-stream ( stream checksum -- value )

checksum-lines ( lines checksum -- value )

checksum-file ( path checksum -- value )

Checksums should implement at least one of checksum-bytes and checksum-stream. Implementing checksum-lines is optional.

Checksums can also implement a stateful checksum protocol that allows users to push bytes when needed and then at a later point request the checksum value. The default implementation is not very efficient, storing all of the bytes and then calling checksum-bytes when get-checksum is requested.

initialize-checksum-state ( checksum -- checksum-state )

add-checksum-bytes ( checksum-state data -- checksum-state )

add-checksum-stream ( checksum-state stream -- checksum-state )

add-checksum-lines ( checksum-state lines -- checksum-state )

add-checksum-file ( checksum-state path -- checksum-state )

get-checksum ( checksum-state -- value )

Checksum implementations:
CRC32 checksum
MD5 checksum
SHA-2 checksum
Adler-32 checksum
OpenSSL checksums
Internet checksum
Checksumming with External Utilities