sh2 - SHA-256 module
Module Description
The sh2 module implements the SHA-256 algorithm.
Module Words
SHA-256 structure
- sh2% ( -- n )
- Get the required space for a sha2 variable
SHA-256 variable creation, initialisation and cleanup
- sh2-init ( sh2 -- )
- Initialise the sh2 variable
- sh2-create ( "<spaces>name" -- ; -- sh2 )
- Create a named SHA-256 variable in the dictionary
- sh2-new ( -- sh2 )
- Create a new SHA-256 variable on the heap
- sh2-free ( sh2 -- )
- Free the SHA-256 variable from the heap
SHA-256 words
- sh2-reset ( sh2 -- )
- Reset the SHA-256 state
- sh2-update ( c-addr u sh2 -- )
- Update the SHA-256 with more data c-addr u
- sh2-finish ( sh2 -- u1 u2 u3 u4 u5 u6 u7 u8 )
- Finish the SHA-256 calculation, return the result
- sh2+to-string ( u1 u2 u3 u4 u5 u6 u7 u8 -- c-addr u )
- Convert SHA-256 result to the string c-addr u, using the pictured output area
Inspection
- sh2-dump ( sh2 -- )
- Dump the sh2 variable
Examples
include ffl/sh2.fs
\ Create a SHA-256 variable sh1 in the dictionary
sh2-create sh1
\ Update the variable with data
s" The quick brown fox jumps over the lazy dog" sh1 sh2-update
\ Finish the SHA-256 calculation resulting in 8 unsigned 32 bit words
\ on the stack representing the hash value
sh1 sh2-finish
\ Convert the hash value to a hex string and print
sh2+to-string type cr
\ Create a SHA-256 variable on the heap
sh2-new value sh2
\ Update the variable with multiple data
s" The quick brown fox " sh2 sh2-update
s" jumps over the lazy dog" sh2 sh2-update
\ Finish the calculation
sh2 sh2-finish
\ Convert the hash value to a hex string and print
sh2+to-string type cr
\ Free the variable from the heap
sh2 sh2-free
generated 03-Jun-2010 by ofcfrth-0.10.0