SHA2FINAL224, SHA2FINAL256, SHA2FINAL384, and SHA2FINAL512
Use a token initialized by the corresponding SHA2INIT function to complete a SHA-2 hash of a series of texts and return a CHAR string with that hash value.
- t
- A token returned by a previous invocation of SHA2INITx or SHA2UPDATEx.
- p
- A pointer that specifies the address of a buffer to be added to the hash.
- n
- An expression that specifies the length (in bytes) of that buffer. It must have a computational type and will be converted to type size_t.
The length returned is one eighth of the bit length in the function name, so, for example, SHA2FINAL256 returns a CHAR(32) value.
These functions generate code that executes the KIMD and KLMD assembler instructions.
Examples
The following example performs a 256-bit SHA-2 hash of a file that is read one line at a time into a CHARACTER variable c.
dcl token pointer;
dcl encoded char(32);
token = sha2init256();
on endfile(input);
do loop;
read file(input) into(c);
if endfile(input) then leave;
token = sha2update256(token, addrdata(c), length(c));
end;
encoded = sha2final256(token, sysnull(), 0);
In the example, all the SHA function calls are in the same block of code. This is not necessary: the calls can occur in a set of routines as long as they all use the same token created by the SHA2INIT call.