sh1 - SHA-1 module

Module Description

The sh1 module implements the SHA-1 algorithm.

Module Words

SHA-1 structure

sh1% ( -- n )
Get the required space for a sha1 variable

SHA-1 variable creation, initialisation and destruction

sh1-init ( sh1 -- )
Initialise the sh1

sh1-create ( "<spaces>name" -- ; -- sh1 )
Create a named sha-1 variable in the dictionary

sh1-new ( -- sh1 )
Create a new sha-1 variable on the heap

sh1-free ( sh1 -- )
Free the sha-1 variable from the heap

SHA-1 words

sh1-reset ( sh1 -- )
Reset the SHA-1 state

sh1-update ( c-addr u sh1 -- )
Update the SHA-1 with more data c-addr u

sh1-finish ( sh1 -- u1 u2 u3 u4 u5 )
Finish the SHA-1 calculation, return the sha values

sh1+to-string ( u1 u2 u3 u4 u5 -- c-addr u )
Convert SHA-1 result to the string c-addr u, using the pictured output area

Inspection

sh1-dump ( sh1 -- )
Dump the sh1 variable

Examples

include ffl/sh1.fs

\ Create a SHA-1 variable sh1 in the dictionary

sh1-create sh1

\ Update the variable with data

s" The quick brown fox jumps over the lazy dog" sh1 sh1-update

\ Finish the SHA-1 calculation resulting in 5 unsigned 32 bit words
\ on the stack representing the hash value

sh1 sh1-finish

\ Convert the hash value to a hex string and print

sh1+to-string type cr



\ Create a SHA-1 variable on the heap

sh1-new value sh2

\ Update the variable with multiple data

s" The quick brown fox " sh2 sh1-update
s" jumps over the lazy dog" sh2 sh1-update

\ Finish the calculation

sh2 sh1-finish

\ Convert the hash value to a hex string and print

sh1+to-string type cr

\ Free the variable from the heap

sh2 sh1-free

generated 10-Apr-2008 by ofcfrth-0.5.0